-
Notifications
You must be signed in to change notification settings - Fork 733
Revert PR 2044 #2062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert PR 2044 #2062
Conversation
There was a problem hiding this 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 reverts PR 2044 and replaces it with a more targeted fix by removing an overly broad check for reparsed nodes in external module indicator detection. The change allows reparsed nodes (those synthesized during parsing) to be properly recognized as external module indicators, which improves CommonJS/ES module handling and type inference.
Key Changes
- Removed the
NodeFlagsReparsedcheck fromisAnExternalModuleIndicatorNode()function - Updated 60+ test baselines showing improved compiler behavior and convergence with TypeScript reference implementation
Reviewed Changes
Copilot reviewed 82 out of 82 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
internal/ast/parseoptions.go |
Removed overly restrictive check that prevented reparsed nodes from being external module indicators |
Test baseline files (.types, .symbols, .errors.txt, .js) |
Updated to reflect improved module detection, better type inference, and proper ES module marker emission |
Test diff files (.diff) |
Many show reduction or elimination of differences from TypeScript reference behavior |
|
Going to wait on the other PR since this exposes more problems that would have to be fixed... I am not super content with reverting it |
|
Updated; there are still many regressions by removing this. |
|
What is the pattern to the regressions you're seeing? I'm still surprised we'd consider excluding reparsed nodes from module determination, just seems wrong to do so. |
|
I don't see why we would include them; the old algorithm did not walk into JSDoc nodes, and any other new stuff we stick in the tree to handle expandos or CJS exports and whatnot were not there either, right? If the PR is filtered to diffs, you can see what's regressing: https://github.com/microsoft/typescript-go/pull/2062/files?file-filters%5B%5D=.go&file-filters%5B%5D=.diff I can annotate the PR with a few examples. |
|
To be clear, I agree that ideally we wouldn't do this, but for the most part the problem is that there are other bugs that this is sort of helping with. I don't think we need to keep it forever. |
| +"use strict"; | ||
| +Object.defineProperty(exports, "__esModule", { value: true }); | ||
| +// #38552 | ||
| +export var y = exports.x = void 0; | ||
| // #38552 | ||
| exports.y = exports.x = void 0; | ||
| +export var x = 1; | ||
| exports.x = 1; | ||
| +export var y = 2; | ||
| exports.y = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression but you'll note that the emit is already wrong; we are emitting actual export var x when we shouldn't. These nodes existing in the tree means we are both detecting it as a module and then printing them back.
| + ~~~~~~~ | ||
| +!!! error TS2339: Property 'default' does not exist on type '0'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange error appearing here. g.js is exports.default = 0 which breaks for some reason.
| +"use strict"; | ||
| +Object.defineProperty(exports, "__esModule", { value: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is becoming strict when it shouldn't be; strict is off, alwaysStrict is off, so the determination is only whether or not there's an external module indicator, which Strada must not have had.
| ->import('./bug28014') : Promise<{ version: 1; default: { (): void; version: 1; }; }> | ||
| +>import('./bug28014') : Promise<{ default: () => void; }> | ||
| +>import('./bug28014') : Promise<() => void> | ||
| >'./bug28014' : "./bug28014" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type here changes.
| -/a.ts(2,5): error TS2339: Property 'bar' does not exist on type 'typeof import("/node_modules/foo/index")'. | ||
| - | ||
| - | ||
| -==== /a.ts (1 errors) ==== | ||
| - import foo from "foo"; | ||
| - foo.bar(); | ||
| - ~~~ | ||
| -!!! error TS2339: Property 'bar' does not exist on type 'typeof import("/node_modules/foo/index")'. | ||
| - | ||
| -==== /node_modules/foo/index.js (0 errors) ==== | ||
| - exports.default = { bar() { return 0; } } | ||
| - | ||
| +<no content> No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error disappears.
|
I think a lot of these issues are caused by the re-parser adding a synthetic |
|
Ok, it appears the only reason for that synthetic Also, I agree there are still issues that need to be fixed in this JS module related code. |
I guess to replace my big hammer with a smaller hammer.
#2044