From 6469375149b37a77d67f437eeedb6bf0c5f5d77a Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Sun, 4 Jan 2015 14:42:05 +0100 Subject: [PATCH 01/24] Remove tagged templates error when targeting ES3 or 5 --- src/compiler/checker.ts | 5 ----- src/compiler/diagnosticInformationMap.generated.ts | 1 - src/compiler/diagnosticMessages.json | 5 ----- 3 files changed, 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f8c4caa9630d3..ef17f35dad0d1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6319,11 +6319,6 @@ module ts { } function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type { - // Grammar checking - if (compilerOptions.target < ScriptTarget.ES6) { - grammarErrorOnFirstToken(node.template, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - return getReturnTypeOfSignature(getResolvedSignature(node)); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 99d8d0b72fbf8..c9c4edbe3ac6f 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -117,7 +117,6 @@ module ts { const_declarations_must_be_initialized: { code: 1155, category: DiagnosticCategory.Error, key: "'const' declarations must be initialized", isEarly: true }, const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block.", isEarly: true }, let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block.", isEarly: true }, - Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: DiagnosticCategory.Error, key: "Tagged templates are only available when targeting ECMAScript 6 and higher.", isEarly: true }, Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, An_object_member_cannot_be_declared_optional: { code: 1162, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional.", isEarly: true }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5bec5301721ca..b6a4b83f4303b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -539,11 +539,6 @@ "code": 1157, "isEarly": true }, - "Tagged templates are only available when targeting ECMAScript 6 and higher.": { - "category": "Error", - "code": 1159, - "isEarly": true - }, "Unterminated template literal.": { "category": "Error", "code": 1160 From c2d0bf82c4727bd7ac632f295e0f6b3a66aa3de1 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Sun, 4 Jan 2015 14:47:18 +0100 Subject: [PATCH 02/24] Emit tagged templates when targeting ES3 or 5 --- src/compiler/emitter.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 237f3ab509ae7..54683c5e39384 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2059,8 +2059,26 @@ module ts { return; } - Debug.assert(node.parent.kind !== SyntaxKind.TaggedTemplateExpression); - + if (node.parent.kind === SyntaxKind.TaggedTemplateExpression) { + // Emit should like: + // foo(["a", "b", "c"], expressions0, expression1) + // First we emit the string literal array + write("["); + emitLiteral(node.head); + forEach(node.templateSpans, templateSpan => { + write(", "); + emitLiteral(templateSpan.literal); + }); + write("]"); + + // Now we emit the expressions + forEach(node.templateSpans, templateSpan => { + write(", "); + emit(templateSpan.expression); + }); + return; + } + var emitOuterParens = isExpression(node.parent) && templateNeedsParens(node, node.parent); @@ -2487,10 +2505,15 @@ module ts { } function emitTaggedTemplateExpression(node: TaggedTemplateExpression): void { - Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Trying to emit a tagged template in pre-ES6 mode."); emit(node.tag); - write(" "); - emit(node.template); + if (compilerOptions.target >= ScriptTarget.ES6) { + write(" "); + emit(node.template); + } else { + write("("); + emit(node.template); + write(")"); + } } function emitParenExpression(node: ParenthesizedExpression) { From 69d724f5549934e2c9997cd371384631d775d784 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Sun, 4 Jan 2015 20:58:45 +0100 Subject: [PATCH 03/24] Fix tagged templates that consist of a single part MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example: foo `bar` should compile to foo([β€œbar”]) --- src/compiler/emitter.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 54683c5e39384..602e4ccc12c8c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2048,7 +2048,12 @@ module ts { } function getTemplateLiteralAsStringLiteral(node: LiteralExpression): string { - return '"' + escapeString(node.text) + '"'; + if (node.parent.kind === SyntaxKind.TaggedTemplateExpression) { + // Emit tagged template as foo(["string"]) + return '["' + escapeString(node.text) + '"]'; + } else { + return '"' + escapeString(node.text) + '"'; + } } function emitTemplateExpression(node: TemplateExpression): void { From 8f28c95b041ba8cf46e3da93973a95552ae83248 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Mon, 5 Jan 2015 20:30:38 +0100 Subject: [PATCH 04/24] Emit parens when an argument is a comma operator Example: foo`A${ 1 }B${ 2, 3 }C`; --- src/compiler/emitter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 602e4ccc12c8c..f3e4cefa919b5 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2079,7 +2079,9 @@ module ts { // Now we emit the expressions forEach(node.templateSpans, templateSpan => { write(", "); - emit(templateSpan.expression); + var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression + && ( templateSpan.expression).operator === SyntaxKind.CommaToken; + emitParenthesized(templateSpan.expression, needsParens); }); return; } From a13af6b4821917d1195bf0ef97239fa3ddb48779 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Mon, 5 Jan 2015 21:22:12 +0100 Subject: [PATCH 05/24] Move code to separate functions --- src/compiler/emitter.ts | 59 ++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f3e4cefa919b5..3300e542cc5f1 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2030,8 +2030,19 @@ module ts { } return false; } + + function emitDownlevelTaggedTemplateLiteral(node: LiteralExpression) { + // Emit tagged template as foo(["string"]) + write("["); + writer.writeLiteral(getTemplateLiteralAsStringLiteral(node)); + write("]"); + } function emitLiteral(node: LiteralExpression) { + if (node.parent.kind === SyntaxKind.TaggedTemplateExpression && compilerOptions.target < ScriptTarget.ES6) { + return emitDownlevelTaggedTemplateLiteral(node); + } + var text = compilerOptions.target < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; @@ -2048,12 +2059,28 @@ module ts { } function getTemplateLiteralAsStringLiteral(node: LiteralExpression): string { - if (node.parent.kind === SyntaxKind.TaggedTemplateExpression) { - // Emit tagged template as foo(["string"]) - return '["' + escapeString(node.text) + '"]'; - } else { - return '"' + escapeString(node.text) + '"'; - } + return '"' + escapeString(node.text) + '"'; + } + + function emitDownlevelTaggedTemplate(node: TemplateExpression): void { + // Emit should like: + // foo(["a", "b", "c"], expressions0, expression1) + // First we emit the string literal array + write("["); + emitLiteral(node.head); + forEach(node.templateSpans, templateSpan => { + write(", "); + emitLiteral(templateSpan.literal); + }); + write("]"); + + // Now we emit the expressions + forEach(node.templateSpans, templateSpan => { + write(", "); + var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression + && ( templateSpan.expression).operator === SyntaxKind.CommaToken; + emitParenthesized(templateSpan.expression, needsParens); + }); } function emitTemplateExpression(node: TemplateExpression): void { @@ -2065,25 +2092,7 @@ module ts { } if (node.parent.kind === SyntaxKind.TaggedTemplateExpression) { - // Emit should like: - // foo(["a", "b", "c"], expressions0, expression1) - // First we emit the string literal array - write("["); - emitLiteral(node.head); - forEach(node.templateSpans, templateSpan => { - write(", "); - emitLiteral(templateSpan.literal); - }); - write("]"); - - // Now we emit the expressions - forEach(node.templateSpans, templateSpan => { - write(", "); - var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression - && ( templateSpan.expression).operator === SyntaxKind.CommaToken; - emitParenthesized(templateSpan.expression, needsParens); - }); - return; + return emitDownlevelTaggedTemplate(node); } var emitOuterParens = isExpression(node.parent) From 349841e2e34ab2bc640ad2b6e8d0e9dcf22fec9c Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Fri, 9 Jan 2015 21:22:42 +0100 Subject: [PATCH 06/24] Emit var in front of statement with tagged template --- src/compiler/binder.ts | 21 ++++++++ src/compiler/emitter.ts | 112 ++++++++++++++++++++++++++++++---------- src/compiler/types.ts | 2 + 3 files changed, 108 insertions(+), 27 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 201913a50b465..87501045e203d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -65,6 +65,7 @@ module ts { var container: Node; var blockScopeContainer: Node; var lastContainer: Node; + var statement: Statement; var symbolCount = 0; var Symbol = objectAllocator.getSymbolConstructor(); @@ -371,9 +372,25 @@ module ts { function getDestructuringParameterName(node: Declaration) { return "__" + indexOf((node.parent).parameters, node); } + + function bindTaggedTemplateExpression(node: TaggedTemplateExpression) { + if (file.languageVersion >= ScriptTarget.ES6) return; + + statement.downlevelTaggedTemplates.push(node); + } function bind(node: Node) { node.parent = parent; + + var savedStatement = statement; + + if (isStatement(node)) { + statement = node; + if (file.languageVersion < ScriptTarget.ES6) { + statement.downlevelTaggedTemplates = []; + } + } + switch (node.kind) { case SyntaxKind.TypeParameter: bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false); @@ -484,12 +501,16 @@ module ts { case SyntaxKind.SwitchStatement: bindChildren(node, 0, /*isBlockScopeContainer*/ true); break; + case SyntaxKind.TaggedTemplateExpression: + bindTaggedTemplateExpression( node); default: var saveParent = parent; parent = node; forEachChild(node, bind); parent = saveParent; } + + statement = savedStatement; } function bindParameter(node: ParameterDeclaration) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3300e542cc5f1..ddc8a110acd2b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2030,19 +2030,8 @@ module ts { } return false; } - - function emitDownlevelTaggedTemplateLiteral(node: LiteralExpression) { - // Emit tagged template as foo(["string"]) - write("["); - writer.writeLiteral(getTemplateLiteralAsStringLiteral(node)); - write("]"); - } function emitLiteral(node: LiteralExpression) { - if (node.parent.kind === SyntaxKind.TaggedTemplateExpression && compilerOptions.target < ScriptTarget.ES6) { - return emitDownlevelTaggedTemplateLiteral(node); - } - var text = compilerOptions.target < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; @@ -2062,25 +2051,89 @@ module ts { return '"' + escapeString(node.text) + '"'; } - function emitDownlevelTaggedTemplate(node: TemplateExpression): void { - // Emit should like: - // foo(["a", "b", "c"], expressions0, expression1) - // First we emit the string literal array - write("["); - emitLiteral(node.head); - forEach(node.templateSpans, templateSpan => { + function emitDownlevelRawTemplateLiteral(node: LiteralExpression, isLast: boolean) { + var text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" en "}"), + // thus we need to remove those characters. + // First template piece starts with "`", others with "}" + // Last template piece ends with "`", others with "${" + text = text.substring(1, text.length - (isLast ? 1 : 2)); + + write('"' + escapeString(text) + '"'); + } + + function emitDownlevelTaggedTemplateVariable(node: TaggedTemplateExpression) { + node.tempVariable = createTempVariable(node); + + write("var "); + emit(node.tempVariable); + write(";"); + writeLine(); + } + function emitDownlevelTaggedTemplateStrings(node: TaggedTemplateExpression, inLoop: boolean) { + if (!inLoop) { + node.tempVariable = createTempVariable(node); + + write("var "); + } else { + // node.tempVariable is initialized in emitDownlevelTaggedTemplateVariable + + write("("); + } + emit(node.tempVariable); + write(" = ["); + + if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { + emit(node.template); + } else { + emit(( node.template).head); + forEach(( node.template).templateSpans, (child) => { + write(", "); + emit(child.literal); + }); + } + write("]"); + + if (!inLoop) { + write(";"); + writeLine(); + } + else { write(", "); - emitLiteral(templateSpan.literal); - }); + } + emit(node.tempVariable); + write(".raw = ["); + if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { + emitDownlevelRawTemplateLiteral( node.template, true); + } else { + emitDownlevelRawTemplateLiteral(( node.template).head, false); + forEach(( node.template).templateSpans, (child, index) => { + write(", "); + emitDownlevelRawTemplateLiteral(child.literal, index === ( node.template).templateSpans.length - 1); + }); + } write("]"); + if (!inLoop) { + write(";"); + writeLine(); + } + } + + function emitDownlevelTaggedTemplate(node: LiteralExpression | TemplateExpression): void { + // Emit should like: + // foo(tempVar, expressions0, expression1) + emit(( node.parent).tempVariable); // Now we emit the expressions - forEach(node.templateSpans, templateSpan => { - write(", "); - var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression - && ( templateSpan.expression).operator === SyntaxKind.CommaToken; - emitParenthesized(templateSpan.expression, needsParens); - }); + if (node.kind === SyntaxKind.TemplateExpression) { + forEach(( node).templateSpans, templateSpan => { + write(", "); + var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression + && ( templateSpan.expression).operator === SyntaxKind.CommaToken; + emitParenthesized(templateSpan.expression, needsParens); + }); + } } function emitTemplateExpression(node: TemplateExpression): void { @@ -2527,7 +2580,7 @@ module ts { emit(node.template); } else { write("("); - emit(node.template); + emitDownlevelTaggedTemplate(node.template); write(")"); } } @@ -3969,6 +4022,11 @@ module ts { return; } + if (isStatement(node)) { + // TODO: Check whether node is a loop + forEach(( node).downlevelTaggedTemplates, node => emitDownlevelTaggedTemplateStrings(node, false)); + } + if (node.flags & NodeFlags.Ambient) { return emitPinnedOrTripleSlashComments(node); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 60ed8352b9a3d..52a95acfc913a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -692,6 +692,7 @@ module ts { export interface TaggedTemplateExpression extends MemberExpression { tag: LeftHandSideExpression; template: LiteralExpression | TemplateExpression; + tempVariable?: Identifier; // Initialized in emitter.ts } export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression; @@ -703,6 +704,7 @@ module ts { export interface Statement extends Node, ModuleElement { _statementBrand: any; + downlevelTaggedTemplates?: TaggedTemplateExpression[]; // Initialized in binder.ts } export interface Block extends Statement { From 28b90a2be31ab6766a53d7ab300410c2b76b9537 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Mon, 19 Jan 2015 11:09:27 +0100 Subject: [PATCH 07/24] Remove properties from types.ts --- src/compiler/types.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 52a95acfc913a..60ed8352b9a3d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -692,7 +692,6 @@ module ts { export interface TaggedTemplateExpression extends MemberExpression { tag: LeftHandSideExpression; template: LiteralExpression | TemplateExpression; - tempVariable?: Identifier; // Initialized in emitter.ts } export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression; @@ -704,7 +703,6 @@ module ts { export interface Statement extends Node, ModuleElement { _statementBrand: any; - downlevelTaggedTemplates?: TaggedTemplateExpression[]; // Initialized in binder.ts } export interface Block extends Statement { From ed7ae27f4c068bea836c7f0402ba8ec9951d95ba Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Mon, 19 Jan 2015 11:09:57 +0100 Subject: [PATCH 08/24] Remove binding of tagged templates --- src/compiler/binder.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 87501045e203d..23ccaba4b6c2d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -372,12 +372,6 @@ module ts { function getDestructuringParameterName(node: Declaration) { return "__" + indexOf((node.parent).parameters, node); } - - function bindTaggedTemplateExpression(node: TaggedTemplateExpression) { - if (file.languageVersion >= ScriptTarget.ES6) return; - - statement.downlevelTaggedTemplates.push(node); - } function bind(node: Node) { node.parent = parent; @@ -501,8 +495,6 @@ module ts { case SyntaxKind.SwitchStatement: bindChildren(node, 0, /*isBlockScopeContainer*/ true); break; - case SyntaxKind.TaggedTemplateExpression: - bindTaggedTemplateExpression( node); default: var saveParent = parent; parent = node; From d339a52b6a7cd80248dc170e4eb373223fb754d6 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Mon, 19 Jan 2015 11:32:27 +0100 Subject: [PATCH 09/24] Remove statement from binder --- src/compiler/binder.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 23ccaba4b6c2d..aa44179ed243e 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -65,7 +65,6 @@ module ts { var container: Node; var blockScopeContainer: Node; var lastContainer: Node; - var statement: Statement; var symbolCount = 0; var Symbol = objectAllocator.getSymbolConstructor(); @@ -376,15 +375,6 @@ module ts { function bind(node: Node) { node.parent = parent; - var savedStatement = statement; - - if (isStatement(node)) { - statement = node; - if (file.languageVersion < ScriptTarget.ES6) { - statement.downlevelTaggedTemplates = []; - } - } - switch (node.kind) { case SyntaxKind.TypeParameter: bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false); @@ -501,8 +491,6 @@ module ts { forEachChild(node, bind); parent = saveParent; } - - statement = savedStatement; } function bindParameter(node: ParameterDeclaration) { From 161545de97db60c298eb9db4fcf496970d636a62 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Mon, 19 Jan 2015 11:33:43 +0100 Subject: [PATCH 10/24] Change tagged template emit to new style --- src/compiler/emitter.ts | 82 ++++++++++++----------------------------- 1 file changed, 24 insertions(+), 58 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ddc8a110acd2b..d0cbbff92f8f7 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2054,7 +2054,7 @@ module ts { function emitDownlevelRawTemplateLiteral(node: LiteralExpression, isLast: boolean) { var text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" en "}"), + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), // thus we need to remove those characters. // First template piece starts with "`", others with "}" // Last template piece ends with "`", others with "${" @@ -2063,77 +2063,53 @@ module ts { write('"' + escapeString(text) + '"'); } - function emitDownlevelTaggedTemplateVariable(node: TaggedTemplateExpression) { - node.tempVariable = createTempVariable(node); - - write("var "); - emit(node.tempVariable); - write(";"); - writeLine(); - } - function emitDownlevelTaggedTemplateStrings(node: TaggedTemplateExpression, inLoop: boolean) { - if (!inLoop) { - node.tempVariable = createTempVariable(node); - - write("var "); - } else { - // node.tempVariable is initialized in emitDownlevelTaggedTemplateVariable - - write("("); - } - emit(node.tempVariable); + function emitDownlevelTaggedTemplate(node: TaggedTemplateExpression) { + var tempVariable = createTempVariable(node); + recordTempDeclaration(tempVariable); + write("("); + emit(tempVariable); write(" = ["); if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { emit(node.template); - } else { + } + else { emit(( node.template).head); forEach(( node.template).templateSpans, (child) => { write(", "); emit(child.literal); }); } - write("]"); + write("], "); - if (!inLoop) { - write(";"); - writeLine(); - } - else { - write(", "); - } - emit(node.tempVariable); + emit(tempVariable); write(".raw = ["); if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { emitDownlevelRawTemplateLiteral( node.template, true); - } else { + } + else { emitDownlevelRawTemplateLiteral(( node.template).head, false); forEach(( node.template).templateSpans, (child, index) => { write(", "); emitDownlevelRawTemplateLiteral(child.literal, index === ( node.template).templateSpans.length - 1); }); } - write("]"); - if (!inLoop) { - write(";"); - writeLine(); - } - } - - function emitDownlevelTaggedTemplate(node: LiteralExpression | TemplateExpression): void { - // Emit should like: - // foo(tempVar, expressions0, expression1) - emit(( node.parent).tempVariable); + write("], "); + + emit(node.tag); + write("("); + emit(tempVariable); // Now we emit the expressions - if (node.kind === SyntaxKind.TemplateExpression) { - forEach(( node).templateSpans, templateSpan => { + if (node.template.kind === SyntaxKind.TemplateExpression) { + forEach(( node.template).templateSpans, templateSpan => { write(", "); var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression && ( templateSpan.expression).operator === SyntaxKind.CommaToken; emitParenthesized(templateSpan.expression, needsParens); }); } + write("))"); } function emitTemplateExpression(node: TemplateExpression): void { @@ -2144,10 +2120,6 @@ module ts { return; } - if (node.parent.kind === SyntaxKind.TaggedTemplateExpression) { - return emitDownlevelTaggedTemplate(node); - } - var emitOuterParens = isExpression(node.parent) && templateNeedsParens(node, node.parent); @@ -2574,14 +2546,13 @@ module ts { } function emitTaggedTemplateExpression(node: TaggedTemplateExpression): void { - emit(node.tag); if (compilerOptions.target >= ScriptTarget.ES6) { + emit(node.tag); write(" "); emit(node.template); - } else { - write("("); - emitDownlevelTaggedTemplate(node.template); - write(")"); + } + else { + emitDownlevelTaggedTemplate(node); } } @@ -4022,11 +3993,6 @@ module ts { return; } - if (isStatement(node)) { - // TODO: Check whether node is a loop - forEach(( node).downlevelTaggedTemplates, node => emitDownlevelTaggedTemplateStrings(node, false)); - } - if (node.flags & NodeFlags.Ambient) { return emitPinnedOrTripleSlashComments(node); } From 434c908c369e2f837b29650e607baeddc1be25c1 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Mon, 19 Jan 2015 11:45:48 +0100 Subject: [PATCH 11/24] Re-add debug assert & fix indent --- src/compiler/emitter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d0cbbff92f8f7..3631d1f1d1c4f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2061,7 +2061,7 @@ module ts { text = text.substring(1, text.length - (isLast ? 1 : 2)); write('"' + escapeString(text) + '"'); - } + } function emitDownlevelTaggedTemplate(node: TaggedTemplateExpression) { var tempVariable = createTempVariable(node); @@ -2120,6 +2120,8 @@ module ts { return; } + Debug.assert(node.parent.kind !== SyntaxKind.TaggedTemplateExpression); + var emitOuterParens = isExpression(node.parent) && templateNeedsParens(node, node.parent); From cbec9a3a3a4646a660cd32b01f1a6959f9e03dce Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Fri, 23 Jan 2015 15:44:21 +0100 Subject: [PATCH 12/24] Respond to CR --- src/compiler/emitter.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3631d1f1d1c4f..a4374690fb018 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2051,16 +2051,21 @@ module ts { return '"' + escapeString(node.text) + '"'; } - function emitDownlevelRawTemplateLiteral(node: LiteralExpression, isLast: boolean) { + function emitDownlevelRawTemplateLiteral(node: LiteralExpression) { var text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node); // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), // thus we need to remove those characters. // First template piece starts with "`", others with "}" // Last template piece ends with "`", others with "${" + var isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail; text = text.substring(1, text.length - (isLast ? 1 : 2)); - write('"' + escapeString(text) + '"'); + // Newline normalization + text = text.replace(/\r\n?/g, "\n"); + text = escapeString(text); + + write('"' + text + '"'); } function emitDownlevelTaggedTemplate(node: TaggedTemplateExpression) { @@ -2074,8 +2079,8 @@ module ts { emit(node.template); } else { - emit(( node.template).head); - forEach(( node.template).templateSpans, (child) => { + emit((node.template).head); + forEach((node.template).templateSpans, (child) => { write(", "); emit(child.literal); }); @@ -2085,13 +2090,13 @@ module ts { emit(tempVariable); write(".raw = ["); if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { - emitDownlevelRawTemplateLiteral( node.template, true); + emitDownlevelRawTemplateLiteral(node.template); } else { - emitDownlevelRawTemplateLiteral(( node.template).head, false); - forEach(( node.template).templateSpans, (child, index) => { + emitDownlevelRawTemplateLiteral((node.template).head); + forEach((node.template).templateSpans, (child, index) => { write(", "); - emitDownlevelRawTemplateLiteral(child.literal, index === ( node.template).templateSpans.length - 1); + emitDownlevelRawTemplateLiteral(child.literal); }); } write("], "); @@ -2102,10 +2107,10 @@ module ts { // Now we emit the expressions if (node.template.kind === SyntaxKind.TemplateExpression) { - forEach(( node.template).templateSpans, templateSpan => { + forEach((node.template).templateSpans, templateSpan => { write(", "); var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression - && ( templateSpan.expression).operator === SyntaxKind.CommaToken; + && (templateSpan.expression).operator === SyntaxKind.CommaToken; emitParenthesized(templateSpan.expression, needsParens); }); } From 39027d901a8adcc69c7b0d4ce669269406bf40a4 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Fri, 23 Jan 2015 15:46:32 +0100 Subject: [PATCH 13/24] Rename emitParenthesized to emitParenthesizedIf --- src/compiler/emitter.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a4374690fb018..5e7d2d250273b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1953,7 +1953,7 @@ module ts { } } - function emitParenthesized(node: Node, parenthesized: boolean) { + function emitParenthesizedIf(node: Node, parenthesized: boolean) { if (parenthesized) { write("("); } @@ -2111,7 +2111,7 @@ module ts { write(", "); var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression && (templateSpan.expression).operator === SyntaxKind.CommaToken; - emitParenthesized(templateSpan.expression, needsParens); + emitParenthesizedIf(templateSpan.expression, needsParens); }); } write("))"); @@ -2149,7 +2149,7 @@ module ts { var needsParens = templateSpan.expression.kind !== SyntaxKind.ParenthesizedExpression && comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan; write(" + "); - emitParenthesized(templateSpan.expression, needsParens); + emitParenthesizedIf(templateSpan.expression, needsParens); // Only emit if the literal is non-empty. // The binary '+' operator is left-associative, so the first string concatenation // with the head will force the result up to this point to be a string. @@ -2395,7 +2395,7 @@ module ts { var e = elements[pos]; if (e.kind === SyntaxKind.SpreadElementExpression) { e = (e).expression; - emitParenthesized(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccess(e)); + emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccess(e)); pos++; } else { @@ -2703,7 +2703,7 @@ module ts { function emitExpressionStatement(node: ExpressionStatement) { emitLeadingComments(node); - emitParenthesized(node.expression, /*parenthesized*/ node.expression.kind === SyntaxKind.ArrowFunction); + emitParenthesizedIf(node.expression, /*parenthesized*/ node.expression.kind === SyntaxKind.ArrowFunction); write(";"); emitTrailingComments(node); } From 04dd08da70e98aa7e82f0ad23e8f20eb91287050 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Fri, 6 Feb 2015 16:45:26 +0100 Subject: [PATCH 14/24] Resolve missed merge conflict --- src/compiler/emitter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 04a487396e2ea..5059448903c17 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2818,7 +2818,6 @@ module ts { function emitExpressionStatement(node: ExpressionStatement) { emitParenthesizedIf(node.expression, /*parenthesized*/ node.expression.kind === SyntaxKind.ArrowFunction); - emitParenthesized(node.expression, /*parenthesized*/ node.expression.kind === SyntaxKind.ArrowFunction); write(";"); } From 8e16e1d010cca171c1da63bc285c6bccc50049c3 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Fri, 6 Feb 2015 17:02:30 +0100 Subject: [PATCH 15/24] Update baselines --- ...ateStringsTypeArgumentInference.errors.txt | 86 +------------------ ...gedTemplateStringsTypeArgumentInference.js | 57 ++++++------ ...tringsWithIncompatibleTypedTags.errors.txt | 38 +------- ...emplateStringsWithIncompatibleTypedTags.js | 19 ++-- ...ithManyCallAndMemberExpressions.errors.txt | 21 ----- ...StringsWithManyCallAndMemberExpressions.js | 3 +- ...ingsWithManyCallAndMemberExpressions.types | 38 ++++++++ ...eStringsWithOverloadResolution1.errors.txt | 20 +---- ...dTemplateStringsWithOverloadResolution1.js | 13 +-- ...eStringsWithOverloadResolution2.errors.txt | 27 ------ ...dTemplateStringsWithOverloadResolution2.js | 5 +- ...mplateStringsWithOverloadResolution2.types | 60 +++++++++++++ ...eStringsWithOverloadResolution3.errors.txt | 68 +-------------- ...dTemplateStringsWithOverloadResolution3.js | 45 +++++----- ...mplateStringsWithTagsTypedAsAny.errors.txt | 64 -------------- ...taggedTemplateStringsWithTagsTypedAsAny.js | 21 ++--- ...gedTemplateStringsWithTagsTypedAsAny.types | 66 ++++++++++++++ ...essionsInSubstitutionExpression.errors.txt | 5 +- ...tionExpressionsInSubstitutionExpression.js | 5 +- ...gedTemplateStringsWithTypedTags.errors.txt | 64 -------------- .../taggedTemplateStringsWithTypedTags.js | 17 ++-- .../taggedTemplateStringsWithTypedTags.types | 82 ++++++++++++++++++ .../reference/templateStringInModuleName.js | 5 +- .../templateStringInObjectLiteral.js | 5 +- .../templateStringInPropertyName1.js | 3 +- .../templateStringInPropertyName2.js | 3 +- .../templateStringInTaggedTemplate.errors.txt | 7 +- .../templateStringInTaggedTemplate.js | 3 +- ...tringsArrayTypeDefinedInES5Mode.errors.txt | 7 +- ...emplateStringsArrayTypeDefinedInES5Mode.js | 3 +- ...ringsArrayTypeNotDefinedES5Mode.errors.txt | 7 +- ...mplateStringsArrayTypeNotDefinedES5Mode.js | 3 +- 32 files changed, 370 insertions(+), 500 deletions(-) delete mode 100644 tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types delete mode 100644 tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.types delete mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.types delete mode 100644 tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTypedTags.types diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt index 275fdac6ac764..f3706ae8f17de 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt @@ -1,143 +1,69 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(5,10): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(9,17): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(13,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(16,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(20,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(23,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(27,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(28,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(29,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(33,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(34,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(35,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(39,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(40,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(41,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(45,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(46,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(47,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(51,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(52,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(53,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(57,23): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(58,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(64,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(64,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(77,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. Property 'z' is missing in type '{ x: number; y: string; }'. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(77,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(81,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(86,23): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(90,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts (30 errors) ==== +==== tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts (2 errors) ==== // Generic tag with one parameter function noParams(n: T) { } noParams ``; - ~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with parameter which does not use type parameter function noGenericParams(n: string[]) { } noGenericParams ``; - ~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n: T, m: number) { } someGenerics1a `${3}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. function someGenerics1b(n: string[], m: U) { } someGenerics1b `${3}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with argument of function type whose parameter is of type parameter type function someGenerics2a(strs: string[], n: (x: T) => void) { } someGenerics2a `${(n: string) => n}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. function someGenerics2b(strs: string[], n: (x: T, y: U) => void) { } someGenerics2b `${ (n: string, x: number) => n }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter function someGenerics3(strs: string[], producer: () => T) { } someGenerics3 `${() => ''}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics3 `${() => undefined}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics3 `${() => 3}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type function someGenerics4(strs: string[], n: T, f: (x: U) => void) { } someGenerics4 `${4}${ () => null }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics4 `${''}${ () => 3 }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics4 `${ null }${ null }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type function someGenerics5(strs: string[], n: T, f: (x: U) => void) { } someGenerics5 `${ 4 } ${ () => null }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics5 `${ '' }${ () => 3 }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics5 `${null}${null}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with multiple arguments of function types that each have parameters of the same generic type function someGenerics6(strs: string[], a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6 `${ n => n }${ n => n}${ n => n}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics6 `${ n => n }${ n => n}${ n => n}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics6 `${ (n: number) => n }${ (n: number) => n }${ (n: number) => n }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with multiple arguments of function types that each have parameters of different generic type function someGenerics7(strs: string[], a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } someGenerics7 `${ n => n }${ n => n }${ n => n }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics7 `${ n => n }${ n => n }${ n => n }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics7 `${(n: number) => n}${ (n: string) => n}${ (n: number) => n}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with argument of generic function type function someGenerics8(strs: string[], n: T): T { return n; } var x = someGenerics8 `${ someGenerics7 }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. x `${null}${null}${null}`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with multiple parameters of generic type passed arguments with no best common type function someGenerics9(strs: string[], a: T, b: T, c: T): T { @@ -147,8 +73,6 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var a9a: {}; // Generic tag with multiple parameters of generic type passed arguments with multiple best common types @@ -166,27 +90,19 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. !!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var a9e: {}; // Generic tag with multiple parameters of generic type passed arguments with a single best common type var a9d = someGenerics9 `${ { x: 3 }}${ { x: 6 }}${ { x: 6 } }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var a9d: { x: number; }; // Generic tag with multiple parameters of generic type where one argument is of type 'any' var anyVar: any; var a = someGenerics9 `${ 7 }${ anyVar }${ 4 }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var a: any; // Generic tag with multiple parameters of generic type where one argument is [] and the other is not 'any' var arr = someGenerics9 `${ [] }${ null }${ undefined }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var arr: any[]; \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js index 6f3d4ed803a26..04f74aa375256 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js @@ -97,76 +97,77 @@ var arr: any[]; // Generic tag with one parameter function noParams(n) { } -noParams ""; +(_a = [""], _a.raw = [""], noParams(_a)); // Generic tag with parameter which does not use type parameter function noGenericParams(n) { } -noGenericParams ""; +(_b = [""], _b.raw = [""], noGenericParams(_b)); // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n, m) { } -someGenerics1a "" + 3; +(_c = ["", ""], _c.raw = ["", ""], someGenerics1a(_c, 3)); function someGenerics1b(n, m) { } -someGenerics1b "" + 3; +(_d = ["", ""], _d.raw = ["", ""], someGenerics1b(_d, 3)); // Generic tag with argument of function type whose parameter is of type parameter type function someGenerics2a(strs, n) { } -someGenerics2a "" + function (n) { return n; }; +(_e = ["", ""], _e.raw = ["", ""], someGenerics2a(_e, function (n) { return n; })); function someGenerics2b(strs, n) { } -someGenerics2b "" + function (n, x) { return n; }; +(_f = ["", ""], _f.raw = ["", ""], someGenerics2b(_f, function (n, x) { return n; })); // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter function someGenerics3(strs, producer) { } -someGenerics3 "" + function () { return ''; }; -someGenerics3 "" + function () { return undefined; }; -someGenerics3 "" + function () { return 3; }; +(_g = ["", ""], _g.raw = ["", ""], someGenerics3(_g, function () { return ''; })); +(_h = ["", ""], _h.raw = ["", ""], someGenerics3(_h, function () { return undefined; })); +(_j = ["", ""], _j.raw = ["", ""], someGenerics3(_j, function () { return 3; })); // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type function someGenerics4(strs, n, f) { } -someGenerics4 "" + 4 + function () { return null; }; -someGenerics4 "" + '' + function () { return 3; }; -someGenerics4 "" + null + null; +(_k = ["", "", ""], _k.raw = ["", "", ""], someGenerics4(_k, 4, function () { return null; })); +(_l = ["", "", ""], _l.raw = ["", "", ""], someGenerics4(_l, '', function () { return 3; })); +(_m = ["", "", ""], _m.raw = ["", "", ""], someGenerics4(_m, null, null)); // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type function someGenerics5(strs, n, f) { } -someGenerics5 4 + " " + function () { return null; }; -someGenerics5 "" + '' + function () { return 3; }; -someGenerics5 "" + null + null; +(_n = ["", " ", ""], _n.raw = ["", " ", ""], someGenerics5(_n, 4, function () { return null; })); +(_o = ["", "", ""], _o.raw = ["", "", ""], someGenerics5(_o, '', function () { return 3; })); +(_p = ["", "", ""], _p.raw = ["", "", ""], someGenerics5(_p, null, null)); // Generic tag with multiple arguments of function types that each have parameters of the same generic type function someGenerics6(strs, a, b, c) { } -someGenerics6 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; -someGenerics6 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; -someGenerics6 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; +(_q = ["", "", "", ""], _q.raw = ["", "", "", ""], someGenerics6(_q, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); +(_r = ["", "", "", ""], _r.raw = ["", "", "", ""], someGenerics6(_r, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); +(_s = ["", "", "", ""], _s.raw = ["", "", "", ""], someGenerics6(_s, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); // Generic tag with multiple arguments of function types that each have parameters of different generic type function someGenerics7(strs, a, b, c) { } -someGenerics7 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; -someGenerics7 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; -someGenerics7 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; +(_t = ["", "", "", ""], _t.raw = ["", "", "", ""], someGenerics7(_t, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); +(_u = ["", "", "", ""], _u.raw = ["", "", "", ""], someGenerics7(_u, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); +(_v = ["", "", "", ""], _v.raw = ["", "", "", ""], someGenerics7(_v, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); // Generic tag with argument of generic function type function someGenerics8(strs, n) { return n; } -var x = someGenerics8 "" + someGenerics7; -x "" + null + null + null; +var x = (_w = ["", ""], _w.raw = ["", ""], someGenerics8(_w, someGenerics7)); +(_x = ["", "", "", ""], _x.raw = ["", "", "", ""], x(_x, null, null, null)); // Generic tag with multiple parameters of generic type passed arguments with no best common type function someGenerics9(strs, a, b, c) { return null; } -var a9a = someGenerics9 "" + '' + 0 + []; +var a9a = (_y = ["", "", "", ""], _y.raw = ["", "", "", ""], someGenerics9(_y, '', 0, [])); var a9a; -var a9e = someGenerics9 "" + undefined + { x: 6, z: new Date() } + { x: 6, y: '' }; +var a9e = (_z = ["", "", "", ""], _z.raw = ["", "", "", ""], someGenerics9(_z, undefined, { x: 6, z: new Date() }, { x: 6, y: '' })); var a9e; // Generic tag with multiple parameters of generic type passed arguments with a single best common type -var a9d = someGenerics9 "" + { x: 3 } + { x: 6 } + { x: 6 }; +var a9d = (_0 = ["", "", "", ""], _0.raw = ["", "", "", ""], someGenerics9(_0, { x: 3 }, { x: 6 }, { x: 6 })); var a9d; // Generic tag with multiple parameters of generic type where one argument is of type 'any' var anyVar; -var a = someGenerics9 "" + 7 + anyVar + 4; +var a = (_1 = ["", "", "", ""], _1.raw = ["", "", "", ""], someGenerics9(_1, 7, anyVar, 4)); var a; // Generic tag with multiple parameters of generic type where one argument is [] and the other is not 'any' -var arr = someGenerics9 "" + [] + null + undefined; +var arr = (_2 = ["", "", "", ""], _2.raw = ["", "", "", ""], someGenerics9(_2, [], null, undefined)); var arr; +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2; diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt index 6b389218f65d8..166769fbbf53d 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt @@ -1,24 +1,12 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(12,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(14,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(14,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(16,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(18,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(18,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(20,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(22,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(22,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,19): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,25): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,40): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,50): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,57): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts (18 errors) ==== +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts (6 errors) ==== interface I { (stringParts: string[], ...rest: boolean[]): I; g: I; @@ -31,56 +19,32 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTyped var f: I; f `abc` - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc`.member - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`.member; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc`["member"]; - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"]; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc`[0].member `abc${1}def${2}ghi`; - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${ true }def${ true }ghi`["member"].member `abc${ 1 }def${ 2 }ghi`; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js index c3e145afb2b04..9d11379322834 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js @@ -35,14 +35,15 @@ f.thisIsNotATag(`abc${1}def${2}ghi`); //// [taggedTemplateStringsWithIncompatibleTypedTags.js] var f; -f "abc"; -f "abc" + 1 + "def" + 2 + "ghi"; -f "abc".member; -f "abc" + 1 + "def" + 2 + "ghi".member; -f "abc"["member"]; -f "abc" + 1 + "def" + 2 + "ghi"["member"]; -f "abc"[0].member "abc" + 1 + "def" + 2 + "ghi"; -f "abc" + 1 + "def" + 2 + "ghi"["member"].member "abc" + 1 + "def" + 2 + "ghi"; -f "abc" + true + "def" + true + "ghi"["member"].member "abc" + 1 + "def" + 2 + "ghi"; +(_a = ["abc"], _a.raw = ["abc"], f(_a)); +(_b = ["abc", "def", "ghi"], _b.raw = ["abc", "def", "ghi"], f(_b, 1, 2)); +(_c = ["abc"], _c.raw = ["abc"], f(_c)).member; +(_d = ["abc", "def", "ghi"], _d.raw = ["abc", "def", "ghi"], f(_d, 1, 2)).member; +(_e = ["abc"], _e.raw = ["abc"], f(_e))["member"]; +(_f = ["abc", "def", "ghi"], _f.raw = ["abc", "def", "ghi"], f(_f, 1, 2))["member"]; +(_g = ["abc", "def", "ghi"], _g.raw = ["abc", "def", "ghi"], (_h = ["abc"], _h.raw = ["abc"], f(_h))[0].member(_g, 1, 2)); +(_j = ["abc", "def", "ghi"], _j.raw = ["abc", "def", "ghi"], (_k = ["abc", "def", "ghi"], _k.raw = ["abc", "def", "ghi"], f(_k, 1, 2))["member"].member(_j, 1, 2)); +(_l = ["abc", "def", "ghi"], _l.raw = ["abc", "def", "ghi"], (_m = ["abc", "def", "ghi"], _m.raw = ["abc", "def", "ghi"], f(_m, true, true))["member"].member(_l, 1, 2)); f.thisIsNotATag("abc"); f.thisIsNotATag("abc" + 1 + "def" + 2 + "ghi"); +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt deleted file mode 100644 index 17c0b330dbba8..0000000000000 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts(13,23): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts (1 errors) ==== - interface I { - (strs: string[], ...subs: number[]): I; - member: { - new (s: string): { - new (n: number): { - new (): boolean; - } - } - }; - } - var f: I; - - var x = new new new f `abc${ 0 }def`.member("hello")(42) === true; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js index d507e95172135..1814816283bf1 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js @@ -17,4 +17,5 @@ var x = new new new f `abc${ 0 }def`.member("hello")(42) === true; //// [taggedTemplateStringsWithManyCallAndMemberExpressions.js] var f; -var x = new new new f "abc" + 0 + "def".member("hello")(42) === true; +var x = new new new (_a = ["abc", "def"], _a.raw = ["abc", "def"], f(_a, 0)).member("hello")(42) === true; +var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types new file mode 100644 index 0000000000000..6fa83bbde3d3b --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types @@ -0,0 +1,38 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts === +interface I { +>I : I + + (strs: string[], ...subs: number[]): I; +>strs : string[] +>subs : number[] +>I : I + + member: { +>member : new (s: string) => new (n: number) => new () => boolean + + new (s: string): { +>s : string + + new (n: number): { +>n : number + + new (): boolean; + } + } + }; +} +var f: I; +>f : I +>I : I + +var x = new new new f `abc${ 0 }def`.member("hello")(42) === true; +>x : boolean +>new new new f `abc${ 0 }def`.member("hello")(42) === true : boolean +>new new new f `abc${ 0 }def`.member("hello")(42) : boolean +>new new f `abc${ 0 }def`.member("hello")(42) : new () => boolean +>new f `abc${ 0 }def`.member("hello") : new (n: number) => new () => boolean +>f `abc${ 0 }def`.member : new (s: string) => new (n: number) => new () => boolean +>f : I +>member : new (s: string) => new (n: number) => new () => boolean + + diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt index e4c79537ce209..9e450cbb36879 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt @@ -1,16 +1,10 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(12,20): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(14,9): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(16,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(17,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(18,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(19,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(19,20): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(20,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(21,9): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(21,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts (10 errors) ==== +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts (4 errors) ==== function foo(strs: string[]): number; function foo(strs: string[], x: number): string; function foo(strs: string[], x: number, y: number): boolean; @@ -31,25 +25,13 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio !!! error TS2346: Supplied parameters do not match any signature of call target. var u = foo ``; // number - ~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var v = foo `${1}`; // string - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var w = foo `${1}${2}`; // boolean - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var x = foo `${1}${true}`; // boolean (with error) - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~ !!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. var y = foo `${1}${"2"}`; // {} - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var z = foo `${1}${2}${3}`; // any (with error) ~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js index 23298e1df1334..431447df22e38 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js @@ -36,9 +36,10 @@ var c = foo([], 1, 2); // boolean var d = foo([], 1, true); // boolean (with error) var e = foo([], 1, "2"); // {} var f = foo([], 1, 2, 3); // any (with error) -var u = foo ""; // number -var v = foo "" + 1; // string -var w = foo "" + 1 + 2; // boolean -var x = foo "" + 1 + true; // boolean (with error) -var y = foo "" + 1 + "2"; // {} -var z = foo "" + 1 + 2 + 3; // any (with error) +var u = (_a = [""], _a.raw = [""], foo(_a)); // number +var v = (_b = ["", ""], _b.raw = ["", ""], foo(_b, 1)); // string +var w = (_c = ["", "", ""], _c.raw = ["", "", ""], foo(_c, 1, 2)); // boolean +var x = (_d = ["", "", ""], _d.raw = ["", "", ""], foo(_d, 1, true)); // boolean (with error) +var y = (_e = ["", "", ""], _e.raw = ["", "", ""], foo(_e, 1, "2")); // {} +var z = (_f = ["", "", "", ""], _f.raw = ["", "", "", ""], foo(_f, 1, 2, 3)); // any (with error) +var _a, _b, _c, _d, _e, _f; diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.errors.txt deleted file mode 100644 index 3bf4af39779e7..0000000000000 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts(8,14): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts(17,14): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts (2 errors) ==== - - function foo1(strs: TemplateStringsArray, x: number): string; - function foo1(strs: string[], x: number): number; - function foo1(...stuff: any[]): any { - return undefined; - } - - var a = foo1 `${1}`; // string - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - var b = foo1([], 1); // number - - function foo2(strs: string[], x: number): number; - function foo2(strs: TemplateStringsArray, x: number): string; - function foo2(...stuff: any[]): any { - return undefined; - } - - var c = foo2 `${1}`; // number - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - var d = foo2([], 1); // number \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js index 0b1447a3d3ff0..f12008f9581b7 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js @@ -26,7 +26,7 @@ function foo1() { } return undefined; } -var a = foo1 "" + 1; // string +var a = (_a = ["", ""], _a.raw = ["", ""], foo1(_a, 1)); // string var b = foo1([], 1); // number function foo2() { var stuff = []; @@ -35,5 +35,6 @@ function foo2() { } return undefined; } -var c = foo2 "" + 1; // number +var c = (_b = ["", ""], _b.raw = ["", ""], foo2(_b, 1)); // number var d = foo2([], 1); // number +var _a, _b; diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.types b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.types new file mode 100644 index 0000000000000..0863ac3fafc6a --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.types @@ -0,0 +1,60 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts === + +function foo1(strs: TemplateStringsArray, x: number): string; +>foo1 : { (strs: TemplateStringsArray, x: number): string; (strs: string[], x: number): number; } +>strs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>x : number + +function foo1(strs: string[], x: number): number; +>foo1 : { (strs: TemplateStringsArray, x: number): string; (strs: string[], x: number): number; } +>strs : string[] +>x : number + +function foo1(...stuff: any[]): any { +>foo1 : { (strs: TemplateStringsArray, x: number): string; (strs: string[], x: number): number; } +>stuff : any[] + + return undefined; +>undefined : undefined +} + +var a = foo1 `${1}`; // string +>a : string +>foo1 : { (strs: TemplateStringsArray, x: number): string; (strs: string[], x: number): number; } + +var b = foo1([], 1); // number +>b : number +>foo1([], 1) : number +>foo1 : { (strs: TemplateStringsArray, x: number): string; (strs: string[], x: number): number; } +>[] : undefined[] + +function foo2(strs: string[], x: number): number; +>foo2 : { (strs: string[], x: number): number; (strs: TemplateStringsArray, x: number): string; } +>strs : string[] +>x : number + +function foo2(strs: TemplateStringsArray, x: number): string; +>foo2 : { (strs: string[], x: number): number; (strs: TemplateStringsArray, x: number): string; } +>strs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>x : number + +function foo2(...stuff: any[]): any { +>foo2 : { (strs: string[], x: number): number; (strs: TemplateStringsArray, x: number): string; } +>stuff : any[] + + return undefined; +>undefined : undefined +} + +var c = foo2 `${1}`; // number +>c : number +>foo2 : { (strs: string[], x: number): number; (strs: TemplateStringsArray, x: number): string; } + +var d = foo2([], 1); // number +>d : number +>foo2([], 1) : number +>foo2 : { (strs: string[], x: number): number; (strs: TemplateStringsArray, x: number): string; } +>[] : undefined[] + diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.errors.txt index c1a6b228b01c1..0d65c3fd13bd8 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.errors.txt @@ -1,34 +1,12 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(7,21): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(10,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(10,9): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(16,20): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(17,20): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(19,4): error TS2339: Property 'foo' does not exist on type 'Date'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(23,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(26,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(34,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(35,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(36,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(40,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(41,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(42,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(45,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(45,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(54,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(55,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(56,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(57,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(60,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(63,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(63,9): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(64,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(64,18): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(70,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(70,18): error TS2339: Property 'toFixed' does not exist on type 'string'. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(71,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts (28 errors) ==== +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts (6 errors) ==== // Ambiguous call picks the first overload in declaration order function fn1(strs: TemplateStringsArray, s: string): string; @@ -36,13 +14,9 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio function fn1() { return null; } var s: string = fn1 `${ undefined }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // No candidate overloads found fn1 `${ {} }`; // Error - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~ !!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. @@ -51,11 +25,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio function fn2() { return undefined; } var d1: Date = fn2 `${ 0 }${ undefined }`; // contextually typed - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var d2 = fn2 `${ 0 }${ undefined }`; // any - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. d1.foo(); // error ~~~ @@ -64,13 +34,9 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio // Generic and non-generic overload where generic overload is the only candidate fn2 `${ 0 }${ '' }`; // OK - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic and non-generic overload where non-generic overload is the only candidate fn2 `${ '' }${ 0 }`; // OK - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic overloads with differing arity function fn3(strs: TemplateStringsArray, n: T): string; @@ -79,33 +45,19 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio function fn3() { return null; } var s = fn3 `${ 3 }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var s = fn3 `${'' }${ 3 }${ '' }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var n = fn3 `${ 5 }${ 5 }${ 5 }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var n: number; // Generic overloads with differing arity tagging with arguments matching each overload type parameter count var s = fn3 `${ 4 }` - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var s = fn3 `${ '' }${ '' }${ '' }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var n = fn3 `${ '' }${ '' }${ 3 }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic overloads with differing arity tagging with argument count that doesn't match any overload fn3 ``; // Error ~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. - ~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic overloads with constraints function fn4(strs: TemplateStringsArray, n: T, m: U); @@ -115,32 +67,18 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio // Generic overloads with constraints tagged with types that satisfy the constraints fn4 `${ '' }${ 3 }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. fn4 `${ 3 }${ '' }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. fn4 `${ 3 }${ undefined }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. fn4 `${ '' }${ null }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic overloads with constraints called with type arguments that do not satisfy the constraints fn4 `${ null }${ null }`; // Error - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic overloads with constraints called without type arguments but with types that do not satisfy the constraints fn4 `${ true }${ null }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~ !!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number'. fn4 `${ null }${ true }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~ !!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. @@ -149,12 +87,8 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio function fn5(strs: TemplateStringsArray, f: (n: number) => void): number; function fn5() { return undefined; } fn5 `${ (n) => n.toFixed() }`; // will error; 'n' should have type 'string'. - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~~~ !!! error TS2339: Property 'toFixed' does not exist on type 'string'. fn5 `${ (n) => n.substr(0) }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js index dc8a08b4fc449..8c7cb986cd7ba 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js @@ -77,47 +77,48 @@ fn5 `${ (n) => n.substr(0) }`; function fn1() { return null; } -var s = fn1 "" + undefined; +var s = (_a = ["", ""], _a.raw = ["", ""], fn1(_a, undefined)); // No candidate overloads found -fn1 "" + {}; // Error +(_b = ["", ""], _b.raw = ["", ""], fn1(_b, {})); // Error function fn2() { return undefined; } -var d1 = fn2 "" + 0 + undefined; // contextually typed -var d2 = fn2 "" + 0 + undefined; // any +var d1 = (_c = ["", "", ""], _c.raw = ["", "", ""], fn2(_c, 0, undefined)); // contextually typed +var d2 = (_d = ["", "", ""], _d.raw = ["", "", ""], fn2(_d, 0, undefined)); // any d1.foo(); // error d2(); // no error (typed as any) // Generic and non-generic overload where generic overload is the only candidate -fn2 "" + 0 + ''; // OK +(_e = ["", "", ""], _e.raw = ["", "", ""], fn2(_e, 0, '')); // OK // Generic and non-generic overload where non-generic overload is the only candidate -fn2 "" + '' + 0; // OK +(_f = ["", "", ""], _f.raw = ["", "", ""], fn2(_f, '', 0)); // OK function fn3() { return null; } -var s = fn3 "" + 3; -var s = fn3 "" + '' + 3 + ''; -var n = fn3 "" + 5 + 5 + 5; +var s = (_g = ["", ""], _g.raw = ["", ""], fn3(_g, 3)); +var s = (_h = ["", "", "", ""], _h.raw = ["", "", "", ""], fn3(_h, '', 3, '')); +var n = (_j = ["", "", "", ""], _j.raw = ["", "", "", ""], fn3(_j, 5, 5, 5)); var n; // Generic overloads with differing arity tagging with arguments matching each overload type parameter count -var s = fn3 "" + 4; -var s = fn3 "" + '' + '' + ''; -var n = fn3 "" + '' + '' + 3; +var s = (_k = ["", ""], _k.raw = ["", ""], fn3(_k, 4)); +var s = (_l = ["", "", "", ""], _l.raw = ["", "", "", ""], fn3(_l, '', '', '')); +var n = (_m = ["", "", "", ""], _m.raw = ["", "", "", ""], fn3(_m, '', '', 3)); // Generic overloads with differing arity tagging with argument count that doesn't match any overload -fn3 ""; // Error +(_n = [""], _n.raw = [""], fn3(_n)); // Error function fn4() { } // Generic overloads with constraints tagged with types that satisfy the constraints -fn4 "" + '' + 3; -fn4 "" + 3 + ''; -fn4 "" + 3 + undefined; -fn4 "" + '' + null; +(_o = ["", "", ""], _o.raw = ["", "", ""], fn4(_o, '', 3)); +(_p = ["", "", ""], _p.raw = ["", "", ""], fn4(_p, 3, '')); +(_q = ["", "", ""], _q.raw = ["", "", ""], fn4(_q, 3, undefined)); +(_r = ["", "", ""], _r.raw = ["", "", ""], fn4(_r, '', null)); // Generic overloads with constraints called with type arguments that do not satisfy the constraints -fn4 "" + null + null; // Error +(_s = ["", "", ""], _s.raw = ["", "", ""], fn4(_s, null, null)); // Error // Generic overloads with constraints called without type arguments but with types that do not satisfy the constraints -fn4 "" + true + null; -fn4 "" + null + true; +(_t = ["", "", ""], _t.raw = ["", "", ""], fn4(_t, true, null)); +(_u = ["", "", ""], _u.raw = ["", "", ""], fn4(_u, null, true)); function fn5() { return undefined; } -fn5 "" + function (n) { return n.toFixed(); }; // will error; 'n' should have type 'string'. -fn5 "" + function (n) { return n.substr(0); }; +(_v = ["", ""], _v.raw = ["", ""], fn5(_v, function (n) { return n.toFixed(); })); // will error; 'n' should have type 'string'. +(_w = ["", ""], _w.raw = ["", ""], fn5(_w, function (n) { return n.substr(0); })); +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt deleted file mode 100644 index 2557d6cc94ad5..0000000000000 --- a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt +++ /dev/null @@ -1,64 +0,0 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(3,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(5,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(7,7): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(9,7): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(11,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(13,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(15,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(17,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,32): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,46): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts (12 errors) ==== - var f: any; - - f `abc` - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc${1}def${2}ghi`; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f.g.h `abc` - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f.g.h `abc${1}def${2}ghi`; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc`.member - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc${1}def${2}ghi`.member; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc`["member"]; - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc${1}def${2}ghi`["member"]; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc`["member"].someOtherTag `abc${1}def${2}ghi`; - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc${1}def${2}ghi`["member"].someOtherTag `abc${1}def${2}ghi`; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f.thisIsNotATag(`abc`); - - f.thisIsNotATag(`abc${1}def${2}ghi`); \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.js b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.js index d5c6b8b31f6d2..fd83d9d0ba025 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.js @@ -27,15 +27,16 @@ f.thisIsNotATag(`abc${1}def${2}ghi`); //// [taggedTemplateStringsWithTagsTypedAsAny.js] var f; -f "abc"; -f "abc" + 1 + "def" + 2 + "ghi"; -f.g.h "abc"; -f.g.h "abc" + 1 + "def" + 2 + "ghi"; -f "abc".member; -f "abc" + 1 + "def" + 2 + "ghi".member; -f "abc"["member"]; -f "abc" + 1 + "def" + 2 + "ghi"["member"]; -f "abc"["member"].someOtherTag "abc" + 1 + "def" + 2 + "ghi"; -f "abc" + 1 + "def" + 2 + "ghi"["member"].someOtherTag "abc" + 1 + "def" + 2 + "ghi"; +(_a = ["abc"], _a.raw = ["abc"], f(_a)); +(_b = ["abc", "def", "ghi"], _b.raw = ["abc", "def", "ghi"], f(_b, 1, 2)); +(_c = ["abc"], _c.raw = ["abc"], f.g.h(_c)); +(_d = ["abc", "def", "ghi"], _d.raw = ["abc", "def", "ghi"], f.g.h(_d, 1, 2)); +(_e = ["abc"], _e.raw = ["abc"], f(_e)).member; +(_f = ["abc", "def", "ghi"], _f.raw = ["abc", "def", "ghi"], f(_f, 1, 2)).member; +(_g = ["abc"], _g.raw = ["abc"], f(_g))["member"]; +(_h = ["abc", "def", "ghi"], _h.raw = ["abc", "def", "ghi"], f(_h, 1, 2))["member"]; +(_j = ["abc", "def", "ghi"], _j.raw = ["abc", "def", "ghi"], (_k = ["abc"], _k.raw = ["abc"], f(_k))["member"].someOtherTag(_j, 1, 2)); +(_l = ["abc", "def", "ghi"], _l.raw = ["abc", "def", "ghi"], (_m = ["abc", "def", "ghi"], _m.raw = ["abc", "def", "ghi"], f(_m, 1, 2))["member"].someOtherTag(_l, 1, 2)); f.thisIsNotATag("abc"); f.thisIsNotATag("abc" + 1 + "def" + 2 + "ghi"); +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.types b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.types new file mode 100644 index 0000000000000..a9b7c9dfdca60 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.types @@ -0,0 +1,66 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts === +var f: any; +>f : any + +f `abc` +>f : any + +f `abc${1}def${2}ghi`; +>f : any + +f.g.h `abc` +>f.g.h : any +>f.g : any +>f : any +>g : any +>h : any + +f.g.h `abc${1}def${2}ghi`; +>f.g.h : any +>f.g : any +>f : any +>g : any +>h : any + +f `abc`.member +>f `abc`.member : any +>f : any +>member : any + +f `abc${1}def${2}ghi`.member; +>f `abc${1}def${2}ghi`.member : any +>f : any +>member : any + +f `abc`["member"]; +>f `abc`["member"] : any +>f : any + +f `abc${1}def${2}ghi`["member"]; +>f `abc${1}def${2}ghi`["member"] : any +>f : any + +f `abc`["member"].someOtherTag `abc${1}def${2}ghi`; +>f `abc`["member"].someOtherTag : any +>f `abc`["member"] : any +>f : any +>someOtherTag : any + +f `abc${1}def${2}ghi`["member"].someOtherTag `abc${1}def${2}ghi`; +>f `abc${1}def${2}ghi`["member"].someOtherTag : any +>f `abc${1}def${2}ghi`["member"] : any +>f : any +>someOtherTag : any + +f.thisIsNotATag(`abc`); +>f.thisIsNotATag(`abc`) : any +>f.thisIsNotATag : any +>f : any +>thisIsNotATag : any + +f.thisIsNotATag(`abc${1}def${2}ghi`); +>f.thisIsNotATag(`abc${1}def${2}ghi`) : any +>f.thisIsNotATag : any +>f : any +>thisIsNotATag : any + diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt index b38a70ca18b76..88bfac2321188 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.errors.txt @@ -1,15 +1,12 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts(6,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts(6,31): error TS2322: Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts (2 errors) ==== +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts (1 errors) ==== function foo(...rest: any[]) { } foo `${function (x: number) { x = "bad"; } }`; - ~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js index eb46f4b603f4b..10a8f1f2a123b 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js @@ -13,6 +13,7 @@ function foo() { rest[_i - 0] = arguments[_i]; } } -foo "" + function (x) { +(_a = ["", ""], _a.raw = ["", ""], foo(_a, function (x) { x = "bad"; -}; +})); +var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt deleted file mode 100644 index 28050ec96c1a0..0000000000000 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt +++ /dev/null @@ -1,64 +0,0 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(12,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(14,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(16,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(18,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(20,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(22,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,19): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,40): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts (10 errors) ==== - interface I { - (stringParts: string[], ...rest: number[]): I; - g: I; - h: I; - member: I; - thisIsNotATag(x: string): void - [x: number]: I; - } - - var f: I; - - f `abc` - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc${1}def${2}ghi`; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc`.member - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc${1}def${2}ghi`.member; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc`["member"]; - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc${1}def${2}ghi`["member"]; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc`[0].member `abc${1}def${2}ghi`; - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - f.thisIsNotATag(`abc`); - - f.thisIsNotATag(`abc${1}def${2}ghi`); - \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js index c2424a07a47cb..fcc2cda86dc29 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js @@ -33,13 +33,14 @@ f.thisIsNotATag(`abc${1}def${2}ghi`); //// [taggedTemplateStringsWithTypedTags.js] var f; -f "abc"; -f "abc" + 1 + "def" + 2 + "ghi"; -f "abc".member; -f "abc" + 1 + "def" + 2 + "ghi".member; -f "abc"["member"]; -f "abc" + 1 + "def" + 2 + "ghi"["member"]; -f "abc"[0].member "abc" + 1 + "def" + 2 + "ghi"; -f "abc" + 1 + "def" + 2 + "ghi"["member"].member "abc" + 1 + "def" + 2 + "ghi"; +(_a = ["abc"], _a.raw = ["abc"], f(_a)); +(_b = ["abc", "def", "ghi"], _b.raw = ["abc", "def", "ghi"], f(_b, 1, 2)); +(_c = ["abc"], _c.raw = ["abc"], f(_c)).member; +(_d = ["abc", "def", "ghi"], _d.raw = ["abc", "def", "ghi"], f(_d, 1, 2)).member; +(_e = ["abc"], _e.raw = ["abc"], f(_e))["member"]; +(_f = ["abc", "def", "ghi"], _f.raw = ["abc", "def", "ghi"], f(_f, 1, 2))["member"]; +(_g = ["abc", "def", "ghi"], _g.raw = ["abc", "def", "ghi"], (_h = ["abc"], _h.raw = ["abc"], f(_h))[0].member(_g, 1, 2)); +(_j = ["abc", "def", "ghi"], _j.raw = ["abc", "def", "ghi"], (_k = ["abc", "def", "ghi"], _k.raw = ["abc", "def", "ghi"], f(_k, 1, 2))["member"].member(_j, 1, 2)); f.thisIsNotATag("abc"); f.thisIsNotATag("abc" + 1 + "def" + 2 + "ghi"); +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.types b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.types new file mode 100644 index 0000000000000..5c8ba71188bed --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.types @@ -0,0 +1,82 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts === +interface I { +>I : I + + (stringParts: string[], ...rest: number[]): I; +>stringParts : string[] +>rest : number[] +>I : I + + g: I; +>g : I +>I : I + + h: I; +>h : I +>I : I + + member: I; +>member : I +>I : I + + thisIsNotATag(x: string): void +>thisIsNotATag : (x: string) => void +>x : string + + [x: number]: I; +>x : number +>I : I +} + +var f: I; +>f : I +>I : I + +f `abc` +>f : I + +f `abc${1}def${2}ghi`; +>f : I + +f `abc`.member +>f `abc`.member : I +>f : I +>member : I + +f `abc${1}def${2}ghi`.member; +>f `abc${1}def${2}ghi`.member : I +>f : I +>member : I + +f `abc`["member"]; +>f `abc`["member"] : I +>f : I + +f `abc${1}def${2}ghi`["member"]; +>f `abc${1}def${2}ghi`["member"] : I +>f : I + +f `abc`[0].member `abc${1}def${2}ghi`; +>f `abc`[0].member : I +>f `abc`[0] : I +>f : I +>member : I + +f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; +>f `abc${1}def${2}ghi`["member"].member : I +>f `abc${1}def${2}ghi`["member"] : I +>f : I +>member : I + +f.thisIsNotATag(`abc`); +>f.thisIsNotATag(`abc`) : void +>f.thisIsNotATag : (x: string) => void +>f : I +>thisIsNotATag : (x: string) => void + +f.thisIsNotATag(`abc${1}def${2}ghi`); +>f.thisIsNotATag(`abc${1}def${2}ghi`) : void +>f.thisIsNotATag : (x: string) => void +>f : I +>thisIsNotATag : (x: string) => void + diff --git a/tests/baselines/reference/templateStringInModuleName.js b/tests/baselines/reference/templateStringInModuleName.js index 561f308a3d0e0..36f619176e435 100644 --- a/tests/baselines/reference/templateStringInModuleName.js +++ b/tests/baselines/reference/templateStringInModuleName.js @@ -7,10 +7,11 @@ declare module `M${2}` { //// [templateStringInModuleName.js] declare; -module "M1"; +(_a = ["M1"], _a.raw = ["M1"], module(_a)); { } declare; -module "M" + 2; +(_b = ["M", ""], _b.raw = ["M", ""], module(_b, 2)); { } +var _a, _b; diff --git a/tests/baselines/reference/templateStringInObjectLiteral.js b/tests/baselines/reference/templateStringInObjectLiteral.js index b026aedf4d311..0381e9a95e7c9 100644 --- a/tests/baselines/reference/templateStringInObjectLiteral.js +++ b/tests/baselines/reference/templateStringInObjectLiteral.js @@ -5,7 +5,8 @@ var x = { } //// [templateStringInObjectLiteral.js] -var x = { +var x = (_a = ["b"], _a.raw = ["b"], { a: "abc" + 123 + "def" -} "b"; +}(_a)); 321; +var _a; diff --git a/tests/baselines/reference/templateStringInPropertyName1.js b/tests/baselines/reference/templateStringInPropertyName1.js index 5a396398f6772..239ba78d82739 100644 --- a/tests/baselines/reference/templateStringInPropertyName1.js +++ b/tests/baselines/reference/templateStringInPropertyName1.js @@ -4,5 +4,6 @@ var x = { } //// [templateStringInPropertyName1.js] -var x = {} "a"; +var x = (_a = ["a"], _a.raw = ["a"], {}(_a)); 321; +var _a; diff --git a/tests/baselines/reference/templateStringInPropertyName2.js b/tests/baselines/reference/templateStringInPropertyName2.js index 623f6a69a41c4..8a71a6e30be5c 100644 --- a/tests/baselines/reference/templateStringInPropertyName2.js +++ b/tests/baselines/reference/templateStringInPropertyName2.js @@ -4,5 +4,6 @@ var x = { } //// [templateStringInPropertyName2.js] -var x = {} "abc" + 123 + "def" + 456 + "ghi"; +var x = (_a = ["abc", "def", "ghi"], _a.raw = ["abc", "def", "ghi"], {}(_a, 123, 456)); 321; +var _a; diff --git a/tests/baselines/reference/templateStringInTaggedTemplate.errors.txt b/tests/baselines/reference/templateStringInTaggedTemplate.errors.txt index 9106cdb615182..18ce24a0b3b50 100644 --- a/tests/baselines/reference/templateStringInTaggedTemplate.errors.txt +++ b/tests/baselines/reference/templateStringInTaggedTemplate.errors.txt @@ -1,10 +1,7 @@ tests/cases/conformance/es6/templates/templateStringInTaggedTemplate.ts(1,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. -tests/cases/conformance/es6/templates/templateStringInTaggedTemplate.ts(1,42): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -==== tests/cases/conformance/es6/templates/templateStringInTaggedTemplate.ts (2 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInTaggedTemplate.ts (1 errors) ==== `I AM THE ${ `${ `TAG` } ` } PORTION` `I ${ "AM" } THE TEMPLATE PORTION` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. - ~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInTaggedTemplate.js b/tests/baselines/reference/templateStringInTaggedTemplate.js index c6d98b0f82663..61964b06d473f 100644 --- a/tests/baselines/reference/templateStringInTaggedTemplate.js +++ b/tests/baselines/reference/templateStringInTaggedTemplate.js @@ -2,4 +2,5 @@ `I AM THE ${ `${ `TAG` } ` } PORTION` `I ${ "AM" } THE TEMPLATE PORTION` //// [templateStringInTaggedTemplate.js] -"I AM THE " + "TAG" + " " + " PORTION" "I " + "AM" + " THE TEMPLATE PORTION"; +(_a = ["I ", " THE TEMPLATE PORTION"], _a.raw = ["I ", " THE TEMPLATE PORTION"], "I AM THE " + "TAG" + " " + " PORTION"(_a, "AM")); +var _a; diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt index 61b82bcb459ca..7ac2eff865299 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt @@ -2,10 +2,9 @@ lib.d.ts(515,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. Property 'raw' is missing in type '{ [x: number]: undefined; }'. -tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(10,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -==== tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts (3 errors) ==== +==== tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts (2 errors) ==== class TemplateStringsArray { ~~~~~~~~~~~~~~~~~~~~ @@ -20,6 +19,4 @@ tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(10,3): error TS !!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. !!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. - f `abcdef${ 1234 }${ 5678 }ghijkl`; - ~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file + f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.js b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.js index a724943c0f3e8..5d5f925fe69af 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.js +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.js @@ -19,4 +19,5 @@ var TemplateStringsArray = (function () { function f(x, y, z) { } f({}, 10, 10); -f "abcdef" + 1234 + 5678 + "ghijkl"; +(_a = ["abcdef", "", "ghijkl"], _a.raw = ["abcdef", "", "ghijkl"], f(_a, 1234, 5678)); +var _a; diff --git a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt index b233ad963c706..e8bf38c104861 100644 --- a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt @@ -1,9 +1,8 @@ tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(5,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. Property 'raw' is missing in type '{ [x: number]: undefined; }'. -tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(7,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -==== tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts (2 errors) ==== +==== tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts (1 errors) ==== function f(x: TemplateStringsArray, y: number, z: number) { } @@ -13,6 +12,4 @@ tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(7,3): error TS !!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. !!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. - f `abcdef${ 1234 }${ 5678 }ghijkl`; - ~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file + f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.js b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.js index c6cc4ee8408f8..69d61d7955461 100644 --- a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.js +++ b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.js @@ -11,4 +11,5 @@ f `abcdef${ 1234 }${ 5678 }ghijkl`; function f(x, y, z) { } f({}, 10, 10); -f "abcdef" + 1234 + 5678 + "ghijkl"; +(_a = ["abcdef", "", "ghijkl"], _a.raw = ["abcdef", "", "ghijkl"], f(_a, 1234, 5678)); +var _a; From f77bedd6f671a8a70c0baa4ec3558f8628177de0 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Fri, 13 Feb 2015 18:34:32 +0100 Subject: [PATCH 16/24] Emit parens for tag of tagged template if necessary --- src/compiler/emitter.ts | 6 +++--- tests/baselines/reference/templateStringInObjectLiteral.js | 4 ++-- tests/baselines/reference/templateStringInPropertyName1.js | 2 +- tests/baselines/reference/templateStringInPropertyName2.js | 2 +- tests/baselines/reference/templateStringInTaggedTemplate.js | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5059448903c17..108fa8a5e4110 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2189,7 +2189,7 @@ module ts { } write("], "); - emit(node.tag); + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); write("("); emit(tempVariable); @@ -2475,7 +2475,7 @@ module ts { emit((node).expression); } - function needsParenthesisForPropertyAccess(node: Expression) { + function needsParenthesisForPropertyAccessOrInvocation(node: Expression) { switch (node.kind) { case SyntaxKind.Identifier: case SyntaxKind.ArrayLiteralExpression: @@ -2517,7 +2517,7 @@ module ts { var e = elements[pos]; if (e.kind === SyntaxKind.SpreadElementExpression) { e = (e).expression; - emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccess(e)); + emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; } else { diff --git a/tests/baselines/reference/templateStringInObjectLiteral.js b/tests/baselines/reference/templateStringInObjectLiteral.js index 0381e9a95e7c9..5a096b0adface 100644 --- a/tests/baselines/reference/templateStringInObjectLiteral.js +++ b/tests/baselines/reference/templateStringInObjectLiteral.js @@ -5,8 +5,8 @@ var x = { } //// [templateStringInObjectLiteral.js] -var x = (_a = ["b"], _a.raw = ["b"], { +var x = (_a = ["b"], _a.raw = ["b"], ({ a: "abc" + 123 + "def" -}(_a)); +})(_a)); 321; var _a; diff --git a/tests/baselines/reference/templateStringInPropertyName1.js b/tests/baselines/reference/templateStringInPropertyName1.js index 239ba78d82739..18e35c475e380 100644 --- a/tests/baselines/reference/templateStringInPropertyName1.js +++ b/tests/baselines/reference/templateStringInPropertyName1.js @@ -4,6 +4,6 @@ var x = { } //// [templateStringInPropertyName1.js] -var x = (_a = ["a"], _a.raw = ["a"], {}(_a)); +var x = (_a = ["a"], _a.raw = ["a"], ({})(_a)); 321; var _a; diff --git a/tests/baselines/reference/templateStringInPropertyName2.js b/tests/baselines/reference/templateStringInPropertyName2.js index 8a71a6e30be5c..1a2995ca08fe5 100644 --- a/tests/baselines/reference/templateStringInPropertyName2.js +++ b/tests/baselines/reference/templateStringInPropertyName2.js @@ -4,6 +4,6 @@ var x = { } //// [templateStringInPropertyName2.js] -var x = (_a = ["abc", "def", "ghi"], _a.raw = ["abc", "def", "ghi"], {}(_a, 123, 456)); +var x = (_a = ["abc", "def", "ghi"], _a.raw = ["abc", "def", "ghi"], ({})(_a, 123, 456)); 321; var _a; diff --git a/tests/baselines/reference/templateStringInTaggedTemplate.js b/tests/baselines/reference/templateStringInTaggedTemplate.js index 61964b06d473f..3ba70ba84b637 100644 --- a/tests/baselines/reference/templateStringInTaggedTemplate.js +++ b/tests/baselines/reference/templateStringInTaggedTemplate.js @@ -2,5 +2,5 @@ `I AM THE ${ `${ `TAG` } ` } PORTION` `I ${ "AM" } THE TEMPLATE PORTION` //// [templateStringInTaggedTemplate.js] -(_a = ["I ", " THE TEMPLATE PORTION"], _a.raw = ["I ", " THE TEMPLATE PORTION"], "I AM THE " + "TAG" + " " + " PORTION"(_a, "AM")); +(_a = ["I ", " THE TEMPLATE PORTION"], _a.raw = ["I ", " THE TEMPLATE PORTION"], ("I AM THE " + "TAG" + " " + " PORTION")(_a, "AM")); var _a; From c4008c3497d3f8d2a4e86bc606552f1047009b1a Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Mon, 16 Feb 2015 20:16:13 +0100 Subject: [PATCH 17/24] Update tests Fixed merge conflicts in tests --- ...gedTemplateStringsTypeArgumentInference.js | 76 +++---------------- ...dTemplateStringsWithOverloadResolution3.js | 6 -- 2 files changed, 11 insertions(+), 71 deletions(-) diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js index 8ea5185335010..5b078893c6e3d 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js @@ -95,100 +95,46 @@ var arr: any[]; //// [taggedTemplateStringsTypeArgumentInference.js] // Generic tag with one parameter -<<<<<<< HEAD -function noParams(n) { -} +function noParams(n) { } (_a = [""], _a.raw = [""], noParams(_a)); // Generic tag with parameter which does not use type parameter -function noGenericParams(n) { -} +function noGenericParams(n) { } (_b = [""], _b.raw = [""], noGenericParams(_b)); // Generic tag with multiple type parameters and only one used in parameter type annotation -function someGenerics1a(n, m) { -} +function someGenerics1a(n, m) { } (_c = ["", ""], _c.raw = ["", ""], someGenerics1a(_c, 3)); -function someGenerics1b(n, m) { -} +function someGenerics1b(n, m) { } (_d = ["", ""], _d.raw = ["", ""], someGenerics1b(_d, 3)); // Generic tag with argument of function type whose parameter is of type parameter type -function someGenerics2a(strs, n) { -} +function someGenerics2a(strs, n) { } (_e = ["", ""], _e.raw = ["", ""], someGenerics2a(_e, function (n) { return n; })); -function someGenerics2b(strs, n) { -} +function someGenerics2b(strs, n) { } (_f = ["", ""], _f.raw = ["", ""], someGenerics2b(_f, function (n, x) { return n; })); // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter -function someGenerics3(strs, producer) { -} +function someGenerics3(strs, producer) { } (_g = ["", ""], _g.raw = ["", ""], someGenerics3(_g, function () { return ''; })); (_h = ["", ""], _h.raw = ["", ""], someGenerics3(_h, function () { return undefined; })); (_j = ["", ""], _j.raw = ["", ""], someGenerics3(_j, function () { return 3; })); // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type -function someGenerics4(strs, n, f) { -} +function someGenerics4(strs, n, f) { } (_k = ["", "", ""], _k.raw = ["", "", ""], someGenerics4(_k, 4, function () { return null; })); (_l = ["", "", ""], _l.raw = ["", "", ""], someGenerics4(_l, '', function () { return 3; })); (_m = ["", "", ""], _m.raw = ["", "", ""], someGenerics4(_m, null, null)); // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type -function someGenerics5(strs, n, f) { -} +function someGenerics5(strs, n, f) { } (_n = ["", " ", ""], _n.raw = ["", " ", ""], someGenerics5(_n, 4, function () { return null; })); (_o = ["", "", ""], _o.raw = ["", "", ""], someGenerics5(_o, '', function () { return 3; })); (_p = ["", "", ""], _p.raw = ["", "", ""], someGenerics5(_p, null, null)); // Generic tag with multiple arguments of function types that each have parameters of the same generic type -function someGenerics6(strs, a, b, c) { -} +function someGenerics6(strs, a, b, c) { } (_q = ["", "", "", ""], _q.raw = ["", "", "", ""], someGenerics6(_q, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); (_r = ["", "", "", ""], _r.raw = ["", "", "", ""], someGenerics6(_r, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); (_s = ["", "", "", ""], _s.raw = ["", "", "", ""], someGenerics6(_s, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); // Generic tag with multiple arguments of function types that each have parameters of different generic type -function someGenerics7(strs, a, b, c) { -} +function someGenerics7(strs, a, b, c) { } (_t = ["", "", "", ""], _t.raw = ["", "", "", ""], someGenerics7(_t, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); (_u = ["", "", "", ""], _u.raw = ["", "", "", ""], someGenerics7(_u, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); (_v = ["", "", "", ""], _v.raw = ["", "", "", ""], someGenerics7(_v, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); -======= -function noParams(n) { } -noParams ""; -// Generic tag with parameter which does not use type parameter -function noGenericParams(n) { } -noGenericParams ""; -// Generic tag with multiple type parameters and only one used in parameter type annotation -function someGenerics1a(n, m) { } -someGenerics1a "" + 3; -function someGenerics1b(n, m) { } -someGenerics1b "" + 3; -// Generic tag with argument of function type whose parameter is of type parameter type -function someGenerics2a(strs, n) { } -someGenerics2a "" + function (n) { return n; }; -function someGenerics2b(strs, n) { } -someGenerics2b "" + function (n, x) { return n; }; -// Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter -function someGenerics3(strs, producer) { } -someGenerics3 "" + function () { return ''; }; -someGenerics3 "" + function () { return undefined; }; -someGenerics3 "" + function () { return 3; }; -// 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type -function someGenerics4(strs, n, f) { } -someGenerics4 "" + 4 + function () { return null; }; -someGenerics4 "" + '' + function () { return 3; }; -someGenerics4 "" + null + null; -// 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type -function someGenerics5(strs, n, f) { } -someGenerics5 4 + " " + function () { return null; }; -someGenerics5 "" + '' + function () { return 3; }; -someGenerics5 "" + null + null; -// Generic tag with multiple arguments of function types that each have parameters of the same generic type -function someGenerics6(strs, a, b, c) { } -someGenerics6 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; -someGenerics6 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; -someGenerics6 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; -// Generic tag with multiple arguments of function types that each have parameters of different generic type -function someGenerics7(strs, a, b, c) { } -someGenerics7 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; -someGenerics7 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; -someGenerics7 "" + function (n) { return n; } + function (n) { return n; } + function (n) { return n; }; ->>>>>>> master // Generic tag with argument of generic function type function someGenerics8(strs, n) { return n; diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js index 3ef61d2c66b49..dfb4bf43b3554 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js @@ -103,14 +103,8 @@ var s = (_k = ["", ""], _k.raw = ["", ""], fn3(_k, 4)); var s = (_l = ["", "", "", ""], _l.raw = ["", "", "", ""], fn3(_l, '', '', '')); var n = (_m = ["", "", "", ""], _m.raw = ["", "", "", ""], fn3(_m, '', '', 3)); // Generic overloads with differing arity tagging with argument count that doesn't match any overload -<<<<<<< HEAD (_n = [""], _n.raw = [""], fn3(_n)); // Error -function fn4() { -} -======= -fn3 ""; // Error function fn4() { } ->>>>>>> master // Generic overloads with constraints tagged with types that satisfy the constraints (_o = ["", "", ""], _o.raw = ["", "", ""], fn4(_o, '', 3)); (_p = ["", "", ""], _p.raw = ["", "", ""], fn4(_p, 3, '')); From f8832598b9ad094774bad6470d2661ed6abeb4cd Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Sat, 21 Feb 2015 14:48:10 +0100 Subject: [PATCH 18/24] Add tests for tagged templates --- .../taggedTemplateStringsHexadecimalEscapes.js | 15 +++++++++++++++ ...ggedTemplateStringsHexadecimalEscapes.types | 9 +++++++++ ...ggedTemplateStringsHexadecimalEscapesES6.js | 10 ++++++++++ ...dTemplateStringsHexadecimalEscapesES6.types | 9 +++++++++ ...ggedTemplateStringsWithMultilineTemplate.js | 18 ++++++++++++++++++ ...dTemplateStringsWithMultilineTemplate.types | 12 ++++++++++++ ...dTemplateStringsWithMultilineTemplateES6.js | 16 ++++++++++++++++ ...mplateStringsWithMultilineTemplateES6.types | 12 ++++++++++++ ...emplateStringsWithUnicodeEscapes.errors.txt | 10 ++++++++++ .../taggedTemplateStringsWithUnicodeEscapes.js | 15 +++++++++++++++ ...lateStringsWithUnicodeEscapesES6.errors.txt | 10 ++++++++++ ...ggedTemplateStringsWithUnicodeEscapesES6.js | 10 ++++++++++ ...ggedTemplateStringsWithWhitespaceEscapes.js | 15 +++++++++++++++ ...dTemplateStringsWithWhitespaceEscapes.types | 9 +++++++++ ...dTemplateStringsWithWhitespaceEscapesES6.js | 10 ++++++++++ ...mplateStringsWithWhitespaceEscapesES6.types | 9 +++++++++ .../taggedTemplateStringsHexadecimalEscapes.ts | 4 ++++ ...ggedTemplateStringsHexadecimalEscapesES6.ts | 5 +++++ ...ggedTemplateStringsWithMultilineTemplate.ts | 7 +++++++ ...dTemplateStringsWithMultilineTemplateES6.ts | 8 ++++++++ .../taggedTemplateStringsWithUnicodeEscapes.ts | 4 ++++ ...ggedTemplateStringsWithUnicodeEscapesES6.ts | 5 +++++ ...ggedTemplateStringsWithWhitespaceEscapes.ts | 4 ++++ ...dTemplateStringsWithWhitespaceEscapesES6.ts | 5 +++++ 24 files changed, 231 insertions(+) create mode 100644 tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js create mode 100644 tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.types create mode 100644 tests/baselines/reference/taggedTemplateStringsHexadecimalEscapesES6.js create mode 100644 tests/baselines/reference/taggedTemplateStringsHexadecimalEscapesES6.types create mode 100644 tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.types create mode 100644 tests/baselines/reference/taggedTemplateStringsWithMultilineTemplateES6.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithMultilineTemplateES6.types create mode 100644 tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapesES6.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapesES6.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.types create mode 100644 tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapesES6.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapesES6.types create mode 100644 tests/cases/compiler/taggedTemplateStringsHexadecimalEscapes.ts create mode 100644 tests/cases/compiler/taggedTemplateStringsHexadecimalEscapesES6.ts create mode 100644 tests/cases/compiler/taggedTemplateStringsWithMultilineTemplate.ts create mode 100644 tests/cases/compiler/taggedTemplateStringsWithMultilineTemplateES6.ts create mode 100644 tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapes.ts create mode 100644 tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapesES6.ts create mode 100644 tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapes.ts create mode 100644 tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapesES6.ts diff --git a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js new file mode 100644 index 0000000000000..e4482ded0c2dd --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js @@ -0,0 +1,15 @@ +//// [taggedTemplateStringsHexadecimalEscapes.ts] +function f(...args: any[]) { +} + +f `\x0D${ "Interrupted CRLF" }\x0A`; + +//// [taggedTemplateStringsHexadecimalEscapes.js] +function f() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } +} +(_a = ["\r", "\n"], _a.raw = ["\\x0D", "\\x0A"], f(_a, "Interrupted CRLF")); +var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.types b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.types new file mode 100644 index 0000000000000..37f583efd5901 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/taggedTemplateStringsHexadecimalEscapes.ts === +function f(...args: any[]) { +>f : (...args: any[]) => void +>args : any[] +} + +f `\x0D${ "Interrupted CRLF" }\x0A`; +>f : (...args: any[]) => void + diff --git a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapesES6.js b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapesES6.js new file mode 100644 index 0000000000000..31a0358973f17 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapesES6.js @@ -0,0 +1,10 @@ +//// [taggedTemplateStringsHexadecimalEscapesES6.ts] +function f(...args: any[]) { +} + +f `\x0D${ "Interrupted CRLF" }\x0A`; + +//// [taggedTemplateStringsHexadecimalEscapesES6.js] +function f(...args) { +} +f `\x0D${"Interrupted CRLF"}\x0A`; diff --git a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapesES6.types b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapesES6.types new file mode 100644 index 0000000000000..b96c0664e2f77 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapesES6.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/taggedTemplateStringsHexadecimalEscapesES6.ts === +function f(...args: any[]) { +>f : (...args: any[]) => void +>args : any[] +} + +f `\x0D${ "Interrupted CRLF" }\x0A`; +>f : (...args: any[]) => void + diff --git a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js new file mode 100644 index 0000000000000..cee9d1efce431 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js @@ -0,0 +1,18 @@ +//// [taggedTemplateStringsWithMultilineTemplate.ts] +function f(...args: any[]): void { +} + +f ` +\ + +`; + +//// [taggedTemplateStringsWithMultilineTemplate.js] +function f() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } +} +(_a = ["\n\n"], _a.raw = ["\n\\\n\n"], f(_a)); +var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.types b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.types new file mode 100644 index 0000000000000..ec687ac0fae4b --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/taggedTemplateStringsWithMultilineTemplate.ts === +function f(...args: any[]): void { +>f : (...args: any[]) => void +>args : any[] +} + +f ` +>f : (...args: any[]) => void + +\ + +`; diff --git a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplateES6.js b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplateES6.js new file mode 100644 index 0000000000000..f1d0fb896da09 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplateES6.js @@ -0,0 +1,16 @@ +//// [taggedTemplateStringsWithMultilineTemplateES6.ts] +function f(...args: any[]): void { +} + +f ` +\ + +`; + +//// [taggedTemplateStringsWithMultilineTemplateES6.js] +function f(...args) { +} +f ` +\ + +`; diff --git a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplateES6.types b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplateES6.types new file mode 100644 index 0000000000000..7047f7194c30b --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplateES6.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/taggedTemplateStringsWithMultilineTemplateES6.ts === +function f(...args: any[]): void { +>f : (...args: any[]) => void +>args : any[] +} + +f ` +>f : (...args: any[]) => void + +\ + +`; diff --git a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.errors.txt new file mode 100644 index 0000000000000..df3def2cb2229 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapes.ts(4,7): error TS1125: Hexadecimal digit expected. + + +==== tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapes.ts (1 errors) ==== + function f(...args: any[]) { + } + + f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`; + +!!! error TS1125: Hexadecimal digit expected. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js new file mode 100644 index 0000000000000..75ea677551104 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js @@ -0,0 +1,15 @@ +//// [taggedTemplateStringsWithUnicodeEscapes.ts] +function f(...args: any[]) { +} + +f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`; + +//// [taggedTemplateStringsWithUnicodeEscapes.js] +function f() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } +} +(_a = ["'{1f4a\u0039}'", "'πŸ’©'"], _a.raw = ["'\\u{1f4a\u0039}'", "'\\uD83D\\uDCA\u0039'"], f(_a, " should be converted to ")); +var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapesES6.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapesES6.errors.txt new file mode 100644 index 0000000000000..c48b43dc3ff88 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapesES6.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapesES6.ts(4,7): error TS1125: Hexadecimal digit expected. + + +==== tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapesES6.ts (1 errors) ==== + function f(...args: any[]) { + } + + f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`; + +!!! error TS1125: Hexadecimal digit expected. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapesES6.js b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapesES6.js new file mode 100644 index 0000000000000..6ca5fa5b03ab9 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapesES6.js @@ -0,0 +1,10 @@ +//// [taggedTemplateStringsWithUnicodeEscapesES6.ts] +function f(...args: any[]) { +} + +f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`; + +//// [taggedTemplateStringsWithUnicodeEscapesES6.js] +function f(...args) { +} +f `'\u{1f4a9}'${" should be converted to "}'\uD83D\uDCA9'`; diff --git a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js new file mode 100644 index 0000000000000..65af8da59f997 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js @@ -0,0 +1,15 @@ +//// [taggedTemplateStringsWithWhitespaceEscapes.ts] +function f(...args: any[]) { +} + +f `\t\n\v\f\r\\`; + +//// [taggedTemplateStringsWithWhitespaceEscapes.js] +function f() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } +} +(_a = ["\t\n\v\f\r\\"], _a.raw = ["\\t\\n\\v\\f\\r\\\\"], f(_a)); +var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.types b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.types new file mode 100644 index 0000000000000..89027983cbae9 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapes.ts === +function f(...args: any[]) { +>f : (...args: any[]) => void +>args : any[] +} + +f `\t\n\v\f\r\\`; +>f : (...args: any[]) => void + diff --git a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapesES6.js b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapesES6.js new file mode 100644 index 0000000000000..09a4aa765b443 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapesES6.js @@ -0,0 +1,10 @@ +//// [taggedTemplateStringsWithWhitespaceEscapesES6.ts] +function f(...args: any[]) { +} + +f `\t\n\v\f\r\\`; + +//// [taggedTemplateStringsWithWhitespaceEscapesES6.js] +function f(...args) { +} +f `\t\n\v\f\r\\`; diff --git a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapesES6.types b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapesES6.types new file mode 100644 index 0000000000000..5aeef9207ebe8 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapesES6.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapesES6.ts === +function f(...args: any[]) { +>f : (...args: any[]) => void +>args : any[] +} + +f `\t\n\v\f\r\\`; +>f : (...args: any[]) => void + diff --git a/tests/cases/compiler/taggedTemplateStringsHexadecimalEscapes.ts b/tests/cases/compiler/taggedTemplateStringsHexadecimalEscapes.ts new file mode 100644 index 0000000000000..09f9200f8051a --- /dev/null +++ b/tests/cases/compiler/taggedTemplateStringsHexadecimalEscapes.ts @@ -0,0 +1,4 @@ +function f(...args: any[]) { +} + +f `\x0D${ "Interrupted CRLF" }\x0A`; \ No newline at end of file diff --git a/tests/cases/compiler/taggedTemplateStringsHexadecimalEscapesES6.ts b/tests/cases/compiler/taggedTemplateStringsHexadecimalEscapesES6.ts new file mode 100644 index 0000000000000..38c8e09f6cc03 --- /dev/null +++ b/tests/cases/compiler/taggedTemplateStringsHexadecimalEscapesES6.ts @@ -0,0 +1,5 @@ +//@target: es6 +function f(...args: any[]) { +} + +f `\x0D${ "Interrupted CRLF" }\x0A`; \ No newline at end of file diff --git a/tests/cases/compiler/taggedTemplateStringsWithMultilineTemplate.ts b/tests/cases/compiler/taggedTemplateStringsWithMultilineTemplate.ts new file mode 100644 index 0000000000000..80aeabb94d4fb --- /dev/null +++ b/tests/cases/compiler/taggedTemplateStringsWithMultilineTemplate.ts @@ -0,0 +1,7 @@ +function f(...args: any[]): void { +} + +f ` +\ + +`; \ No newline at end of file diff --git a/tests/cases/compiler/taggedTemplateStringsWithMultilineTemplateES6.ts b/tests/cases/compiler/taggedTemplateStringsWithMultilineTemplateES6.ts new file mode 100644 index 0000000000000..7478e3dd403c1 --- /dev/null +++ b/tests/cases/compiler/taggedTemplateStringsWithMultilineTemplateES6.ts @@ -0,0 +1,8 @@ +//@target: es6 +function f(...args: any[]): void { +} + +f ` +\ + +`; \ No newline at end of file diff --git a/tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapes.ts b/tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapes.ts new file mode 100644 index 0000000000000..f035371332835 --- /dev/null +++ b/tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapes.ts @@ -0,0 +1,4 @@ +function f(...args: any[]) { +} + +f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`; \ No newline at end of file diff --git a/tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapesES6.ts b/tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapesES6.ts new file mode 100644 index 0000000000000..039f723780f01 --- /dev/null +++ b/tests/cases/compiler/taggedTemplateStringsWithUnicodeEscapesES6.ts @@ -0,0 +1,5 @@ +//@target: es6 +function f(...args: any[]) { +} + +f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`; \ No newline at end of file diff --git a/tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapes.ts b/tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapes.ts new file mode 100644 index 0000000000000..f2c2ba315e47b --- /dev/null +++ b/tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapes.ts @@ -0,0 +1,4 @@ +function f(...args: any[]) { +} + +f `\t\n\v\f\r\\`; \ No newline at end of file diff --git a/tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapesES6.ts b/tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapesES6.ts new file mode 100644 index 0000000000000..8519d85d79bbb --- /dev/null +++ b/tests/cases/compiler/taggedTemplateStringsWithWhitespaceEscapesES6.ts @@ -0,0 +1,5 @@ +//@target: es6 +function f(...args: any[]) { +} + +f `\t\n\v\f\r\\`; \ No newline at end of file From 35c815ef15a4ff031d500d1efeb39d2d902d7776 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Sun, 22 Feb 2015 10:07:32 +0100 Subject: [PATCH 19/24] Respond to code review --- src/compiler/emitter.ts | 49 +++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 05969877cf15e..0eb3dbd0e54cf 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2140,6 +2140,9 @@ module ts { } function emitDownlevelRawTemplateLiteral(node: LiteralExpression) { + // Find original source text, since we need to emit the raw strings of the tagged template. + // The raw strings contain the (escaped) strings of what the user wrote. + // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". var text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node); // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), @@ -2149,45 +2152,43 @@ module ts { var isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail; text = text.substring(1, text.length - (isLast ? 1 : 2)); - // Newline normalization + // Newline normalization: + // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's + // and LineTerminatorSequences are normalized to for both TV and TRV. text = text.replace(/\r\n?/g, "\n"); text = escapeString(text); write('"' + text + '"'); } - function emitDownlevelTaggedTemplate(node: TaggedTemplateExpression) { - var tempVariable = createTempVariable(node); - recordTempDeclaration(tempVariable); - write("("); - emit(tempVariable); - write(" = ["); - + function emitDownlevelTaggedTemplateArray(node: TaggedTemplateExpression, callback: (literal: LiteralExpression) => void) { + write("["); if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { - emit(node.template); + callback(node.template); } else { - emit((node.template).head); + callback((node.template).head); forEach((node.template).templateSpans, (child) => { write(", "); - emit(child.literal); + callback(child.literal); }); } - write("], "); + write("]"); + } + + function emitDownlevelTaggedTemplate(node: TaggedTemplateExpression) { + var tempVariable = createTempVariable(node); + recordTempDeclaration(tempVariable); + write("("); + emit(tempVariable); + write(" = "); + emitDownlevelTaggedTemplateArray(node, emit); + write(", "); emit(tempVariable); - write(".raw = ["); - if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { - emitDownlevelRawTemplateLiteral(node.template); - } - else { - emitDownlevelRawTemplateLiteral((node.template).head); - forEach((node.template).templateSpans, (child, index) => { - write(", "); - emitDownlevelRawTemplateLiteral(child.literal); - }); - } - write("], "); + write(".raw = "); + emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); + write(", "); emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); write("("); From c291d12cae6c4810622c543de4f0737b29ae5591 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Sun, 22 Feb 2015 10:21:15 +0100 Subject: [PATCH 20/24] Use createAndRecordTempVariable --- src/compiler/emitter.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5d4fddf0df9ce..a3b85c362add2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2236,8 +2236,7 @@ module ts { } function emitDownlevelTaggedTemplate(node: TaggedTemplateExpression) { - var tempVariable = createTempVariable(node); - recordTempDeclaration(tempVariable); + var tempVariable = createAndRecordTempVariable(node); write("("); emit(tempVariable); write(" = "); From acdc1770ab3035765cc58c70a0ae880cadfafa8b Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Sun, 22 Feb 2015 10:41:21 +0100 Subject: [PATCH 21/24] Update baselines after merging master --- ...gedTemplateStringsTypeArgumentInference.js | 10 +---- ...dTemplateStringsWithOverloadResolution3.js | 42 ++----------------- ...tionExpressionsInSubstitutionExpression.js | 8 +--- .../templateStringInObjectLiteral.js | 8 +--- 4 files changed, 7 insertions(+), 61 deletions(-) diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js index dd3cb16131704..9d3531c26671b 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js @@ -136,17 +136,9 @@ function someGenerics7(strs, a, b, c) { } (_u = ["", "", "", ""], _u.raw = ["", "", "", ""], someGenerics7(_u, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); (_v = ["", "", "", ""], _v.raw = ["", "", "", ""], someGenerics7(_v, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); // Generic tag with argument of generic function type -<<<<<<< HEAD -function someGenerics8(strs, n) { - return n; -} +function someGenerics8(strs, n) { return n; } var x = (_w = ["", ""], _w.raw = ["", ""], someGenerics8(_w, someGenerics7)); (_x = ["", "", "", ""], _x.raw = ["", "", "", ""], x(_x, null, null, null)); -======= -function someGenerics8(strs, n) { return n; } -var x = someGenerics8 "" + someGenerics7; -x "" + null + null + null; ->>>>>>> master // Generic tag with multiple parameters of generic type passed arguments with no best common type function someGenerics9(strs, a, b, c) { return null; diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js index a393ba28a6ad9..4b9df44d3f7e5 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js @@ -74,47 +74,23 @@ fn5 `${ (n) => n.substr(0) }`; //// [taggedTemplateStringsWithOverloadResolution3.js] -<<<<<<< HEAD -function fn1() { - return null; -} +function fn1() { return null; } var s = (_a = ["", ""], _a.raw = ["", ""], fn1(_a, undefined)); // No candidate overloads found (_b = ["", ""], _b.raw = ["", ""], fn1(_b, {})); // Error -function fn2() { - return undefined; -} +function fn2() { return undefined; } var d1 = (_c = ["", "", ""], _c.raw = ["", "", ""], fn2(_c, 0, undefined)); // contextually typed var d2 = (_d = ["", "", ""], _d.raw = ["", "", ""], fn2(_d, 0, undefined)); // any -======= -function fn1() { return null; } -var s = fn1 "" + undefined; -// No candidate overloads found -fn1 "" + {}; // Error -function fn2() { return undefined; } -var d1 = fn2 "" + 0 + undefined; // contextually typed -var d2 = fn2 "" + 0 + undefined; // any ->>>>>>> master d1.foo(); // error d2(); // no error (typed as any) // Generic and non-generic overload where generic overload is the only candidate (_e = ["", "", ""], _e.raw = ["", "", ""], fn2(_e, 0, '')); // OK // Generic and non-generic overload where non-generic overload is the only candidate -<<<<<<< HEAD (_f = ["", "", ""], _f.raw = ["", "", ""], fn2(_f, '', 0)); // OK -function fn3() { - return null; -} +function fn3() { return null; } var s = (_g = ["", ""], _g.raw = ["", ""], fn3(_g, 3)); var s = (_h = ["", "", "", ""], _h.raw = ["", "", "", ""], fn3(_h, '', 3, '')); var n = (_j = ["", "", "", ""], _j.raw = ["", "", "", ""], fn3(_j, 5, 5, 5)); -======= -fn2 "" + '' + 0; // OK -function fn3() { return null; } -var s = fn3 "" + 3; -var s = fn3 "" + '' + 3 + ''; -var n = fn3 "" + 5 + 5 + 5; ->>>>>>> master var n; // Generic overloads with differing arity tagging with arguments matching each overload type parameter count var s = (_k = ["", ""], _k.raw = ["", ""], fn3(_k, 4)); @@ -131,19 +107,9 @@ function fn4() { } // Generic overloads with constraints called with type arguments that do not satisfy the constraints (_s = ["", "", ""], _s.raw = ["", "", ""], fn4(_s, null, null)); // Error // Generic overloads with constraints called without type arguments but with types that do not satisfy the constraints -<<<<<<< HEAD (_t = ["", "", ""], _t.raw = ["", "", ""], fn4(_t, true, null)); (_u = ["", "", ""], _u.raw = ["", "", ""], fn4(_u, null, true)); -function fn5() { - return undefined; -} +function fn5() { return undefined; } (_v = ["", ""], _v.raw = ["", ""], fn5(_v, function (n) { return n.toFixed(); })); // will error; 'n' should have type 'string'. (_w = ["", ""], _w.raw = ["", ""], fn5(_w, function (n) { return n.substr(0); })); var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; -======= -fn4 "" + true + null; -fn4 "" + null + true; -function fn5() { return undefined; } -fn5 "" + function (n) { return n.toFixed(); }; // will error; 'n' should have type 'string'. -fn5 "" + function (n) { return n.substr(0); }; ->>>>>>> master diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js index 6552476a8f110..f7523eb9870dd 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js @@ -13,11 +13,5 @@ function foo() { rest[_i - 0] = arguments[_i]; } } -<<<<<<< HEAD -(_a = ["", ""], _a.raw = ["", ""], foo(_a, function (x) { - x = "bad"; -})); +(_a = ["", ""], _a.raw = ["", ""], foo(_a, function (x) { x = "bad"; })); var _a; -======= -foo "" + function (x) { x = "bad"; }; ->>>>>>> master diff --git a/tests/baselines/reference/templateStringInObjectLiteral.js b/tests/baselines/reference/templateStringInObjectLiteral.js index 92a03415d844a..2e4de70f57c9d 100644 --- a/tests/baselines/reference/templateStringInObjectLiteral.js +++ b/tests/baselines/reference/templateStringInObjectLiteral.js @@ -5,13 +5,7 @@ var x = { } //// [templateStringInObjectLiteral.js] -<<<<<<< HEAD var x = (_a = ["b"], _a.raw = ["b"], ({ - a: "abc" + 123 + "def" -})(_a)); -======= -var x = { - a: "abc" + 123 + "def" } "b"; ->>>>>>> master + a: "abc" + 123 + "def" })(_a)); 321; var _a; From 964ed7f0fd1b6c1eaee47780c59c9086facf7746 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Tue, 24 Feb 2015 06:29:21 +0100 Subject: [PATCH 22/24] Rename callback to literalEmitter --- src/compiler/emitter.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a3b85c362add2..04c32385d3289 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2220,16 +2220,16 @@ module ts { write('"' + text + '"'); } - function emitDownlevelTaggedTemplateArray(node: TaggedTemplateExpression, callback: (literal: LiteralExpression) => void) { + function emitDownlevelTaggedTemplateArray(node: TaggedTemplateExpression, literalEmitter: (literal: LiteralExpression) => void) { write("["); if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { - callback(node.template); + literalEmitter(node.template); } else { - callback((node.template).head); + literalEmitter((node.template).head); forEach((node.template).templateSpans, (child) => { write(", "); - callback(child.literal); + literalEmitter(child.literal); }); } write("]"); From 904b5204c83dfa87b776fa690c4ddc55fc9c5d5d Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Tue, 24 Feb 2015 07:13:38 +0100 Subject: [PATCH 23/24] operator -> operatorToken.kind --- src/compiler/emitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 04c32385d3289..d4f3cd59615a6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2257,7 +2257,7 @@ module ts { forEach((node.template).templateSpans, templateSpan => { write(", "); var needsParens = templateSpan.expression.kind === SyntaxKind.BinaryExpression - && (templateSpan.expression).operator === SyntaxKind.CommaToken; + && (templateSpan.expression).operatorToken.kind === SyntaxKind.CommaToken; emitParenthesizedIf(templateSpan.expression, needsParens); }); } From 2b10d394d4b9bee0c670f84fedf48735c167680f Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Thu, 26 Feb 2015 12:01:19 +0100 Subject: [PATCH 24/24] Update baselines --- .../taggedTemplateStringsHexadecimalEscapes.js | 4 ++++ ...lainCharactersThatArePartsOfEscapes01.errors.txt | 13 ------------- ...StringsPlainCharactersThatArePartsOfEscapes01.js | 3 ++- ...ingsPlainCharactersThatArePartsOfEscapes01.types | 12 ++++++++++++ .../taggedTemplateStringsWithMultilineTemplate.js | 4 ++++ .../taggedTemplateStringsWithUnicodeEscapes.js | 6 +++++- .../taggedTemplateStringsWithWhitespaceEscapes.js | 4 ++++ 7 files changed, 31 insertions(+), 15 deletions(-) delete mode 100644 tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.types diff --git a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js index f07c364d660a4..e4482ded0c2dd 100644 --- a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js +++ b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js @@ -6,6 +6,10 @@ f `\x0D${ "Interrupted CRLF" }\x0A`; //// [taggedTemplateStringsHexadecimalEscapes.js] function f() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } } (_a = ["\r", "\n"], _a.raw = ["\\x0D", "\\x0A"], f(_a, "Interrupted CRLF")); var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.errors.txt b/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.errors.txt deleted file mode 100644 index 93b22614b9568..0000000000000 --- a/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.ts(7,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.ts (1 errors) ==== - - - function f(...x: any[]) { - - } - - f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n` - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js b/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js index 5e5feac077bb4..9450e939f2f69 100644 --- a/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js +++ b/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js @@ -14,4 +14,5 @@ function f() { x[_i - 0] = arguments[_i]; } } -f "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n"; +(_a = ["0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n"], _a.raw = ["0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n"], f(_a)); +var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.types b/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.types new file mode 100644 index 0000000000000..db79359122279 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.ts === + + +function f(...x: any[]) { +>f : (...x: any[]) => void +>x : any[] + +} + +f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n` +>f : (...x: any[]) => void + diff --git a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js index d65b43c05a84b..cee9d1efce431 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js +++ b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js @@ -9,6 +9,10 @@ f ` //// [taggedTemplateStringsWithMultilineTemplate.js] function f() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } } (_a = ["\n\n"], _a.raw = ["\n\\\n\n"], f(_a)); var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js index a046e68787740..bcf0732218ac7 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js +++ b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js @@ -6,6 +6,10 @@ f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`; //// [taggedTemplateStringsWithUnicodeEscapes.js] function f() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } } -(_a = ["'{1f4a\u0039}'", "'πŸ’©'"], _a.raw = ["'\\u{1f4a\u0039}'", "'\\uD83D\\uDCA\u0039'"], f(_a, " should be converted to ")); +(_a = ["'{1f4a9}'", "'πŸ’©'"], _a.raw = ["'\\u{1f4a9}'", "'\\uD83D\\uDCA9'"], f(_a, " should be converted to ")); var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js index 34bbe4e210553..65af8da59f997 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js +++ b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js @@ -6,6 +6,10 @@ f `\t\n\v\f\r\\`; //// [taggedTemplateStringsWithWhitespaceEscapes.js] function f() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } } (_a = ["\t\n\v\f\r\\"], _a.raw = ["\\t\\n\\v\\f\\r\\\\"], f(_a)); var _a;