-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix: const enums + isolatedModules emit invalid code #41933
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5abc363
chore: failing test for const enums and isolatedModules
FauxFaux e333fbd
fix: const enums + isolatedModules emit invalid code
FauxFaux c59b82d
chore: extra test for type-only
FauxFaux dc906ee
feat: explicitly ban --isolatedModules --preserveConstEnums false
FauxFaux 4e317fd
feat: isolatedModules implies preserveConstEnum
FauxFaux 2ed07c8
Update src/compiler/diagnosticMessages.json
FauxFaux 38cef4b
chore: compiler test for argument incompatibility
FauxFaux f5ace46
Add and fix test for namespace import of const enum
andrewbranch 49d77c3
Fix additional bug with reexport of const-enum-only module
andrewbranch 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
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
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
35 changes: 35 additions & 0 deletions
35
...s/baselines/reference/constEnumNamespaceReferenceCausesNoImport(isolatedmodules=false).js
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,35 @@ | ||
//// [tests/cases/compiler/constEnumNamespaceReferenceCausesNoImport.ts] //// | ||
|
||
//// [foo.ts] | ||
export const enum ConstFooEnum { | ||
Some, | ||
Values, | ||
Here | ||
}; | ||
export function fooFunc(): void { /* removed */ } | ||
//// [index.ts] | ||
import * as Foo from "./foo"; | ||
|
||
function check(x: Foo.ConstFooEnum): void { | ||
switch (x) { | ||
case Foo.ConstFooEnum.Some: | ||
break; | ||
} | ||
} | ||
|
||
//// [foo.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.fooFunc = void 0; | ||
; | ||
function fooFunc() { } | ||
exports.fooFunc = fooFunc; | ||
//// [index.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
function check(x) { | ||
switch (x) { | ||
case 0 /* Some */: | ||
break; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...elines/reference/constEnumNamespaceReferenceCausesNoImport(isolatedmodules=false).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,40 @@ | ||
=== tests/cases/compiler/foo.ts === | ||
export const enum ConstFooEnum { | ||
>ConstFooEnum : Symbol(ConstFooEnum, Decl(foo.ts, 0, 0)) | ||
|
||
Some, | ||
>Some : Symbol(ConstFooEnum.Some, Decl(foo.ts, 0, 32)) | ||
|
||
Values, | ||
>Values : Symbol(ConstFooEnum.Values, Decl(foo.ts, 1, 9)) | ||
|
||
Here | ||
>Here : Symbol(ConstFooEnum.Here, Decl(foo.ts, 2, 11)) | ||
|
||
}; | ||
export function fooFunc(): void { /* removed */ } | ||
>fooFunc : Symbol(fooFunc, Decl(foo.ts, 4, 2)) | ||
|
||
=== tests/cases/compiler/index.ts === | ||
import * as Foo from "./foo"; | ||
>Foo : Symbol(Foo, Decl(index.ts, 0, 6)) | ||
|
||
function check(x: Foo.ConstFooEnum): void { | ||
>check : Symbol(check, Decl(index.ts, 0, 29)) | ||
>x : Symbol(x, Decl(index.ts, 2, 15)) | ||
>Foo : Symbol(Foo, Decl(index.ts, 0, 6)) | ||
>ConstFooEnum : Symbol(Foo.ConstFooEnum, Decl(foo.ts, 0, 0)) | ||
|
||
switch (x) { | ||
>x : Symbol(x, Decl(index.ts, 2, 15)) | ||
|
||
case Foo.ConstFooEnum.Some: | ||
>Foo.ConstFooEnum.Some : Symbol(Foo.ConstFooEnum.Some, Decl(foo.ts, 0, 32)) | ||
>Foo.ConstFooEnum : Symbol(Foo.ConstFooEnum, Decl(foo.ts, 0, 0)) | ||
>Foo : Symbol(Foo, Decl(index.ts, 0, 6)) | ||
>ConstFooEnum : Symbol(Foo.ConstFooEnum, Decl(foo.ts, 0, 0)) | ||
>Some : Symbol(Foo.ConstFooEnum.Some, Decl(foo.ts, 0, 32)) | ||
|
||
break; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...aselines/reference/constEnumNamespaceReferenceCausesNoImport(isolatedmodules=false).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,39 @@ | ||
=== tests/cases/compiler/foo.ts === | ||
export const enum ConstFooEnum { | ||
>ConstFooEnum : ConstFooEnum | ||
|
||
Some, | ||
>Some : ConstFooEnum.Some | ||
|
||
Values, | ||
>Values : ConstFooEnum.Values | ||
|
||
Here | ||
>Here : ConstFooEnum.Here | ||
|
||
}; | ||
export function fooFunc(): void { /* removed */ } | ||
>fooFunc : () => void | ||
|
||
=== tests/cases/compiler/index.ts === | ||
import * as Foo from "./foo"; | ||
>Foo : typeof Foo | ||
|
||
function check(x: Foo.ConstFooEnum): void { | ||
>check : (x: Foo.ConstFooEnum) => void | ||
>x : Foo.ConstFooEnum | ||
>Foo : any | ||
|
||
switch (x) { | ||
>x : Foo.ConstFooEnum | ||
|
||
case Foo.ConstFooEnum.Some: | ||
>Foo.ConstFooEnum.Some : Foo.ConstFooEnum.Some | ||
>Foo.ConstFooEnum : typeof Foo.ConstFooEnum | ||
>Foo : typeof Foo | ||
>ConstFooEnum : typeof Foo.ConstFooEnum | ||
>Some : Foo.ConstFooEnum.Some | ||
|
||
break; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/constEnumNamespaceReferenceCausesNoImport(isolatedmodules=true).js
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,42 @@ | ||
//// [tests/cases/compiler/constEnumNamespaceReferenceCausesNoImport.ts] //// | ||
|
||
//// [foo.ts] | ||
export const enum ConstFooEnum { | ||
Some, | ||
Values, | ||
Here | ||
}; | ||
export function fooFunc(): void { /* removed */ } | ||
//// [index.ts] | ||
import * as Foo from "./foo"; | ||
|
||
function check(x: Foo.ConstFooEnum): void { | ||
switch (x) { | ||
case Foo.ConstFooEnum.Some: | ||
break; | ||
} | ||
} | ||
|
||
//// [foo.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.fooFunc = exports.ConstFooEnum = void 0; | ||
var ConstFooEnum; | ||
(function (ConstFooEnum) { | ||
ConstFooEnum[ConstFooEnum["Some"] = 0] = "Some"; | ||
ConstFooEnum[ConstFooEnum["Values"] = 1] = "Values"; | ||
ConstFooEnum[ConstFooEnum["Here"] = 2] = "Here"; | ||
})(ConstFooEnum = exports.ConstFooEnum || (exports.ConstFooEnum = {})); | ||
; | ||
function fooFunc() { } | ||
exports.fooFunc = fooFunc; | ||
//// [index.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
var Foo = require("./foo"); | ||
function check(x) { | ||
switch (x) { | ||
case Foo.ConstFooEnum.Some: | ||
break; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...selines/reference/constEnumNamespaceReferenceCausesNoImport(isolatedmodules=true).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,40 @@ | ||
=== tests/cases/compiler/foo.ts === | ||
export const enum ConstFooEnum { | ||
>ConstFooEnum : Symbol(ConstFooEnum, Decl(foo.ts, 0, 0)) | ||
|
||
Some, | ||
>Some : Symbol(ConstFooEnum.Some, Decl(foo.ts, 0, 32)) | ||
|
||
Values, | ||
>Values : Symbol(ConstFooEnum.Values, Decl(foo.ts, 1, 9)) | ||
|
||
Here | ||
>Here : Symbol(ConstFooEnum.Here, Decl(foo.ts, 2, 11)) | ||
|
||
}; | ||
export function fooFunc(): void { /* removed */ } | ||
>fooFunc : Symbol(fooFunc, Decl(foo.ts, 4, 2)) | ||
|
||
=== tests/cases/compiler/index.ts === | ||
import * as Foo from "./foo"; | ||
>Foo : Symbol(Foo, Decl(index.ts, 0, 6)) | ||
|
||
function check(x: Foo.ConstFooEnum): void { | ||
>check : Symbol(check, Decl(index.ts, 0, 29)) | ||
>x : Symbol(x, Decl(index.ts, 2, 15)) | ||
>Foo : Symbol(Foo, Decl(index.ts, 0, 6)) | ||
>ConstFooEnum : Symbol(Foo.ConstFooEnum, Decl(foo.ts, 0, 0)) | ||
|
||
switch (x) { | ||
>x : Symbol(x, Decl(index.ts, 2, 15)) | ||
|
||
case Foo.ConstFooEnum.Some: | ||
>Foo.ConstFooEnum.Some : Symbol(Foo.ConstFooEnum.Some, Decl(foo.ts, 0, 32)) | ||
>Foo.ConstFooEnum : Symbol(Foo.ConstFooEnum, Decl(foo.ts, 0, 0)) | ||
>Foo : Symbol(Foo, Decl(index.ts, 0, 6)) | ||
>ConstFooEnum : Symbol(Foo.ConstFooEnum, Decl(foo.ts, 0, 0)) | ||
>Some : Symbol(Foo.ConstFooEnum.Some, Decl(foo.ts, 0, 32)) | ||
|
||
break; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...baselines/reference/constEnumNamespaceReferenceCausesNoImport(isolatedmodules=true).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,39 @@ | ||
=== tests/cases/compiler/foo.ts === | ||
export const enum ConstFooEnum { | ||
>ConstFooEnum : ConstFooEnum | ||
|
||
Some, | ||
>Some : ConstFooEnum.Some | ||
|
||
Values, | ||
>Values : ConstFooEnum.Values | ||
|
||
Here | ||
>Here : ConstFooEnum.Here | ||
|
||
}; | ||
export function fooFunc(): void { /* removed */ } | ||
>fooFunc : () => void | ||
|
||
=== tests/cases/compiler/index.ts === | ||
import * as Foo from "./foo"; | ||
>Foo : typeof Foo | ||
|
||
function check(x: Foo.ConstFooEnum): void { | ||
>check : (x: Foo.ConstFooEnum) => void | ||
>x : Foo.ConstFooEnum | ||
>Foo : any | ||
|
||
switch (x) { | ||
>x : Foo.ConstFooEnum | ||
|
||
case Foo.ConstFooEnum.Some: | ||
>Foo.ConstFooEnum.Some : Foo.ConstFooEnum.Some | ||
>Foo.ConstFooEnum : typeof Foo.ConstFooEnum | ||
>Foo : typeof Foo | ||
>ConstFooEnum : typeof Foo.ConstFooEnum | ||
>Some : Foo.ConstFooEnum.Some | ||
|
||
break; | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.