-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
isolatedModules errors for non-literal enum initializers (#56736)
- Loading branch information
Showing
9 changed files
with
274 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/enumNoInitializerFollowsNonLiteralInitializer.errors.txt
This file contains 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,34 @@ | ||
bad.ts(4,5): error TS18056: Enum member following a non-literal numeric member must have an initializer when 'isolatedModules' is enabled. | ||
|
||
|
||
==== ./helpers.ts (0 errors) ==== | ||
export const foo = 2; | ||
|
||
==== ./bad.ts (1 errors) ==== | ||
import { foo } from "./helpers"; | ||
enum A { | ||
a = foo, | ||
b, | ||
~ | ||
!!! error TS18056: Enum member following a non-literal numeric member must have an initializer when 'isolatedModules' is enabled. | ||
} | ||
|
||
==== ./good.ts (0 errors) ==== | ||
import { foo } from "./helpers"; | ||
enum A { | ||
a = foo, | ||
b = 3, | ||
} | ||
enum B { | ||
a = 1 + 1, | ||
b, | ||
} | ||
enum C { | ||
a = +2, | ||
b, | ||
} | ||
enum D { | ||
a = (2), | ||
b, | ||
} | ||
|
70 changes: 70 additions & 0 deletions
70
tests/baselines/reference/enumNoInitializerFollowsNonLiteralInitializer.js
This file contains 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,70 @@ | ||
//// [tests/cases/compiler/enumNoInitializerFollowsNonLiteralInitializer.ts] //// | ||
|
||
//// [helpers.ts] | ||
export const foo = 2; | ||
|
||
//// [bad.ts] | ||
import { foo } from "./helpers"; | ||
enum A { | ||
a = foo, | ||
b, | ||
} | ||
|
||
//// [good.ts] | ||
import { foo } from "./helpers"; | ||
enum A { | ||
a = foo, | ||
b = 3, | ||
} | ||
enum B { | ||
a = 1 + 1, | ||
b, | ||
} | ||
enum C { | ||
a = +2, | ||
b, | ||
} | ||
enum D { | ||
a = (2), | ||
b, | ||
} | ||
|
||
|
||
//// [helpers.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.foo = void 0; | ||
exports.foo = 2; | ||
//// [bad.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var helpers_1 = require("./helpers"); | ||
var A; | ||
(function (A) { | ||
A[A["a"] = 2] = "a"; | ||
A[A["b"] = 3] = "b"; | ||
})(A || (A = {})); | ||
//// [good.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var helpers_1 = require("./helpers"); | ||
var A; | ||
(function (A) { | ||
A[A["a"] = 2] = "a"; | ||
A[A["b"] = 3] = "b"; | ||
})(A || (A = {})); | ||
var B; | ||
(function (B) { | ||
B[B["a"] = 2] = "a"; | ||
B[B["b"] = 3] = "b"; | ||
})(B || (B = {})); | ||
var C; | ||
(function (C) { | ||
C[C["a"] = 2] = "a"; | ||
C[C["b"] = 3] = "b"; | ||
})(C || (C = {})); | ||
var D; | ||
(function (D) { | ||
D[D["a"] = 2] = "a"; | ||
D[D["b"] = 3] = "b"; | ||
})(D || (D = {})); |
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/enumWithNonLiteralStringInitializer.errors.txt
This file contains 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,24 @@ | ||
bad.ts(3,8): error TS18055: 'A.a' has a string type, but must have syntactically recognizable string syntax when 'isolatedModules' is enabled. | ||
|
||
|
||
==== ./helpers.ts (0 errors) ==== | ||
export const foo = 2; | ||
export const bar = "bar"; | ||
|
||
==== ./bad.ts (1 errors) ==== | ||
import { bar } from "./helpers"; | ||
enum A { | ||
a = bar, | ||
~~~ | ||
!!! error TS18055: 'A.a' has a string type, but must have syntactically recognizable string syntax when 'isolatedModules' is enabled. | ||
} | ||
|
||
==== ./good.ts (0 errors) ==== | ||
import { foo } from "./helpers"; | ||
enum A { | ||
a = `${foo}`, | ||
b = "" + 2, | ||
c = 2 + "", | ||
d = ("foo"), | ||
} | ||
|
47 changes: 47 additions & 0 deletions
47
tests/baselines/reference/enumWithNonLiteralStringInitializer.js
This file contains 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,47 @@ | ||
//// [tests/cases/compiler/enumWithNonLiteralStringInitializer.ts] //// | ||
|
||
//// [helpers.ts] | ||
export const foo = 2; | ||
export const bar = "bar"; | ||
|
||
//// [bad.ts] | ||
import { bar } from "./helpers"; | ||
enum A { | ||
a = bar, | ||
} | ||
|
||
//// [good.ts] | ||
import { foo } from "./helpers"; | ||
enum A { | ||
a = `${foo}`, | ||
b = "" + 2, | ||
c = 2 + "", | ||
d = ("foo"), | ||
} | ||
|
||
|
||
//// [helpers.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.bar = exports.foo = void 0; | ||
exports.foo = 2; | ||
exports.bar = "bar"; | ||
//// [bad.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var helpers_1 = require("./helpers"); | ||
var A; | ||
(function (A) { | ||
A["a"] = "bar"; | ||
})(A || (A = {})); | ||
//// [good.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var helpers_1 = require("./helpers"); | ||
var A; | ||
(function (A) { | ||
A["a"] = "2"; | ||
A["b"] = "2"; | ||
A["c"] = "2"; | ||
A["d"] = "foo"; | ||
})(A || (A = {})); |
This file contains 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
31 changes: 31 additions & 0 deletions
31
tests/cases/compiler/enumNoInitializerFollowsNonLiteralInitializer.ts
This file contains 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,31 @@ | ||
// @isolatedModules: true | ||
// @noTypesAndSymbols: true | ||
|
||
// @filename: ./helpers.ts | ||
export const foo = 2; | ||
|
||
// @filename: ./bad.ts | ||
import { foo } from "./helpers"; | ||
enum A { | ||
a = foo, | ||
b, | ||
} | ||
|
||
// @filename: ./good.ts | ||
import { foo } from "./helpers"; | ||
enum A { | ||
a = foo, | ||
b = 3, | ||
} | ||
enum B { | ||
a = 1 + 1, | ||
b, | ||
} | ||
enum C { | ||
a = +2, | ||
b, | ||
} | ||
enum D { | ||
a = (2), | ||
b, | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/cases/compiler/enumWithNonLiteralStringInitializer.ts
This file contains 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,21 @@ | ||
// @isolatedModules: true | ||
// @noTypesAndSymbols: true | ||
|
||
// @filename: ./helpers.ts | ||
export const foo = 2; | ||
export const bar = "bar"; | ||
|
||
// @filename: ./bad.ts | ||
import { bar } from "./helpers"; | ||
enum A { | ||
a = bar, | ||
} | ||
|
||
// @filename: ./good.ts | ||
import { foo } from "./helpers"; | ||
enum A { | ||
a = `${foo}`, | ||
b = "" + 2, | ||
c = 2 + "", | ||
d = ("foo"), | ||
} |