Skip to content

Conversation

@jakebailey
Copy link
Member

@jakebailey jakebailey commented Oct 28, 2025

Various things I noticed while looking at #1963

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the shouldEmitImportEqualsDeclaration function to match the TypeScript reference implementation. The original ported version had different conditional logic that caused import equals declarations to be omitted in certain scenarios, leading to numerous emit differences in test baselines.

Key Changes

  • Simplified the conditional logic in shouldEmitImportEqualsDeclaration to correctly emit import declarations in non-external modules
  • Fixed the logic to use OR instead of AND for the conditions, matching TypeScript's behavior

Reviewed Changes

Copilot reviewed 82 out of 83 changed files in this pull request and generated 1 comment.

File Description
internal/transformers/tstransforms/importelision.go Corrected the shouldEmitImportEqualsDeclaration function logic to match TypeScript's reference implementation
Multiple baseline .diff files Test baseline differences removed as the port now converges with stable TypeScript behavior
Multiple baseline reference files Updated baselines showing correct emission of import equals declarations

@jakebailey jakebailey changed the title Fix shouldEmitImportEqualsDeclaration Fix import declaration assignment emit Oct 28, 2025
@jakebailey jakebailey marked this pull request as draft October 28, 2025 03:13
-exports.a = x.c;
-module.exports = x;
+Object.defineProperty(exports, "__esModule", { value: true });
+Object.defineProperty(exports, "__esModule", { value: true });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    module x {
        interface c {
        }
    }
    export import a = x.c;
                      ~
!!! error TS2708: Cannot use namespace 'x' as a value.
                        ~
!!! error TS2694: Namespace 'x' has no exported member 'c'.
    export = x;
    ~~~~~~~~~~~
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.

Hard to feel bad about breaking this one though...

@jakebailey jakebailey force-pushed the jabaile/fix-shouldEmitImportEqualsDeclaration branch from 3715a7a to 6157576 Compare October 28, 2025 16:13
@jakebailey jakebailey changed the title Fix import declaration assignment emit Fix various module emit differences Oct 28, 2025
@jakebailey jakebailey force-pushed the jabaile/fix-shouldEmitImportEqualsDeclaration branch from 6157576 to 982e906 Compare October 28, 2025 16:21
@jakebailey jakebailey marked this pull request as ready for review October 28, 2025 16:23
Comment on lines +797 to +801
if (symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsClass|ast.SymbolFlagsRegularEnum) == 0) &&
state == ast.ModuleInstanceStateConstEnumOnly &&
symbol.Flags&ast.SymbolFlagsConstEnumOnlyModule == 0 {
symbol.Flags |= ast.SymbolFlagsConstEnumOnlyModule
} else {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old compiler used a boolean | undefined on every symbol for this. Corsa uses a flag but didn't make the behavior match the tristate. Doing this instead to avoid adding a Tristate to all symbols.

v.Name().Clone(tx.Factory()),
))
} else if ast.IsIdentifier(v.Name()) {
expression := tx.transformInitializedVariable(v)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old compiler had this func instead which did something special with exports, unlike ConvertVariableDeclarationToAssignmentExpression which is new. Not extremely familiar, though.

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.

2 participants