Skip to content

Commit 464f655

Browse files
committed
Merge branch 'minor-3' of https://github.com/jbondc/TypeScript into jbondc-minor-3
2 parents cc4511d + 8ae53a4 commit 464f655

File tree

9 files changed

+234
-33
lines changed

9 files changed

+234
-33
lines changed

src/compiler/emitter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
17831783

17841784
emit(node.expression);
17851785
let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
1786-
write(".");
1786+
if (!indentedBeforeDot && node.expression.kind === SyntaxKind.NumericLiteral) {
1787+
write(" ."); // JS compat with numeric literal
1788+
} else {
1789+
write(".");
1790+
}
17871791
let indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name);
17881792
emit(node.name);
17891793
decreaseIndentIf(indentedBeforeDot, indentedAfterDot);

src/compiler/parser.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,20 +1830,30 @@ namespace ts {
18301830
}
18311831

18321832
let tokenPos = scanner.getTokenPos();
1833+
let nextCharCode: number;
1834+
18331835
nextToken();
18341836
finishNode(node);
18351837

1836-
// Octal literals are not allowed in strict mode or ES5
1837-
// Note that theoretically the following condition would hold true literals like 009,
1838-
// which is not octal.But because of how the scanner separates the tokens, we would
1839-
// never get a token like this. Instead, we would get 00 and 9 as two separate tokens.
1840-
// We also do not need to check for negatives because any prefix operator would be part of a
1841-
// parent unary expression.
1842-
if (node.kind === SyntaxKind.NumericLiteral
1843-
&& sourceText.charCodeAt(tokenPos) === CharacterCodes._0
1844-
&& isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
1845-
1846-
node.flags |= NodeFlags.OctalLiteral;
1838+
if (node.kind === SyntaxKind.NumericLiteral) {
1839+
// Octal literals are not allowed in strict mode or ES5
1840+
// Note that theoretically the following condition would hold true literals like 009,
1841+
// which is not octal.But because of how the scanner separates the tokens, we would
1842+
// never get a token like this. Instead, we would get 00 and 9 as two separate tokens.
1843+
// We also do not need to check for negatives because any prefix operator would be part of a
1844+
// parent unary expression.
1845+
if (sourceText.charCodeAt(tokenPos) === CharacterCodes._0 && isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
1846+
node.flags |= NodeFlags.OctalLiteral;
1847+
}
1848+
else if (token === SyntaxKind.Identifier && sourceText.charCodeAt(node.end-1) === CharacterCodes.dot) {
1849+
nextCharCode = sourceText.charCodeAt(node.end);
1850+
if (!isWhiteSpace(nextCharCode) && !isLineBreak(nextCharCode)) {
1851+
// If we see 23.Identifier, go back 1 char to scan .Identifier
1852+
node.end = node.end - 1;
1853+
scanner.setTextPos(node.end);
1854+
nextToken()
1855+
}
1856+
}
18471857
}
18481858

18491859
return node;

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ namespace ts {
18811881
CarriageReturnLineFeed = 0,
18821882
LineFeed = 1,
18831883
}
1884-
1884+
18851885
export interface LineAndCharacter {
18861886
line: number;
18871887
/*

tests/baselines/reference/numLit.errors.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/baselines/reference/numLit.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,36 @@
22
1..toString();
33
1.0.toString();
44
1.toString();
5-
1.+2.0 + 3. ;
5+
1.+2.0 + 3. ;
6+
7+
// Preserve whitespace where important for JS compatibility
8+
var i: number = 1;
9+
var test1 = i.toString();
10+
var test2 = 2.toString(); // emitted as 2 .toString()
11+
var test3 = 3 .toString();
12+
var test4 = 3 .toString();
13+
var test5 = 3 .toString();
14+
var test6 = 3.['toString']();
15+
var test7 = 3
16+
.toString();
17+
var test8 = new Number(4).toString();
18+
var test9 = 3. + 3.
19+
620

721
//// [numLit.js]
8-
1..toString();
9-
1.0.toString();
10-
1.;
11-
toString();
22+
1. .toString();
23+
1.0 .toString();
24+
1 .toString();
1225
1. + 2.0 + 3.;
26+
// Preserve whitespace where important for JS compatibility
27+
var i = 1;
28+
var test1 = i.toString();
29+
var test2 = 2 .toString(); // emitted as 2 .toString()
30+
var test3 = 3 .toString();
31+
var test4 = 3 .toString();
32+
var test5 = 3 .toString();
33+
var test6 = 3.['toString']();
34+
var test7 = 3
35+
.toString();
36+
var test8 = new Number(4).toString();
37+
var test9 = 3. + 3.;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
=== tests/cases/compiler/numLit.ts ===
2+
1..toString();
3+
>1..toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
4+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
5+
6+
1.0.toString();
7+
>1.0.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
8+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
9+
10+
1.toString();
11+
>1.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
12+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
13+
14+
1.+2.0 + 3. ;
15+
16+
// Preserve whitespace where important for JS compatibility
17+
var i: number = 1;
18+
>i : Symbol(i, Decl(numLit.ts, 6, 3))
19+
20+
var test1 = i.toString();
21+
>test1 : Symbol(test1, Decl(numLit.ts, 7, 3))
22+
>i.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
23+
>i : Symbol(i, Decl(numLit.ts, 6, 3))
24+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
25+
26+
var test2 = 2.toString(); // emitted as 2 .toString()
27+
>test2 : Symbol(test2, Decl(numLit.ts, 8, 3))
28+
>2.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
29+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
30+
31+
var test3 = 3 .toString();
32+
>test3 : Symbol(test3, Decl(numLit.ts, 9, 3))
33+
>3 .toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
34+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
35+
36+
var test4 = 3 .toString();
37+
>test4 : Symbol(test4, Decl(numLit.ts, 10, 3))
38+
>3 .toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
39+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
40+
41+
var test5 = 3 .toString();
42+
>test5 : Symbol(test5, Decl(numLit.ts, 11, 3))
43+
>3 .toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
44+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
45+
46+
var test6 = 3.['toString']();
47+
>test6 : Symbol(test6, Decl(numLit.ts, 12, 3))
48+
>'toString' : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
49+
50+
var test7 = 3
51+
>test7 : Symbol(test7, Decl(numLit.ts, 13, 3))
52+
>3.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
53+
54+
.toString();
55+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
56+
57+
var test8 = new Number(4).toString();
58+
>test8 : Symbol(test8, Decl(numLit.ts, 15, 3))
59+
>new Number(4).toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
60+
>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11))
61+
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
62+
63+
var test9 = 3. + 3.
64+
>test9 : Symbol(test9, Decl(numLit.ts, 16, 3))
65+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
=== tests/cases/compiler/numLit.ts ===
2+
1..toString();
3+
>1..toString() : string
4+
>1..toString : (radix?: number) => string
5+
>1. : number
6+
>toString : (radix?: number) => string
7+
8+
1.0.toString();
9+
>1.0.toString() : string
10+
>1.0.toString : (radix?: number) => string
11+
>1.0 : number
12+
>toString : (radix?: number) => string
13+
14+
1.toString();
15+
>1.toString() : string
16+
>1.toString : (radix?: number) => string
17+
>1 : number
18+
>toString : (radix?: number) => string
19+
20+
1.+2.0 + 3. ;
21+
>1.+2.0 + 3. : number
22+
>1.+2.0 : number
23+
>1. : number
24+
>2.0 : number
25+
>3. : number
26+
27+
// Preserve whitespace where important for JS compatibility
28+
var i: number = 1;
29+
>i : number
30+
>1 : number
31+
32+
var test1 = i.toString();
33+
>test1 : string
34+
>i.toString() : string
35+
>i.toString : (radix?: number) => string
36+
>i : number
37+
>toString : (radix?: number) => string
38+
39+
var test2 = 2.toString(); // emitted as 2 .toString()
40+
>test2 : string
41+
>2.toString() : string
42+
>2.toString : (radix?: number) => string
43+
>2 : number
44+
>toString : (radix?: number) => string
45+
46+
var test3 = 3 .toString();
47+
>test3 : string
48+
>3 .toString() : string
49+
>3 .toString : (radix?: number) => string
50+
>3 : number
51+
>toString : (radix?: number) => string
52+
53+
var test4 = 3 .toString();
54+
>test4 : string
55+
>3 .toString() : string
56+
>3 .toString : (radix?: number) => string
57+
>3 : number
58+
>toString : (radix?: number) => string
59+
60+
var test5 = 3 .toString();
61+
>test5 : string
62+
>3 .toString() : string
63+
>3 .toString : (radix?: number) => string
64+
>3 : number
65+
>toString : (radix?: number) => string
66+
67+
var test6 = 3.['toString']();
68+
>test6 : string
69+
>3.['toString']() : string
70+
>3.['toString'] : (radix?: number) => string
71+
>3. : number
72+
>'toString' : string
73+
74+
var test7 = 3
75+
>test7 : string
76+
>3.toString() : string
77+
>3.toString : (radix?: number) => string
78+
>3 : number
79+
80+
.toString();
81+
>toString : (radix?: number) => string
82+
83+
var test8 = new Number(4).toString();
84+
>test8 : string
85+
>new Number(4).toString() : string
86+
>new Number(4).toString : (radix?: number) => string
87+
>new Number(4) : Number
88+
>Number : NumberConstructor
89+
>4 : number
90+
>toString : (radix?: number) => string
91+
92+
var test9 = 3. + 3.
93+
>test9 : number
94+
>3. + 3. : number
95+
>3. : number
96+
>3. : number
97+

tests/baselines/reference/toStringOnPrimitives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ aBool.toString();
88
true.toString();
99
var aBool = false;
1010
aBool.toString();
11-
1..toString();
11+
1. .toString();

tests/cases/compiler/numLit.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
1..toString();
22
1.0.toString();
33
1.toString();
4-
1.+2.0 + 3. ;
4+
1.+2.0 + 3. ;
5+
6+
// Preserve whitespace where important for JS compatibility
7+
var i: number = 1;
8+
var test1 = i.toString();
9+
var test2 = 2.toString(); // emitted as 2 .toString()
10+
var test3 = 3 .toString();
11+
var test4 = 3 .toString();
12+
var test5 = 3 .toString();
13+
var test6 = 3.['toString']();
14+
var test7 = 3
15+
.toString();
16+
var test8 = new Number(4).toString();
17+
var test9 = 3. + 3.

0 commit comments

Comments
 (0)