-
Notifications
You must be signed in to change notification settings - Fork 645
Attempt to fix commonjs module resolution weirdness #1135
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
Open
muglug
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
muglug:muglug-fix-module-resolution-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
testdata/baselines/reference/compiler/commonJsModule.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//// [tests/cases/compiler/commonJsModule.ts] //// | ||
|
||
=== shared.vars.js === | ||
const foo = ['bar', 'baz']; | ||
>foo : Symbol(foo, Decl(shared.vars.js, 0, 5)) | ||
|
||
module.exports = { | ||
>module.exports : Symbol(export=, Decl(shared.vars.js, 0, 27)) | ||
>module : Symbol(module.exports) | ||
>exports : Symbol(export=, Decl(shared.vars.js, 0, 27)) | ||
|
||
foo, | ||
>foo : Symbol(foo, Decl(shared.vars.js, 2, 18)) | ||
|
||
}; | ||
|
||
=== index.ts === | ||
import { foo } from "./shared.vars"; | ||
>foo : Symbol(foo, Decl(index.ts, 0, 8)) | ||
|
||
console.log(foo); | ||
>console.log : Symbol(log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(log, Decl(lib.dom.d.ts, --, --)) | ||
>foo : Symbol(foo, Decl(index.ts, 0, 8)) | ||
|
32 changes: 32 additions & 0 deletions
32
testdata/baselines/reference/compiler/commonJsModule.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//// [tests/cases/compiler/commonJsModule.ts] //// | ||
|
||
=== shared.vars.js === | ||
const foo = ['bar', 'baz']; | ||
>foo : string[] | ||
>['bar', 'baz'] : string[] | ||
>'bar' : "bar" | ||
>'baz' : "baz" | ||
|
||
module.exports = { | ||
>module.exports = { foo,} : { foo: string[]; } | ||
>module.exports : { foo: string[]; } | ||
>module : { "export=": { foo: string[]; }; } | ||
>exports : { foo: string[]; } | ||
>{ foo,} : { foo: string[]; } | ||
|
||
foo, | ||
>foo : string[] | ||
|
||
}; | ||
|
||
=== index.ts === | ||
import { foo } from "./shared.vars"; | ||
>foo : string[] | ||
|
||
console.log(foo); | ||
>console.log(foo) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>foo : string[] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
...ata/baselines/reference/submodule/conformance/conflictingCommonJSES2015Exports.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
bug24934.js(2,1): error TS2309: An export assignment cannot be used in a module with other exported elements. | ||
use.js(1,21): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. | ||
|
||
|
||
==== bug24934.js (1 errors) ==== | ||
export function abc(a, b, c) { return 5; } | ||
module.exports = { abc }; | ||
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2309: An export assignment cannot be used in a module with other exported elements. | ||
==== use.js (1 errors) ==== | ||
==== use.js (0 errors) ==== | ||
import { abc } from './bug24934'; | ||
~~~~~~~~~~~~ | ||
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. | ||
abc(1, 2, 3); | ||
|
13 changes: 0 additions & 13 deletions
13
testdata/baselines/reference/submodule/conformance/reExportJsFromTs.errors.txt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
testdata/baselines/reference/submoduleAccepted/conformance/reExportJsFromTs.errors.txt.diff
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @allowJs: true | ||
// @noEmit: true | ||
// @esModuleInterop: true | ||
// @module: commonjs | ||
// @Filename: shared.vars.js | ||
const foo = ['bar', 'baz']; | ||
|
||
module.exports = { | ||
foo, | ||
}; | ||
|
||
// @Filename: index.ts | ||
import { foo } from "./shared.vars"; | ||
|
||
console.log(foo); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 original code didn't do something like this; @sandersn is this because the JS the external module symbol isn't the source file anymore?
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.
Also, I think this check could just be in the previous if statement? (But I don't know if it's right in any case.)
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.
I don't understand how this fix is related to the previous code or to the repro in the bug. If you want to know if the file is a commonjs module, there's still CommonJSModuleIndicator in Corsa. But there's nothing about that in the Strada code either.