Skip to content

Commit 4c82450

Browse files
author
Andy
authored
Treat NoSubstitutionTemplateLiteral same as a StringLiteral (microsoft#17704)
1 parent 2c4361a commit 4c82450

102 files changed

Lines changed: 170 additions & 158 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/compiler/checker.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17757,15 +17757,14 @@ namespace ts {
1775717757
return getBestChoiceType(type1, type2);
1775817758
}
1775917759

17760-
function checkLiteralExpression(node: Expression): Type {
17761-
if (node.kind === SyntaxKind.NumericLiteral) {
17762-
checkGrammarNumericLiteral(<NumericLiteral>node);
17763-
}
17760+
function checkLiteralExpression(node: LiteralExpression | Token<SyntaxKind.TrueKeyword | SyntaxKind.FalseKeyword>): Type {
1776417761
switch (node.kind) {
17762+
case SyntaxKind.NoSubstitutionTemplateLiteral:
1776517763
case SyntaxKind.StringLiteral:
17766-
return getFreshTypeOfLiteralType(getLiteralType((<LiteralExpression>node).text));
17764+
return getFreshTypeOfLiteralType(getLiteralType(node.text));
1776717765
case SyntaxKind.NumericLiteral:
17768-
return getFreshTypeOfLiteralType(getLiteralType(+(<LiteralExpression>node).text));
17766+
checkGrammarNumericLiteral(<NumericLiteral>node);
17767+
return getFreshTypeOfLiteralType(getLiteralType(+node.text));
1776917768
case SyntaxKind.TrueKeyword:
1777017769
return trueType;
1777117770
case SyntaxKind.FalseKeyword:
@@ -17983,15 +17982,14 @@ namespace ts {
1798317982
return checkSuperExpression(node);
1798417983
case SyntaxKind.NullKeyword:
1798517984
return nullWideningType;
17985+
case SyntaxKind.NoSubstitutionTemplateLiteral:
1798617986
case SyntaxKind.StringLiteral:
1798717987
case SyntaxKind.NumericLiteral:
1798817988
case SyntaxKind.TrueKeyword:
1798917989
case SyntaxKind.FalseKeyword:
17990-
return checkLiteralExpression(node);
17990+
return checkLiteralExpression(node as LiteralExpression);
1799117991
case SyntaxKind.TemplateExpression:
1799217992
return checkTemplateExpression(<TemplateExpression>node);
17993-
case SyntaxKind.NoSubstitutionTemplateLiteral:
17994-
return stringType;
1799517993
case SyntaxKind.RegularExpressionLiteral:
1799617994
return globalRegExpType;
1799717995
case SyntaxKind.ArrayLiteralExpression:

tests/baselines/reference/asOperator3.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var d = `Hello ${123} World` as string;
3636
var e = `Hello` as string;
3737
>e : string
3838
>`Hello` as string : string
39-
>`Hello` : string
39+
>`Hello` : "Hello"
4040

4141
var f = 1 + `${1} end of string` as string;
4242
>f : string
@@ -59,5 +59,5 @@ var h = tag `Hello` as string;
5959
>tag `Hello` as string : string
6060
>tag `Hello` : any
6161
>tag : (...x: any[]) => any
62-
>`Hello` : string
62+
>`Hello` : "Hello"
6363

tests/baselines/reference/asOperatorASI.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var x = 10
1414
as `Hello world`; // should not error
1515
>as `Hello world` : any
1616
>as : (...args: any[]) => any
17-
>`Hello world` : string
17+
>`Hello world` : "Hello world"
1818

1919
// Example 2
2020
var y = 20

tests/baselines/reference/computedPropertyNames10_ES5.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var v = {
4646
>true : true
4747

4848
[`hello bye`]() { },
49-
>`hello bye` : string
49+
>`hello bye` : "hello bye"
5050

5151
[`hello ${a} bye`]() { }
5252
>`hello ${a} bye` : string

tests/baselines/reference/computedPropertyNames10_ES6.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var v = {
4646
>true : true
4747

4848
[`hello bye`]() { },
49-
>`hello bye` : string
49+
>`hello bye` : "hello bye"
5050

5151
[`hello ${a} bye`]() { }
5252
>`hello ${a} bye` : string

tests/baselines/reference/computedPropertyNames11_ES5.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var v = {
5555
>0 : 0
5656

5757
set [`hello bye`](v) { },
58-
>`hello bye` : string
58+
>`hello bye` : "hello bye"
5959
>v : any
6060

6161
get [`hello ${a} bye`]() { return 0; }

tests/baselines/reference/computedPropertyNames11_ES6.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var v = {
5555
>0 : 0
5656

5757
set [`hello bye`](v) { },
58-
>`hello bye` : string
58+
>`hello bye` : "hello bye"
5959
>v : any
6060

6161
get [`hello ${a} bye`]() { return 0; }

tests/baselines/reference/computedPropertyNames13_ES5.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class C {
4545
>true : true
4646

4747
[`hello bye`]() { }
48-
>`hello bye` : string
48+
>`hello bye` : "hello bye"
4949

5050
static [`hello ${a} bye`]() { }
5151
>`hello ${a} bye` : string

tests/baselines/reference/computedPropertyNames13_ES6.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class C {
4545
>true : true
4646

4747
[`hello bye`]() { }
48-
>`hello bye` : string
48+
>`hello bye` : "hello bye"
4949

5050
static [`hello ${a} bye`]() { }
5151
>`hello ${a} bye` : string

tests/baselines/reference/computedPropertyNames16_ES5.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class C {
5454
>0 : 0
5555

5656
set [`hello bye`](v) { }
57-
>`hello bye` : string
57+
>`hello bye` : "hello bye"
5858
>v : any
5959

6060
get [`hello ${a} bye`]() { return 0; }

0 commit comments

Comments
 (0)