Merge pull request #4157 from Microsoft/spaceAfterDotInConstEnums
emit space before the dot for property/element access expressions if …
This commit is contained in:
commit
6ae746e1ad
9 changed files with 648 additions and 9 deletions
|
@ -2006,12 +2006,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean {
|
function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean {
|
||||||
if (compilerOptions.isolatedModules) {
|
let constantValue = tryGetConstEnumValue(node);
|
||||||
// do not inline enum values in separate compilation mode
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let constantValue = resolver.getConstantValue(node);
|
|
||||||
if (constantValue !== undefined) {
|
if (constantValue !== undefined) {
|
||||||
write(constantValue.toString());
|
write(constantValue.toString());
|
||||||
if (!compilerOptions.removeComments) {
|
if (!compilerOptions.removeComments) {
|
||||||
|
@ -2023,6 +2018,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function tryGetConstEnumValue(node: Node): number {
|
||||||
|
if (compilerOptions.isolatedModules) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.ElementAccessExpression
|
||||||
|
? resolver.getConstantValue(<PropertyAccessExpression | ElementAccessExpression>node)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
|
||||||
// Returns 'true' if the code was actually indented, false otherwise.
|
// Returns 'true' if the code was actually indented, false otherwise.
|
||||||
// If the code is not indented, an optional valueToWriteWhenNotIndenting will be
|
// If the code is not indented, an optional valueToWriteWhenNotIndenting will be
|
||||||
// emitted instead.
|
// emitted instead.
|
||||||
|
@ -2054,11 +2059,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
|
let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
|
||||||
|
|
||||||
// 1 .toString is a valid property access, emit a space after the literal
|
// 1 .toString is a valid property access, emit a space after the literal
|
||||||
|
// Also emit a space if expression is a integer const enum value - it will appear in generated code as numeric literal
|
||||||
let shouldEmitSpace: boolean;
|
let shouldEmitSpace: boolean;
|
||||||
if (!indentedBeforeDot && node.expression.kind === SyntaxKind.NumericLiteral) {
|
if (!indentedBeforeDot) {
|
||||||
|
if (node.expression.kind === SyntaxKind.NumericLiteral) {
|
||||||
|
// check if numeric literal was originally written with a dot
|
||||||
let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression);
|
let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression);
|
||||||
shouldEmitSpace = text.indexOf(tokenToString(SyntaxKind.DotToken)) < 0;
|
shouldEmitSpace = text.indexOf(tokenToString(SyntaxKind.DotToken)) < 0;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// check if constant enum value is integer
|
||||||
|
let constantValue = tryGetConstEnumValue(node.expression);
|
||||||
|
// isFinite handles cases when constantValue is undefined
|
||||||
|
shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldEmitSpace) {
|
if (shouldEmitSpace) {
|
||||||
write(" .");
|
write(" .");
|
||||||
|
|
37
tests/baselines/reference/constEnumToStringNoComments.js
Normal file
37
tests/baselines/reference/constEnumToStringNoComments.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
//// [constEnumToStringNoComments.ts]
|
||||||
|
const enum Foo {
|
||||||
|
X = 100,
|
||||||
|
Y = 0.5,
|
||||||
|
Z = 2.,
|
||||||
|
A = -1,
|
||||||
|
B = -1.5,
|
||||||
|
C = -1.
|
||||||
|
}
|
||||||
|
|
||||||
|
let x0 = Foo.X.toString();
|
||||||
|
let x1 = Foo["X"].toString();
|
||||||
|
let y0 = Foo.Y.toString();
|
||||||
|
let y1 = Foo["Y"].toString();
|
||||||
|
let z0 = Foo.Z.toString();
|
||||||
|
let z1 = Foo["Z"].toString();
|
||||||
|
let a0 = Foo.A.toString();
|
||||||
|
let a1 = Foo["A"].toString();
|
||||||
|
let b0 = Foo.B.toString();
|
||||||
|
let b1 = Foo["B"].toString();
|
||||||
|
let c0 = Foo.C.toString();
|
||||||
|
let c1 = Foo["C"].toString();
|
||||||
|
|
||||||
|
|
||||||
|
//// [constEnumToStringNoComments.js]
|
||||||
|
var x0 = 100 .toString();
|
||||||
|
var x1 = 100 .toString();
|
||||||
|
var y0 = 0.5.toString();
|
||||||
|
var y1 = 0.5.toString();
|
||||||
|
var z0 = 2 .toString();
|
||||||
|
var z1 = 2 .toString();
|
||||||
|
var a0 = -1 .toString();
|
||||||
|
var a1 = -1 .toString();
|
||||||
|
var b0 = -1.5.toString();
|
||||||
|
var b1 = -1.5.toString();
|
||||||
|
var c0 = -1 .toString();
|
||||||
|
var c1 = -1 .toString();
|
113
tests/baselines/reference/constEnumToStringNoComments.symbols
Normal file
113
tests/baselines/reference/constEnumToStringNoComments.symbols
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
=== tests/cases/compiler/constEnumToStringNoComments.ts ===
|
||||||
|
const enum Foo {
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
|
||||||
|
X = 100,
|
||||||
|
>X : Symbol(Foo.X, Decl(constEnumToStringNoComments.ts, 0, 16))
|
||||||
|
|
||||||
|
Y = 0.5,
|
||||||
|
>Y : Symbol(Foo.Y, Decl(constEnumToStringNoComments.ts, 1, 12))
|
||||||
|
|
||||||
|
Z = 2.,
|
||||||
|
>Z : Symbol(Foo.Z, Decl(constEnumToStringNoComments.ts, 2, 12))
|
||||||
|
|
||||||
|
A = -1,
|
||||||
|
>A : Symbol(Foo.A, Decl(constEnumToStringNoComments.ts, 3, 11))
|
||||||
|
|
||||||
|
B = -1.5,
|
||||||
|
>B : Symbol(Foo.B, Decl(constEnumToStringNoComments.ts, 4, 11))
|
||||||
|
|
||||||
|
C = -1.
|
||||||
|
>C : Symbol(Foo.C, Decl(constEnumToStringNoComments.ts, 5, 13))
|
||||||
|
}
|
||||||
|
|
||||||
|
let x0 = Foo.X.toString();
|
||||||
|
>x0 : Symbol(x0, Decl(constEnumToStringNoComments.ts, 9, 3))
|
||||||
|
>Foo.X.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.X : Symbol(Foo.X, Decl(constEnumToStringNoComments.ts, 0, 16))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>X : Symbol(Foo.X, Decl(constEnumToStringNoComments.ts, 0, 16))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let x1 = Foo["X"].toString();
|
||||||
|
>x1 : Symbol(x1, Decl(constEnumToStringNoComments.ts, 10, 3))
|
||||||
|
>Foo["X"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>"X" : Symbol(Foo.X, Decl(constEnumToStringNoComments.ts, 0, 16))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let y0 = Foo.Y.toString();
|
||||||
|
>y0 : Symbol(y0, Decl(constEnumToStringNoComments.ts, 11, 3))
|
||||||
|
>Foo.Y.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.Y : Symbol(Foo.Y, Decl(constEnumToStringNoComments.ts, 1, 12))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>Y : Symbol(Foo.Y, Decl(constEnumToStringNoComments.ts, 1, 12))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let y1 = Foo["Y"].toString();
|
||||||
|
>y1 : Symbol(y1, Decl(constEnumToStringNoComments.ts, 12, 3))
|
||||||
|
>Foo["Y"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>"Y" : Symbol(Foo.Y, Decl(constEnumToStringNoComments.ts, 1, 12))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let z0 = Foo.Z.toString();
|
||||||
|
>z0 : Symbol(z0, Decl(constEnumToStringNoComments.ts, 13, 3))
|
||||||
|
>Foo.Z.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.Z : Symbol(Foo.Z, Decl(constEnumToStringNoComments.ts, 2, 12))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>Z : Symbol(Foo.Z, Decl(constEnumToStringNoComments.ts, 2, 12))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let z1 = Foo["Z"].toString();
|
||||||
|
>z1 : Symbol(z1, Decl(constEnumToStringNoComments.ts, 14, 3))
|
||||||
|
>Foo["Z"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>"Z" : Symbol(Foo.Z, Decl(constEnumToStringNoComments.ts, 2, 12))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let a0 = Foo.A.toString();
|
||||||
|
>a0 : Symbol(a0, Decl(constEnumToStringNoComments.ts, 15, 3))
|
||||||
|
>Foo.A.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.A : Symbol(Foo.A, Decl(constEnumToStringNoComments.ts, 3, 11))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>A : Symbol(Foo.A, Decl(constEnumToStringNoComments.ts, 3, 11))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let a1 = Foo["A"].toString();
|
||||||
|
>a1 : Symbol(a1, Decl(constEnumToStringNoComments.ts, 16, 3))
|
||||||
|
>Foo["A"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>"A" : Symbol(Foo.A, Decl(constEnumToStringNoComments.ts, 3, 11))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let b0 = Foo.B.toString();
|
||||||
|
>b0 : Symbol(b0, Decl(constEnumToStringNoComments.ts, 17, 3))
|
||||||
|
>Foo.B.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.B : Symbol(Foo.B, Decl(constEnumToStringNoComments.ts, 4, 11))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>B : Symbol(Foo.B, Decl(constEnumToStringNoComments.ts, 4, 11))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let b1 = Foo["B"].toString();
|
||||||
|
>b1 : Symbol(b1, Decl(constEnumToStringNoComments.ts, 18, 3))
|
||||||
|
>Foo["B"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>"B" : Symbol(Foo.B, Decl(constEnumToStringNoComments.ts, 4, 11))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let c0 = Foo.C.toString();
|
||||||
|
>c0 : Symbol(c0, Decl(constEnumToStringNoComments.ts, 19, 3))
|
||||||
|
>Foo.C.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.C : Symbol(Foo.C, Decl(constEnumToStringNoComments.ts, 5, 13))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>C : Symbol(Foo.C, Decl(constEnumToStringNoComments.ts, 5, 13))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let c1 = Foo["C"].toString();
|
||||||
|
>c1 : Symbol(c1, Decl(constEnumToStringNoComments.ts, 20, 3))
|
||||||
|
>Foo["C"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0))
|
||||||
|
>"C" : Symbol(Foo.C, Decl(constEnumToStringNoComments.ts, 5, 13))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
140
tests/baselines/reference/constEnumToStringNoComments.types
Normal file
140
tests/baselines/reference/constEnumToStringNoComments.types
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
=== tests/cases/compiler/constEnumToStringNoComments.ts ===
|
||||||
|
const enum Foo {
|
||||||
|
>Foo : Foo
|
||||||
|
|
||||||
|
X = 100,
|
||||||
|
>X : Foo
|
||||||
|
>100 : number
|
||||||
|
|
||||||
|
Y = 0.5,
|
||||||
|
>Y : Foo
|
||||||
|
>0.5 : number
|
||||||
|
|
||||||
|
Z = 2.,
|
||||||
|
>Z : Foo
|
||||||
|
>2. : number
|
||||||
|
|
||||||
|
A = -1,
|
||||||
|
>A : Foo
|
||||||
|
>-1 : number
|
||||||
|
>1 : number
|
||||||
|
|
||||||
|
B = -1.5,
|
||||||
|
>B : Foo
|
||||||
|
>-1.5 : number
|
||||||
|
>1.5 : number
|
||||||
|
|
||||||
|
C = -1.
|
||||||
|
>C : Foo
|
||||||
|
>-1. : number
|
||||||
|
>1. : number
|
||||||
|
}
|
||||||
|
|
||||||
|
let x0 = Foo.X.toString();
|
||||||
|
>x0 : string
|
||||||
|
>Foo.X.toString() : string
|
||||||
|
>Foo.X.toString : (radix?: number) => string
|
||||||
|
>Foo.X : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>X : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let x1 = Foo["X"].toString();
|
||||||
|
>x1 : string
|
||||||
|
>Foo["X"].toString() : string
|
||||||
|
>Foo["X"].toString : (radix?: number) => string
|
||||||
|
>Foo["X"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"X" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let y0 = Foo.Y.toString();
|
||||||
|
>y0 : string
|
||||||
|
>Foo.Y.toString() : string
|
||||||
|
>Foo.Y.toString : (radix?: number) => string
|
||||||
|
>Foo.Y : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>Y : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let y1 = Foo["Y"].toString();
|
||||||
|
>y1 : string
|
||||||
|
>Foo["Y"].toString() : string
|
||||||
|
>Foo["Y"].toString : (radix?: number) => string
|
||||||
|
>Foo["Y"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"Y" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let z0 = Foo.Z.toString();
|
||||||
|
>z0 : string
|
||||||
|
>Foo.Z.toString() : string
|
||||||
|
>Foo.Z.toString : (radix?: number) => string
|
||||||
|
>Foo.Z : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>Z : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let z1 = Foo["Z"].toString();
|
||||||
|
>z1 : string
|
||||||
|
>Foo["Z"].toString() : string
|
||||||
|
>Foo["Z"].toString : (radix?: number) => string
|
||||||
|
>Foo["Z"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"Z" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let a0 = Foo.A.toString();
|
||||||
|
>a0 : string
|
||||||
|
>Foo.A.toString() : string
|
||||||
|
>Foo.A.toString : (radix?: number) => string
|
||||||
|
>Foo.A : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>A : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let a1 = Foo["A"].toString();
|
||||||
|
>a1 : string
|
||||||
|
>Foo["A"].toString() : string
|
||||||
|
>Foo["A"].toString : (radix?: number) => string
|
||||||
|
>Foo["A"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"A" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let b0 = Foo.B.toString();
|
||||||
|
>b0 : string
|
||||||
|
>Foo.B.toString() : string
|
||||||
|
>Foo.B.toString : (radix?: number) => string
|
||||||
|
>Foo.B : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>B : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let b1 = Foo["B"].toString();
|
||||||
|
>b1 : string
|
||||||
|
>Foo["B"].toString() : string
|
||||||
|
>Foo["B"].toString : (radix?: number) => string
|
||||||
|
>Foo["B"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"B" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let c0 = Foo.C.toString();
|
||||||
|
>c0 : string
|
||||||
|
>Foo.C.toString() : string
|
||||||
|
>Foo.C.toString : (radix?: number) => string
|
||||||
|
>Foo.C : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>C : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let c1 = Foo["C"].toString();
|
||||||
|
>c1 : string
|
||||||
|
>Foo["C"].toString() : string
|
||||||
|
>Foo["C"].toString : (radix?: number) => string
|
||||||
|
>Foo["C"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"C" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
37
tests/baselines/reference/constEnumToStringWithComments.js
Normal file
37
tests/baselines/reference/constEnumToStringWithComments.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
//// [constEnumToStringWithComments.ts]
|
||||||
|
const enum Foo {
|
||||||
|
X = 100,
|
||||||
|
Y = 0.5,
|
||||||
|
Z = 2.,
|
||||||
|
A = -1,
|
||||||
|
B = -1.5,
|
||||||
|
C = -1.
|
||||||
|
}
|
||||||
|
|
||||||
|
let x0 = Foo.X.toString();
|
||||||
|
let x1 = Foo["X"].toString();
|
||||||
|
let y0 = Foo.Y.toString();
|
||||||
|
let y1 = Foo["Y"].toString();
|
||||||
|
let z0 = Foo.Z.toString();
|
||||||
|
let z1 = Foo["Z"].toString();
|
||||||
|
let a0 = Foo.A.toString();
|
||||||
|
let a1 = Foo["A"].toString();
|
||||||
|
let b0 = Foo.B.toString();
|
||||||
|
let b1 = Foo["B"].toString();
|
||||||
|
let c0 = Foo.C.toString();
|
||||||
|
let c1 = Foo["C"].toString();
|
||||||
|
|
||||||
|
|
||||||
|
//// [constEnumToStringWithComments.js]
|
||||||
|
var x0 = 100 /* X */ .toString();
|
||||||
|
var x1 = 100 /* "X" */ .toString();
|
||||||
|
var y0 = 0.5 /* Y */.toString();
|
||||||
|
var y1 = 0.5 /* "Y" */.toString();
|
||||||
|
var z0 = 2 /* Z */ .toString();
|
||||||
|
var z1 = 2 /* "Z" */ .toString();
|
||||||
|
var a0 = -1 /* A */ .toString();
|
||||||
|
var a1 = -1 /* "A" */ .toString();
|
||||||
|
var b0 = -1.5 /* B */.toString();
|
||||||
|
var b1 = -1.5 /* "B" */.toString();
|
||||||
|
var c0 = -1 /* C */ .toString();
|
||||||
|
var c1 = -1 /* "C" */ .toString();
|
113
tests/baselines/reference/constEnumToStringWithComments.symbols
Normal file
113
tests/baselines/reference/constEnumToStringWithComments.symbols
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
=== tests/cases/compiler/constEnumToStringWithComments.ts ===
|
||||||
|
const enum Foo {
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
|
||||||
|
X = 100,
|
||||||
|
>X : Symbol(Foo.X, Decl(constEnumToStringWithComments.ts, 0, 16))
|
||||||
|
|
||||||
|
Y = 0.5,
|
||||||
|
>Y : Symbol(Foo.Y, Decl(constEnumToStringWithComments.ts, 1, 12))
|
||||||
|
|
||||||
|
Z = 2.,
|
||||||
|
>Z : Symbol(Foo.Z, Decl(constEnumToStringWithComments.ts, 2, 12))
|
||||||
|
|
||||||
|
A = -1,
|
||||||
|
>A : Symbol(Foo.A, Decl(constEnumToStringWithComments.ts, 3, 11))
|
||||||
|
|
||||||
|
B = -1.5,
|
||||||
|
>B : Symbol(Foo.B, Decl(constEnumToStringWithComments.ts, 4, 11))
|
||||||
|
|
||||||
|
C = -1.
|
||||||
|
>C : Symbol(Foo.C, Decl(constEnumToStringWithComments.ts, 5, 13))
|
||||||
|
}
|
||||||
|
|
||||||
|
let x0 = Foo.X.toString();
|
||||||
|
>x0 : Symbol(x0, Decl(constEnumToStringWithComments.ts, 9, 3))
|
||||||
|
>Foo.X.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.X : Symbol(Foo.X, Decl(constEnumToStringWithComments.ts, 0, 16))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>X : Symbol(Foo.X, Decl(constEnumToStringWithComments.ts, 0, 16))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let x1 = Foo["X"].toString();
|
||||||
|
>x1 : Symbol(x1, Decl(constEnumToStringWithComments.ts, 10, 3))
|
||||||
|
>Foo["X"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>"X" : Symbol(Foo.X, Decl(constEnumToStringWithComments.ts, 0, 16))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let y0 = Foo.Y.toString();
|
||||||
|
>y0 : Symbol(y0, Decl(constEnumToStringWithComments.ts, 11, 3))
|
||||||
|
>Foo.Y.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.Y : Symbol(Foo.Y, Decl(constEnumToStringWithComments.ts, 1, 12))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>Y : Symbol(Foo.Y, Decl(constEnumToStringWithComments.ts, 1, 12))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let y1 = Foo["Y"].toString();
|
||||||
|
>y1 : Symbol(y1, Decl(constEnumToStringWithComments.ts, 12, 3))
|
||||||
|
>Foo["Y"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>"Y" : Symbol(Foo.Y, Decl(constEnumToStringWithComments.ts, 1, 12))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let z0 = Foo.Z.toString();
|
||||||
|
>z0 : Symbol(z0, Decl(constEnumToStringWithComments.ts, 13, 3))
|
||||||
|
>Foo.Z.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.Z : Symbol(Foo.Z, Decl(constEnumToStringWithComments.ts, 2, 12))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>Z : Symbol(Foo.Z, Decl(constEnumToStringWithComments.ts, 2, 12))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let z1 = Foo["Z"].toString();
|
||||||
|
>z1 : Symbol(z1, Decl(constEnumToStringWithComments.ts, 14, 3))
|
||||||
|
>Foo["Z"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>"Z" : Symbol(Foo.Z, Decl(constEnumToStringWithComments.ts, 2, 12))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let a0 = Foo.A.toString();
|
||||||
|
>a0 : Symbol(a0, Decl(constEnumToStringWithComments.ts, 15, 3))
|
||||||
|
>Foo.A.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.A : Symbol(Foo.A, Decl(constEnumToStringWithComments.ts, 3, 11))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>A : Symbol(Foo.A, Decl(constEnumToStringWithComments.ts, 3, 11))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let a1 = Foo["A"].toString();
|
||||||
|
>a1 : Symbol(a1, Decl(constEnumToStringWithComments.ts, 16, 3))
|
||||||
|
>Foo["A"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>"A" : Symbol(Foo.A, Decl(constEnumToStringWithComments.ts, 3, 11))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let b0 = Foo.B.toString();
|
||||||
|
>b0 : Symbol(b0, Decl(constEnumToStringWithComments.ts, 17, 3))
|
||||||
|
>Foo.B.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.B : Symbol(Foo.B, Decl(constEnumToStringWithComments.ts, 4, 11))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>B : Symbol(Foo.B, Decl(constEnumToStringWithComments.ts, 4, 11))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let b1 = Foo["B"].toString();
|
||||||
|
>b1 : Symbol(b1, Decl(constEnumToStringWithComments.ts, 18, 3))
|
||||||
|
>Foo["B"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>"B" : Symbol(Foo.B, Decl(constEnumToStringWithComments.ts, 4, 11))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let c0 = Foo.C.toString();
|
||||||
|
>c0 : Symbol(c0, Decl(constEnumToStringWithComments.ts, 19, 3))
|
||||||
|
>Foo.C.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo.C : Symbol(Foo.C, Decl(constEnumToStringWithComments.ts, 5, 13))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>C : Symbol(Foo.C, Decl(constEnumToStringWithComments.ts, 5, 13))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
||||||
|
let c1 = Foo["C"].toString();
|
||||||
|
>c1 : Symbol(c1, Decl(constEnumToStringWithComments.ts, 20, 3))
|
||||||
|
>Foo["C"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0))
|
||||||
|
>"C" : Symbol(Foo.C, Decl(constEnumToStringWithComments.ts, 5, 13))
|
||||||
|
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
|
||||||
|
|
140
tests/baselines/reference/constEnumToStringWithComments.types
Normal file
140
tests/baselines/reference/constEnumToStringWithComments.types
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
=== tests/cases/compiler/constEnumToStringWithComments.ts ===
|
||||||
|
const enum Foo {
|
||||||
|
>Foo : Foo
|
||||||
|
|
||||||
|
X = 100,
|
||||||
|
>X : Foo
|
||||||
|
>100 : number
|
||||||
|
|
||||||
|
Y = 0.5,
|
||||||
|
>Y : Foo
|
||||||
|
>0.5 : number
|
||||||
|
|
||||||
|
Z = 2.,
|
||||||
|
>Z : Foo
|
||||||
|
>2. : number
|
||||||
|
|
||||||
|
A = -1,
|
||||||
|
>A : Foo
|
||||||
|
>-1 : number
|
||||||
|
>1 : number
|
||||||
|
|
||||||
|
B = -1.5,
|
||||||
|
>B : Foo
|
||||||
|
>-1.5 : number
|
||||||
|
>1.5 : number
|
||||||
|
|
||||||
|
C = -1.
|
||||||
|
>C : Foo
|
||||||
|
>-1. : number
|
||||||
|
>1. : number
|
||||||
|
}
|
||||||
|
|
||||||
|
let x0 = Foo.X.toString();
|
||||||
|
>x0 : string
|
||||||
|
>Foo.X.toString() : string
|
||||||
|
>Foo.X.toString : (radix?: number) => string
|
||||||
|
>Foo.X : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>X : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let x1 = Foo["X"].toString();
|
||||||
|
>x1 : string
|
||||||
|
>Foo["X"].toString() : string
|
||||||
|
>Foo["X"].toString : (radix?: number) => string
|
||||||
|
>Foo["X"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"X" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let y0 = Foo.Y.toString();
|
||||||
|
>y0 : string
|
||||||
|
>Foo.Y.toString() : string
|
||||||
|
>Foo.Y.toString : (radix?: number) => string
|
||||||
|
>Foo.Y : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>Y : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let y1 = Foo["Y"].toString();
|
||||||
|
>y1 : string
|
||||||
|
>Foo["Y"].toString() : string
|
||||||
|
>Foo["Y"].toString : (radix?: number) => string
|
||||||
|
>Foo["Y"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"Y" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let z0 = Foo.Z.toString();
|
||||||
|
>z0 : string
|
||||||
|
>Foo.Z.toString() : string
|
||||||
|
>Foo.Z.toString : (radix?: number) => string
|
||||||
|
>Foo.Z : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>Z : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let z1 = Foo["Z"].toString();
|
||||||
|
>z1 : string
|
||||||
|
>Foo["Z"].toString() : string
|
||||||
|
>Foo["Z"].toString : (radix?: number) => string
|
||||||
|
>Foo["Z"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"Z" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let a0 = Foo.A.toString();
|
||||||
|
>a0 : string
|
||||||
|
>Foo.A.toString() : string
|
||||||
|
>Foo.A.toString : (radix?: number) => string
|
||||||
|
>Foo.A : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>A : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let a1 = Foo["A"].toString();
|
||||||
|
>a1 : string
|
||||||
|
>Foo["A"].toString() : string
|
||||||
|
>Foo["A"].toString : (radix?: number) => string
|
||||||
|
>Foo["A"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"A" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let b0 = Foo.B.toString();
|
||||||
|
>b0 : string
|
||||||
|
>Foo.B.toString() : string
|
||||||
|
>Foo.B.toString : (radix?: number) => string
|
||||||
|
>Foo.B : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>B : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let b1 = Foo["B"].toString();
|
||||||
|
>b1 : string
|
||||||
|
>Foo["B"].toString() : string
|
||||||
|
>Foo["B"].toString : (radix?: number) => string
|
||||||
|
>Foo["B"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"B" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let c0 = Foo.C.toString();
|
||||||
|
>c0 : string
|
||||||
|
>Foo.C.toString() : string
|
||||||
|
>Foo.C.toString : (radix?: number) => string
|
||||||
|
>Foo.C : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>C : Foo
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
||||||
|
let c1 = Foo["C"].toString();
|
||||||
|
>c1 : string
|
||||||
|
>Foo["C"].toString() : string
|
||||||
|
>Foo["C"].toString : (radix?: number) => string
|
||||||
|
>Foo["C"] : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
>"C" : string
|
||||||
|
>toString : (radix?: number) => string
|
||||||
|
|
22
tests/cases/compiler/constEnumToStringNoComments.ts
Normal file
22
tests/cases/compiler/constEnumToStringNoComments.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// @comments: false
|
||||||
|
const enum Foo {
|
||||||
|
X = 100,
|
||||||
|
Y = 0.5,
|
||||||
|
Z = 2.,
|
||||||
|
A = -1,
|
||||||
|
B = -1.5,
|
||||||
|
C = -1.
|
||||||
|
}
|
||||||
|
|
||||||
|
let x0 = Foo.X.toString();
|
||||||
|
let x1 = Foo["X"].toString();
|
||||||
|
let y0 = Foo.Y.toString();
|
||||||
|
let y1 = Foo["Y"].toString();
|
||||||
|
let z0 = Foo.Z.toString();
|
||||||
|
let z1 = Foo["Z"].toString();
|
||||||
|
let a0 = Foo.A.toString();
|
||||||
|
let a1 = Foo["A"].toString();
|
||||||
|
let b0 = Foo.B.toString();
|
||||||
|
let b1 = Foo["B"].toString();
|
||||||
|
let c0 = Foo.C.toString();
|
||||||
|
let c1 = Foo["C"].toString();
|
22
tests/cases/compiler/constEnumToStringWithComments.ts
Normal file
22
tests/cases/compiler/constEnumToStringWithComments.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// @comments: true
|
||||||
|
const enum Foo {
|
||||||
|
X = 100,
|
||||||
|
Y = 0.5,
|
||||||
|
Z = 2.,
|
||||||
|
A = -1,
|
||||||
|
B = -1.5,
|
||||||
|
C = -1.
|
||||||
|
}
|
||||||
|
|
||||||
|
let x0 = Foo.X.toString();
|
||||||
|
let x1 = Foo["X"].toString();
|
||||||
|
let y0 = Foo.Y.toString();
|
||||||
|
let y1 = Foo["Y"].toString();
|
||||||
|
let z0 = Foo.Z.toString();
|
||||||
|
let z1 = Foo["Z"].toString();
|
||||||
|
let a0 = Foo.A.toString();
|
||||||
|
let a1 = Foo["A"].toString();
|
||||||
|
let b0 = Foo.B.toString();
|
||||||
|
let b1 = Foo["B"].toString();
|
||||||
|
let c0 = Foo.C.toString();
|
||||||
|
let c1 = Foo["C"].toString();
|
Loading…
Reference in a new issue