-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap inline negative const enum with parens (#55065)
Co-authored-by: Oleksandr T <[email protected]>
- Loading branch information
1 parent
cd23992
commit 6c942fa
Showing
10 changed files
with
279 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as evaluator from "../../_namespaces/evaluator"; | ||
|
||
describe("unittests:: evaluation:: constEnum", () => { | ||
it("correct order of operations for inlined negative numbers", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
const enum TestEnum { | ||
A = 1, | ||
B = -1 | ||
} | ||
export const a = typeof TestEnum.A.toString(); | ||
export const b = typeof TestEnum.B.toString(); | ||
`); | ||
assert.equal(result.a, "string"); | ||
assert.equal(result.b, "string"); | ||
}); | ||
}); |
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,33 @@ | ||
//// [tests/cases/conformance/constEnums/constEnumPropertyAccess3.ts] //// | ||
|
||
//// [constEnumPropertyAccess3.ts] | ||
const enum E { | ||
A = ~1, | ||
B = -1, | ||
C = ~(1 + 1), | ||
D = -(1 + 2), | ||
E = 1 - 10, | ||
} | ||
|
||
E.A.toString(); | ||
E.B.toString(); | ||
E.C.toString(); | ||
E.D.toString(); | ||
|
||
E["A"].toString(); | ||
E["B"].toString(); | ||
E["C"].toString(); | ||
E["D"].toString(); | ||
E["E"].toString(); | ||
|
||
|
||
//// [constEnumPropertyAccess3.js] | ||
(-2 /* E.A */).toString(); | ||
(-1 /* E.B */).toString(); | ||
(-3 /* E.C */).toString(); | ||
(-3 /* E.D */).toString(); | ||
(-2 /* E["A"] */).toString(); | ||
(-1 /* E["B"] */).toString(); | ||
(-3 /* E["C"] */).toString(); | ||
(-3 /* E["D"] */).toString(); | ||
(-9 /* E["E"] */).toString(); |
80 changes: 80 additions & 0 deletions
80
tests/baselines/reference/constEnumPropertyAccess3.symbols
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,80 @@ | ||
//// [tests/cases/conformance/constEnums/constEnumPropertyAccess3.ts] //// | ||
|
||
=== constEnumPropertyAccess3.ts === | ||
const enum E { | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
|
||
A = ~1, | ||
>A : Symbol(E.A, Decl(constEnumPropertyAccess3.ts, 0, 14)) | ||
|
||
B = -1, | ||
>B : Symbol(E.B, Decl(constEnumPropertyAccess3.ts, 1, 11)) | ||
|
||
C = ~(1 + 1), | ||
>C : Symbol(E.C, Decl(constEnumPropertyAccess3.ts, 2, 11)) | ||
|
||
D = -(1 + 2), | ||
>D : Symbol(E.D, Decl(constEnumPropertyAccess3.ts, 3, 17)) | ||
|
||
E = 1 - 10, | ||
>E : Symbol(E.E, Decl(constEnumPropertyAccess3.ts, 4, 17)) | ||
} | ||
|
||
E.A.toString(); | ||
>E.A.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>E.A : Symbol(E.A, Decl(constEnumPropertyAccess3.ts, 0, 14)) | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
>A : Symbol(E.A, Decl(constEnumPropertyAccess3.ts, 0, 14)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
||
E.B.toString(); | ||
>E.B.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>E.B : Symbol(E.B, Decl(constEnumPropertyAccess3.ts, 1, 11)) | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
>B : Symbol(E.B, Decl(constEnumPropertyAccess3.ts, 1, 11)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
||
E.C.toString(); | ||
>E.C.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>E.C : Symbol(E.C, Decl(constEnumPropertyAccess3.ts, 2, 11)) | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
>C : Symbol(E.C, Decl(constEnumPropertyAccess3.ts, 2, 11)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
||
E.D.toString(); | ||
>E.D.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>E.D : Symbol(E.D, Decl(constEnumPropertyAccess3.ts, 3, 17)) | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
>D : Symbol(E.D, Decl(constEnumPropertyAccess3.ts, 3, 17)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
||
E["A"].toString(); | ||
>E["A"].toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
>"A" : Symbol(E.A, Decl(constEnumPropertyAccess3.ts, 0, 14)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
||
E["B"].toString(); | ||
>E["B"].toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
>"B" : Symbol(E.B, Decl(constEnumPropertyAccess3.ts, 1, 11)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
||
E["C"].toString(); | ||
>E["C"].toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
>"C" : Symbol(E.C, Decl(constEnumPropertyAccess3.ts, 2, 11)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
||
E["D"].toString(); | ||
>E["D"].toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
>"D" : Symbol(E.D, Decl(constEnumPropertyAccess3.ts, 3, 17)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
||
E["E"].toString(); | ||
>E["E"].toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
>E : Symbol(E, Decl(constEnumPropertyAccess3.ts, 0, 0)) | ||
>"E" : Symbol(E.E, Decl(constEnumPropertyAccess3.ts, 4, 17)) | ||
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) | ||
|
111 changes: 111 additions & 0 deletions
111
tests/baselines/reference/constEnumPropertyAccess3.types
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,111 @@ | ||
//// [tests/cases/conformance/constEnums/constEnumPropertyAccess3.ts] //// | ||
|
||
=== constEnumPropertyAccess3.ts === | ||
const enum E { | ||
>E : E | ||
|
||
A = ~1, | ||
>A : E.A | ||
>~1 : number | ||
>1 : 1 | ||
|
||
B = -1, | ||
>B : E.B | ||
>-1 : -1 | ||
>1 : 1 | ||
|
||
C = ~(1 + 1), | ||
>C : E.C | ||
>~(1 + 1) : number | ||
>(1 + 1) : number | ||
>1 + 1 : number | ||
>1 : 1 | ||
>1 : 1 | ||
|
||
D = -(1 + 2), | ||
>D : E.C | ||
>-(1 + 2) : number | ||
>(1 + 2) : number | ||
>1 + 2 : number | ||
>1 : 1 | ||
>2 : 2 | ||
|
||
E = 1 - 10, | ||
>E : E.E | ||
>1 - 10 : number | ||
>1 : 1 | ||
>10 : 10 | ||
} | ||
|
||
E.A.toString(); | ||
>E.A.toString() : string | ||
>E.A.toString : (radix?: number) => string | ||
>E.A : E.A | ||
>E : typeof E | ||
>A : E.A | ||
>toString : (radix?: number) => string | ||
|
||
E.B.toString(); | ||
>E.B.toString() : string | ||
>E.B.toString : (radix?: number) => string | ||
>E.B : E.B | ||
>E : typeof E | ||
>B : E.B | ||
>toString : (radix?: number) => string | ||
|
||
E.C.toString(); | ||
>E.C.toString() : string | ||
>E.C.toString : (radix?: number) => string | ||
>E.C : E.C | ||
>E : typeof E | ||
>C : E.C | ||
>toString : (radix?: number) => string | ||
|
||
E.D.toString(); | ||
>E.D.toString() : string | ||
>E.D.toString : (radix?: number) => string | ||
>E.D : E.C | ||
>E : typeof E | ||
>D : E.C | ||
>toString : (radix?: number) => string | ||
|
||
E["A"].toString(); | ||
>E["A"].toString() : string | ||
>E["A"].toString : (radix?: number) => string | ||
>E["A"] : E.A | ||
>E : typeof E | ||
>"A" : "A" | ||
>toString : (radix?: number) => string | ||
|
||
E["B"].toString(); | ||
>E["B"].toString() : string | ||
>E["B"].toString : (radix?: number) => string | ||
>E["B"] : E.B | ||
>E : typeof E | ||
>"B" : "B" | ||
>toString : (radix?: number) => string | ||
|
||
E["C"].toString(); | ||
>E["C"].toString() : string | ||
>E["C"].toString : (radix?: number) => string | ||
>E["C"] : E.C | ||
>E : typeof E | ||
>"C" : "C" | ||
>toString : (radix?: number) => string | ||
|
||
E["D"].toString(); | ||
>E["D"].toString() : string | ||
>E["D"].toString : (radix?: number) => string | ||
>E["D"] : E.C | ||
>E : typeof E | ||
>"D" : "D" | ||
>toString : (radix?: number) => string | ||
|
||
E["E"].toString(); | ||
>E["E"].toString() : string | ||
>E["E"].toString : (radix?: number) => string | ||
>E["E"] : E.E | ||
>E : typeof E | ||
>"E" : "E" | ||
>toString : (radix?: number) => string | ||
|
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
18 changes: 18 additions & 0 deletions
18
tests/cases/conformance/constEnums/constEnumPropertyAccess3.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,18 @@ | ||
const enum E { | ||
A = ~1, | ||
B = -1, | ||
C = ~(1 + 1), | ||
D = -(1 + 2), | ||
E = 1 - 10, | ||
} | ||
|
||
E.A.toString(); | ||
E.B.toString(); | ||
E.C.toString(); | ||
E.D.toString(); | ||
|
||
E["A"].toString(); | ||
E["B"].toString(); | ||
E["C"].toString(); | ||
E["D"].toString(); | ||
E["E"].toString(); |