Skip to content

Elide bare side-effect imports in JS declaration emit#3624

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-export-reordering-issue
Draft

Elide bare side-effect imports in JS declaration emit#3624
Copilot wants to merge 2 commits intomainfrom
copilot/fix-export-reordering-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

The declaration transformer was preserving bare side-effect imports (e.g. import "fs";) in .d.ts output for JS source files. Strada's JS declaration path synthesizes declarations symbolically via resolver.getDeclarationStatementsForSourceFile and therefore never emits these — per the issue discussion, the agreed behavior is to keep eliding them so side-effect imports remain scoped to runtime emit only.

Changes

  • internal/transformers/declarations/transform.go — In transformImportDeclaration, return nil for ImportClause == nil when the current source file is JS:

    if decl.ImportClause == nil {
        // import "mod" - possibly needed for side effects in TS files...
        if tx.state.currentSourceFile != nil && tx.state.currentSourceFile.IsJS() {
            return nil
        }
        return tx.Factory().UpdateImportDeclaration(...)
    }

    TS source files retain the existing behavior of preserving bare side-effect imports.

  • Baselines — Updated to reflect the elision and converge with Strada:

    • nodeModulesAllowJsExportAssignment (module=node16/18/20/nodenext): file.d.ts now emits export {}; (synthesized for moduleness) instead of import "fs";.
    • jsDeclarationsExportForms / jsDeclarationsExportFormsErr (target=es2015): bare import "./xxx" lines removed from aggregating JS files.

The export = a reordering noted in the issue was already produced by current emit and is acknowledged in the thread as preferable (closer to original source); only the .js baselines needed refreshing for it.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/4e98096b-8f7e-4e0f-8c5e-7aeca971e2d2

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix baselines export reordering and ESM side-effect import Elide bare side-effect imports in JS declaration emit Apr 27, 2026
Copilot AI requested a review from RyanCavanaugh April 27, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Baselines: export = a reordered; ESM side-effect import replaces export {}

2 participants