Treat NoSubstitutionTemplateLiteral same as a StringLiteral (#17704)

This commit is contained in:
Andy
2017-08-10 06:53:48 -07:00
committed by GitHub
parent 2c4361aadf
commit 4c824505ad
102 changed files with 170 additions and 158 deletions

View File

@@ -17757,15 +17757,14 @@ namespace ts {
return getBestChoiceType(type1, type2);
}
function checkLiteralExpression(node: Expression): Type {
if (node.kind === SyntaxKind.NumericLiteral) {
checkGrammarNumericLiteral(<NumericLiteral>node);
}
function checkLiteralExpression(node: LiteralExpression | Token<SyntaxKind.TrueKeyword | SyntaxKind.FalseKeyword>): Type {
switch (node.kind) {
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.StringLiteral:
return getFreshTypeOfLiteralType(getLiteralType((<LiteralExpression>node).text));
return getFreshTypeOfLiteralType(getLiteralType(node.text));
case SyntaxKind.NumericLiteral:
return getFreshTypeOfLiteralType(getLiteralType(+(<LiteralExpression>node).text));
checkGrammarNumericLiteral(<NumericLiteral>node);
return getFreshTypeOfLiteralType(getLiteralType(+node.text));
case SyntaxKind.TrueKeyword:
return trueType;
case SyntaxKind.FalseKeyword:
@@ -17983,15 +17982,14 @@ namespace ts {
return checkSuperExpression(node);
case SyntaxKind.NullKeyword:
return nullWideningType;
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.StringLiteral:
case SyntaxKind.NumericLiteral:
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
return checkLiteralExpression(node);
return checkLiteralExpression(node as LiteralExpression);
case SyntaxKind.TemplateExpression:
return checkTemplateExpression(<TemplateExpression>node);
case SyntaxKind.NoSubstitutionTemplateLiteral:
return stringType;
case SyntaxKind.RegularExpressionLiteral:
return globalRegExpType;
case SyntaxKind.ArrayLiteralExpression: