From 518a5d3a48c18ff83d3709a7122adbc243256a67 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Oct 2014 17:12:13 -0700 Subject: [PATCH 01/15] Rudimentary template support, excluding tagging. --- src/compiler/checker.ts | 85 ++------ src/compiler/core.ts | 19 +- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 6 +- src/compiler/emitter.ts | 101 ++++++++- src/compiler/parser.ts | 155 +++++++++++++- src/compiler/scanner.ts | 201 ++++++++++++------ src/compiler/types.ts | 30 ++- 8 files changed, 445 insertions(+), 153 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6927be355a86f..dc5e3a7d906c9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4103,11 +4103,11 @@ module ts { } return createArrayType(elementType); } - + function isNumericName(name: string) { return (name !== "") && !isNaN(name); } - + function checkObjectLiteral(node: ObjectLiteral, contextualMapper?: TypeMapper): Type { var members = node.symbol.members; var properties: SymbolTable = {}; @@ -5227,6 +5227,12 @@ module ts { return resultType; } + function checkTemplateExpression(node: TemplateExpression): void { + forEach((node).templateSpans, templateSpan => { + checkExpression(templateSpan.expression); + }); + } + function checkExpressionWithContextualType(node: Expression, contextualType: Type, contextualMapper?: TypeMapper): Type { var saveContextualType = node.contextualType; node.contextualType = contextualType; @@ -5280,7 +5286,11 @@ module ts { return booleanType; case SyntaxKind.NumericLiteral: return numberType; + case SyntaxKind.TemplateExpression: + checkTemplateExpression(node); + // fall through case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: return stringType; case SyntaxKind.RegularExpressionLiteral: return globalRegExpType; @@ -7229,77 +7239,6 @@ module ts { return node.parent && node.parent.kind === SyntaxKind.TypeReference; } - function isExpression(node: Node): boolean { - switch (node.kind) { - case SyntaxKind.ThisKeyword: - case SyntaxKind.SuperKeyword: - case SyntaxKind.NullKeyword: - case SyntaxKind.TrueKeyword: - case SyntaxKind.FalseKeyword: - case SyntaxKind.RegularExpressionLiteral: - case SyntaxKind.ArrayLiteral: - case SyntaxKind.ObjectLiteral: - case SyntaxKind.PropertyAccess: - case SyntaxKind.IndexedAccess: - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - case SyntaxKind.TypeAssertion: - case SyntaxKind.ParenExpression: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.PrefixOperator: - case SyntaxKind.PostfixOperator: - case SyntaxKind.BinaryExpression: - case SyntaxKind.ConditionalExpression: - case SyntaxKind.OmittedExpression: - return true; - case SyntaxKind.QualifiedName: - while (node.parent.kind === SyntaxKind.QualifiedName) node = node.parent; - return node.parent.kind === SyntaxKind.TypeQuery; - case SyntaxKind.Identifier: - if (node.parent.kind === SyntaxKind.TypeQuery) { - return true; - } - // Fall through - case SyntaxKind.NumericLiteral: - case SyntaxKind.StringLiteral: - var parent = node.parent; - switch (parent.kind) { - case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: - case SyntaxKind.Property: - case SyntaxKind.EnumMember: - case SyntaxKind.PropertyAssignment: - return (parent).initializer === node; - case SyntaxKind.ExpressionStatement: - case SyntaxKind.IfStatement: - case SyntaxKind.DoStatement: - case SyntaxKind.WhileStatement: - case SyntaxKind.ReturnStatement: - case SyntaxKind.WithStatement: - case SyntaxKind.SwitchStatement: - case SyntaxKind.CaseClause: - case SyntaxKind.ThrowStatement: - case SyntaxKind.SwitchStatement: - return (parent).expression === node; - case SyntaxKind.ForStatement: - return (parent).initializer === node || - (parent).condition === node || - (parent).iterator === node; - case SyntaxKind.ForInStatement: - return (parent).variable === node || - (parent).expression === node; - case SyntaxKind.TypeAssertion: - return node === (parent).operand; - default: - if (isExpression(parent)) { - return true; - } - } - } - return false; - } - function isTypeNode(node: Node): boolean { if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) { return true; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 3da94137fc856..6a4f4beaa33f5 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -5,6 +5,12 @@ module ts { [index: string]: T; } + export enum Comparison { + LessThan = -1, + EqualTo = 0, + GreaterThan = 1 + } + export interface StringSet extends Map { } export function forEach(array: T[], callback: (element: T) => U): U { @@ -79,6 +85,7 @@ module ts { export function concatenate(array1: T[], array2: T[]): T[] { if (!array2 || !array2.length) return array1; if (!array1 || !array1.length) return array2; + return array1.concat(array2); } @@ -304,11 +311,11 @@ module ts { }; } - export function compareValues(a: T, b: T): number { - if (a === b) return 0; - if (a === undefined) return -1; - if (b === undefined) return 1; - return a < b ? -1 : 1; + export function compareValues(a: T, b: T): Comparison { + if (a === b) return Comparison.EqualTo; + if (a === undefined) return Comparison.LessThan; + if (b === undefined) return Comparison.GreaterThan; + return a < b ? Comparison.LessThan : Comparison.GreaterThan; } function getDiagnosticFilename(diagnostic: Diagnostic): string { @@ -333,7 +340,7 @@ module ts { var previousDiagnostic = diagnostics[0]; for (var i = 1; i < diagnostics.length; i++) { var currentDiagnostic = diagnostics[i]; - var isDupe = compareDiagnostics(currentDiagnostic, previousDiagnostic) === 0; + var isDupe = compareDiagnostics(currentDiagnostic, previousDiagnostic) === Comparison.EqualTo; if (!isDupe) { newDiagnostics.push(currentDiagnostic); previousDiagnostic = currentDiagnostic; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index c9d296d8bccca..a38da38eccf76 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -122,6 +122,7 @@ module ts { const_must_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "const must be declared inside a block." }, let_must_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "let must be declared inside a block." }, Only_var_declarations_can_be_exported: { code: 1158, category: DiagnosticCategory.Error, key: "Only var declarations can be exported." }, + Invalid_template_literal_expected: { code: 1159, category: DiagnosticCategory.Error, key: "Invalid template literal; expected '}'" }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 68b5395224a51..41eae297be52d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -449,7 +449,7 @@ }, "An enum member cannot have a numeric name.": { "category": "Error", - "code": 1151 + "code": 1151 }, "'var', 'let' or 'const' expected.": { "category": "Error", @@ -479,6 +479,10 @@ "category": "Error", "code": 1158 }, + "Invalid template literal; expected '}'": { + "category": "Error", + "code": 1159 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8c0dd818d32be..eb1eafbf9b2d8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -792,14 +792,101 @@ module ts { } } - function emitLiteral(node: LiteralExpression) { - var text = getSourceTextOfLocalNode(node); - if (node.kind === SyntaxKind.StringLiteral && compilerOptions.sourceMap) { + function emitLiteral(node: LiteralExpression): void { + var text = getLiteralText(); + + if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } else { write(text); } + + function getLiteralText() { + if (compilerOptions.target < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind)) { + return getTemplateLiteralAsStringLiteral(node) + } + + return getSourceTextOfLocalNode(node); + } + } + + function getTemplateLiteralAsStringLiteral(node: LiteralExpression): string { + return "\"" + escapeString(node.text) + "\""; + } + + function emitTemplateExpression(node: TemplateExpression): void { + if (compilerOptions.target >= ScriptTarget.ES6) { + forEachChild(node, emitNode); + return; + } + + var templateNeedsParens = isExpression(node.parent) && + comparePrecedenceToBinaryPlus(node.parent) !== Comparison.LessThan; + + if (templateNeedsParens) { + write("("); + } + + emitLiteral(node.head); + + forEach(node.templateSpans, templateSpan => { + var needsParens = comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan; + + write(" + "); + + if (needsParens) { + write("("); + } + emit(templateSpan.expression); + if (needsParens) { + write(")"); + } + + write(" + ") + emitLiteral(templateSpan.literal); + }); + + if (templateNeedsParens) { + write(")"); + } + + /** + * Returns whether the expression has lesser, greater, + * or equal precedence to the binary '+' operator + */ + function comparePrecedenceToBinaryPlus(expression: Expression): Comparison { + // All binary expressions have lower precedence than '+' apart from '*', '/', and '%'. + // All unary operators have a higher precedence apart from yield. + // Arrow functions and conditionals have a lower precedence, + // although we convert the former into regular function expressions in ES5 mode, + // and in ES6 mode this function won't get called anyway. + // + // TODO (drosen): Note that we need to account for the upcoming 'yield' and + // spread ('...') unary operators that are anticipated for ES6. + switch (expression.kind) { + case SyntaxKind.BinaryExpression: + switch ((expression).operator) { + case SyntaxKind.AsteriskToken: + case SyntaxKind.SlashToken: + case SyntaxKind.PercentToken: + return Comparison.GreaterThan; + case SyntaxKind.PlusToken: + return Comparison.EqualTo; + default: + return Comparison.LessThan; + } + case SyntaxKind.ConditionalExpression: + return Comparison.LessThan; + default: + return Comparison.GreaterThan; + } + } + + } + + function emitTemplateSpan(span: TemplateSpan) { + forEachChild(span, emitNode); } // This function specifically handles numeric/string literals for enum and accessor 'identifiers'. @@ -2091,7 +2178,15 @@ module ts { case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: return emitLiteral(node); + case SyntaxKind.TemplateExpression: + return emitTemplateExpression(node); + case SyntaxKind.TemplateSpan: + return emitTemplateSpan(node); case SyntaxKind.QualifiedName: return emitPropertyAccess(node); case SyntaxKind.ArrayLiteral: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b011220095c1c..f6ea10c4384bb 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -344,6 +344,10 @@ module ts { child((node).externalModuleName); case SyntaxKind.ExportAssignment: return child((node).exportName); + case SyntaxKind.TemplateExpression: + return child((node).head) || children((node).templateSpans); + case SyntaxKind.TemplateSpan: + return child((node).expression) || child((node).literal); } } @@ -448,10 +452,95 @@ module ts { } } + export function isExpression(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ThisKeyword: + case SyntaxKind.SuperKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.ArrayLiteral: + case SyntaxKind.ObjectLiteral: + case SyntaxKind.PropertyAccess: + case SyntaxKind.IndexedAccess: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TypeAssertion: + case SyntaxKind.ParenExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.PrefixOperator: + case SyntaxKind.PostfixOperator: + case SyntaxKind.BinaryExpression: + case SyntaxKind.ConditionalExpression: + case SyntaxKind.TemplateExpression: + case SyntaxKind.OmittedExpression: + return true; + case SyntaxKind.QualifiedName: + while (node.parent.kind === SyntaxKind.QualifiedName) node = node.parent; + return node.parent.kind === SyntaxKind.TypeQuery; + case SyntaxKind.Identifier: + if (node.parent.kind === SyntaxKind.TypeQuery) { + return true; + } + // fall through + case SyntaxKind.NumericLiteral: + case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + var parent = node.parent; + switch (parent.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.Parameter: + case SyntaxKind.Property: + case SyntaxKind.EnumMember: + case SyntaxKind.PropertyAssignment: + return (parent).initializer === node; + case SyntaxKind.ExpressionStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.ReturnStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseClause: + case SyntaxKind.ThrowStatement: + case SyntaxKind.SwitchStatement: + return (parent).expression === node; + case SyntaxKind.ForStatement: + return (parent).initializer === node || + (parent).condition === node || + (parent).iterator === node; + case SyntaxKind.ForInStatement: + return (parent).variable === node || + (parent).expression === node; + case SyntaxKind.TypeAssertion: + return node === (parent).operand; + default: + if (isExpression(parent)) { + return true; + } + } + } + return false; + } + export function hasRestParameters(s: SignatureDeclaration): boolean { return s.parameters.length > 0 && (s.parameters[s.parameters.length - 1].flags & NodeFlags.Rest) !== 0; } + export function isLiteralKind(kind: SyntaxKind): boolean { + return SyntaxKind.FirstLiteralToken <= kind && kind <= SyntaxKind.LastLiteralToken; + } + + export function isTextualLiteralKind(kind: SyntaxKind): boolean { + return kind === SyntaxKind.StringLiteral || kind === SyntaxKind.NoSubstitutionTemplateLiteral; + } + + export function isTemplateLiteralKind(kind: SyntaxKind): boolean { + return SyntaxKind.FirstTemplateToken <= kind && kind <= SyntaxKind.LastTemplateToken; + } + export function isInAmbientContext(node: Node): boolean { while (node) { if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) return true; @@ -460,6 +549,7 @@ module ts { return false; } + export function isDeclaration(node: Node): boolean { switch (node.kind) { case SyntaxKind.TypeParameter: @@ -875,6 +965,10 @@ module ts { return token = scanner.reScanSlashToken(); } + function reScanTemplateToken(): SyntaxKind { + return token = scanner.reScanTemplateToken(); + } + function lookAheadHelper(callback: () => T, alwaysResetState: boolean): T { // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). @@ -1021,7 +1115,9 @@ module ts { } function isPropertyName(): boolean { - return token >= SyntaxKind.Identifier || token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral; + return token >= SyntaxKind.Identifier || + token === SyntaxKind.StringLiteral || + token === SyntaxKind.NumericLiteral; } function parsePropertyName(): Identifier { @@ -1296,7 +1392,44 @@ module ts { return finishNode(node); } - function parseLiteralNode(internName?:boolean): LiteralExpression { + function parseTemplateExpression() { + var template = createNode(SyntaxKind.TemplateExpression); + + template.head = parseLiteralNode(); + Debug.assert(template.head.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind"); + + var templateSpans: TemplateSpan[] = []; + do { + templateSpans.push(parseTemplateSpan()); + } + while (templateSpans[templateSpans.length - 1].literal.kind === SyntaxKind.TemplateMiddle) + + template.templateSpans = templateSpans; + return finishNode(template); + } + + function parseTemplateSpan(): TemplateSpan { + var span = createNode(SyntaxKind.TemplateSpan); + span.expression = parseExpression(/*noIn*/ false); + + var literal: LiteralExpression; + + if (token === SyntaxKind.CloseBraceToken) { + reScanTemplateToken() + literal = parseLiteralNode(); + } + else { + error(Diagnostics.Invalid_template_literal_expected); + literal = createMissingNode(); + literal.text = ""; + } + + span.literal = literal; + + return finishNode(span); + } + + function parseLiteralNode(internName?: boolean): LiteralExpression { var node = createNode(token); var text = scanner.getTokenValue(); node.text = internName ? internIdentifier(text) : text; @@ -1308,7 +1441,7 @@ module ts { // Octal literals are not allowed in strict mode or ES5 // Note that theoretically the following condition would hold true literals like 009, // which is not octal.But because of how the scanner separates the tokens, we would - // never get a token like this.Instead, we would get 00 and 9 as two separate tokens. + // never get a token like this. Instead, we would get 00 and 9 as two separate tokens. // We also do not need to check for negatives because any prefix operator would be part of a // parent unary expression. if (node.kind === SyntaxKind.NumericLiteral @@ -1327,7 +1460,9 @@ module ts { } function parseStringLiteral(): LiteralExpression { - if (token === SyntaxKind.StringLiteral) return parseLiteralNode(/*internName:*/ true); + if (token === SyntaxKind.StringLiteral) { + return parseLiteralNode(/*internName:*/ true); + } error(Diagnostics.String_literal_expected); return createMissingNode(); } @@ -1755,6 +1890,8 @@ module ts { case SyntaxKind.FalseKeyword: case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateHead: case SyntaxKind.OpenParenToken: case SyntaxKind.OpenBracketToken: case SyntaxKind.OpenBraceToken: @@ -1846,8 +1983,8 @@ module ts { } // Now see if we might be in cases '2' or '3'. - // If the expression was a LHS expression, and we have an assignment operator, then - // we're in '2' or '3'. Consume the assignment and return. + // If the expression was a LHS expression, and we have an assignment operator, then + // we're in '2' or '3'. Consume the assignment and return. if (isLeftHandSideExpression(expr) && isAssignmentOperator()) { if (isInStrictMode && isEvalOrArgumentsIdentifier(expr)) { // ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an @@ -1879,6 +2016,8 @@ module ts { case SyntaxKind.RegularExpressionLiteral: case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateExpression: case SyntaxKind.FalseKeyword: case SyntaxKind.NullKeyword: case SyntaxKind.ThisKeyword: @@ -2343,6 +2482,7 @@ module ts { return parseTokenNode(); case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: return parseLiteralNode(); case SyntaxKind.OpenParenToken: return parseParenExpression(); @@ -2360,6 +2500,9 @@ module ts { return parseLiteralNode(); } break; + case SyntaxKind.TemplateHead: + return parseTemplateExpression(); + default: if (isIdentifier()) { return parseIdentifier(); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 81d16b5f4874d..0d207b1ae92f0 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -24,6 +24,7 @@ module ts { isReservedWord(): boolean; reScanGreaterToken(): SyntaxKind; reScanSlashToken(): SyntaxKind; + reScanTemplateToken(): SyntaxKind; scan(): SyntaxKind; setText(text: string): void; setTextPos(textPos: number): void; @@ -465,7 +466,7 @@ module ts { var len: number; // Length of text var startPos: number; // Start position of whitespace before current token var tokenPos: number; // Start position of text of current token - var token: number; + var token: SyntaxKind; var tokenValue: string; var precedingLineBreak: boolean; @@ -518,10 +519,10 @@ module ts { return +(text.substring(start, pos)); } - function scanHexDigits(count: number, exact?: boolean): number { + function scanHexDigits(count: number, useExactCount?: boolean): number { var digits = 0; var value = 0; - while (digits < count || !exact) { + while (digits < count || !useExactCount) { var ch = text.charCodeAt(pos); if (ch >= CharacterCodes._0 && ch <= CharacterCodes._9) { value = value * 16 + ch - CharacterCodes._0; @@ -562,60 +563,7 @@ module ts { } if (ch === CharacterCodes.backslash) { result += text.substring(start, pos); - pos++; - if (pos >= len) { - error(Diagnostics.Unexpected_end_of_text); - break; - } - ch = text.charCodeAt(pos++); - switch (ch) { - case CharacterCodes._0: - result += "\0"; - break; - case CharacterCodes.b: - result += "\b"; - break; - case CharacterCodes.t: - result += "\t"; - break; - case CharacterCodes.n: - result += "\n"; - break; - case CharacterCodes.v: - result += "\v"; - break; - case CharacterCodes.f: - result += "\f"; - break; - case CharacterCodes.r: - result += "\r"; - break; - case CharacterCodes.singleQuote: - result += "\'"; - break; - case CharacterCodes.doubleQuote: - result += "\""; - break; - case CharacterCodes.x: - case CharacterCodes.u: - var ch = scanHexDigits(ch === CharacterCodes.x ? 2 : 4, true); - if (ch >= 0) { - result += String.fromCharCode(ch); - } - else { - error(Diagnostics.Hexadecimal_digit_expected); - } - break; - case CharacterCodes.carriageReturn: - if (pos < len && text.charCodeAt(pos) === CharacterCodes.lineFeed) pos++; - break; - case CharacterCodes.lineFeed: - case CharacterCodes.lineSeparator: - case CharacterCodes.paragraphSeparator: - break; - default: - result += String.fromCharCode(ch); - } + result += scanEscapeSequence(); start = pos; continue; } @@ -629,13 +577,134 @@ module ts { return result; } + /** + * Sets the current 'tokenValue' and returns a NoSubstitutionTemplateLiteral or + * a literal component of a TemplateExpression. + */ + function scanTemplateAndSetTokenValue(): SyntaxKind { + var isStartOfTemplate = text.charCodeAt(pos) === CharacterCodes.backtick; + + pos++; + var start = pos; + var contents = "" + var resultingToken = SyntaxKind.Unknown; + + while (true) { + if (pos >= len) { + contents += text.substring(start, pos); + error(Diagnostics.Unexpected_end_of_text); + resultingToken = isStartOfTemplate ? SyntaxKind.NoSubstitutionTemplateLiteral : SyntaxKind.TemplateTail; + break; + } + + var currChar = text.charCodeAt(pos); + + // '`' + if (currChar === CharacterCodes.backtick) { + contents += text.substring(start, pos); + pos++; + resultingToken = isStartOfTemplate ? SyntaxKind.NoSubstitutionTemplateLiteral : SyntaxKind.TemplateTail; + break; + } + + // '${' + if (currChar === CharacterCodes.$ && pos + 1 < len && text.charCodeAt(pos + 1) === CharacterCodes.openBrace) { + contents += text.substring(start, pos); + pos += 2; + resultingToken = isStartOfTemplate ? SyntaxKind.TemplateHead : SyntaxKind.TemplateMiddle; + break; + } + + // Escape character + if (currChar === CharacterCodes.backslash) { + contents += text.substring(start, pos); + contents += scanEscapeSequence(); + start = pos; + continue; + } + + // Speculated ECMAScript 6 Spec 11.8.6.1: + // and LineTerminatorSequences are normalized to for Template Values + // An explicit EscapeSequence is needed to include a or sequence. + if (currChar === CharacterCodes.carriageReturn) { + contents += text.substring(start, pos); + + if (pos + 1 < len && text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) { + pos++; + } + pos++; + contents += "\n"; + start = pos; + continue; + } + + pos++; + } + + tokenValue = contents; + return resultingToken; + } + + function scanEscapeSequence(): string { + pos++; + if (pos >= len) { + error(Diagnostics.Unexpected_end_of_text); + return ""; + } + var ch = text.charCodeAt(pos++); + switch (ch) { + case CharacterCodes._0: + return "\0"; + case CharacterCodes.b: + return "\b"; + case CharacterCodes.t: + return "\t"; + case CharacterCodes.n: + return "\n"; + case CharacterCodes.v: + return "\v"; + case CharacterCodes.f: + return "\f"; + case CharacterCodes.r: + return "\r"; + case CharacterCodes.singleQuote: + return "\'"; + case CharacterCodes.doubleQuote: + return "\""; + case CharacterCodes.x: + case CharacterCodes.u: + var ch = scanHexDigits(ch === CharacterCodes.x ? 2 : 4, /*useExactCount*/ true); + if (ch >= 0) { + return String.fromCharCode(ch); + } + else { + error(Diagnostics.Hexadecimal_digit_expected); + return "" + } + + // when encountering a LineContinuation (i.e. a backslash and a line terminator sequence), + // the line terminator is interpreted to be "the empty code unit sequence". + case CharacterCodes.carriageReturn: + if (pos < len && text.charCodeAt(pos) === CharacterCodes.lineFeed) { + pos++; + } + // fall through + case CharacterCodes.lineFeed: + case CharacterCodes.lineSeparator: + case CharacterCodes.paragraphSeparator: + return "" + default: + return String.fromCharCode(ch); + } + } + // Current character is known to be a backslash. Check for Unicode escape of the form '\uXXXX' // and return code point value if valid Unicode escape is found. Otherwise return -1. function peekUnicodeEscape(): number { if (pos + 5 < len && text.charCodeAt(pos + 1) === CharacterCodes.u) { var start = pos; pos += 2; - var value = scanHexDigits(4, true); + var value = scanHexDigits(4, /*useExactCount*/ true); pos = start; return value; } @@ -734,6 +803,8 @@ module ts { case CharacterCodes.singleQuote: tokenValue = scanString(); return token = SyntaxKind.StringLiteral; + case CharacterCodes.backtick: + return token = scanTemplateAndSetTokenValue() case CharacterCodes.percent: if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.PercentEqualsToken; @@ -851,7 +922,7 @@ module ts { case CharacterCodes._0: if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.X || text.charCodeAt(pos + 1) === CharacterCodes.x)) { pos += 2; - var value = scanHexDigits(1, false); + var value = scanHexDigits(1, /*useExactCount*/ false); if (value < 0) { error(Diagnostics.Hexadecimal_digit_expected); value = 0; @@ -1037,6 +1108,15 @@ module ts { return token; } + /** + * Unconditionally back up and scan a template expression portion. + */ + function reScanTemplateToken(): SyntaxKind { + Debug.assert("'reScanTemplateToken' should only be called on a '}'"); + pos = tokenPos; + return token = scanTemplateAndSetTokenValue(); + } + function tryScan(callback: () => T): T { var savePos = pos; var saveStartPos = startPos; @@ -1085,10 +1165,11 @@ module ts { isReservedWord: () => token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastReservedWord, reScanGreaterToken: reScanGreaterToken, reScanSlashToken: reScanSlashToken, + reScanTemplateToken: reScanTemplateToken, scan: scan, setText: setText, setTextPos: setTextPos, - tryScan: tryScan + tryScan: tryScan, }; } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 09cd613e8f341..e7400f28bf9c4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -20,6 +20,11 @@ module ts { NumericLiteral, StringLiteral, RegularExpressionLiteral, + NoSubstitutionTemplateLiteral, + // Pseudo-literals + TemplateHead, + TemplateMiddle, + TemplateTail, // Punctuation OpenBraceToken, CloseBraceToken, @@ -170,6 +175,8 @@ module ts { PostfixOperator, BinaryExpression, ConditionalExpression, + TemplateExpression, + TemplateSpan, OmittedExpression, // Element Block, @@ -230,7 +237,11 @@ module ts { FirstToken = EndOfFileToken, LastToken = StringKeyword, FirstTriviaToken = SingleLineCommentTrivia, - LastTriviaToken = WhitespaceTrivia + LastTriviaToken = WhitespaceTrivia, + FirstLiteralToken = NumericLiteral, + LastLiteralToken = NoSubstitutionTemplateLiteral, + FirstTemplateToken = NoSubstitutionTemplateLiteral, + LastTemplateToken = TemplateTail } export enum NodeFlags { @@ -369,13 +380,23 @@ module ts { body: Node; // Required, whereas the member inherited from FunctionDeclaration is optional } - // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral - // this means quotes have been removed and escapes have been converted to actual characters. For a NumericLiteral, the - // stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". + // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, + // or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. + // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". export interface LiteralExpression extends Expression { text: string; } + export interface TemplateExpression extends Expression { + head: LiteralExpression; + templateSpans: TemplateSpan[] + } + + export interface TemplateSpan extends Node { + expression: Expression; + literal: LiteralExpression; + } + export interface ParenExpression extends Expression { expression: Expression; } @@ -1189,6 +1210,7 @@ module ts { asterisk = 0x2A, // * at = 0x40, // @ backslash = 0x5C, // \ + backtick = 0x60, // ` bar = 0x7C, // | caret = 0x5E, // ^ closeBrace = 0x7D, // } From c0893e153f0ea1a7606c6ebefe61d869bff24b59 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 22 Oct 2014 15:48:22 -0700 Subject: [PATCH 02/15] Added tests and baselines for templates. --- .../reference/templateStringInArray.js | 5 +++ .../reference/templateStringInArray.types | 5 +++ .../templateStringInArrowFunction.js | 5 +++ .../templateStringInArrowFunction.types | 7 ++++ .../templateStringInArrowFunctionES6.js | 5 +++ .../templateStringInArrowFunctionES6.types | 7 ++++ .../templateStringInBinaryAddition.js | 5 +++ .../templateStringInBinaryAddition.types | 5 +++ .../templateStringInBinaryAdditionES6.js | 5 +++ .../templateStringInBinaryAdditionES6.types | 5 +++ .../reference/templateStringInConditional.js | 5 +++ .../templateStringInConditional.types | 5 +++ .../templateStringInConditionalES6.js | 5 +++ .../templateStringInConditionalES6.types | 5 +++ .../templateStringInDeleteExpression.js | 5 +++ .../templateStringInDeleteExpression.types | 4 ++ .../templateStringInDeleteExpressionES6.js | 5 +++ .../templateStringInDeleteExpressionES6.types | 4 ++ .../templateStringInDivision.errors.txt | 7 ++++ .../reference/templateStringInDivision.js | 5 +++ .../templateStringInEqualityChecks.js | 8 ++++ .../templateStringInEqualityChecks.types | 17 +++++++++ .../templateStringInEqualityChecksES6.js | 8 ++++ .../templateStringInEqualityChecksES6.types | 17 +++++++++ .../templateStringInFunctionExpression.js | 11 ++++++ .../templateStringInFunctionExpression.types | 9 +++++ .../templateStringInFunctionExpressionES6.js | 11 ++++++ ...emplateStringInFunctionExpressionES6.types | 9 +++++ ...teStringInFunctionParameterType.errors.txt | 20 ++++++++++ ...tringInFunctionParameterTypeES6.errors.txt | 20 ++++++++++ .../reference/templateStringInInOperator.js | 5 +++ .../templateStringInInOperator.types | 8 ++++ .../templateStringInInOperatorES6.js | 5 +++ .../templateStringInInOperatorES6.types | 8 ++++ .../templateStringInIndexExpression.js | 5 +++ .../templateStringInIndexExpression.types | 4 ++ .../templateStringInIndexExpressionES6.js | 5 +++ .../templateStringInIndexExpressionES6.types | 4 ++ .../templateStringInInstanceOf.errors.txt | 7 ++++ .../reference/templateStringInInstanceOf.js | 5 +++ .../templateStringInInstanceOfES6.errors.txt | 7 ++++ .../templateStringInInstanceOfES6.js | 5 +++ .../templateStringInModuleName.errors.txt | 38 +++++++++++++++++++ .../templateStringInModuleNameES6.errors.txt | 38 +++++++++++++++++++ .../templateStringInModulo.errors.txt | 7 ++++ .../reference/templateStringInModulo.js | 5 +++ .../templateStringInModuloES6.errors.txt | 7 ++++ .../reference/templateStringInModuloES6.js | 5 +++ .../templateStringInMultiplication.errors.txt | 7 ++++ .../templateStringInMultiplication.js | 5 +++ ...mplateStringInMultiplicationES6.errors.txt | 7 ++++ .../templateStringInMultiplicationES6.js | 5 +++ .../templateStringInNewOperator.errors.txt | 7 ++++ .../reference/templateStringInNewOperator.js | 5 +++ .../templateStringInNewOperatorES6.errors.txt | 7 ++++ .../templateStringInNewOperatorES6.js | 5 +++ .../templateStringInObjectLiteral.errors.txt | 16 ++++++++ ...emplateStringInObjectLiteralES6.errors.txt | 16 ++++++++ .../reference/templateStringInParentheses.js | 5 +++ .../templateStringInParentheses.types | 5 +++ .../templateStringInParenthesesES6.js | 5 +++ .../templateStringInParenthesesES6.types | 5 +++ .../templateStringInSwitchAndCase.js | 15 ++++++++ .../templateStringInSwitchAndCase.types | 8 ++++ .../templateStringInSwitchAndCaseES6.js | 15 ++++++++ .../templateStringInSwitchAndCaseES6.types | 8 ++++ .../templateStringInTypeAssertion.js | 5 +++ .../templateStringInTypeAssertion.types | 5 +++ .../templateStringInTypeAssertionES6.js | 5 +++ .../templateStringInTypeAssertionES6.types | 5 +++ .../reference/templateStringInTypeOf.js | 5 +++ .../reference/templateStringInTypeOf.types | 5 +++ .../reference/templateStringInTypeOfES6.js | 5 +++ .../reference/templateStringInTypeOfES6.types | 5 +++ .../reference/templateStringInUnaryPlus.js | 5 +++ .../reference/templateStringInUnaryPlus.types | 5 +++ .../reference/templateStringInUnaryPlusES6.js | 5 +++ .../templateStringInUnaryPlusES6.types | 5 +++ .../reference/templateStringInWhile.js | 9 +++++ .../reference/templateStringInWhile.types | 5 +++ .../reference/templateStringInWhileES6.js | 9 +++++ .../reference/templateStringInWhileES6.types | 5 +++ .../templateStringInYieldKeyword.errors.txt | 23 +++++++++++ .../templateStringWithEmbeddedAddition.js | 5 +++ .../templateStringWithEmbeddedAddition.types | 5 +++ .../templateStringWithEmbeddedAdditionES6.js | 5 +++ ...emplateStringWithEmbeddedAdditionES6.types | 5 +++ .../templateStringWithEmbeddedArray.js | 5 +++ .../templateStringWithEmbeddedArray.types | 5 +++ .../templateStringWithEmbeddedArrayES6.js | 5 +++ .../templateStringWithEmbeddedArrayES6.types | 5 +++ ...templateStringWithEmbeddedArrowFunction.js | 5 +++ ...plateStringWithEmbeddedArrowFunction.types | 7 ++++ ...plateStringWithEmbeddedArrowFunctionES6.js | 5 +++ ...teStringWithEmbeddedArrowFunctionES6.types | 7 ++++ .../templateStringWithEmbeddedComments.js | 16 ++++++++ .../templateStringWithEmbeddedComments.types | 14 +++++++ .../templateStringWithEmbeddedCommentsES6.js | 16 ++++++++ ...emplateStringWithEmbeddedCommentsES6.types | 14 +++++++ ...teStringWithEmbeddedConditional.errors.txt | 7 ++++ .../templateStringWithEmbeddedConditional.js | 5 +++ ...tringWithEmbeddedConditionalES6.errors.txt | 7 ++++ ...emplateStringWithEmbeddedConditionalES6.js | 5 +++ .../templateStringWithEmbeddedDivision.js | 5 +++ .../templateStringWithEmbeddedDivision.types | 5 +++ .../templateStringWithEmbeddedDivisionES6.js | 5 +++ ...emplateStringWithEmbeddedDivisionES6.types | 5 +++ ...ateStringWithEmbeddedFunctionExpression.js | 7 ++++ ...StringWithEmbeddedFunctionExpression.types | 7 ++++ ...StringWithEmbeddedFunctionExpressionES6.js | 7 ++++ ...ingWithEmbeddedFunctionExpressionES6.types | 7 ++++ .../templateStringWithEmbeddedInOperator.js | 5 +++ ...templateStringWithEmbeddedInOperator.types | 8 ++++ ...templateStringWithEmbeddedInOperatorES6.js | 5 +++ ...plateStringWithEmbeddedInOperatorES6.types | 8 ++++ ...ateStringWithEmbeddedInstanceOf.errors.txt | 7 ++++ .../templateStringWithEmbeddedInstanceOf.js | 5 +++ ...StringWithEmbeddedInstanceOfES6.errors.txt | 7 ++++ ...templateStringWithEmbeddedInstanceOfES6.js | 5 +++ .../templateStringWithEmbeddedModulo.js | 5 +++ .../templateStringWithEmbeddedModulo.types | 5 +++ .../templateStringWithEmbeddedModuloES6.js | 5 +++ .../templateStringWithEmbeddedModuloES6.types | 5 +++ ...emplateStringWithEmbeddedMultiplication.js | 5 +++ ...lateStringWithEmbeddedMultiplication.types | 5 +++ ...lateStringWithEmbeddedMultiplicationES6.js | 5 +++ ...eStringWithEmbeddedMultiplicationES6.types | 5 +++ .../templateStringWithEmbeddedNewOperator.js | 5 +++ ...emplateStringWithEmbeddedNewOperator.types | 6 +++ ...emplateStringWithEmbeddedNewOperatorES6.js | 5 +++ ...lateStringWithEmbeddedNewOperatorES6.types | 6 +++ ...templateStringWithEmbeddedObjectLiteral.js | 5 +++ ...plateStringWithEmbeddedObjectLiteral.types | 7 ++++ ...plateStringWithEmbeddedObjectLiteralES6.js | 5 +++ ...teStringWithEmbeddedObjectLiteralES6.types | 7 ++++ ...emplateStringWithEmbeddedTemplateString.js | 5 +++ ...lateStringWithEmbeddedTemplateString.types | 4 ++ ...lateStringWithEmbeddedTemplateStringES6.js | 5 +++ ...eStringWithEmbeddedTemplateStringES6.types | 4 ++ ...ringWithEmbeddedTypeAssertionOnAddition.js | 5 +++ ...gWithEmbeddedTypeAssertionOnAddition.types | 7 ++++ ...gWithEmbeddedTypeAssertionOnAdditionES6.js | 5 +++ ...thEmbeddedTypeAssertionOnAdditionES6.types | 7 ++++ ...emplateStringWithEmbeddedTypeOfOperator.js | 5 +++ ...lateStringWithEmbeddedTypeOfOperator.types | 5 +++ ...lateStringWithEmbeddedTypeOfOperatorES6.js | 5 +++ ...eStringWithEmbeddedTypeOfOperatorES6.types | 5 +++ .../templateStringWithEmbeddedUnaryPlus.js | 5 +++ .../templateStringWithEmbeddedUnaryPlus.types | 6 +++ .../templateStringWithEmbeddedUnaryPlusES6.js | 5 +++ ...mplateStringWithEmbeddedUnaryPlusES6.types | 6 +++ ...eStringWithEmbeddedYieldKeyword.errors.txt | 34 +++++++++++++++++ ...ringWithEmbeddedYieldKeywordES6.errors.txt | 34 +++++++++++++++++ ...ateStringWithOpenCommentInStringPortion.js | 5 +++ ...StringWithOpenCommentInStringPortion.types | 3 ++ ...StringWithOpenCommentInStringPortionES6.js | 5 +++ ...ingWithOpenCommentInStringPortionES6.types | 3 ++ .../templateStringWithPropertyAccess.js | 5 +++ .../templateStringWithPropertyAccess.types | 6 +++ .../templateStringWithPropertyAccessES6.js | 5 +++ .../templateStringWithPropertyAccessES6.types | 6 +++ .../es6/templates/templateStringInArray.ts | 1 + .../templateStringInArrowFunction.ts | 1 + .../templateStringInArrowFunctionES6.ts | 2 + .../templateStringInBinaryAddition.ts | 1 + .../templateStringInBinaryAdditionES6.ts | 2 + .../templates/templateStringInConditional.ts | 1 + .../templateStringInConditionalES6.ts | 2 + .../templateStringInDeleteExpression.ts | 1 + .../templateStringInDeleteExpressionES6.ts | 2 + .../es6/templates/templateStringInDivision.ts | 1 + .../templateStringInEqualityChecks.ts | 4 ++ .../templateStringInEqualityChecksES6.ts | 5 +++ .../templateStringInFunctionExpression.ts | 4 ++ .../templateStringInFunctionExpressionES6.ts | 5 +++ .../templateStringInFunctionParameterType.ts | 5 +++ ...emplateStringInFunctionParameterTypeES6.ts | 6 +++ .../templates/templateStringInInOperator.ts | 1 + .../templateStringInInOperatorES6.ts | 2 + .../templateStringInIndexExpression.ts | 1 + .../templateStringInIndexExpressionES6.ts | 2 + .../templates/templateStringInInstanceOf.ts | 1 + .../templateStringInInstanceOfES6.ts | 2 + .../templates/templateStringInModuleName.ts | 5 +++ .../templateStringInModuleNameES6.ts | 6 +++ .../es6/templates/templateStringInModulo.ts | 1 + .../templates/templateStringInModuloES6.ts | 2 + .../templateStringInMultiplication.ts | 1 + .../templateStringInMultiplicationES6.ts | 2 + .../templates/templateStringInNewOperator.ts | 1 + .../templateStringInNewOperatorES6.ts | 2 + .../templateStringInObjectLiteral.ts | 4 ++ .../templateStringInObjectLiteralES6.ts | 5 +++ .../templates/templateStringInParentheses.ts | 1 + .../templateStringInParenthesesES6.ts | 2 + .../templateStringInSwitchAndCase.ts | 6 +++ .../templateStringInSwitchAndCaseES6.ts | 7 ++++ .../templateStringInTypeAssertion.ts | 1 + .../templateStringInTypeAssertionES6.ts | 2 + .../es6/templates/templateStringInTypeOf.ts | 1 + .../templates/templateStringInTypeOfES6.ts | 2 + .../templates/templateStringInUnaryPlus.ts | 1 + .../templates/templateStringInUnaryPlusES6.ts | 2 + .../es6/templates/templateStringInWhile.ts | 3 ++ .../es6/templates/templateStringInWhileES6.ts | 4 ++ .../templates/templateStringInYieldKeyword.ts | 4 ++ .../templateStringWithEmbeddedAddition.ts | 1 + .../templateStringWithEmbeddedAdditionES6.ts | 2 + .../templateStringWithEmbeddedArray.ts | 1 + .../templateStringWithEmbeddedArrayES6.ts | 2 + ...templateStringWithEmbeddedArrowFunction.ts | 1 + ...plateStringWithEmbeddedArrowFunctionES6.ts | 2 + .../templateStringWithEmbeddedComments.ts | 12 ++++++ .../templateStringWithEmbeddedCommentsES6.ts | 12 ++++++ .../templateStringWithEmbeddedConditional.ts | 1 + ...emplateStringWithEmbeddedConditionalES6.ts | 2 + .../templateStringWithEmbeddedDivision.ts | 1 + .../templateStringWithEmbeddedDivisionES6.ts | 2 + ...ateStringWithEmbeddedFunctionExpression.ts | 1 + ...StringWithEmbeddedFunctionExpressionES6.ts | 2 + .../templateStringWithEmbeddedInOperator.ts | 1 + ...templateStringWithEmbeddedInOperatorES6.ts | 2 + .../templateStringWithEmbeddedInstanceOf.ts | 1 + ...templateStringWithEmbeddedInstanceOfES6.ts | 2 + .../templateStringWithEmbeddedModulo.ts | 1 + .../templateStringWithEmbeddedModuloES6.ts | 2 + ...emplateStringWithEmbeddedMultiplication.ts | 1 + ...lateStringWithEmbeddedMultiplicationES6.ts | 2 + .../templateStringWithEmbeddedNewOperator.ts | 1 + ...emplateStringWithEmbeddedNewOperatorES6.ts | 2 + ...templateStringWithEmbeddedObjectLiteral.ts | 1 + ...plateStringWithEmbeddedObjectLiteralES6.ts | 2 + ...emplateStringWithEmbeddedTemplateString.ts | 1 + ...lateStringWithEmbeddedTemplateStringES6.ts | 2 + ...ringWithEmbeddedTypeAssertionOnAddition.ts | 1 + ...gWithEmbeddedTypeAssertionOnAdditionES6.ts | 2 + ...emplateStringWithEmbeddedTypeOfOperator.ts | 1 + ...lateStringWithEmbeddedTypeOfOperatorES6.ts | 2 + .../templateStringWithEmbeddedUnaryPlus.ts | 1 + .../templateStringWithEmbeddedUnaryPlusES6.ts | 2 + .../templateStringWithEmbeddedYieldKeyword.ts | 4 ++ ...mplateStringWithEmbeddedYieldKeywordES6.ts | 5 +++ ...ateStringWithOpenCommentInStringPortion.ts | 1 + ...StringWithOpenCommentInStringPortionES6.ts | 2 + .../templateStringWithPropertyAccess.ts | 1 + .../templateStringWithPropertyAccessES6.ts | 2 + 246 files changed, 1385 insertions(+) create mode 100644 tests/baselines/reference/templateStringInArray.js create mode 100644 tests/baselines/reference/templateStringInArray.types create mode 100644 tests/baselines/reference/templateStringInArrowFunction.js create mode 100644 tests/baselines/reference/templateStringInArrowFunction.types create mode 100644 tests/baselines/reference/templateStringInArrowFunctionES6.js create mode 100644 tests/baselines/reference/templateStringInArrowFunctionES6.types create mode 100644 tests/baselines/reference/templateStringInBinaryAddition.js create mode 100644 tests/baselines/reference/templateStringInBinaryAddition.types create mode 100644 tests/baselines/reference/templateStringInBinaryAdditionES6.js create mode 100644 tests/baselines/reference/templateStringInBinaryAdditionES6.types create mode 100644 tests/baselines/reference/templateStringInConditional.js create mode 100644 tests/baselines/reference/templateStringInConditional.types create mode 100644 tests/baselines/reference/templateStringInConditionalES6.js create mode 100644 tests/baselines/reference/templateStringInConditionalES6.types create mode 100644 tests/baselines/reference/templateStringInDeleteExpression.js create mode 100644 tests/baselines/reference/templateStringInDeleteExpression.types create mode 100644 tests/baselines/reference/templateStringInDeleteExpressionES6.js create mode 100644 tests/baselines/reference/templateStringInDeleteExpressionES6.types create mode 100644 tests/baselines/reference/templateStringInDivision.errors.txt create mode 100644 tests/baselines/reference/templateStringInDivision.js create mode 100644 tests/baselines/reference/templateStringInEqualityChecks.js create mode 100644 tests/baselines/reference/templateStringInEqualityChecks.types create mode 100644 tests/baselines/reference/templateStringInEqualityChecksES6.js create mode 100644 tests/baselines/reference/templateStringInEqualityChecksES6.types create mode 100644 tests/baselines/reference/templateStringInFunctionExpression.js create mode 100644 tests/baselines/reference/templateStringInFunctionExpression.types create mode 100644 tests/baselines/reference/templateStringInFunctionExpressionES6.js create mode 100644 tests/baselines/reference/templateStringInFunctionExpressionES6.types create mode 100644 tests/baselines/reference/templateStringInFunctionParameterType.errors.txt create mode 100644 tests/baselines/reference/templateStringInFunctionParameterTypeES6.errors.txt create mode 100644 tests/baselines/reference/templateStringInInOperator.js create mode 100644 tests/baselines/reference/templateStringInInOperator.types create mode 100644 tests/baselines/reference/templateStringInInOperatorES6.js create mode 100644 tests/baselines/reference/templateStringInInOperatorES6.types create mode 100644 tests/baselines/reference/templateStringInIndexExpression.js create mode 100644 tests/baselines/reference/templateStringInIndexExpression.types create mode 100644 tests/baselines/reference/templateStringInIndexExpressionES6.js create mode 100644 tests/baselines/reference/templateStringInIndexExpressionES6.types create mode 100644 tests/baselines/reference/templateStringInInstanceOf.errors.txt create mode 100644 tests/baselines/reference/templateStringInInstanceOf.js create mode 100644 tests/baselines/reference/templateStringInInstanceOfES6.errors.txt create mode 100644 tests/baselines/reference/templateStringInInstanceOfES6.js create mode 100644 tests/baselines/reference/templateStringInModuleName.errors.txt create mode 100644 tests/baselines/reference/templateStringInModuleNameES6.errors.txt create mode 100644 tests/baselines/reference/templateStringInModulo.errors.txt create mode 100644 tests/baselines/reference/templateStringInModulo.js create mode 100644 tests/baselines/reference/templateStringInModuloES6.errors.txt create mode 100644 tests/baselines/reference/templateStringInModuloES6.js create mode 100644 tests/baselines/reference/templateStringInMultiplication.errors.txt create mode 100644 tests/baselines/reference/templateStringInMultiplication.js create mode 100644 tests/baselines/reference/templateStringInMultiplicationES6.errors.txt create mode 100644 tests/baselines/reference/templateStringInMultiplicationES6.js create mode 100644 tests/baselines/reference/templateStringInNewOperator.errors.txt create mode 100644 tests/baselines/reference/templateStringInNewOperator.js create mode 100644 tests/baselines/reference/templateStringInNewOperatorES6.errors.txt create mode 100644 tests/baselines/reference/templateStringInNewOperatorES6.js create mode 100644 tests/baselines/reference/templateStringInObjectLiteral.errors.txt create mode 100644 tests/baselines/reference/templateStringInObjectLiteralES6.errors.txt create mode 100644 tests/baselines/reference/templateStringInParentheses.js create mode 100644 tests/baselines/reference/templateStringInParentheses.types create mode 100644 tests/baselines/reference/templateStringInParenthesesES6.js create mode 100644 tests/baselines/reference/templateStringInParenthesesES6.types create mode 100644 tests/baselines/reference/templateStringInSwitchAndCase.js create mode 100644 tests/baselines/reference/templateStringInSwitchAndCase.types create mode 100644 tests/baselines/reference/templateStringInSwitchAndCaseES6.js create mode 100644 tests/baselines/reference/templateStringInSwitchAndCaseES6.types create mode 100644 tests/baselines/reference/templateStringInTypeAssertion.js create mode 100644 tests/baselines/reference/templateStringInTypeAssertion.types create mode 100644 tests/baselines/reference/templateStringInTypeAssertionES6.js create mode 100644 tests/baselines/reference/templateStringInTypeAssertionES6.types create mode 100644 tests/baselines/reference/templateStringInTypeOf.js create mode 100644 tests/baselines/reference/templateStringInTypeOf.types create mode 100644 tests/baselines/reference/templateStringInTypeOfES6.js create mode 100644 tests/baselines/reference/templateStringInTypeOfES6.types create mode 100644 tests/baselines/reference/templateStringInUnaryPlus.js create mode 100644 tests/baselines/reference/templateStringInUnaryPlus.types create mode 100644 tests/baselines/reference/templateStringInUnaryPlusES6.js create mode 100644 tests/baselines/reference/templateStringInUnaryPlusES6.types create mode 100644 tests/baselines/reference/templateStringInWhile.js create mode 100644 tests/baselines/reference/templateStringInWhile.types create mode 100644 tests/baselines/reference/templateStringInWhileES6.js create mode 100644 tests/baselines/reference/templateStringInWhileES6.types create mode 100644 tests/baselines/reference/templateStringInYieldKeyword.errors.txt create mode 100644 tests/baselines/reference/templateStringWithEmbeddedAddition.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedAddition.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedAdditionES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedAdditionES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedArray.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedArray.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedArrayES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedArrayES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedArrowFunction.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedArrowFunction.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedArrowFunctionES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedArrowFunctionES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedComments.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedComments.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedCommentsES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedCommentsES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedConditional.errors.txt create mode 100644 tests/baselines/reference/templateStringWithEmbeddedConditional.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedConditionalES6.errors.txt create mode 100644 tests/baselines/reference/templateStringWithEmbeddedConditionalES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedDivision.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedDivision.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedDivisionES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedDivisionES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedFunctionExpression.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedFunctionExpression.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedFunctionExpressionES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedFunctionExpressionES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedInOperator.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedInOperator.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedInOperatorES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedInOperatorES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedInstanceOf.errors.txt create mode 100644 tests/baselines/reference/templateStringWithEmbeddedInstanceOf.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedInstanceOfES6.errors.txt create mode 100644 tests/baselines/reference/templateStringWithEmbeddedInstanceOfES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedModulo.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedModulo.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedModuloES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedModuloES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedMultiplication.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedMultiplication.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedMultiplicationES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedMultiplicationES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedNewOperator.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedNewOperator.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedObjectLiteral.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedObjectLiteral.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedObjectLiteralES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedObjectLiteralES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTemplateString.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTemplateString.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTemplateStringES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTemplateStringES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAddition.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAddition.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAdditionES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAdditionES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTypeOfOperator.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTypeOfOperator.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTypeOfOperatorES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedTypeOfOperatorES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedUnaryPlus.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedUnaryPlus.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedUnaryPlusES6.js create mode 100644 tests/baselines/reference/templateStringWithEmbeddedUnaryPlusES6.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt create mode 100644 tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt create mode 100644 tests/baselines/reference/templateStringWithOpenCommentInStringPortion.js create mode 100644 tests/baselines/reference/templateStringWithOpenCommentInStringPortion.types create mode 100644 tests/baselines/reference/templateStringWithOpenCommentInStringPortionES6.js create mode 100644 tests/baselines/reference/templateStringWithOpenCommentInStringPortionES6.types create mode 100644 tests/baselines/reference/templateStringWithPropertyAccess.js create mode 100644 tests/baselines/reference/templateStringWithPropertyAccess.types create mode 100644 tests/baselines/reference/templateStringWithPropertyAccessES6.js create mode 100644 tests/baselines/reference/templateStringWithPropertyAccessES6.types create mode 100644 tests/cases/conformance/es6/templates/templateStringInArray.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInArrowFunction.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInArrowFunctionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInBinaryAddition.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInBinaryAdditionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInConditional.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInConditionalES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInDeleteExpression.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInDeleteExpressionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInDivision.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInEqualityChecks.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInEqualityChecksES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInFunctionExpression.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInFunctionExpressionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInFunctionParameterType.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInFunctionParameterTypeES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInInOperator.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInInOperatorES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInIndexExpression.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInIndexExpressionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInInstanceOf.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInInstanceOfES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInModuleName.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInModulo.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInModuloES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInMultiplication.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInMultiplicationES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInNewOperator.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInNewOperatorES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInParentheses.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInParenthesesES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInSwitchAndCase.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInSwitchAndCaseES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInTypeAssertion.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInTypeAssertionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInTypeOf.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInTypeOfES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInUnaryPlus.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInUnaryPlusES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInWhile.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInWhileES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedAddition.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedAdditionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedArray.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrayES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunction.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunctionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedComments.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedCommentsES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditional.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditionalES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivision.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivisionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpression.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpressionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperator.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperatorES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOf.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOfES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedModulo.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedModuloES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplication.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplicationES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperator.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperatorES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteral.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteralES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateString.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateStringES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAddition.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAdditionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperator.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperatorES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlus.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlusES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortion.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortionES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithPropertyAccess.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithPropertyAccessES6.ts diff --git a/tests/baselines/reference/templateStringInArray.js b/tests/baselines/reference/templateStringInArray.js new file mode 100644 index 0000000000000..97d0b1a636b36 --- /dev/null +++ b/tests/baselines/reference/templateStringInArray.js @@ -0,0 +1,5 @@ +//// [templateStringInArray.ts] +var x = [1, 2, `abc${ 123 }def`]; + +//// [templateStringInArray.js] +var x = [1, 2, ("abc" + 123 + "def")]; diff --git a/tests/baselines/reference/templateStringInArray.types b/tests/baselines/reference/templateStringInArray.types new file mode 100644 index 0000000000000..4934bece9f4a0 --- /dev/null +++ b/tests/baselines/reference/templateStringInArray.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInArray.ts === +var x = [1, 2, `abc${ 123 }def`]; +>x : {}[] +>[1, 2, `abc${ 123 }def`] : {}[] + diff --git a/tests/baselines/reference/templateStringInArrowFunction.js b/tests/baselines/reference/templateStringInArrowFunction.js new file mode 100644 index 0000000000000..4c4890633e179 --- /dev/null +++ b/tests/baselines/reference/templateStringInArrowFunction.js @@ -0,0 +1,5 @@ +//// [templateStringInArrowFunction.ts] +var x = x => `abc${ x }def`; + +//// [templateStringInArrowFunction.js] +var x = function (x) { return ("abc" + x + "def"); }; diff --git a/tests/baselines/reference/templateStringInArrowFunction.types b/tests/baselines/reference/templateStringInArrowFunction.types new file mode 100644 index 0000000000000..e17f4d6d2eaf4 --- /dev/null +++ b/tests/baselines/reference/templateStringInArrowFunction.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringInArrowFunction.ts === +var x = x => `abc${ x }def`; +>x : (x: any) => string +>x => `abc${ x }def` : (x: any) => string +>x : any +>x : unknown + diff --git a/tests/baselines/reference/templateStringInArrowFunctionES6.js b/tests/baselines/reference/templateStringInArrowFunctionES6.js new file mode 100644 index 0000000000000..633b96e9da410 --- /dev/null +++ b/tests/baselines/reference/templateStringInArrowFunctionES6.js @@ -0,0 +1,5 @@ +//// [templateStringInArrowFunctionES6.ts] +var x = x => `abc${ x }def`; + +//// [templateStringInArrowFunctionES6.js] +var x = function (x) { return `abc${x}def`; }; diff --git a/tests/baselines/reference/templateStringInArrowFunctionES6.types b/tests/baselines/reference/templateStringInArrowFunctionES6.types new file mode 100644 index 0000000000000..38fca60e64758 --- /dev/null +++ b/tests/baselines/reference/templateStringInArrowFunctionES6.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringInArrowFunctionES6.ts === +var x = x => `abc${ x }def`; +>x : (x: any) => string +>x => `abc${ x }def` : (x: any) => string +>x : any +>x : unknown + diff --git a/tests/baselines/reference/templateStringInBinaryAddition.js b/tests/baselines/reference/templateStringInBinaryAddition.js new file mode 100644 index 0000000000000..0e1f728005ca1 --- /dev/null +++ b/tests/baselines/reference/templateStringInBinaryAddition.js @@ -0,0 +1,5 @@ +//// [templateStringInBinaryAddition.ts] +var x = 10 + `abc${ 10 }def`; + +//// [templateStringInBinaryAddition.js] +var x = 10 + ("abc" + 10 + "def"); diff --git a/tests/baselines/reference/templateStringInBinaryAddition.types b/tests/baselines/reference/templateStringInBinaryAddition.types new file mode 100644 index 0000000000000..f722ff696f490 --- /dev/null +++ b/tests/baselines/reference/templateStringInBinaryAddition.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInBinaryAddition.ts === +var x = 10 + `abc${ 10 }def`; +>x : string +>10 + `abc${ 10 }def` : string + diff --git a/tests/baselines/reference/templateStringInBinaryAdditionES6.js b/tests/baselines/reference/templateStringInBinaryAdditionES6.js new file mode 100644 index 0000000000000..7a40d4cc54fa6 --- /dev/null +++ b/tests/baselines/reference/templateStringInBinaryAdditionES6.js @@ -0,0 +1,5 @@ +//// [templateStringInBinaryAdditionES6.ts] +var x = 10 + `abc${ 10 }def`; + +//// [templateStringInBinaryAdditionES6.js] +var x = 10 + `abc${10}def`; diff --git a/tests/baselines/reference/templateStringInBinaryAdditionES6.types b/tests/baselines/reference/templateStringInBinaryAdditionES6.types new file mode 100644 index 0000000000000..b421d7dc70ec9 --- /dev/null +++ b/tests/baselines/reference/templateStringInBinaryAdditionES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInBinaryAdditionES6.ts === +var x = 10 + `abc${ 10 }def`; +>x : string +>10 + `abc${ 10 }def` : string + diff --git a/tests/baselines/reference/templateStringInConditional.js b/tests/baselines/reference/templateStringInConditional.js new file mode 100644 index 0000000000000..8ffcf24e5f490 --- /dev/null +++ b/tests/baselines/reference/templateStringInConditional.js @@ -0,0 +1,5 @@ +//// [templateStringInConditional.ts] +var x = `abc${ " " }def` ? `abc${ " " }def` : `abc${ " " }def`; + +//// [templateStringInConditional.js] +var x = "abc" + " " + "def" ? "abc" + " " + "def" : "abc" + " " + "def"; diff --git a/tests/baselines/reference/templateStringInConditional.types b/tests/baselines/reference/templateStringInConditional.types new file mode 100644 index 0000000000000..b4ff36b3891dc --- /dev/null +++ b/tests/baselines/reference/templateStringInConditional.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInConditional.ts === +var x = `abc${ " " }def` ? `abc${ " " }def` : `abc${ " " }def`; +>x : string +>`abc${ " " }def` ? `abc${ " " }def` : `abc${ " " }def` : string + diff --git a/tests/baselines/reference/templateStringInConditionalES6.js b/tests/baselines/reference/templateStringInConditionalES6.js new file mode 100644 index 0000000000000..d212b5c771751 --- /dev/null +++ b/tests/baselines/reference/templateStringInConditionalES6.js @@ -0,0 +1,5 @@ +//// [templateStringInConditionalES6.ts] +var x = `abc${ " " }def` ? `abc${ " " }def` : `abc${ " " }def`; + +//// [templateStringInConditionalES6.js] +var x = `abc${" "}def` ? `abc${" "}def` : `abc${" "}def`; diff --git a/tests/baselines/reference/templateStringInConditionalES6.types b/tests/baselines/reference/templateStringInConditionalES6.types new file mode 100644 index 0000000000000..c211ced258332 --- /dev/null +++ b/tests/baselines/reference/templateStringInConditionalES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInConditionalES6.ts === +var x = `abc${ " " }def` ? `abc${ " " }def` : `abc${ " " }def`; +>x : string +>`abc${ " " }def` ? `abc${ " " }def` : `abc${ " " }def` : string + diff --git a/tests/baselines/reference/templateStringInDeleteExpression.js b/tests/baselines/reference/templateStringInDeleteExpression.js new file mode 100644 index 0000000000000..e8da2e2ba32e2 --- /dev/null +++ b/tests/baselines/reference/templateStringInDeleteExpression.js @@ -0,0 +1,5 @@ +//// [templateStringInDeleteExpression.ts] +delete `abc${0}abc`; + +//// [templateStringInDeleteExpression.js] +delete ("abc" + 0 + "abc"); diff --git a/tests/baselines/reference/templateStringInDeleteExpression.types b/tests/baselines/reference/templateStringInDeleteExpression.types new file mode 100644 index 0000000000000..88693e5a9bbca --- /dev/null +++ b/tests/baselines/reference/templateStringInDeleteExpression.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/templates/templateStringInDeleteExpression.ts === +delete `abc${0}abc`; +>delete `abc${0}abc` : boolean + diff --git a/tests/baselines/reference/templateStringInDeleteExpressionES6.js b/tests/baselines/reference/templateStringInDeleteExpressionES6.js new file mode 100644 index 0000000000000..19f5d51b021f3 --- /dev/null +++ b/tests/baselines/reference/templateStringInDeleteExpressionES6.js @@ -0,0 +1,5 @@ +//// [templateStringInDeleteExpressionES6.ts] +delete `abc${0}abc`; + +//// [templateStringInDeleteExpressionES6.js] +delete `abc${0}abc`; diff --git a/tests/baselines/reference/templateStringInDeleteExpressionES6.types b/tests/baselines/reference/templateStringInDeleteExpressionES6.types new file mode 100644 index 0000000000000..d67d4d8c703b6 --- /dev/null +++ b/tests/baselines/reference/templateStringInDeleteExpressionES6.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/templates/templateStringInDeleteExpressionES6.ts === +delete `abc${0}abc`; +>delete `abc${0}abc` : boolean + diff --git a/tests/baselines/reference/templateStringInDivision.errors.txt b/tests/baselines/reference/templateStringInDivision.errors.txt new file mode 100644 index 0000000000000..32cc483039939 --- /dev/null +++ b/tests/baselines/reference/templateStringInDivision.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringInDivision.ts(1,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/conformance/es6/templates/templateStringInDivision.ts (1 errors) ==== + var x = `abc${ 1 }def` / 1; + ~~~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInDivision.js b/tests/baselines/reference/templateStringInDivision.js new file mode 100644 index 0000000000000..d624d73f6bb66 --- /dev/null +++ b/tests/baselines/reference/templateStringInDivision.js @@ -0,0 +1,5 @@ +//// [templateStringInDivision.ts] +var x = `abc${ 1 }def` / 1; + +//// [templateStringInDivision.js] +var x = ("abc" + 1 + "def") / 1; diff --git a/tests/baselines/reference/templateStringInEqualityChecks.js b/tests/baselines/reference/templateStringInEqualityChecks.js new file mode 100644 index 0000000000000..54f5fa610c286 --- /dev/null +++ b/tests/baselines/reference/templateStringInEqualityChecks.js @@ -0,0 +1,8 @@ +//// [templateStringInEqualityChecks.ts] +var x = `abc${0}abc` === `abc` || + `abc` !== `abc${0}abc` && + `abc${0}abc` == "abc0abc" && + "abc0abc" !== `abc${0}abc`; + +//// [templateStringInEqualityChecks.js] +var x = "abc" + 0 + "abc" === "abc" || "abc" !== "abc" + 0 + "abc" && "abc" + 0 + "abc" == "abc0abc" && "abc0abc" !== "abc" + 0 + "abc"; diff --git a/tests/baselines/reference/templateStringInEqualityChecks.types b/tests/baselines/reference/templateStringInEqualityChecks.types new file mode 100644 index 0000000000000..a942d4bce98bd --- /dev/null +++ b/tests/baselines/reference/templateStringInEqualityChecks.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/templates/templateStringInEqualityChecks.ts === +var x = `abc${0}abc` === `abc` || +>x : boolean +>`abc${0}abc` === `abc` || `abc` !== `abc${0}abc` && `abc${0}abc` == "abc0abc" && "abc0abc" !== `abc${0}abc` : boolean +>`abc${0}abc` === `abc` : boolean + + `abc` !== `abc${0}abc` && +>`abc` !== `abc${0}abc` && `abc${0}abc` == "abc0abc" && "abc0abc" !== `abc${0}abc` : boolean +>`abc` !== `abc${0}abc` && `abc${0}abc` == "abc0abc" : boolean +>`abc` !== `abc${0}abc` : boolean + + `abc${0}abc` == "abc0abc" && +>`abc${0}abc` == "abc0abc" : boolean + + "abc0abc" !== `abc${0}abc`; +>"abc0abc" !== `abc${0}abc` : boolean + diff --git a/tests/baselines/reference/templateStringInEqualityChecksES6.js b/tests/baselines/reference/templateStringInEqualityChecksES6.js new file mode 100644 index 0000000000000..317db1ab366bd --- /dev/null +++ b/tests/baselines/reference/templateStringInEqualityChecksES6.js @@ -0,0 +1,8 @@ +//// [templateStringInEqualityChecksES6.ts] +var x = `abc${0}abc` === `abc` || + `abc` !== `abc${0}abc` && + `abc${0}abc` == "abc0abc" && + "abc0abc" !== `abc${0}abc`; + +//// [templateStringInEqualityChecksES6.js] +var x = `abc${0}abc` === `abc` || `abc` !== `abc${0}abc` && `abc${0}abc` == "abc0abc" && "abc0abc" !== `abc${0}abc`; diff --git a/tests/baselines/reference/templateStringInEqualityChecksES6.types b/tests/baselines/reference/templateStringInEqualityChecksES6.types new file mode 100644 index 0000000000000..ffe300ccd3816 --- /dev/null +++ b/tests/baselines/reference/templateStringInEqualityChecksES6.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/templates/templateStringInEqualityChecksES6.ts === +var x = `abc${0}abc` === `abc` || +>x : boolean +>`abc${0}abc` === `abc` || `abc` !== `abc${0}abc` && `abc${0}abc` == "abc0abc" && "abc0abc" !== `abc${0}abc` : boolean +>`abc${0}abc` === `abc` : boolean + + `abc` !== `abc${0}abc` && +>`abc` !== `abc${0}abc` && `abc${0}abc` == "abc0abc" && "abc0abc" !== `abc${0}abc` : boolean +>`abc` !== `abc${0}abc` && `abc${0}abc` == "abc0abc" : boolean +>`abc` !== `abc${0}abc` : boolean + + `abc${0}abc` == "abc0abc" && +>`abc${0}abc` == "abc0abc" : boolean + + "abc0abc" !== `abc${0}abc`; +>"abc0abc" !== `abc${0}abc` : boolean + diff --git a/tests/baselines/reference/templateStringInFunctionExpression.js b/tests/baselines/reference/templateStringInFunctionExpression.js new file mode 100644 index 0000000000000..9711b2edc3a36 --- /dev/null +++ b/tests/baselines/reference/templateStringInFunctionExpression.js @@ -0,0 +1,11 @@ +//// [templateStringInFunctionExpression.ts] +var x = function y() { + `abc${ 0 }def` + return `abc${ 0 }def`; +}; + +//// [templateStringInFunctionExpression.js] +var x = function y() { + "abc" + 0 + "def"; + return "abc" + 0 + "def"; +}; diff --git a/tests/baselines/reference/templateStringInFunctionExpression.types b/tests/baselines/reference/templateStringInFunctionExpression.types new file mode 100644 index 0000000000000..1ec389488ec90 --- /dev/null +++ b/tests/baselines/reference/templateStringInFunctionExpression.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/templates/templateStringInFunctionExpression.ts === +var x = function y() { +>x : () => string +>function y() { `abc${ 0 }def` return `abc${ 0 }def`;} : () => string +>y : () => string + + `abc${ 0 }def` + return `abc${ 0 }def`; +}; diff --git a/tests/baselines/reference/templateStringInFunctionExpressionES6.js b/tests/baselines/reference/templateStringInFunctionExpressionES6.js new file mode 100644 index 0000000000000..e7cffe1471b9b --- /dev/null +++ b/tests/baselines/reference/templateStringInFunctionExpressionES6.js @@ -0,0 +1,11 @@ +//// [templateStringInFunctionExpressionES6.ts] +var x = function y() { + `abc${ 0 }def` + return `abc${ 0 }def`; +}; + +//// [templateStringInFunctionExpressionES6.js] +var x = function y() { + `abc${0}def`; + return `abc${0}def`; +}; diff --git a/tests/baselines/reference/templateStringInFunctionExpressionES6.types b/tests/baselines/reference/templateStringInFunctionExpressionES6.types new file mode 100644 index 0000000000000..a31558fbe373e --- /dev/null +++ b/tests/baselines/reference/templateStringInFunctionExpressionES6.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/templates/templateStringInFunctionExpressionES6.ts === +var x = function y() { +>x : () => string +>function y() { `abc${ 0 }def` return `abc${ 0 }def`;} : () => string +>y : () => string + + `abc${ 0 }def` + return `abc${ 0 }def`; +}; diff --git a/tests/baselines/reference/templateStringInFunctionParameterType.errors.txt b/tests/baselines/reference/templateStringInFunctionParameterType.errors.txt new file mode 100644 index 0000000000000..e0c35e3f19fef --- /dev/null +++ b/tests/baselines/reference/templateStringInFunctionParameterType.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/templates/templateStringInFunctionParameterType.ts(1,12): error TS1138: Parameter declaration expected. +tests/cases/conformance/es6/templates/templateStringInFunctionParameterType.ts(1,19): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInFunctionParameterType.ts(1,1): error TS2394: Overload signature is not compatible with function implementation. +tests/cases/conformance/es6/templates/templateStringInFunctionParameterType.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration. + + +==== tests/cases/conformance/es6/templates/templateStringInFunctionParameterType.ts (4 errors) ==== + function f(`hello`); + ~~~~~~~ +!!! error TS1138: Parameter declaration expected. + ~ +!!! error TS1005: ';' expected. + ~~~~~~~~~~~ +!!! error TS2394: Overload signature is not compatible with function implementation. + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + function f(x: string); + function f(x: string) { + return x; + } \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInFunctionParameterTypeES6.errors.txt b/tests/baselines/reference/templateStringInFunctionParameterTypeES6.errors.txt new file mode 100644 index 0000000000000..948c9ccc6cd84 --- /dev/null +++ b/tests/baselines/reference/templateStringInFunctionParameterTypeES6.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/templates/templateStringInFunctionParameterTypeES6.ts(1,12): error TS1138: Parameter declaration expected. +tests/cases/conformance/es6/templates/templateStringInFunctionParameterTypeES6.ts(1,19): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInFunctionParameterTypeES6.ts(1,1): error TS2394: Overload signature is not compatible with function implementation. +tests/cases/conformance/es6/templates/templateStringInFunctionParameterTypeES6.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration. + + +==== tests/cases/conformance/es6/templates/templateStringInFunctionParameterTypeES6.ts (4 errors) ==== + function f(`hello`); + ~~~~~~~ +!!! error TS1138: Parameter declaration expected. + ~ +!!! error TS1005: ';' expected. + ~~~~~~~~~~~ +!!! error TS2394: Overload signature is not compatible with function implementation. + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + function f(x: string); + function f(x: string) { + return x; + } \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInInOperator.js b/tests/baselines/reference/templateStringInInOperator.js new file mode 100644 index 0000000000000..18890c9858a9d --- /dev/null +++ b/tests/baselines/reference/templateStringInInOperator.js @@ -0,0 +1,5 @@ +//// [templateStringInInOperator.ts] +var x = `${ "hi" }` in { hi: 10, hello: 20}; + +//// [templateStringInInOperator.js] +var x = "" + "hi" + "" in { hi: 10, hello: 20 }; diff --git a/tests/baselines/reference/templateStringInInOperator.types b/tests/baselines/reference/templateStringInInOperator.types new file mode 100644 index 0000000000000..da35bdc499c3c --- /dev/null +++ b/tests/baselines/reference/templateStringInInOperator.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/templates/templateStringInInOperator.ts === +var x = `${ "hi" }` in { hi: 10, hello: 20}; +>x : boolean +>`${ "hi" }` in { hi: 10, hello: 20} : boolean +>{ hi: 10, hello: 20} : { hi: number; hello: number; } +>hi : number +>hello : number + diff --git a/tests/baselines/reference/templateStringInInOperatorES6.js b/tests/baselines/reference/templateStringInInOperatorES6.js new file mode 100644 index 0000000000000..bd4daef3b6d64 --- /dev/null +++ b/tests/baselines/reference/templateStringInInOperatorES6.js @@ -0,0 +1,5 @@ +//// [templateStringInInOperatorES6.ts] +var x = `${ "hi" }` in { hi: 10, hello: 20}; + +//// [templateStringInInOperatorES6.js] +var x = `${"hi"}` in { hi: 10, hello: 20 }; diff --git a/tests/baselines/reference/templateStringInInOperatorES6.types b/tests/baselines/reference/templateStringInInOperatorES6.types new file mode 100644 index 0000000000000..7af0d7a2f480a --- /dev/null +++ b/tests/baselines/reference/templateStringInInOperatorES6.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/templates/templateStringInInOperatorES6.ts === +var x = `${ "hi" }` in { hi: 10, hello: 20}; +>x : boolean +>`${ "hi" }` in { hi: 10, hello: 20} : boolean +>{ hi: 10, hello: 20} : { hi: number; hello: number; } +>hi : number +>hello : number + diff --git a/tests/baselines/reference/templateStringInIndexExpression.js b/tests/baselines/reference/templateStringInIndexExpression.js new file mode 100644 index 0000000000000..680cfb49f47e4 --- /dev/null +++ b/tests/baselines/reference/templateStringInIndexExpression.js @@ -0,0 +1,5 @@ +//// [templateStringInIndexExpression.ts] +`abc${0}abc`[`0`]; + +//// [templateStringInIndexExpression.js] +("abc" + 0 + "abc")["0"]; diff --git a/tests/baselines/reference/templateStringInIndexExpression.types b/tests/baselines/reference/templateStringInIndexExpression.types new file mode 100644 index 0000000000000..a0270b850ab16 --- /dev/null +++ b/tests/baselines/reference/templateStringInIndexExpression.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/templates/templateStringInIndexExpression.ts === +`abc${0}abc`[`0`]; +>`abc${0}abc`[`0`] : any + diff --git a/tests/baselines/reference/templateStringInIndexExpressionES6.js b/tests/baselines/reference/templateStringInIndexExpressionES6.js new file mode 100644 index 0000000000000..c1c87211a0561 --- /dev/null +++ b/tests/baselines/reference/templateStringInIndexExpressionES6.js @@ -0,0 +1,5 @@ +//// [templateStringInIndexExpressionES6.ts] +`abc${0}abc`[`0`]; + +//// [templateStringInIndexExpressionES6.js] +`abc${0}abc`[`0`]; diff --git a/tests/baselines/reference/templateStringInIndexExpressionES6.types b/tests/baselines/reference/templateStringInIndexExpressionES6.types new file mode 100644 index 0000000000000..aceb22da52977 --- /dev/null +++ b/tests/baselines/reference/templateStringInIndexExpressionES6.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/templates/templateStringInIndexExpressionES6.ts === +`abc${0}abc`[`0`]; +>`abc${0}abc`[`0`] : any + diff --git a/tests/baselines/reference/templateStringInInstanceOf.errors.txt b/tests/baselines/reference/templateStringInInstanceOf.errors.txt new file mode 100644 index 0000000000000..04d2584712bc5 --- /dev/null +++ b/tests/baselines/reference/templateStringInInstanceOf.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringInInstanceOf.ts(1,9): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. + + +==== tests/cases/conformance/es6/templates/templateStringInInstanceOf.ts (1 errors) ==== + var x = `abc${ 0 }def` instanceof String; + ~~~~~~~~~~~~~~ +!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInInstanceOf.js b/tests/baselines/reference/templateStringInInstanceOf.js new file mode 100644 index 0000000000000..ccf022cc70336 --- /dev/null +++ b/tests/baselines/reference/templateStringInInstanceOf.js @@ -0,0 +1,5 @@ +//// [templateStringInInstanceOf.ts] +var x = `abc${ 0 }def` instanceof String; + +//// [templateStringInInstanceOf.js] +var x = "abc" + 0 + "def" instanceof String; diff --git a/tests/baselines/reference/templateStringInInstanceOfES6.errors.txt b/tests/baselines/reference/templateStringInInstanceOfES6.errors.txt new file mode 100644 index 0000000000000..0fc8c81ab924c --- /dev/null +++ b/tests/baselines/reference/templateStringInInstanceOfES6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringInInstanceOfES6.ts(1,9): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. + + +==== tests/cases/conformance/es6/templates/templateStringInInstanceOfES6.ts (1 errors) ==== + var x = `abc${ 0 }def` instanceof String; + ~~~~~~~~~~~~~~ +!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInInstanceOfES6.js b/tests/baselines/reference/templateStringInInstanceOfES6.js new file mode 100644 index 0000000000000..793c183d13765 --- /dev/null +++ b/tests/baselines/reference/templateStringInInstanceOfES6.js @@ -0,0 +1,5 @@ +//// [templateStringInInstanceOfES6.ts] +var x = `abc${ 0 }def` instanceof String; + +//// [templateStringInInstanceOfES6.js] +var x = `abc${0}def` instanceof String; diff --git a/tests/baselines/reference/templateStringInModuleName.errors.txt b/tests/baselines/reference/templateStringInModuleName.errors.txt new file mode 100644 index 0000000000000..4aa06a6232b93 --- /dev/null +++ b/tests/baselines/reference/templateStringInModuleName.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,16): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,21): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,16): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,24): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,1): error TS2304: Cannot find name 'declare'. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS2304: Cannot find name 'module'. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,1): error TS2304: Cannot find name 'declare'. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS2304: Cannot find name 'module'. + + +==== tests/cases/conformance/es6/templates/templateStringInModuleName.ts (10 errors) ==== + declare module `M1` { + ~~~~~~ +!!! error TS1005: ';' expected. + ~~~~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~~ +!!! error TS2304: Cannot find name 'module'. + } + + declare module `M${2}` { + ~~~~~~ +!!! error TS1005: ';' expected. + ~~~~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~~ +!!! error TS2304: Cannot find name 'module'. + } \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInModuleNameES6.errors.txt b/tests/baselines/reference/templateStringInModuleNameES6.errors.txt new file mode 100644 index 0000000000000..fa2bed3d474a3 --- /dev/null +++ b/tests/baselines/reference/templateStringInModuleNameES6.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,9): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,16): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,21): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,9): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,16): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,24): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,1): error TS2304: Cannot find name 'declare'. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,9): error TS2304: Cannot find name 'module'. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,1): error TS2304: Cannot find name 'declare'. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,9): error TS2304: Cannot find name 'module'. + + +==== tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts (10 errors) ==== + declare module `M1` { + ~~~~~~ +!!! error TS1005: ';' expected. + ~~~~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~~ +!!! error TS2304: Cannot find name 'module'. + } + + declare module `M${2}` { + ~~~~~~ +!!! error TS1005: ';' expected. + ~~~~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~~ +!!! error TS2304: Cannot find name 'module'. + } \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInModulo.errors.txt b/tests/baselines/reference/templateStringInModulo.errors.txt new file mode 100644 index 0000000000000..f9f0b0257d66a --- /dev/null +++ b/tests/baselines/reference/templateStringInModulo.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringInModulo.ts(1,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/conformance/es6/templates/templateStringInModulo.ts (1 errors) ==== + var x = 1 % `abc${ 1 }def`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInModulo.js b/tests/baselines/reference/templateStringInModulo.js new file mode 100644 index 0000000000000..65d5ec7eaab3a --- /dev/null +++ b/tests/baselines/reference/templateStringInModulo.js @@ -0,0 +1,5 @@ +//// [templateStringInModulo.ts] +var x = 1 % `abc${ 1 }def`; + +//// [templateStringInModulo.js] +var x = 1 % ("abc" + 1 + "def"); diff --git a/tests/baselines/reference/templateStringInModuloES6.errors.txt b/tests/baselines/reference/templateStringInModuloES6.errors.txt new file mode 100644 index 0000000000000..db410876b9153 --- /dev/null +++ b/tests/baselines/reference/templateStringInModuloES6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringInModuloES6.ts(1,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/conformance/es6/templates/templateStringInModuloES6.ts (1 errors) ==== + var x = 1 % `abc${ 1 }def`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInModuloES6.js b/tests/baselines/reference/templateStringInModuloES6.js new file mode 100644 index 0000000000000..2fae209b85fd0 --- /dev/null +++ b/tests/baselines/reference/templateStringInModuloES6.js @@ -0,0 +1,5 @@ +//// [templateStringInModuloES6.ts] +var x = 1 % `abc${ 1 }def`; + +//// [templateStringInModuloES6.js] +var x = 1 % `abc${1}def`; diff --git a/tests/baselines/reference/templateStringInMultiplication.errors.txt b/tests/baselines/reference/templateStringInMultiplication.errors.txt new file mode 100644 index 0000000000000..11a4ea9985e90 --- /dev/null +++ b/tests/baselines/reference/templateStringInMultiplication.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringInMultiplication.ts(1,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/conformance/es6/templates/templateStringInMultiplication.ts (1 errors) ==== + var x = 1 * `abc${ 1 }def`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInMultiplication.js b/tests/baselines/reference/templateStringInMultiplication.js new file mode 100644 index 0000000000000..e48db6e1715a8 --- /dev/null +++ b/tests/baselines/reference/templateStringInMultiplication.js @@ -0,0 +1,5 @@ +//// [templateStringInMultiplication.ts] +var x = 1 * `abc${ 1 }def`; + +//// [templateStringInMultiplication.js] +var x = 1 * ("abc" + 1 + "def"); diff --git a/tests/baselines/reference/templateStringInMultiplicationES6.errors.txt b/tests/baselines/reference/templateStringInMultiplicationES6.errors.txt new file mode 100644 index 0000000000000..ee27091778f31 --- /dev/null +++ b/tests/baselines/reference/templateStringInMultiplicationES6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringInMultiplicationES6.ts(1,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/conformance/es6/templates/templateStringInMultiplicationES6.ts (1 errors) ==== + var x = 1 * `abc${ 1 }def`; + ~~~~~~~~~~~~~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInMultiplicationES6.js b/tests/baselines/reference/templateStringInMultiplicationES6.js new file mode 100644 index 0000000000000..f890e900301ea --- /dev/null +++ b/tests/baselines/reference/templateStringInMultiplicationES6.js @@ -0,0 +1,5 @@ +//// [templateStringInMultiplicationES6.ts] +var x = 1 * `abc${ 1 }def`; + +//// [templateStringInMultiplicationES6.js] +var x = 1 * `abc${1}def`; diff --git a/tests/baselines/reference/templateStringInNewOperator.errors.txt b/tests/baselines/reference/templateStringInNewOperator.errors.txt new file mode 100644 index 0000000000000..eed7415e5d25e --- /dev/null +++ b/tests/baselines/reference/templateStringInNewOperator.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringInNewOperator.ts(1,9): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. + + +==== tests/cases/conformance/es6/templates/templateStringInNewOperator.ts (1 errors) ==== + var x = new `abc${ 1 }def`; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInNewOperator.js b/tests/baselines/reference/templateStringInNewOperator.js new file mode 100644 index 0000000000000..8d76d59f7eecb --- /dev/null +++ b/tests/baselines/reference/templateStringInNewOperator.js @@ -0,0 +1,5 @@ +//// [templateStringInNewOperator.ts] +var x = new `abc${ 1 }def`; + +//// [templateStringInNewOperator.js] +var x = new ("abc" + 1 + "def"); diff --git a/tests/baselines/reference/templateStringInNewOperatorES6.errors.txt b/tests/baselines/reference/templateStringInNewOperatorES6.errors.txt new file mode 100644 index 0000000000000..f4363d9ff2056 --- /dev/null +++ b/tests/baselines/reference/templateStringInNewOperatorES6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringInNewOperatorES6.ts(1,9): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. + + +==== tests/cases/conformance/es6/templates/templateStringInNewOperatorES6.ts (1 errors) ==== + var x = new `abc${ 1 }def`; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInNewOperatorES6.js b/tests/baselines/reference/templateStringInNewOperatorES6.js new file mode 100644 index 0000000000000..066978f736b41 --- /dev/null +++ b/tests/baselines/reference/templateStringInNewOperatorES6.js @@ -0,0 +1,5 @@ +//// [templateStringInNewOperatorES6.ts] +var x = new `abc${ 1 }def`; + +//// [templateStringInNewOperatorES6.js] +var x = new `abc${1}def`; diff --git a/tests/baselines/reference/templateStringInObjectLiteral.errors.txt b/tests/baselines/reference/templateStringInObjectLiteral.errors.txt new file mode 100644 index 0000000000000..60fa4f9989452 --- /dev/null +++ b/tests/baselines/reference/templateStringInObjectLiteral.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(3,5): error TS1136: Property assignment expected. +tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(3,8): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(4,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts (3 errors) ==== + var x = { + a: `abc${ 123 }def`, + `b`: 321 + ~~~ +!!! error TS1136: Property assignment expected. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInObjectLiteralES6.errors.txt b/tests/baselines/reference/templateStringInObjectLiteralES6.errors.txt new file mode 100644 index 0000000000000..6514356aedc0d --- /dev/null +++ b/tests/baselines/reference/templateStringInObjectLiteralES6.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts(3,5): error TS1136: Property assignment expected. +tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts(3,8): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts(4,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts (3 errors) ==== + var x = { + a: `abc${ 123 }def`, + `b`: 321 + ~~~ +!!! error TS1136: Property assignment expected. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInParentheses.js b/tests/baselines/reference/templateStringInParentheses.js new file mode 100644 index 0000000000000..381e8ffd800e9 --- /dev/null +++ b/tests/baselines/reference/templateStringInParentheses.js @@ -0,0 +1,5 @@ +//// [templateStringInParentheses.ts] +var x = (`abc${0}abc`); + +//// [templateStringInParentheses.js] +var x = (("abc" + 0 + "abc")); diff --git a/tests/baselines/reference/templateStringInParentheses.types b/tests/baselines/reference/templateStringInParentheses.types new file mode 100644 index 0000000000000..7e597dc01088c --- /dev/null +++ b/tests/baselines/reference/templateStringInParentheses.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInParentheses.ts === +var x = (`abc${0}abc`); +>x : string +>(`abc${0}abc`) : string + diff --git a/tests/baselines/reference/templateStringInParenthesesES6.js b/tests/baselines/reference/templateStringInParenthesesES6.js new file mode 100644 index 0000000000000..0776ea594d292 --- /dev/null +++ b/tests/baselines/reference/templateStringInParenthesesES6.js @@ -0,0 +1,5 @@ +//// [templateStringInParenthesesES6.ts] +var x = (`abc${0}abc`); + +//// [templateStringInParenthesesES6.js] +var x = (`abc${0}abc`); diff --git a/tests/baselines/reference/templateStringInParenthesesES6.types b/tests/baselines/reference/templateStringInParenthesesES6.types new file mode 100644 index 0000000000000..3afb3530dee74 --- /dev/null +++ b/tests/baselines/reference/templateStringInParenthesesES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInParenthesesES6.ts === +var x = (`abc${0}abc`); +>x : string +>(`abc${0}abc`) : string + diff --git a/tests/baselines/reference/templateStringInSwitchAndCase.js b/tests/baselines/reference/templateStringInSwitchAndCase.js new file mode 100644 index 0000000000000..67f182f8012d3 --- /dev/null +++ b/tests/baselines/reference/templateStringInSwitchAndCase.js @@ -0,0 +1,15 @@ +//// [templateStringInSwitchAndCase.ts] +switch (`abc${0}abc`) { + case `abc`: + case `123`: + case `abc${0}abc`: + `def${1}def`; +} + +//// [templateStringInSwitchAndCase.js] +switch ("abc" + 0 + "abc") { + case "abc": + case "123": + case "abc" + 0 + "abc": + "def" + 1 + "def"; +} diff --git a/tests/baselines/reference/templateStringInSwitchAndCase.types b/tests/baselines/reference/templateStringInSwitchAndCase.types new file mode 100644 index 0000000000000..26ec05dbca6f3 --- /dev/null +++ b/tests/baselines/reference/templateStringInSwitchAndCase.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/templates/templateStringInSwitchAndCase.ts === +switch (`abc${0}abc`) { +No type information for this code. case `abc`: +No type information for this code. case `123`: +No type information for this code. case `abc${0}abc`: +No type information for this code. `def${1}def`; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInSwitchAndCaseES6.js b/tests/baselines/reference/templateStringInSwitchAndCaseES6.js new file mode 100644 index 0000000000000..b52cb48cfdec3 --- /dev/null +++ b/tests/baselines/reference/templateStringInSwitchAndCaseES6.js @@ -0,0 +1,15 @@ +//// [templateStringInSwitchAndCaseES6.ts] +switch (`abc${0}abc`) { + case `abc`: + case `123`: + case `abc${0}abc`: + `def${1}def`; +} + +//// [templateStringInSwitchAndCaseES6.js] +switch (`abc${0}abc`) { + case `abc`: + case `123`: + case `abc${0}abc`: + `def${1}def`; +} diff --git a/tests/baselines/reference/templateStringInSwitchAndCaseES6.types b/tests/baselines/reference/templateStringInSwitchAndCaseES6.types new file mode 100644 index 0000000000000..6bd8772ff4942 --- /dev/null +++ b/tests/baselines/reference/templateStringInSwitchAndCaseES6.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/templates/templateStringInSwitchAndCaseES6.ts === +switch (`abc${0}abc`) { +No type information for this code. case `abc`: +No type information for this code. case `123`: +No type information for this code. case `abc${0}abc`: +No type information for this code. `def${1}def`; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInTypeAssertion.js b/tests/baselines/reference/templateStringInTypeAssertion.js new file mode 100644 index 0000000000000..94533248b6d43 --- /dev/null +++ b/tests/baselines/reference/templateStringInTypeAssertion.js @@ -0,0 +1,5 @@ +//// [templateStringInTypeAssertion.ts] +var x = `abc${ 123 }def`; + +//// [templateStringInTypeAssertion.js] +var x = ("abc" + 123 + "def"); diff --git a/tests/baselines/reference/templateStringInTypeAssertion.types b/tests/baselines/reference/templateStringInTypeAssertion.types new file mode 100644 index 0000000000000..006ba12c1c6e7 --- /dev/null +++ b/tests/baselines/reference/templateStringInTypeAssertion.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInTypeAssertion.ts === +var x = `abc${ 123 }def`; +>x : any +>`abc${ 123 }def` : any + diff --git a/tests/baselines/reference/templateStringInTypeAssertionES6.js b/tests/baselines/reference/templateStringInTypeAssertionES6.js new file mode 100644 index 0000000000000..08331911c7d84 --- /dev/null +++ b/tests/baselines/reference/templateStringInTypeAssertionES6.js @@ -0,0 +1,5 @@ +//// [templateStringInTypeAssertionES6.ts] +var x = `abc${ 123 }def`; + +//// [templateStringInTypeAssertionES6.js] +var x = `abc${123}def`; diff --git a/tests/baselines/reference/templateStringInTypeAssertionES6.types b/tests/baselines/reference/templateStringInTypeAssertionES6.types new file mode 100644 index 0000000000000..26d7ccc2e6000 --- /dev/null +++ b/tests/baselines/reference/templateStringInTypeAssertionES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInTypeAssertionES6.ts === +var x = `abc${ 123 }def`; +>x : any +>`abc${ 123 }def` : any + diff --git a/tests/baselines/reference/templateStringInTypeOf.js b/tests/baselines/reference/templateStringInTypeOf.js new file mode 100644 index 0000000000000..2543091df8831 --- /dev/null +++ b/tests/baselines/reference/templateStringInTypeOf.js @@ -0,0 +1,5 @@ +//// [templateStringInTypeOf.ts] +var x = typeof `abc${ 123 }def`; + +//// [templateStringInTypeOf.js] +var x = typeof ("abc" + 123 + "def"); diff --git a/tests/baselines/reference/templateStringInTypeOf.types b/tests/baselines/reference/templateStringInTypeOf.types new file mode 100644 index 0000000000000..8b94bc7ea1a16 --- /dev/null +++ b/tests/baselines/reference/templateStringInTypeOf.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInTypeOf.ts === +var x = typeof `abc${ 123 }def`; +>x : string +>typeof `abc${ 123 }def` : string + diff --git a/tests/baselines/reference/templateStringInTypeOfES6.js b/tests/baselines/reference/templateStringInTypeOfES6.js new file mode 100644 index 0000000000000..e8566277449d6 --- /dev/null +++ b/tests/baselines/reference/templateStringInTypeOfES6.js @@ -0,0 +1,5 @@ +//// [templateStringInTypeOfES6.ts] +var x = typeof `abc${ 123 }def`; + +//// [templateStringInTypeOfES6.js] +var x = typeof `abc${123}def`; diff --git a/tests/baselines/reference/templateStringInTypeOfES6.types b/tests/baselines/reference/templateStringInTypeOfES6.types new file mode 100644 index 0000000000000..457af8de0de4d --- /dev/null +++ b/tests/baselines/reference/templateStringInTypeOfES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInTypeOfES6.ts === +var x = typeof `abc${ 123 }def`; +>x : string +>typeof `abc${ 123 }def` : string + diff --git a/tests/baselines/reference/templateStringInUnaryPlus.js b/tests/baselines/reference/templateStringInUnaryPlus.js new file mode 100644 index 0000000000000..83f107b3ac2fd --- /dev/null +++ b/tests/baselines/reference/templateStringInUnaryPlus.js @@ -0,0 +1,5 @@ +//// [templateStringInUnaryPlus.ts] +var x = +`abc${ 123 }def`; + +//// [templateStringInUnaryPlus.js] +var x = +("abc" + 123 + "def"); diff --git a/tests/baselines/reference/templateStringInUnaryPlus.types b/tests/baselines/reference/templateStringInUnaryPlus.types new file mode 100644 index 0000000000000..4746f2c1fc7b0 --- /dev/null +++ b/tests/baselines/reference/templateStringInUnaryPlus.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInUnaryPlus.ts === +var x = +`abc${ 123 }def`; +>x : number +>+`abc${ 123 }def` : number + diff --git a/tests/baselines/reference/templateStringInUnaryPlusES6.js b/tests/baselines/reference/templateStringInUnaryPlusES6.js new file mode 100644 index 0000000000000..efeed300f7c97 --- /dev/null +++ b/tests/baselines/reference/templateStringInUnaryPlusES6.js @@ -0,0 +1,5 @@ +//// [templateStringInUnaryPlusES6.ts] +var x = +`abc${ 123 }def`; + +//// [templateStringInUnaryPlusES6.js] +var x = +`abc${123}def`; diff --git a/tests/baselines/reference/templateStringInUnaryPlusES6.types b/tests/baselines/reference/templateStringInUnaryPlusES6.types new file mode 100644 index 0000000000000..67ad03fc53cb1 --- /dev/null +++ b/tests/baselines/reference/templateStringInUnaryPlusES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInUnaryPlusES6.ts === +var x = +`abc${ 123 }def`; +>x : number +>+`abc${ 123 }def` : number + diff --git a/tests/baselines/reference/templateStringInWhile.js b/tests/baselines/reference/templateStringInWhile.js new file mode 100644 index 0000000000000..31f7dba45d1da --- /dev/null +++ b/tests/baselines/reference/templateStringInWhile.js @@ -0,0 +1,9 @@ +//// [templateStringInWhile.ts] +while (`abc${0}abc`) { + `def${1}def`; +} + +//// [templateStringInWhile.js] +while ("abc" + 0 + "abc") { + "def" + 1 + "def"; +} diff --git a/tests/baselines/reference/templateStringInWhile.types b/tests/baselines/reference/templateStringInWhile.types new file mode 100644 index 0000000000000..1b080f31f1ca7 --- /dev/null +++ b/tests/baselines/reference/templateStringInWhile.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInWhile.ts === +while (`abc${0}abc`) { +No type information for this code. `def${1}def`; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInWhileES6.js b/tests/baselines/reference/templateStringInWhileES6.js new file mode 100644 index 0000000000000..a4f19b80d0a6d --- /dev/null +++ b/tests/baselines/reference/templateStringInWhileES6.js @@ -0,0 +1,9 @@ +//// [templateStringInWhileES6.ts] +while (`abc${0}abc`) { + `def${1}def`; +} + +//// [templateStringInWhileES6.js] +while (`abc${0}abc`) { + `def${1}def`; +} diff --git a/tests/baselines/reference/templateStringInWhileES6.types b/tests/baselines/reference/templateStringInWhileES6.types new file mode 100644 index 0000000000000..d4ef3b02fe245 --- /dev/null +++ b/tests/baselines/reference/templateStringInWhileES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringInWhileES6.ts === +while (`abc${0}abc`) { +No type information for this code. `def${1}def`; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInYieldKeyword.errors.txt b/tests/baselines/reference/templateStringInYieldKeyword.errors.txt new file mode 100644 index 0000000000000..61a9ddf39341e --- /dev/null +++ b/tests/baselines/reference/templateStringInYieldKeyword.errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,9): error TS1003: Identifier expected. +tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,15): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,19): error TS1005: ',' expected. +tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,11): error TS2304: Cannot find name 'gen'. +tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,13): error TS2304: Cannot find name 'yield'. + + +==== tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts (5 errors) ==== + function* gen { + ~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + ~~~ +!!! error TS2304: Cannot find name 'gen'. + // Once this is supported, the inner expression does not need to be parenthesized. + var x = yield `abc${ x }def`; + ~~~~~~ +!!! error TS1005: ',' expected. + ~~~~~ +!!! error TS2304: Cannot find name 'yield'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedAddition.js b/tests/baselines/reference/templateStringWithEmbeddedAddition.js new file mode 100644 index 0000000000000..2cf74941600fd --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedAddition.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedAddition.ts] +var x = `abc${ 10 + 10 }def`; + +//// [templateStringWithEmbeddedAddition.js] +var x = "abc" + (10 + 10) + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedAddition.types b/tests/baselines/reference/templateStringWithEmbeddedAddition.types new file mode 100644 index 0000000000000..3a6bf864cb63e --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedAddition.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedAddition.ts === +var x = `abc${ 10 + 10 }def`; +>x : string +>10 + 10 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedAdditionES6.js b/tests/baselines/reference/templateStringWithEmbeddedAdditionES6.js new file mode 100644 index 0000000000000..72beea32d5720 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedAdditionES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedAdditionES6.ts] +var x = `abc${ 10 + 10 }def`; + +//// [templateStringWithEmbeddedAdditionES6.js] +var x = `abc${10 + 10}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedAdditionES6.types b/tests/baselines/reference/templateStringWithEmbeddedAdditionES6.types new file mode 100644 index 0000000000000..699162a378389 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedAdditionES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedAdditionES6.ts === +var x = `abc${ 10 + 10 }def`; +>x : string +>10 + 10 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedArray.js b/tests/baselines/reference/templateStringWithEmbeddedArray.js new file mode 100644 index 0000000000000..1fb6512db478b --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedArray.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedArray.ts] +var x = `abc${ [1,2,3] }def`; + +//// [templateStringWithEmbeddedArray.js] +var x = "abc" + [1, 2, 3] + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedArray.types b/tests/baselines/reference/templateStringWithEmbeddedArray.types new file mode 100644 index 0000000000000..4c022d8a4014b --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedArray.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedArray.ts === +var x = `abc${ [1,2,3] }def`; +>x : string +>[1,2,3] : number[] + diff --git a/tests/baselines/reference/templateStringWithEmbeddedArrayES6.js b/tests/baselines/reference/templateStringWithEmbeddedArrayES6.js new file mode 100644 index 0000000000000..804ef7a4e78ae --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedArrayES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedArrayES6.ts] +var x = `abc${ [1,2,3] }def`; + +//// [templateStringWithEmbeddedArrayES6.js] +var x = `abc${[1, 2, 3]}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedArrayES6.types b/tests/baselines/reference/templateStringWithEmbeddedArrayES6.types new file mode 100644 index 0000000000000..06876fa3f0e51 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedArrayES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrayES6.ts === +var x = `abc${ [1,2,3] }def`; +>x : string +>[1,2,3] : number[] + diff --git a/tests/baselines/reference/templateStringWithEmbeddedArrowFunction.js b/tests/baselines/reference/templateStringWithEmbeddedArrowFunction.js new file mode 100644 index 0000000000000..eb2579b0cc32b --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedArrowFunction.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedArrowFunction.ts] +var x = `abc${ x => x }def`; + +//// [templateStringWithEmbeddedArrowFunction.js] +var x = "abc" + function (x) { return x; } + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedArrowFunction.types b/tests/baselines/reference/templateStringWithEmbeddedArrowFunction.types new file mode 100644 index 0000000000000..d6f25761999fb --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedArrowFunction.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunction.ts === +var x = `abc${ x => x }def`; +>x : string +>x => x : (x: any) => any +>x : any +>x : any + diff --git a/tests/baselines/reference/templateStringWithEmbeddedArrowFunctionES6.js b/tests/baselines/reference/templateStringWithEmbeddedArrowFunctionES6.js new file mode 100644 index 0000000000000..f6f068aaa371c --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedArrowFunctionES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedArrowFunctionES6.ts] +var x = `abc${ x => x }def`; + +//// [templateStringWithEmbeddedArrowFunctionES6.js] +var x = `abc${function (x) { return x; }}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedArrowFunctionES6.types b/tests/baselines/reference/templateStringWithEmbeddedArrowFunctionES6.types new file mode 100644 index 0000000000000..748f457f22bbc --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedArrowFunctionES6.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunctionES6.ts === +var x = `abc${ x => x }def`; +>x : string +>x => x : (x: any) => any +>x : any +>x : any + diff --git a/tests/baselines/reference/templateStringWithEmbeddedComments.js b/tests/baselines/reference/templateStringWithEmbeddedComments.js new file mode 100644 index 0000000000000..58a73e89ba7a2 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedComments.js @@ -0,0 +1,16 @@ +//// [templateStringWithEmbeddedComments.ts] +`head${ // single line comment +10 +} +middle${ +/* Multi- + * line + * comment + */ + 20 + // closing comment +} +tail`; + +//// [templateStringWithEmbeddedComments.js] +"head" + 10 + "\nmiddle" + 20 + "\ntail"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedComments.types b/tests/baselines/reference/templateStringWithEmbeddedComments.types new file mode 100644 index 0000000000000..a375ef6ab6ff4 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedComments.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedComments.ts === +`head${ // single line comment +No type information for this code.10 +No type information for this code.} +No type information for this code.middle${ +No type information for this code./* Multi- +No type information for this code. * line +No type information for this code. * comment +No type information for this code. */ +No type information for this code. 20 +No type information for this code. // closing comment +No type information for this code.} +No type information for this code.tail`; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedCommentsES6.js b/tests/baselines/reference/templateStringWithEmbeddedCommentsES6.js new file mode 100644 index 0000000000000..c6b3649ad2aed --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedCommentsES6.js @@ -0,0 +1,16 @@ +//// [templateStringWithEmbeddedCommentsES6.ts] +`head${ // single line comment +10 +} +middle${ +/* Multi- + * line + * comment + */ + 20 + // closing comment +} +tail`; + +//// [templateStringWithEmbeddedCommentsES6.js] +"head" + 10 + "\nmiddle" + 20 + "\ntail"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedCommentsES6.types b/tests/baselines/reference/templateStringWithEmbeddedCommentsES6.types new file mode 100644 index 0000000000000..0c79ee294d939 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedCommentsES6.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedCommentsES6.ts === +`head${ // single line comment +No type information for this code.10 +No type information for this code.} +No type information for this code.middle${ +No type information for this code./* Multi- +No type information for this code. * line +No type information for this code. * comment +No type information for this code. */ +No type information for this code. 20 +No type information for this code. // closing comment +No type information for this code.} +No type information for this code.tail`; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditional.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedConditional.errors.txt new file mode 100644 index 0000000000000..5b21885a60fd6 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedConditional.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditional.ts(1,16): error TS2367: No best common type exists between 'boolean' and 'string'. + + +==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditional.ts (1 errors) ==== + var x = `abc${ true ? false : " " }def`; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2367: No best common type exists between 'boolean' and 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditional.js b/tests/baselines/reference/templateStringWithEmbeddedConditional.js new file mode 100644 index 0000000000000..5b03f56a019fb --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedConditional.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedConditional.ts] +var x = `abc${ true ? false : " " }def`; + +//// [templateStringWithEmbeddedConditional.js] +var x = "abc" + (true ? false : " ") + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.errors.txt new file mode 100644 index 0000000000000..2fc26fd24b703 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditionalES6.ts(1,16): error TS2367: No best common type exists between 'boolean' and 'string'. + + +==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditionalES6.ts (1 errors) ==== + var x = `abc${ true ? false : " " }def`; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2367: No best common type exists between 'boolean' and 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.js b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.js new file mode 100644 index 0000000000000..f6cae50a5117d --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedConditionalES6.ts] +var x = `abc${ true ? false : " " }def`; + +//// [templateStringWithEmbeddedConditionalES6.js] +var x = `abc${true ? false : " "}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedDivision.js b/tests/baselines/reference/templateStringWithEmbeddedDivision.js new file mode 100644 index 0000000000000..f9996ae035d9d --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedDivision.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedDivision.ts] +var x = `abc${ 1 / 1 }def`; + +//// [templateStringWithEmbeddedDivision.js] +var x = "abc" + 1 / 1 + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedDivision.types b/tests/baselines/reference/templateStringWithEmbeddedDivision.types new file mode 100644 index 0000000000000..e742733a23cf5 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedDivision.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivision.ts === +var x = `abc${ 1 / 1 }def`; +>x : string +>1 / 1 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedDivisionES6.js b/tests/baselines/reference/templateStringWithEmbeddedDivisionES6.js new file mode 100644 index 0000000000000..47715d3f31bb9 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedDivisionES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedDivisionES6.ts] +var x = `abc${ 1 / 1 }def`; + +//// [templateStringWithEmbeddedDivisionES6.js] +var x = `abc${1 / 1}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedDivisionES6.types b/tests/baselines/reference/templateStringWithEmbeddedDivisionES6.types new file mode 100644 index 0000000000000..20bdc9449d116 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedDivisionES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivisionES6.ts === +var x = `abc${ 1 / 1 }def`; +>x : string +>1 / 1 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedFunctionExpression.js b/tests/baselines/reference/templateStringWithEmbeddedFunctionExpression.js new file mode 100644 index 0000000000000..3447ff87ac383 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedFunctionExpression.js @@ -0,0 +1,7 @@ +//// [templateStringWithEmbeddedFunctionExpression.ts] +var x = `abc${ function y() { return y; } }def`; + +//// [templateStringWithEmbeddedFunctionExpression.js] +var x = "abc" + function y() { + return y; +} + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedFunctionExpression.types b/tests/baselines/reference/templateStringWithEmbeddedFunctionExpression.types new file mode 100644 index 0000000000000..e66313848a606 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedFunctionExpression.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpression.ts === +var x = `abc${ function y() { return y; } }def`; +>x : string +>function y() { return y; } : () => any +>y : () => any +>y : () => any + diff --git a/tests/baselines/reference/templateStringWithEmbeddedFunctionExpressionES6.js b/tests/baselines/reference/templateStringWithEmbeddedFunctionExpressionES6.js new file mode 100644 index 0000000000000..46e37c0ac18fb --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedFunctionExpressionES6.js @@ -0,0 +1,7 @@ +//// [templateStringWithEmbeddedFunctionExpressionES6.ts] +var x = `abc${ function y() { return y; } }def`; + +//// [templateStringWithEmbeddedFunctionExpressionES6.js] +var x = `abc${function y() { + return y; +}}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedFunctionExpressionES6.types b/tests/baselines/reference/templateStringWithEmbeddedFunctionExpressionES6.types new file mode 100644 index 0000000000000..e5c55c2736c38 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedFunctionExpressionES6.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpressionES6.ts === +var x = `abc${ function y() { return y; } }def`; +>x : string +>function y() { return y; } : () => any +>y : () => any +>y : () => any + diff --git a/tests/baselines/reference/templateStringWithEmbeddedInOperator.js b/tests/baselines/reference/templateStringWithEmbeddedInOperator.js new file mode 100644 index 0000000000000..091843ea52e9a --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedInOperator.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedInOperator.ts] +var x = `abc${ "hi" in { hi: 10, hello: 20} }def`; + +//// [templateStringWithEmbeddedInOperator.js] +var x = "abc" + ("hi" in { hi: 10, hello: 20 }) + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedInOperator.types b/tests/baselines/reference/templateStringWithEmbeddedInOperator.types new file mode 100644 index 0000000000000..bff1ea66e1d99 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedInOperator.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperator.ts === +var x = `abc${ "hi" in { hi: 10, hello: 20} }def`; +>x : string +>"hi" in { hi: 10, hello: 20} : boolean +>{ hi: 10, hello: 20} : { hi: number; hello: number; } +>hi : number +>hello : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedInOperatorES6.js b/tests/baselines/reference/templateStringWithEmbeddedInOperatorES6.js new file mode 100644 index 0000000000000..f6510c2fab989 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedInOperatorES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedInOperatorES6.ts] +var x = `abc${ "hi" in { hi: 10, hello: 20} }def`; + +//// [templateStringWithEmbeddedInOperatorES6.js] +var x = `abc${"hi" in { hi: 10, hello: 20 }}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedInOperatorES6.types b/tests/baselines/reference/templateStringWithEmbeddedInOperatorES6.types new file mode 100644 index 0000000000000..6bba79af40da8 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedInOperatorES6.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperatorES6.ts === +var x = `abc${ "hi" in { hi: 10, hello: 20} }def`; +>x : string +>"hi" in { hi: 10, hello: 20} : boolean +>{ hi: 10, hello: 20} : { hi: number; hello: number; } +>hi : number +>hello : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedInstanceOf.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedInstanceOf.errors.txt new file mode 100644 index 0000000000000..08c8c21b5ee4d --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedInstanceOf.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOf.ts(1,16): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. + + +==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOf.ts (1 errors) ==== + var x = `abc${ "hello" instanceof String }def`; + ~~~~~~~ +!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedInstanceOf.js b/tests/baselines/reference/templateStringWithEmbeddedInstanceOf.js new file mode 100644 index 0000000000000..009f6bf988d0d --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedInstanceOf.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedInstanceOf.ts] +var x = `abc${ "hello" instanceof String }def`; + +//// [templateStringWithEmbeddedInstanceOf.js] +var x = "abc" + ("hello" instanceof String) + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedInstanceOfES6.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedInstanceOfES6.errors.txt new file mode 100644 index 0000000000000..85ebb9966ca22 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedInstanceOfES6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOfES6.ts(1,16): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. + + +==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOfES6.ts (1 errors) ==== + var x = `abc${ "hello" instanceof String }def`; + ~~~~~~~ +!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedInstanceOfES6.js b/tests/baselines/reference/templateStringWithEmbeddedInstanceOfES6.js new file mode 100644 index 0000000000000..16a2d2c6797ce --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedInstanceOfES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedInstanceOfES6.ts] +var x = `abc${ "hello" instanceof String }def`; + +//// [templateStringWithEmbeddedInstanceOfES6.js] +var x = `abc${"hello" instanceof String}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedModulo.js b/tests/baselines/reference/templateStringWithEmbeddedModulo.js new file mode 100644 index 0000000000000..6fe9be6431454 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedModulo.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedModulo.ts] +var x = `abc${ 1 % 1 }def`; + +//// [templateStringWithEmbeddedModulo.js] +var x = "abc" + 1 % 1 + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedModulo.types b/tests/baselines/reference/templateStringWithEmbeddedModulo.types new file mode 100644 index 0000000000000..0c24f56684677 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedModulo.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedModulo.ts === +var x = `abc${ 1 % 1 }def`; +>x : string +>1 % 1 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedModuloES6.js b/tests/baselines/reference/templateStringWithEmbeddedModuloES6.js new file mode 100644 index 0000000000000..0226277d98754 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedModuloES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedModuloES6.ts] +var x = `abc${ 1 % 1 }def`; + +//// [templateStringWithEmbeddedModuloES6.js] +var x = `abc${1 % 1}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedModuloES6.types b/tests/baselines/reference/templateStringWithEmbeddedModuloES6.types new file mode 100644 index 0000000000000..02f42a956b978 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedModuloES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedModuloES6.ts === +var x = `abc${ 1 % 1 }def`; +>x : string +>1 % 1 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedMultiplication.js b/tests/baselines/reference/templateStringWithEmbeddedMultiplication.js new file mode 100644 index 0000000000000..7ac4b1b534c78 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedMultiplication.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedMultiplication.ts] +var x = `abc${ 7 * 6 }def`; + +//// [templateStringWithEmbeddedMultiplication.js] +var x = "abc" + 7 * 6 + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedMultiplication.types b/tests/baselines/reference/templateStringWithEmbeddedMultiplication.types new file mode 100644 index 0000000000000..60c7bab0d1e27 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedMultiplication.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplication.ts === +var x = `abc${ 7 * 6 }def`; +>x : string +>7 * 6 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedMultiplicationES6.js b/tests/baselines/reference/templateStringWithEmbeddedMultiplicationES6.js new file mode 100644 index 0000000000000..3624fe7878a6b --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedMultiplicationES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedMultiplicationES6.ts] +var x = `abc${ 7 * 6 }def`; + +//// [templateStringWithEmbeddedMultiplicationES6.js] +var x = `abc${7 * 6}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedMultiplicationES6.types b/tests/baselines/reference/templateStringWithEmbeddedMultiplicationES6.types new file mode 100644 index 0000000000000..5c078b9c1ed3f --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedMultiplicationES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplicationES6.ts === +var x = `abc${ 7 * 6 }def`; +>x : string +>7 * 6 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedNewOperator.js b/tests/baselines/reference/templateStringWithEmbeddedNewOperator.js new file mode 100644 index 0000000000000..480fbe2573daf --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedNewOperator.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedNewOperator.ts] +var x = `abc${ new String("Hi") }def`; + +//// [templateStringWithEmbeddedNewOperator.js] +var x = "abc" + new String("Hi") + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedNewOperator.types b/tests/baselines/reference/templateStringWithEmbeddedNewOperator.types new file mode 100644 index 0000000000000..00bf35330037c --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedNewOperator.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperator.ts === +var x = `abc${ new String("Hi") }def`; +>x : string +>new String("Hi") : String +>String : { (value?: any): string; new (value?: any): String; prototype: String; fromCharCode(...codes: number[]): string; } + diff --git a/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.js b/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.js new file mode 100644 index 0000000000000..8549e4c6e34fa --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedNewOperatorES6.ts] +var x = `abc${ new String("Hi") }def`; + +//// [templateStringWithEmbeddedNewOperatorES6.js] +var x = `abc${new String("Hi")}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.types b/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.types new file mode 100644 index 0000000000000..36c28473d56bd --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperatorES6.ts === +var x = `abc${ new String("Hi") }def`; +>x : string +>new String("Hi") : String +>String : { (value?: any): string; new (value?: any): String; prototype: String; fromCharCode(...codes: number[]): string; } + diff --git a/tests/baselines/reference/templateStringWithEmbeddedObjectLiteral.js b/tests/baselines/reference/templateStringWithEmbeddedObjectLiteral.js new file mode 100644 index 0000000000000..40ecf486245da --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedObjectLiteral.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedObjectLiteral.ts] +var x = `abc${ { x: 10, y: 20 } }def`; + +//// [templateStringWithEmbeddedObjectLiteral.js] +var x = "abc" + { x: 10, y: 20 } + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedObjectLiteral.types b/tests/baselines/reference/templateStringWithEmbeddedObjectLiteral.types new file mode 100644 index 0000000000000..0b053e532d81b --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedObjectLiteral.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteral.ts === +var x = `abc${ { x: 10, y: 20 } }def`; +>x : string +>{ x: 10, y: 20 } : { x: number; y: number; } +>x : number +>y : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedObjectLiteralES6.js b/tests/baselines/reference/templateStringWithEmbeddedObjectLiteralES6.js new file mode 100644 index 0000000000000..dbc3837e1330d --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedObjectLiteralES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedObjectLiteralES6.ts] +var x = `abc${ { x: 10, y: 20 } }def`; + +//// [templateStringWithEmbeddedObjectLiteralES6.js] +var x = `abc${{ x: 10, y: 20 }}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedObjectLiteralES6.types b/tests/baselines/reference/templateStringWithEmbeddedObjectLiteralES6.types new file mode 100644 index 0000000000000..1cf1783fec835 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedObjectLiteralES6.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteralES6.ts === +var x = `abc${ { x: 10, y: 20 } }def`; +>x : string +>{ x: 10, y: 20 } : { x: number; y: number; } +>x : number +>y : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedTemplateString.js b/tests/baselines/reference/templateStringWithEmbeddedTemplateString.js new file mode 100644 index 0000000000000..c0059dbb9508d --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTemplateString.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedTemplateString.ts] +var x = `123${ `456 ${ " | " } 654` }321 123${ `456 ${ " | " } 654` }321`; + +//// [templateStringWithEmbeddedTemplateString.js] +var x = "123" + "456 " + " | " + " 654" + "321 123" + "456 " + " | " + " 654" + "321"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedTemplateString.types b/tests/baselines/reference/templateStringWithEmbeddedTemplateString.types new file mode 100644 index 0000000000000..f63f684222ee3 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTemplateString.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateString.ts === +var x = `123${ `456 ${ " | " } 654` }321 123${ `456 ${ " | " } 654` }321`; +>x : string + diff --git a/tests/baselines/reference/templateStringWithEmbeddedTemplateStringES6.js b/tests/baselines/reference/templateStringWithEmbeddedTemplateStringES6.js new file mode 100644 index 0000000000000..0d1fec18af16d --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTemplateStringES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedTemplateStringES6.ts] +var x = `123${ `456 ${ " | " } 654` }321 123${ `456 ${ " | " } 654` }321`; + +//// [templateStringWithEmbeddedTemplateStringES6.js] +var x = `123${`456 ${" | "} 654`}321 123${`456 ${" | "} 654`}321`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedTemplateStringES6.types b/tests/baselines/reference/templateStringWithEmbeddedTemplateStringES6.types new file mode 100644 index 0000000000000..05816bbcbcea0 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTemplateStringES6.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateStringES6.ts === +var x = `123${ `456 ${ " | " } 654` }321 123${ `456 ${ " | " } 654` }321`; +>x : string + diff --git a/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAddition.js b/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAddition.js new file mode 100644 index 0000000000000..89d9ba6940c8c --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAddition.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedTypeAssertionOnAddition.ts] +var x = `abc${ (10 + 10) }def`; + +//// [templateStringWithEmbeddedTypeAssertionOnAddition.js] +var x = "abc" + (10 + 10) + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAddition.types b/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAddition.types new file mode 100644 index 0000000000000..8b0b5ab37d08a --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAddition.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAddition.ts === +var x = `abc${ (10 + 10) }def`; +>x : string +>(10 + 10) : any +>(10 + 10) : number +>10 + 10 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAdditionES6.js b/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAdditionES6.js new file mode 100644 index 0000000000000..c6422679f3fef --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAdditionES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedTypeAssertionOnAdditionES6.ts] +var x = `abc${ (10 + 10) }def`; + +//// [templateStringWithEmbeddedTypeAssertionOnAdditionES6.js] +var x = `abc${(10 + 10)}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAdditionES6.types b/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAdditionES6.types new file mode 100644 index 0000000000000..007fdb6473642 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTypeAssertionOnAdditionES6.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAdditionES6.ts === +var x = `abc${ (10 + 10) }def`; +>x : string +>(10 + 10) : any +>(10 + 10) : number +>10 + 10 : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperator.js b/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperator.js new file mode 100644 index 0000000000000..10450707b11a3 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperator.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedTypeOfOperator.ts] +var x = `abc${ typeof "hi" }def`; + +//// [templateStringWithEmbeddedTypeOfOperator.js] +var x = "abc" + typeof "hi" + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperator.types b/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperator.types new file mode 100644 index 0000000000000..ebf391981f1cb --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperator.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperator.ts === +var x = `abc${ typeof "hi" }def`; +>x : string +>typeof "hi" : string + diff --git a/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperatorES6.js b/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperatorES6.js new file mode 100644 index 0000000000000..8d148744fae36 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperatorES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedTypeOfOperatorES6.ts] +var x = `abc${ typeof "hi" }def`; + +//// [templateStringWithEmbeddedTypeOfOperatorES6.js] +var x = `abc${typeof "hi"}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperatorES6.types b/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperatorES6.types new file mode 100644 index 0000000000000..cf14a0a0880a6 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedTypeOfOperatorES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperatorES6.ts === +var x = `abc${ typeof "hi" }def`; +>x : string +>typeof "hi" : string + diff --git a/tests/baselines/reference/templateStringWithEmbeddedUnaryPlus.js b/tests/baselines/reference/templateStringWithEmbeddedUnaryPlus.js new file mode 100644 index 0000000000000..a4a9c1a850859 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedUnaryPlus.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedUnaryPlus.ts] +var x = `abc${ +Infinity }def`; + +//// [templateStringWithEmbeddedUnaryPlus.js] +var x = "abc" + +Infinity + "def"; diff --git a/tests/baselines/reference/templateStringWithEmbeddedUnaryPlus.types b/tests/baselines/reference/templateStringWithEmbeddedUnaryPlus.types new file mode 100644 index 0000000000000..62ffab420ad0b --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedUnaryPlus.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlus.ts === +var x = `abc${ +Infinity }def`; +>x : string +>+Infinity : number +>Infinity : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedUnaryPlusES6.js b/tests/baselines/reference/templateStringWithEmbeddedUnaryPlusES6.js new file mode 100644 index 0000000000000..4b42bc1083a64 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedUnaryPlusES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithEmbeddedUnaryPlusES6.ts] +var x = `abc${ +Infinity }def`; + +//// [templateStringWithEmbeddedUnaryPlusES6.js] +var x = `abc${+Infinity}def`; diff --git a/tests/baselines/reference/templateStringWithEmbeddedUnaryPlusES6.types b/tests/baselines/reference/templateStringWithEmbeddedUnaryPlusES6.types new file mode 100644 index 0000000000000..7a002d79b6ffc --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedUnaryPlusES6.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlusES6.ts === +var x = `abc${ +Infinity }def`; +>x : string +>+Infinity : number +>Infinity : number + diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt new file mode 100644 index 0000000000000..40709f4a7b5ae --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,9): error TS1003: Identifier expected. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,15): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,26): error TS1159: Invalid template literal; expected '}' +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,33): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(5,1): error TS1126: Unexpected end of text. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,11): error TS2304: Cannot find name 'gen'. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,20): error TS2304: Cannot find name 'yield'. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,30): error TS2304: Cannot find name 'def'. + + +==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts (8 errors) ==== + function* gen { + ~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + ~~~ +!!! error TS2304: Cannot find name 'gen'. + // Once this is supported, yield *must* be parenthesized. + var x = `abc${ yield 10 }def`; + ~~ +!!! error TS1159: Invalid template literal; expected '}' + ~~ + ~~~~~ +!!! error TS2304: Cannot find name 'yield'. + ~~~ +!!! error TS2304: Cannot find name 'def'. + } + ~ + + +!!! error TS1005: ';' expected. + +!!! error TS1126: Unexpected end of text. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt new file mode 100644 index 0000000000000..51917ac4e6cfe --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,9): error TS1003: Identifier expected. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,17): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,26): error TS1159: Invalid template literal; expected '}' +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,33): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(5,1): error TS1126: Unexpected end of text. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,11): error TS2304: Cannot find name 'gen'. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,20): error TS2304: Cannot find name 'yield'. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,30): error TS2304: Cannot find name 'def'. + + +==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts (8 errors) ==== + function* gen() { + ~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + ~~~ +!!! error TS2304: Cannot find name 'gen'. + // Once this is supported, yield *must* be parenthesized. + var x = `abc${ yield 10 }def`; + ~~ +!!! error TS1159: Invalid template literal; expected '}' + ~~ + ~~~~~ +!!! error TS2304: Cannot find name 'yield'. + ~~~ +!!! error TS2304: Cannot find name 'def'. + } + ~ + + +!!! error TS1005: ';' expected. + +!!! error TS1126: Unexpected end of text. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithOpenCommentInStringPortion.js b/tests/baselines/reference/templateStringWithOpenCommentInStringPortion.js new file mode 100644 index 0000000000000..233ab78a19538 --- /dev/null +++ b/tests/baselines/reference/templateStringWithOpenCommentInStringPortion.js @@ -0,0 +1,5 @@ +//// [templateStringWithOpenCommentInStringPortion.ts] +` /**head ${ 10 } // still middle ${ 20 } /* still tail ` + +//// [templateStringWithOpenCommentInStringPortion.js] +" /**head " + 10 + " // still middle " + 20 + " /* still tail "; diff --git a/tests/baselines/reference/templateStringWithOpenCommentInStringPortion.types b/tests/baselines/reference/templateStringWithOpenCommentInStringPortion.types new file mode 100644 index 0000000000000..66070a70ec769 --- /dev/null +++ b/tests/baselines/reference/templateStringWithOpenCommentInStringPortion.types @@ -0,0 +1,3 @@ +=== tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortion.ts === +` /**head ${ 10 } // still middle ${ 20 } /* still tail ` +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithOpenCommentInStringPortionES6.js b/tests/baselines/reference/templateStringWithOpenCommentInStringPortionES6.js new file mode 100644 index 0000000000000..45d2d86e97e7c --- /dev/null +++ b/tests/baselines/reference/templateStringWithOpenCommentInStringPortionES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithOpenCommentInStringPortionES6.ts] +` /**head ${ 10 } // still middle ${ 20 } /* still tail ` + +//// [templateStringWithOpenCommentInStringPortionES6.js] +` /**head ${10} // still middle ${20} /* still tail `; diff --git a/tests/baselines/reference/templateStringWithOpenCommentInStringPortionES6.types b/tests/baselines/reference/templateStringWithOpenCommentInStringPortionES6.types new file mode 100644 index 0000000000000..08b5484f3ab7f --- /dev/null +++ b/tests/baselines/reference/templateStringWithOpenCommentInStringPortionES6.types @@ -0,0 +1,3 @@ +=== tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortionES6.ts === +` /**head ${ 10 } // still middle ${ 20 } /* still tail ` +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithPropertyAccess.js b/tests/baselines/reference/templateStringWithPropertyAccess.js new file mode 100644 index 0000000000000..9866b6bd53be5 --- /dev/null +++ b/tests/baselines/reference/templateStringWithPropertyAccess.js @@ -0,0 +1,5 @@ +//// [templateStringWithPropertyAccess.ts] +`abc${0}abc`.indexOf(`abc`); + +//// [templateStringWithPropertyAccess.js] +("abc" + 0 + "abc").indexOf("abc"); diff --git a/tests/baselines/reference/templateStringWithPropertyAccess.types b/tests/baselines/reference/templateStringWithPropertyAccess.types new file mode 100644 index 0000000000000..ae9dbb5249d1a --- /dev/null +++ b/tests/baselines/reference/templateStringWithPropertyAccess.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/templates/templateStringWithPropertyAccess.ts === +`abc${0}abc`.indexOf(`abc`); +>`abc${0}abc`.indexOf(`abc`) : number +>`abc${0}abc`.indexOf : (searchString: string, position?: number) => number +>indexOf : (searchString: string, position?: number) => number + diff --git a/tests/baselines/reference/templateStringWithPropertyAccessES6.js b/tests/baselines/reference/templateStringWithPropertyAccessES6.js new file mode 100644 index 0000000000000..72f3a16b5c4a4 --- /dev/null +++ b/tests/baselines/reference/templateStringWithPropertyAccessES6.js @@ -0,0 +1,5 @@ +//// [templateStringWithPropertyAccessES6.ts] +`abc${0}abc`.indexOf(`abc`); + +//// [templateStringWithPropertyAccessES6.js] +`abc${0}abc`.indexOf(`abc`); diff --git a/tests/baselines/reference/templateStringWithPropertyAccessES6.types b/tests/baselines/reference/templateStringWithPropertyAccessES6.types new file mode 100644 index 0000000000000..80ea8a0ef8b5f --- /dev/null +++ b/tests/baselines/reference/templateStringWithPropertyAccessES6.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/templates/templateStringWithPropertyAccessES6.ts === +`abc${0}abc`.indexOf(`abc`); +>`abc${0}abc`.indexOf(`abc`) : number +>`abc${0}abc`.indexOf : (searchString: string, position?: number) => number +>indexOf : (searchString: string, position?: number) => number + diff --git a/tests/cases/conformance/es6/templates/templateStringInArray.ts b/tests/cases/conformance/es6/templates/templateStringInArray.ts new file mode 100644 index 0000000000000..2d2e5e323b5d7 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInArray.ts @@ -0,0 +1 @@ +var x = [1, 2, `abc${ 123 }def`]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInArrowFunction.ts b/tests/cases/conformance/es6/templates/templateStringInArrowFunction.ts new file mode 100644 index 0000000000000..9820edb2ac329 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInArrowFunction.ts @@ -0,0 +1 @@ +var x = x => `abc${ x }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInArrowFunctionES6.ts b/tests/cases/conformance/es6/templates/templateStringInArrowFunctionES6.ts new file mode 100644 index 0000000000000..066fc1c74b120 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInArrowFunctionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = x => `abc${ x }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInBinaryAddition.ts b/tests/cases/conformance/es6/templates/templateStringInBinaryAddition.ts new file mode 100644 index 0000000000000..7f00313ca868c --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInBinaryAddition.ts @@ -0,0 +1 @@ +var x = 10 + `abc${ 10 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInBinaryAdditionES6.ts b/tests/cases/conformance/es6/templates/templateStringInBinaryAdditionES6.ts new file mode 100644 index 0000000000000..5f44e3cb9d47c --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInBinaryAdditionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = 10 + `abc${ 10 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInConditional.ts b/tests/cases/conformance/es6/templates/templateStringInConditional.ts new file mode 100644 index 0000000000000..aff80b60efc6e --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInConditional.ts @@ -0,0 +1 @@ +var x = `abc${ " " }def` ? `abc${ " " }def` : `abc${ " " }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInConditionalES6.ts b/tests/cases/conformance/es6/templates/templateStringInConditionalES6.ts new file mode 100644 index 0000000000000..c0b800259f322 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInConditionalES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ " " }def` ? `abc${ " " }def` : `abc${ " " }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInDeleteExpression.ts b/tests/cases/conformance/es6/templates/templateStringInDeleteExpression.ts new file mode 100644 index 0000000000000..f3af01582a5d3 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInDeleteExpression.ts @@ -0,0 +1 @@ +delete `abc${0}abc`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInDeleteExpressionES6.ts b/tests/cases/conformance/es6/templates/templateStringInDeleteExpressionES6.ts new file mode 100644 index 0000000000000..cd81c11453a07 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInDeleteExpressionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +delete `abc${0}abc`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInDivision.ts b/tests/cases/conformance/es6/templates/templateStringInDivision.ts new file mode 100644 index 0000000000000..9650f5e2455cc --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInDivision.ts @@ -0,0 +1 @@ +var x = `abc${ 1 }def` / 1; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInEqualityChecks.ts b/tests/cases/conformance/es6/templates/templateStringInEqualityChecks.ts new file mode 100644 index 0000000000000..37b8511368e3a --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInEqualityChecks.ts @@ -0,0 +1,4 @@ +var x = `abc${0}abc` === `abc` || + `abc` !== `abc${0}abc` && + `abc${0}abc` == "abc0abc" && + "abc0abc" !== `abc${0}abc`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInEqualityChecksES6.ts b/tests/cases/conformance/es6/templates/templateStringInEqualityChecksES6.ts new file mode 100644 index 0000000000000..5254474b82b28 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInEqualityChecksES6.ts @@ -0,0 +1,5 @@ +// @target: ES6 +var x = `abc${0}abc` === `abc` || + `abc` !== `abc${0}abc` && + `abc${0}abc` == "abc0abc" && + "abc0abc" !== `abc${0}abc`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInFunctionExpression.ts b/tests/cases/conformance/es6/templates/templateStringInFunctionExpression.ts new file mode 100644 index 0000000000000..5f0c5a4c96fc6 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInFunctionExpression.ts @@ -0,0 +1,4 @@ +var x = function y() { + `abc${ 0 }def` + return `abc${ 0 }def`; +}; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInFunctionExpressionES6.ts b/tests/cases/conformance/es6/templates/templateStringInFunctionExpressionES6.ts new file mode 100644 index 0000000000000..729ecbd07442a --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInFunctionExpressionES6.ts @@ -0,0 +1,5 @@ +// @target: ES6 +var x = function y() { + `abc${ 0 }def` + return `abc${ 0 }def`; +}; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInFunctionParameterType.ts b/tests/cases/conformance/es6/templates/templateStringInFunctionParameterType.ts new file mode 100644 index 0000000000000..628ba29081b2b --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInFunctionParameterType.ts @@ -0,0 +1,5 @@ +function f(`hello`); +function f(x: string); +function f(x: string) { + return x; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInFunctionParameterTypeES6.ts b/tests/cases/conformance/es6/templates/templateStringInFunctionParameterTypeES6.ts new file mode 100644 index 0000000000000..03fb0a7de88dd --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInFunctionParameterTypeES6.ts @@ -0,0 +1,6 @@ +// @target: ES6 +function f(`hello`); +function f(x: string); +function f(x: string) { + return x; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInInOperator.ts b/tests/cases/conformance/es6/templates/templateStringInInOperator.ts new file mode 100644 index 0000000000000..cc50b275144f3 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInInOperator.ts @@ -0,0 +1 @@ +var x = `${ "hi" }` in { hi: 10, hello: 20}; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInInOperatorES6.ts b/tests/cases/conformance/es6/templates/templateStringInInOperatorES6.ts new file mode 100644 index 0000000000000..5a23a0b4e3f07 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInInOperatorES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `${ "hi" }` in { hi: 10, hello: 20}; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInIndexExpression.ts b/tests/cases/conformance/es6/templates/templateStringInIndexExpression.ts new file mode 100644 index 0000000000000..792e92a4dc787 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInIndexExpression.ts @@ -0,0 +1 @@ +`abc${0}abc`[`0`]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInIndexExpressionES6.ts b/tests/cases/conformance/es6/templates/templateStringInIndexExpressionES6.ts new file mode 100644 index 0000000000000..6a431b3bb1325 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInIndexExpressionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +`abc${0}abc`[`0`]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInInstanceOf.ts b/tests/cases/conformance/es6/templates/templateStringInInstanceOf.ts new file mode 100644 index 0000000000000..12ec4e7baf73f --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInInstanceOf.ts @@ -0,0 +1 @@ +var x = `abc${ 0 }def` instanceof String; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInInstanceOfES6.ts b/tests/cases/conformance/es6/templates/templateStringInInstanceOfES6.ts new file mode 100644 index 0000000000000..6afe22b74b6bd --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInInstanceOfES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ 0 }def` instanceof String; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInModuleName.ts b/tests/cases/conformance/es6/templates/templateStringInModuleName.ts new file mode 100644 index 0000000000000..8ed5038ffbfcd --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInModuleName.ts @@ -0,0 +1,5 @@ +declare module `M1` { +} + +declare module `M${2}` { +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts b/tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts new file mode 100644 index 0000000000000..44d3999febc5e --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts @@ -0,0 +1,6 @@ +// @target: ES6 +declare module `M1` { +} + +declare module `M${2}` { +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInModulo.ts b/tests/cases/conformance/es6/templates/templateStringInModulo.ts new file mode 100644 index 0000000000000..69d7faeda759f --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInModulo.ts @@ -0,0 +1 @@ +var x = 1 % `abc${ 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInModuloES6.ts b/tests/cases/conformance/es6/templates/templateStringInModuloES6.ts new file mode 100644 index 0000000000000..0d05c3570babb --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInModuloES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = 1 % `abc${ 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInMultiplication.ts b/tests/cases/conformance/es6/templates/templateStringInMultiplication.ts new file mode 100644 index 0000000000000..a8ba70bf10255 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInMultiplication.ts @@ -0,0 +1 @@ +var x = 1 * `abc${ 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInMultiplicationES6.ts b/tests/cases/conformance/es6/templates/templateStringInMultiplicationES6.ts new file mode 100644 index 0000000000000..c0ffa96d98c19 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInMultiplicationES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = 1 * `abc${ 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInNewOperator.ts b/tests/cases/conformance/es6/templates/templateStringInNewOperator.ts new file mode 100644 index 0000000000000..f53dd3023d236 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInNewOperator.ts @@ -0,0 +1 @@ +var x = new `abc${ 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInNewOperatorES6.ts b/tests/cases/conformance/es6/templates/templateStringInNewOperatorES6.ts new file mode 100644 index 0000000000000..aad17d31ae2b2 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInNewOperatorES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = new `abc${ 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts b/tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts new file mode 100644 index 0000000000000..e1ce34a20db0a --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts @@ -0,0 +1,4 @@ +var x = { + a: `abc${ 123 }def`, + `b`: 321 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts b/tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts new file mode 100644 index 0000000000000..9ef032e4c88dc --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts @@ -0,0 +1,5 @@ +// @target: ES6 +var x = { + a: `abc${ 123 }def`, + `b`: 321 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInParentheses.ts b/tests/cases/conformance/es6/templates/templateStringInParentheses.ts new file mode 100644 index 0000000000000..de5948e2bc203 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInParentheses.ts @@ -0,0 +1 @@ +var x = (`abc${0}abc`); \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInParenthesesES6.ts b/tests/cases/conformance/es6/templates/templateStringInParenthesesES6.ts new file mode 100644 index 0000000000000..856392e7c140f --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInParenthesesES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = (`abc${0}abc`); \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInSwitchAndCase.ts b/tests/cases/conformance/es6/templates/templateStringInSwitchAndCase.ts new file mode 100644 index 0000000000000..3b88a23c2984d --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInSwitchAndCase.ts @@ -0,0 +1,6 @@ +switch (`abc${0}abc`) { + case `abc`: + case `123`: + case `abc${0}abc`: + `def${1}def`; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInSwitchAndCaseES6.ts b/tests/cases/conformance/es6/templates/templateStringInSwitchAndCaseES6.ts new file mode 100644 index 0000000000000..c1872816ccc76 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInSwitchAndCaseES6.ts @@ -0,0 +1,7 @@ +// @target: ES6 +switch (`abc${0}abc`) { + case `abc`: + case `123`: + case `abc${0}abc`: + `def${1}def`; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInTypeAssertion.ts b/tests/cases/conformance/es6/templates/templateStringInTypeAssertion.ts new file mode 100644 index 0000000000000..b5a29156f5650 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInTypeAssertion.ts @@ -0,0 +1 @@ +var x = `abc${ 123 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInTypeAssertionES6.ts b/tests/cases/conformance/es6/templates/templateStringInTypeAssertionES6.ts new file mode 100644 index 0000000000000..e1fc20728a071 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInTypeAssertionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ 123 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInTypeOf.ts b/tests/cases/conformance/es6/templates/templateStringInTypeOf.ts new file mode 100644 index 0000000000000..da69e86c0b705 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInTypeOf.ts @@ -0,0 +1 @@ +var x = typeof `abc${ 123 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInTypeOfES6.ts b/tests/cases/conformance/es6/templates/templateStringInTypeOfES6.ts new file mode 100644 index 0000000000000..a5f96923daa5b --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInTypeOfES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = typeof `abc${ 123 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInUnaryPlus.ts b/tests/cases/conformance/es6/templates/templateStringInUnaryPlus.ts new file mode 100644 index 0000000000000..3f9b667d51d3a --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInUnaryPlus.ts @@ -0,0 +1 @@ +var x = +`abc${ 123 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInUnaryPlusES6.ts b/tests/cases/conformance/es6/templates/templateStringInUnaryPlusES6.ts new file mode 100644 index 0000000000000..4baba61696d1a --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInUnaryPlusES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = +`abc${ 123 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInWhile.ts b/tests/cases/conformance/es6/templates/templateStringInWhile.ts new file mode 100644 index 0000000000000..8baeaeadc9723 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInWhile.ts @@ -0,0 +1,3 @@ +while (`abc${0}abc`) { + `def${1}def`; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInWhileES6.ts b/tests/cases/conformance/es6/templates/templateStringInWhileES6.ts new file mode 100644 index 0000000000000..d30cdb4ec2ac1 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInWhileES6.ts @@ -0,0 +1,4 @@ +// @target: ES6 +while (`abc${0}abc`) { + `def${1}def`; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts b/tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts new file mode 100644 index 0000000000000..4a80e452251b3 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts @@ -0,0 +1,4 @@ +function* gen { + // Once this is supported, the inner expression does not need to be parenthesized. + var x = yield `abc${ x }def`; +} diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedAddition.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedAddition.ts new file mode 100644 index 0000000000000..73f9c6b6b84c3 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedAddition.ts @@ -0,0 +1 @@ +var x = `abc${ 10 + 10 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedAdditionES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedAdditionES6.ts new file mode 100644 index 0000000000000..12cda7856fa68 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedAdditionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ 10 + 10 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArray.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArray.ts new file mode 100644 index 0000000000000..77ea762070bc8 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArray.ts @@ -0,0 +1 @@ +var x = `abc${ [1,2,3] }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrayES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrayES6.ts new file mode 100644 index 0000000000000..2be90b5abfa77 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrayES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ [1,2,3] }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunction.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunction.ts new file mode 100644 index 0000000000000..8d879732c7918 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunction.ts @@ -0,0 +1 @@ +var x = `abc${ x => x }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunctionES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunctionES6.ts new file mode 100644 index 0000000000000..946bd41470fb5 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedArrowFunctionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ x => x }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedComments.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedComments.ts new file mode 100644 index 0000000000000..2cb295bbfeb98 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedComments.ts @@ -0,0 +1,12 @@ +`head${ // single line comment +10 +} +middle${ +/* Multi- + * line + * comment + */ + 20 + // closing comment +} +tail`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedCommentsES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedCommentsES6.ts new file mode 100644 index 0000000000000..2cb295bbfeb98 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedCommentsES6.ts @@ -0,0 +1,12 @@ +`head${ // single line comment +10 +} +middle${ +/* Multi- + * line + * comment + */ + 20 + // closing comment +} +tail`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditional.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditional.ts new file mode 100644 index 0000000000000..6c70bbc9b0469 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditional.ts @@ -0,0 +1 @@ +var x = `abc${ true ? false : " " }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditionalES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditionalES6.ts new file mode 100644 index 0000000000000..b1366210a2843 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditionalES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ true ? false : " " }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivision.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivision.ts new file mode 100644 index 0000000000000..82ea537dc131d --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivision.ts @@ -0,0 +1 @@ +var x = `abc${ 1 / 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivisionES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivisionES6.ts new file mode 100644 index 0000000000000..04f3740e3ae21 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedDivisionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ 1 / 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpression.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpression.ts new file mode 100644 index 0000000000000..05c69d962e5be --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpression.ts @@ -0,0 +1 @@ +var x = `abc${ function y() { return y; } }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpressionES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpressionES6.ts new file mode 100644 index 0000000000000..3aab00817ee1e --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedFunctionExpressionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ function y() { return y; } }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperator.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperator.ts new file mode 100644 index 0000000000000..0e823e0ee1185 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperator.ts @@ -0,0 +1 @@ +var x = `abc${ "hi" in { hi: 10, hello: 20} }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperatorES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperatorES6.ts new file mode 100644 index 0000000000000..c678d54246785 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInOperatorES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ "hi" in { hi: 10, hello: 20} }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOf.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOf.ts new file mode 100644 index 0000000000000..b8cd9ba5740a9 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOf.ts @@ -0,0 +1 @@ +var x = `abc${ "hello" instanceof String }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOfES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOfES6.ts new file mode 100644 index 0000000000000..a6598788b9242 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedInstanceOfES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ "hello" instanceof String }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedModulo.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedModulo.ts new file mode 100644 index 0000000000000..675627cb25d1c --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedModulo.ts @@ -0,0 +1 @@ +var x = `abc${ 1 % 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedModuloES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedModuloES6.ts new file mode 100644 index 0000000000000..8b6d3ed7ef26b --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedModuloES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ 1 % 1 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplication.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplication.ts new file mode 100644 index 0000000000000..09a99646fc829 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplication.ts @@ -0,0 +1 @@ +var x = `abc${ 7 * 6 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplicationES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplicationES6.ts new file mode 100644 index 0000000000000..1378909e1c62e --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedMultiplicationES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ 7 * 6 }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperator.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperator.ts new file mode 100644 index 0000000000000..0f2652f892b1e --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperator.ts @@ -0,0 +1 @@ +var x = `abc${ new String("Hi") }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperatorES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperatorES6.ts new file mode 100644 index 0000000000000..4313531575a95 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperatorES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ new String("Hi") }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteral.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteral.ts new file mode 100644 index 0000000000000..bfdbb3d6a3481 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteral.ts @@ -0,0 +1 @@ +var x = `abc${ { x: 10, y: 20 } }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteralES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteralES6.ts new file mode 100644 index 0000000000000..9927f5fe95e26 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedObjectLiteralES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ { x: 10, y: 20 } }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateString.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateString.ts new file mode 100644 index 0000000000000..4fc2778aa4f5d --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateString.ts @@ -0,0 +1 @@ +var x = `123${ `456 ${ " | " } 654` }321 123${ `456 ${ " | " } 654` }321`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateStringES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateStringES6.ts new file mode 100644 index 0000000000000..4f8063ab03b2e --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTemplateStringES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `123${ `456 ${ " | " } 654` }321 123${ `456 ${ " | " } 654` }321`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAddition.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAddition.ts new file mode 100644 index 0000000000000..90a0e3561a394 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAddition.ts @@ -0,0 +1 @@ +var x = `abc${ (10 + 10) }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAdditionES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAdditionES6.ts new file mode 100644 index 0000000000000..9c0537b6489da --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeAssertionOnAdditionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ (10 + 10) }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperator.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperator.ts new file mode 100644 index 0000000000000..1a93e586bdaf5 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperator.ts @@ -0,0 +1 @@ +var x = `abc${ typeof "hi" }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperatorES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperatorES6.ts new file mode 100644 index 0000000000000..534cd667f43c9 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedTypeOfOperatorES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ typeof "hi" }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlus.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlus.ts new file mode 100644 index 0000000000000..f97583812e47b --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlus.ts @@ -0,0 +1 @@ +var x = `abc${ +Infinity }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlusES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlusES6.ts new file mode 100644 index 0000000000000..7b724dba57926 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedUnaryPlusES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +var x = `abc${ +Infinity }def`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts new file mode 100644 index 0000000000000..cbf7f27258127 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts @@ -0,0 +1,4 @@ +function* gen { + // Once this is supported, yield *must* be parenthesized. + var x = `abc${ yield 10 }def`; +} diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts new file mode 100644 index 0000000000000..5a7409aef79c8 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts @@ -0,0 +1,5 @@ +// @target: ES6 +function* gen() { + // Once this is supported, yield *must* be parenthesized. + var x = `abc${ yield 10 }def`; +} diff --git a/tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortion.ts b/tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortion.ts new file mode 100644 index 0000000000000..9101c8e3e6b94 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortion.ts @@ -0,0 +1 @@ +` /**head ${ 10 } // still middle ${ 20 } /* still tail ` \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortionES6.ts b/tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortionES6.ts new file mode 100644 index 0000000000000..cb7f76540ccc5 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithOpenCommentInStringPortionES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +` /**head ${ 10 } // still middle ${ 20 } /* still tail ` \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithPropertyAccess.ts b/tests/cases/conformance/es6/templates/templateStringWithPropertyAccess.ts new file mode 100644 index 0000000000000..87682fff572fa --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithPropertyAccess.ts @@ -0,0 +1 @@ +`abc${0}abc`.indexOf(`abc`); \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithPropertyAccessES6.ts b/tests/cases/conformance/es6/templates/templateStringWithPropertyAccessES6.ts new file mode 100644 index 0000000000000..261ea75bde65c --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithPropertyAccessES6.ts @@ -0,0 +1,2 @@ +// @target: ES6 +`abc${0}abc`.indexOf(`abc`); \ No newline at end of file From e7096280b4e3f378b3ca78e50e6e26e1be5db509 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 23 Oct 2014 16:32:43 -0700 Subject: [PATCH 03/15] Added support for tagged template strings, updated baselines. Still need to implement some error recovery and add tests. --- src/compiler/checker.ts | 13 +++++++++ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 +++ src/compiler/emitter.ts | 9 ++++++ src/compiler/parser.ts | 28 ++++++++++++++++--- src/compiler/types.ts | 10 ++++++- .../templateStringInModuleName.errors.txt | 12 ++++---- .../templateStringInModuleNameES6.errors.txt | 8 +----- .../templateStringInObjectLiteral.errors.txt | 14 ++++++++-- ...emplateStringInObjectLiteralES6.errors.txt | 9 ++++-- .../templateStringInYieldKeyword.errors.txt | 6 ++-- ...emplateStringWithEmbeddedConditional.types | 5 ++++ ...lateStringWithEmbeddedConditionalES6.types | 5 ++++ ...eStringWithEmbeddedYieldKeyword.errors.txt | 6 ++-- ...ringWithEmbeddedYieldKeywordES6.errors.txt | 7 +---- 15 files changed, 101 insertions(+), 36 deletions(-) create mode 100644 tests/baselines/reference/templateStringWithEmbeddedConditional.types create mode 100644 tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e600d695b65fe..8430ad2a83b2b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5422,6 +5422,13 @@ module ts { return getReturnTypeOfSignature(signature); } + function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type { + // TODO (drosen): Make sure substitutions are assignable to the tag's arguments. + checkExpression(node.tag); + checkExpression(node.template); + return anyType; + } + function checkTypeAssertion(node: TypeAssertion): Type { var exprType = checkExpression(node.operand); var targetType = getTypeFromTypeNode(node.type); @@ -6012,6 +6019,8 @@ module ts { case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: return checkCallExpression(node); + case SyntaxKind.TaggedTemplateExpression: + return checkTaggedTemplateExpression(node); case SyntaxKind.TypeAssertion: return checkTypeAssertion(node); case SyntaxKind.ParenExpression: @@ -7744,6 +7753,7 @@ module ts { case SyntaxKind.IndexedAccess: case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: + case SyntaxKind.TaggedTemplateExpression: case SyntaxKind.TypeAssertion: case SyntaxKind.ParenExpression: case SyntaxKind.PrefixOperator: @@ -8020,6 +8030,9 @@ module ts { case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: return (parent).typeArguments && (parent).typeArguments.indexOf(node) >= 0; + case SyntaxKind.TaggedTemplateExpression: + // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. + return false; } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index e26cbcf8bb678..22c014186e02b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -121,6 +121,7 @@ module ts { const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." }, let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." }, Invalid_template_literal_expected: { code: 1158, category: DiagnosticCategory.Error, key: "Invalid template literal; expected '}'" }, + 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." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0c89ba66e09f0..92eaea3dde735 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -475,6 +475,10 @@ "category": "Error", "code": 1158 }, + "Tagged templates are only available when targeting ECMAScript 6 and higher.": { + "category": "Error", + "code": 1159 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 11bf50c8c3447..e8550fbce3196 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1064,6 +1064,13 @@ 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); + } + function emitParenExpression(node: ParenExpression) { if (node.expression.kind === SyntaxKind.TypeAssertion) { var operand = (node.expression).operand; @@ -2197,6 +2204,8 @@ module ts { return emitCallExpression(node); case SyntaxKind.NewExpression: return emitNewExpression(node); + case SyntaxKind.TaggedTemplateExpression: + return emitTaggedTemplateExpression(node); case SyntaxKind.TypeAssertion: return emit((node).operand); case SyntaxKind.ParenExpression: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 719ce8f081140..5a56c21ef78a4 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -244,6 +244,9 @@ module ts { return child((node).func) || children((node).typeArguments) || children((node).arguments); + case SyntaxKind.TaggedTemplateExpression: + return child((node).tag) || + child((node).template); case SyntaxKind.TypeAssertion: return child((node).type) || child((node).operand); @@ -470,6 +473,7 @@ module ts { case SyntaxKind.IndexedAccess: case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: + case SyntaxKind.TaggedTemplateExpression: case SyntaxKind.TypeAssertion: case SyntaxKind.ParenExpression: case SyntaxKind.FunctionExpression: @@ -2074,6 +2078,7 @@ module ts { case SyntaxKind.IndexedAccess: case SyntaxKind.NewExpression: case SyntaxKind.CallExpression: + case SyntaxKind.TaggedTemplateExpression: case SyntaxKind.ArrayLiteral: case SyntaxKind.ParenExpression: case SyntaxKind.ObjectLiteral: @@ -2440,7 +2445,7 @@ module ts { function parseCallAndAccess(expr: Expression, inNewExpression: boolean): Expression { while (true) { - var dotStart = scanner.getTokenPos(); + var dotOrBracketStart = scanner.getTokenPos(); if (parseOptional(SyntaxKind.DotToken)) { var propertyAccess = createNode(SyntaxKind.PropertyAccess, expr.pos); // Technically a keyword is valid here as all keywords are identifier names. @@ -2463,7 +2468,7 @@ module ts { // In the first case though, ASI will not take effect because there is not a // line terminator after the keyword. if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord() && lookAhead(() => scanner.isReservedWord())) { - grammarErrorAtPos(dotStart, scanner.getStartPos() - dotStart, Diagnostics.Identifier_expected); + grammarErrorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, Diagnostics.Identifier_expected); var id = createMissingNode(); } else { @@ -2476,7 +2481,6 @@ module ts { continue; } - var bracketStart = scanner.getTokenPos(); if (parseOptional(SyntaxKind.OpenBracketToken)) { var indexedAccess = createNode(SyntaxKind.IndexedAccess, expr.pos); @@ -2486,7 +2490,7 @@ module ts { // Check for that common pattern and report a better error message. if (inNewExpression && parseOptional(SyntaxKind.CloseBracketToken)) { indexedAccess.index = createMissingNode(); - grammarErrorAtPos(bracketStart, scanner.getStartPos() - bracketStart, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); + grammarErrorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); } else { indexedAccess.index = parseExpression(); @@ -2519,6 +2523,22 @@ module ts { expr = finishNode(callExpr); continue; } + + if (token === SyntaxKind.NoSubstitutionTemplateLiteral || token === SyntaxKind.TemplateHead) { + var tagExpression = createNode(SyntaxKind.TaggedTemplateExpression, expr.pos); + tagExpression.tag = expr; + tagExpression.template = token === SyntaxKind.NoSubstitutionTemplateLiteral + ? parseLiteralNode() + : parseTemplateExpression(); + expr = finishNode(tagExpression); + + if (languageVersion < ScriptTarget.ES6) { + grammarErrorOnNode(expr, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + + continue; + } + return expr; } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9531f88894819..0c5fe20b713da 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -169,6 +169,7 @@ module ts { IndexedAccess, CallExpression, NewExpression, + TaggedTemplateExpression, TypeAssertion, ParenExpression, FunctionExpression, @@ -437,6 +438,12 @@ module ts { export interface NewExpression extends CallExpression { } + export interface TaggedTemplateExpression extends Expression { + tag: Expression; + // Either a LiteralExpression of kind NoSubstitutionTemplateLiteral, or a TemplateExpression + template: Expression; + } + export interface TypeAssertion extends Expression { type: TypeNode; operand: Expression; @@ -819,10 +826,11 @@ module ts { Prototype = 0x04000000, // Prototype property (no source representation) UnionProperty = 0x08000000, // Property in union type - BlockScopedVariable = 0x10000000, // A block-scoped variable (let ot const) + BlockScopedVariable = 0x10000000, // A block-scoped variable (let or const) Variable = FunctionScopedVariable | BlockScopedVariable, Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor, + Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter, Namespace = ValueModule | NamespaceModule, Module = ValueModule | NamespaceModule, diff --git a/tests/baselines/reference/templateStringInModuleName.errors.txt b/tests/baselines/reference/templateStringInModuleName.errors.txt index 4aa06a6232b93..fb6188d9d9af9 100644 --- a/tests/baselines/reference/templateStringInModuleName.errors.txt +++ b/tests/baselines/reference/templateStringInModuleName.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,16): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,21): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,16): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,24): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,1): error TS2304: Cannot find name 'declare'. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS2304: Cannot find name 'module'. @@ -14,8 +14,8 @@ tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error declare module `M1` { ~~~~~~ !!! error TS1005: ';' expected. - ~~~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~~~ +!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS1005: ';' expected. ~~~~~~~ @@ -27,8 +27,8 @@ tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error declare module `M${2}` { ~~~~~~ !!! error TS1005: ';' expected. - ~~~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~~~~~~ +!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS1005: ';' expected. ~~~~~~~ diff --git a/tests/baselines/reference/templateStringInModuleNameES6.errors.txt b/tests/baselines/reference/templateStringInModuleNameES6.errors.txt index fa2bed3d474a3..228fd32357ce7 100644 --- a/tests/baselines/reference/templateStringInModuleNameES6.errors.txt +++ b/tests/baselines/reference/templateStringInModuleNameES6.errors.txt @@ -1,8 +1,6 @@ tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,16): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,21): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,16): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,24): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,1): error TS2304: Cannot find name 'declare'. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,9): error TS2304: Cannot find name 'module'. @@ -10,11 +8,9 @@ tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,1): err tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,9): error TS2304: Cannot find name 'module'. -==== tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts (10 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts (8 errors) ==== declare module `M1` { ~~~~~~ -!!! error TS1005: ';' expected. - ~~~~ !!! error TS1005: ';' expected. ~ !!! error TS1005: ';' expected. @@ -26,8 +22,6 @@ tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,9): err declare module `M${2}` { ~~~~~~ -!!! error TS1005: ';' expected. - ~~~~ !!! error TS1005: ';' expected. ~ !!! error TS1005: ';' expected. diff --git a/tests/baselines/reference/templateStringInObjectLiteral.errors.txt b/tests/baselines/reference/templateStringInObjectLiteral.errors.txt index 60fa4f9989452..e190ea3a8150a 100644 --- a/tests/baselines/reference/templateStringInObjectLiteral.errors.txt +++ b/tests/baselines/reference/templateStringInObjectLiteral.errors.txt @@ -1,16 +1,24 @@ +tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(1,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(3,5): error TS1136: Property assignment expected. -tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(3,8): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(3,8): error TS1005: ',' expected. +tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(3,10): error TS1134: Variable declaration expected. tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(4,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts (3 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts (5 errors) ==== var x = { + ~ a: `abc${ 123 }def`, + ~~~~~~~~~~~~~~~~~~~~~~~~ `b`: 321 + ~~~~~~~ +!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~ !!! error TS1136: Property assignment expected. ~ -!!! error TS1005: ';' expected. +!!! error TS1005: ',' expected. + ~~~ +!!! error TS1134: Variable declaration expected. } ~ !!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInObjectLiteralES6.errors.txt b/tests/baselines/reference/templateStringInObjectLiteralES6.errors.txt index 6514356aedc0d..ae21ecd4739c7 100644 --- a/tests/baselines/reference/templateStringInObjectLiteralES6.errors.txt +++ b/tests/baselines/reference/templateStringInObjectLiteralES6.errors.txt @@ -1,16 +1,19 @@ tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts(3,5): error TS1136: Property assignment expected. -tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts(3,8): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts(3,8): error TS1005: ',' expected. +tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts(3,10): error TS1134: Variable declaration expected. tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts(4,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts (3 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInObjectLiteralES6.ts (4 errors) ==== var x = { a: `abc${ 123 }def`, `b`: 321 ~~~ !!! error TS1136: Property assignment expected. ~ -!!! error TS1005: ';' expected. +!!! error TS1005: ',' expected. + ~~~ +!!! error TS1134: Variable declaration expected. } ~ !!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInYieldKeyword.errors.txt b/tests/baselines/reference/templateStringInYieldKeyword.errors.txt index 61a9ddf39341e..b70af797c5cf7 100644 --- a/tests/baselines/reference/templateStringInYieldKeyword.errors.txt +++ b/tests/baselines/reference/templateStringInYieldKeyword.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,9): error TS1003: Identifier expected. tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,15): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,19): error TS1005: ',' expected. +tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,11): error TS2304: Cannot find name 'gen'. tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,13): error TS2304: Cannot find name 'yield'. @@ -15,8 +15,8 @@ tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,13): err !!! error TS2304: Cannot find name 'gen'. // Once this is supported, the inner expression does not need to be parenthesized. var x = yield `abc${ x }def`; - ~~~~~~ -!!! error TS1005: ',' expected. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~ !!! error TS2304: Cannot find name 'yield'. } diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditional.types b/tests/baselines/reference/templateStringWithEmbeddedConditional.types new file mode 100644 index 0000000000000..de4249792e7f4 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedConditional.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditional.ts === +var x = `abc${ true ? false : " " }def`; +>x : string +>true ? false : " " : string | boolean + diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types new file mode 100644 index 0000000000000..3fa96510f41d7 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedConditionalES6.ts === +var x = `abc${ true ? false : " " }def`; +>x : string +>true ? false : " " : string | boolean + diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt index a040d0cb2f461..b9e803a8a140d 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,9): error TS1003: Identifier expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,15): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,26): error TS1158: Invalid template literal; expected '}' -tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,33): error TS1005: ';' expected. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,30): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(5,1): error TS1126: Unexpected end of text. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,11): error TS2304: Cannot find name 'gen'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,20): error TS2304: Cannot find name 'yield'. @@ -20,7 +20,7 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts( var x = `abc${ yield 10 }def`; ~~ !!! error TS1158: Invalid template literal; expected '}' - ~~ + ~~~~~ ~~~~~ !!! error TS2304: Cannot find name 'yield'. ~~~ @@ -29,6 +29,6 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts( ~ -!!! error TS1005: ';' expected. +!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. !!! error TS1126: Unexpected end of text. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt index 58dd041e47f1c..6cae5332517ba 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt @@ -1,14 +1,13 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,9): error TS1003: Identifier expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,17): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,26): error TS1158: Invalid template literal; expected '}' -tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,33): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(5,1): error TS1126: Unexpected end of text. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,11): error TS2304: Cannot find name 'gen'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,20): error TS2304: Cannot find name 'yield'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,30): error TS2304: Cannot find name 'def'. -==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts (8 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts (7 errors) ==== function* gen() { ~ !!! error TS1003: Identifier expected. @@ -20,15 +19,11 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6. var x = `abc${ yield 10 }def`; ~~ !!! error TS1158: Invalid template literal; expected '}' - ~~ ~~~~~ !!! error TS2304: Cannot find name 'yield'. ~~~ !!! error TS2304: Cannot find name 'def'. } - ~ -!!! error TS1005: ';' expected. - !!! error TS1126: Unexpected end of text. \ No newline at end of file From 0d1a46d68c381b1575c3b50a27e9b3e4e8468401 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 23 Oct 2014 16:55:35 -0700 Subject: [PATCH 04/15] Better test coverage for templates in object literals. These tests still need to be fixed. --- .../templateStringInPropertyAssignment.js | 9 ++++++++ .../templateStringInPropertyAssignment.types | 8 +++++++ .../templateStringInPropertyAssignmentES6.js | 9 ++++++++ ...emplateStringInPropertyAssignmentES6.types | 8 +++++++ .../templateStringInPropertyName1.errors.txt | 22 +++++++++++++++++++ .../templateStringInPropertyName2.errors.txt | 22 +++++++++++++++++++ ...mplateStringInPropertyNameES6_1.errors.txt | 18 +++++++++++++++ ...mplateStringInPropertyNameES6_2.errors.txt | 18 +++++++++++++++ .../templateStringInPropertyAssignment.ts | 3 +++ .../templateStringInPropertyAssignmentES6.ts | 4 ++++ .../templateStringInPropertyName1.ts | 3 +++ .../templateStringInPropertyName2.ts | 3 +++ .../templateStringInPropertyNameES6_1.ts | 4 ++++ .../templateStringInPropertyNameES6_2.ts | 4 ++++ 14 files changed, 135 insertions(+) create mode 100644 tests/baselines/reference/templateStringInPropertyAssignment.js create mode 100644 tests/baselines/reference/templateStringInPropertyAssignment.types create mode 100644 tests/baselines/reference/templateStringInPropertyAssignmentES6.js create mode 100644 tests/baselines/reference/templateStringInPropertyAssignmentES6.types create mode 100644 tests/baselines/reference/templateStringInPropertyName1.errors.txt create mode 100644 tests/baselines/reference/templateStringInPropertyName2.errors.txt create mode 100644 tests/baselines/reference/templateStringInPropertyNameES6_1.errors.txt create mode 100644 tests/baselines/reference/templateStringInPropertyNameES6_2.errors.txt create mode 100644 tests/cases/conformance/es6/templates/templateStringInPropertyAssignment.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInPropertyAssignmentES6.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_1.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_2.ts diff --git a/tests/baselines/reference/templateStringInPropertyAssignment.js b/tests/baselines/reference/templateStringInPropertyAssignment.js new file mode 100644 index 0000000000000..99fb24712c017 --- /dev/null +++ b/tests/baselines/reference/templateStringInPropertyAssignment.js @@ -0,0 +1,9 @@ +//// [templateStringInPropertyAssignment.ts] +var x = { + a: `abc${ 123 }def${ 456 }ghi` +} + +//// [templateStringInPropertyAssignment.js] +var x = { + a: "abc" + 123 + "def" + 456 + "ghi" +}; diff --git a/tests/baselines/reference/templateStringInPropertyAssignment.types b/tests/baselines/reference/templateStringInPropertyAssignment.types new file mode 100644 index 0000000000000..ff5ecb410db04 --- /dev/null +++ b/tests/baselines/reference/templateStringInPropertyAssignment.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/templates/templateStringInPropertyAssignment.ts === +var x = { +>x : { a: string; } +>{ a: `abc${ 123 }def${ 456 }ghi`} : { a: string; } + + a: `abc${ 123 }def${ 456 }ghi` +>a : string +} diff --git a/tests/baselines/reference/templateStringInPropertyAssignmentES6.js b/tests/baselines/reference/templateStringInPropertyAssignmentES6.js new file mode 100644 index 0000000000000..fc35c0a831a2c --- /dev/null +++ b/tests/baselines/reference/templateStringInPropertyAssignmentES6.js @@ -0,0 +1,9 @@ +//// [templateStringInPropertyAssignmentES6.ts] +var x = { + a: `abc${ 123 }def${ 456 }ghi` +} + +//// [templateStringInPropertyAssignmentES6.js] +var x = { + a: `abc${123}def${456}ghi` +}; diff --git a/tests/baselines/reference/templateStringInPropertyAssignmentES6.types b/tests/baselines/reference/templateStringInPropertyAssignmentES6.types new file mode 100644 index 0000000000000..fafc9f12a482e --- /dev/null +++ b/tests/baselines/reference/templateStringInPropertyAssignmentES6.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/templates/templateStringInPropertyAssignmentES6.ts === +var x = { +>x : { a: string; } +>{ a: `abc${ 123 }def${ 456 }ghi`} : { a: string; } + + a: `abc${ 123 }def${ 456 }ghi` +>a : string +} diff --git a/tests/baselines/reference/templateStringInPropertyName1.errors.txt b/tests/baselines/reference/templateStringInPropertyName1.errors.txt new file mode 100644 index 0000000000000..95d509e91517d --- /dev/null +++ b/tests/baselines/reference/templateStringInPropertyName1.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(1,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(2,5): error TS1136: Property assignment expected. +tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(2,8): error TS1005: ',' expected. +tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(2,10): error TS1134: Variable declaration expected. +tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(3,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts (5 errors) ==== + var x = { + ~ + `a`: 321 + ~~~~~~~ +!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. + ~~~ +!!! error TS1136: Property assignment expected. + ~ +!!! error TS1005: ',' expected. + ~~~ +!!! error TS1134: Variable declaration expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInPropertyName2.errors.txt b/tests/baselines/reference/templateStringInPropertyName2.errors.txt new file mode 100644 index 0000000000000..eed5791ea8e69 --- /dev/null +++ b/tests/baselines/reference/templateStringInPropertyName2.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(1,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(2,5): error TS1136: Property assignment expected. +tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(2,32): error TS1005: ',' expected. +tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(2,34): error TS1134: Variable declaration expected. +tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(3,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts (5 errors) ==== + var x = { + ~ + `abc${ 123 }def${ 456 }ghi`: 321 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. + ~~~~~~ +!!! error TS1136: Property assignment expected. + ~ +!!! error TS1005: ',' expected. + ~~~ +!!! error TS1134: Variable declaration expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInPropertyNameES6_1.errors.txt b/tests/baselines/reference/templateStringInPropertyNameES6_1.errors.txt new file mode 100644 index 0000000000000..b45de2faaa1d8 --- /dev/null +++ b/tests/baselines/reference/templateStringInPropertyNameES6_1.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_1.ts(2,5): error TS1136: Property assignment expected. +tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_1.ts(2,8): error TS1005: ',' expected. +tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_1.ts(2,10): error TS1134: Variable declaration expected. +tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_1.ts(3,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_1.ts (4 errors) ==== + var x = { + `a`: 321 + ~~~ +!!! error TS1136: Property assignment expected. + ~ +!!! error TS1005: ',' expected. + ~~~ +!!! error TS1134: Variable declaration expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInPropertyNameES6_2.errors.txt b/tests/baselines/reference/templateStringInPropertyNameES6_2.errors.txt new file mode 100644 index 0000000000000..6b28fe2c71c06 --- /dev/null +++ b/tests/baselines/reference/templateStringInPropertyNameES6_2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_2.ts(2,5): error TS1136: Property assignment expected. +tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_2.ts(2,32): error TS1005: ',' expected. +tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_2.ts(2,34): error TS1134: Variable declaration expected. +tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_2.ts(3,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_2.ts (4 errors) ==== + var x = { + `abc${ 123 }def${ 456 }ghi`: 321 + ~~~~~~ +!!! error TS1136: Property assignment expected. + ~ +!!! error TS1005: ',' expected. + ~~~ +!!! error TS1134: Variable declaration expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInPropertyAssignment.ts b/tests/cases/conformance/es6/templates/templateStringInPropertyAssignment.ts new file mode 100644 index 0000000000000..3b362d942d97b --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInPropertyAssignment.ts @@ -0,0 +1,3 @@ +var x = { + a: `abc${ 123 }def${ 456 }ghi` +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInPropertyAssignmentES6.ts b/tests/cases/conformance/es6/templates/templateStringInPropertyAssignmentES6.ts new file mode 100644 index 0000000000000..6a99df5b34fa6 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInPropertyAssignmentES6.ts @@ -0,0 +1,4 @@ +// @target: ES6 +var x = { + a: `abc${ 123 }def${ 456 }ghi` +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts b/tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts new file mode 100644 index 0000000000000..c3c4ca3ecb5cb --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts @@ -0,0 +1,3 @@ +var x = { + `a`: 321 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts b/tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts new file mode 100644 index 0000000000000..d21ab30888f6a --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts @@ -0,0 +1,3 @@ +var x = { + `abc${ 123 }def${ 456 }ghi`: 321 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_1.ts b/tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_1.ts new file mode 100644 index 0000000000000..9bb814d32cf3e --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_1.ts @@ -0,0 +1,4 @@ +// @target: ES6 +var x = { + `a`: 321 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_2.ts b/tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_2.ts new file mode 100644 index 0000000000000..7179f217caab0 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringInPropertyNameES6_2.ts @@ -0,0 +1,4 @@ +// @target: ES6 +var x = { + `abc${ 123 }def${ 456 }ghi`: 321 +} \ No newline at end of file From a5b77c65f6e0f964a997bcfbe84b05ee23c423a9 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 23 Oct 2014 16:57:17 -0700 Subject: [PATCH 05/15] Added tests for tagged templates. Some should fail when we do typechecking. --- ...emplateStringsWithIncompatibleTypedTags.ts | 30 ++++++++++++++++++ ...lateStringsWithIncompatibleTypedTagsES6.ts | 31 +++++++++++++++++++ ...taggedTemplateStringsWithTagsTypedAsAny.ts | 25 +++++++++++++++ ...gedTemplateStringsWithTagsTypedAsAnyES6.ts | 25 +++++++++++++++ .../taggedTemplateStringsWithTypedTags.ts | 30 ++++++++++++++++++ .../taggedTemplateStringsWithTypedTagsES6.ts | 31 +++++++++++++++++++ 6 files changed, 172 insertions(+) create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAnyES6.ts create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts new file mode 100644 index 0000000000000..cd9da4e43e40b --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts @@ -0,0 +1,30 @@ +interface I { + (stringParts: string[], ...rest: boolean[]): I; + g: I; + h: I; + member: I; + thisIsNotATag(x: string): void + [x: number]: I; +} + +var f: I; + +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.thisIsNotATag(`abc`); + +f.thisIsNotATag(`abc${1}def${2}ghi`); diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts new file mode 100644 index 0000000000000..2e8cbf3a1fafe --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts @@ -0,0 +1,31 @@ +// @target: ES6 +interface I { + (stringParts: string[], ...rest: boolean[]): I; + g: I; + h: I; + member: I; + thisIsNotATag(x: string): void + [x: number]: I; +} + +var f: I; + +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.thisIsNotATag(`abc`); + +f.thisIsNotATag(`abc${1}def${2}ghi`); diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts new file mode 100644 index 0000000000000..08d696cb28810 --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts @@ -0,0 +1,25 @@ +var f: any; + +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`; + +f.thisIsNotATag(`abc`); + +f.thisIsNotATag(`abc${1}def${2}ghi`); \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAnyES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAnyES6.ts new file mode 100644 index 0000000000000..de75e1679ac2a --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAnyES6.ts @@ -0,0 +1,25 @@ +// @target: ES6 +var f: any; +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`; + +f.thisIsNotATag(`abc`); + +f.thisIsNotATag(`abc${1}def${2}ghi`); \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts new file mode 100644 index 0000000000000..9b3852c2ddb23 --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts @@ -0,0 +1,30 @@ +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` + +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.thisIsNotATag(`abc`); + +f.thisIsNotATag(`abc${1}def${2}ghi`); diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts new file mode 100644 index 0000000000000..0dc10820a98c1 --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts @@ -0,0 +1,31 @@ +// @target: ES6 +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` + +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.thisIsNotATag(`abc`); + +f.thisIsNotATag(`abc${1}def${2}ghi`); From 799609c8e8c3a55e9e5b7c5e8a4ed827394dd0d7 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 23 Oct 2014 17:31:12 -0700 Subject: [PATCH 06/15] Tests for tagged templates. --- ...tringsWithIncompatibleTypedTags.errors.txt | 64 +++++++++++++++ ...lateStringsWithIncompatibleTypedTagsES6.js | 45 ++++++++++ ...eStringsWithIncompatibleTypedTagsES6.types | 82 +++++++++++++++++++ ...ithManyCallAndMemberExpressions.errors.txt | 21 +++++ ...ingsWithManyCallAndMemberExpressionsES6.js | 20 +++++ ...sWithManyCallAndMemberExpressionsES6.types | 38 +++++++++ ...mplateStringsWithTagsTypedAsAny.errors.txt | 64 +++++++++++++++ ...gedTemplateStringsWithTagsTypedAsAnyES6.js | 40 +++++++++ ...TemplateStringsWithTagsTypedAsAnyES6.types | 66 +++++++++++++++ ...gedTemplateStringsWithTypedTags.errors.txt | 64 +++++++++++++++ .../taggedTemplateStringsWithTypedTagsES6.js | 45 ++++++++++ ...aggedTemplateStringsWithTypedTagsES6.types | 82 +++++++++++++++++++ ...StringsWithManyCallAndMemberExpressions.ts | 14 ++++ ...ingsWithManyCallAndMemberExpressionsES6.ts | 15 ++++ 14 files changed, 660 insertions(+) create mode 100644 tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.types create mode 100644 tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAnyES6.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAnyES6.types create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.types create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt new file mode 100644 index 0000000000000..21600aa2f9b08 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt @@ -0,0 +1,64 @@ +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(12,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(14,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(16,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(18,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(20,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(22,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. + + +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts (10 errors) ==== + interface I { + (stringParts: string[], ...rest: boolean[]): 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/taggedTemplateStringsWithIncompatibleTypedTagsES6.js b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.js new file mode 100644 index 0000000000000..db68e950c342c --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.js @@ -0,0 +1,45 @@ +//// [taggedTemplateStringsWithIncompatibleTypedTagsES6.ts] +interface I { + (stringParts: string[], ...rest: boolean[]): I; + g: I; + h: I; + member: I; + thisIsNotATag(x: string): void + [x: number]: I; +} + +var f: I; + +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.thisIsNotATag(`abc`); + +f.thisIsNotATag(`abc${1}def${2}ghi`); + + +//// [taggedTemplateStringsWithIncompatibleTypedTagsES6.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.thisIsNotATag(`abc`); +f.thisIsNotATag(`abc${1}def${2}ghi`); diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.types b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.types new file mode 100644 index 0000000000000..572c3c1a8d157 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.types @@ -0,0 +1,82 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts === +interface I { +>I : I + + (stringParts: string[], ...rest: boolean[]): I; +>stringParts : string[] +>rest : boolean[] +>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 : any +>f : I +>member : any + +f `abc${1}def${2}ghi`.member; +>f `abc${1}def${2}ghi`.member : any +>f : I +>member : any + +f `abc`["member"]; +>f `abc`["member"] : any +>f : I + +f `abc${1}def${2}ghi`["member"]; +>f `abc${1}def${2}ghi`["member"] : any +>f : I + +f `abc`[0].member `abc${1}def${2}ghi`; +>f `abc`[0].member : any +>f `abc`[0] : any +>f : I +>member : any + +f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; +>f `abc${1}def${2}ghi`["member"].member : any +>f `abc${1}def${2}ghi`["member"] : any +>f : I +>member : any + +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/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt new file mode 100644 index 0000000000000..3ba890959ebff --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts(13,21): 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/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.js b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.js new file mode 100644 index 0000000000000..4d6a68a921a6c --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.js @@ -0,0 +1,20 @@ +//// [taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts] +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; + + + +//// [taggedTemplateStringsWithManyCallAndMemberExpressionsES6.js] +var f; +var x = new new new f `abc${0}def`.member("hello")(42) === true; diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types new file mode 100644 index 0000000000000..b8fb33771967c --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types @@ -0,0 +1,38 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.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) : any +>new new f `abc${ 0 }def`.member("hello")(42) : any +>new f `abc${ 0 }def`.member("hello") : any +>f `abc${ 0 }def`.member : any +>f : I +>member : any + + diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt new file mode 100644 index 0000000000000..a15e0cbb49b81 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt @@ -0,0 +1,64 @@ +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(3,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(5,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(7,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(9,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(11,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(13,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(15,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(17,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,1): 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/taggedTemplateStringsWithTagsTypedAsAnyES6.js b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAnyES6.js new file mode 100644 index 0000000000000..997e1277442e6 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAnyES6.js @@ -0,0 +1,40 @@ +//// [taggedTemplateStringsWithTagsTypedAsAnyES6.ts] +var f: any; +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`; + +f.thisIsNotATag(`abc`); + +f.thisIsNotATag(`abc${1}def${2}ghi`); + +//// [taggedTemplateStringsWithTagsTypedAsAnyES6.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`; +f.thisIsNotATag(`abc`); +f.thisIsNotATag(`abc${1}def${2}ghi`); diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAnyES6.types b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAnyES6.types new file mode 100644 index 0000000000000..bb651fe1d25a2 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAnyES6.types @@ -0,0 +1,66 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAnyES6.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/taggedTemplateStringsWithTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt new file mode 100644 index 0000000000000..0e4f7a63223c4 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt @@ -0,0 +1,64 @@ +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(12,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(14,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(16,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(18,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(20,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(22,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,1): 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/taggedTemplateStringsWithTypedTagsES6.js b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.js new file mode 100644 index 0000000000000..9eefc46ec302c --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.js @@ -0,0 +1,45 @@ +//// [taggedTemplateStringsWithTypedTagsES6.ts] +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` + +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.thisIsNotATag(`abc`); + +f.thisIsNotATag(`abc${1}def${2}ghi`); + + +//// [taggedTemplateStringsWithTypedTagsES6.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.thisIsNotATag(`abc`); +f.thisIsNotATag(`abc${1}def${2}ghi`); diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.types b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.types new file mode 100644 index 0000000000000..9745320b39752 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.types @@ -0,0 +1,82 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.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 : any +>f : I +>member : any + +f `abc${1}def${2}ghi`.member; +>f `abc${1}def${2}ghi`.member : any +>f : I +>member : any + +f `abc`["member"]; +>f `abc`["member"] : any +>f : I + +f `abc${1}def${2}ghi`["member"]; +>f `abc${1}def${2}ghi`["member"] : any +>f : I + +f `abc`[0].member `abc${1}def${2}ghi`; +>f `abc`[0].member : any +>f `abc`[0] : any +>f : I +>member : any + +f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; +>f `abc${1}def${2}ghi`["member"].member : any +>f `abc${1}def${2}ghi`["member"] : any +>f : I +>member : any + +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/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts new file mode 100644 index 0000000000000..b86996a53f3ac --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts @@ -0,0 +1,14 @@ +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; + diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts new file mode 100644 index 0000000000000..0fe9ad566a9de --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts @@ -0,0 +1,15 @@ +// @target: ES6 +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; + From c03dc107ca5fc1958362ad61ec4a043899244e3e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 24 Oct 2014 17:14:41 -0700 Subject: [PATCH 07/15] Added syntactic classification for templates; also made 'spans' a NodeArray. --- src/compiler/parser.ts | 8 +++++-- src/compiler/types.ts | 2 +- src/services/services.ts | 4 ++++ ...nticClassificationInTemplateExpressions.ts | 21 +++++++++++++++++++ .../syntacticClassificationsTemplates1.ts | 15 +++++++++++++ .../syntacticClassificationsTemplates2.ts | 11 ++++++++++ 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/semanticClassificationInTemplateExpressions.ts create mode 100644 tests/cases/fourslash/syntacticClassificationsTemplates1.ts create mode 100644 tests/cases/fourslash/syntacticClassificationsTemplates2.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5a56c21ef78a4..97122529286dd 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1406,13 +1406,17 @@ module ts { template.head = parseLiteralNode(); Debug.assert(template.head.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind"); - var templateSpans: TemplateSpan[] = []; + var templateSpans = >[]; + templateSpans.pos = getNodePos(); + do { templateSpans.push(parseTemplateSpan()); } while (templateSpans[templateSpans.length - 1].literal.kind === SyntaxKind.TemplateMiddle) - + + templateSpans.end = getNodeEnd(); template.templateSpans = templateSpans; + return finishNode(template); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0c5fe20b713da..44aa2547fc513 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -400,7 +400,7 @@ module ts { export interface TemplateExpression extends Expression { head: LiteralExpression; - templateSpans: TemplateSpan[] + templateSpans: NodeArray; } export interface TemplateSpan extends Node { diff --git a/src/services/services.ts b/src/services/services.ts index 1079381f749d3..86a0a8c770bf5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4901,6 +4901,10 @@ module ts { // TODO: we should get another classification type for these literals. return ClassificationTypeNames.stringLiteral; } + else if (isTemplateLiteralKind(tokenKind)) { + // TODO (drosen): we should *also* get another classification type for these literals. + return ClassificationTypeNames.stringLiteral; + } else if (tokenKind === SyntaxKind.Identifier) { switch (token.parent.kind) { case SyntaxKind.ClassDeclaration: diff --git a/tests/cases/fourslash/semanticClassificationInTemplateExpressions.ts b/tests/cases/fourslash/semanticClassificationInTemplateExpressions.ts new file mode 100644 index 0000000000000..19f6d1062cb66 --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationInTemplateExpressions.ts @@ -0,0 +1,21 @@ +/// + +////module /*0*/M { +//// export class /*1*/C { +//// static x; +//// } +//// export enum /*2*/E { +//// E1 = 0 +//// } +////} +////`abcd${ /*3*/M./*4*/C.x + /*5*/M./*6*/E.E1}efg` + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.className("C", test.marker("1").position), + c.enumName("E", test.marker("2").position), + c.moduleName("M", test.marker("3").position), + c.className("C", test.marker("4").position), + c.moduleName("M", test.marker("5").position), + c.enumName("E", test.marker("6").position)); diff --git a/tests/cases/fourslash/syntacticClassificationsTemplates1.ts b/tests/cases/fourslash/syntacticClassificationsTemplates1.ts new file mode 100644 index 0000000000000..4c79c047c81ac --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsTemplates1.ts @@ -0,0 +1,15 @@ +/// + +////var v = 10e0; +////var x = { +//// p1: `hello world`, +//// p2: `goodbye ${0} cruel ${0} world`, +////}; + +var c = classification; +verify.syntacticClassificationsAre( + c.keyword("var"), c.text("v"), c.operator("="), c.numericLiteral("10e0"), c.punctuation(";"), + c.keyword("var"), c.text("x"), c.operator("="), c.punctuation("{"), + c.text("p1"), c.punctuation(":"), c.stringLiteral("`hello world`"), c.punctuation(","), + c.text("p2"), c.punctuation(":"), c.stringLiteral("`goodbye ${"), c.numericLiteral("0"), c.stringLiteral("} cruel ${"), c.numericLiteral("0"), c.stringLiteral("} world`"), c.punctuation(","), + c.punctuation("}"), c.punctuation(";")); \ No newline at end of file diff --git a/tests/cases/fourslash/syntacticClassificationsTemplates2.ts b/tests/cases/fourslash/syntacticClassificationsTemplates2.ts new file mode 100644 index 0000000000000..19bad4b54a825 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsTemplates2.ts @@ -0,0 +1,11 @@ +/// + +////var tiredOfCanonicalExamples = +////`goodbye "${ `hello world` }" +////and ${ `good${ " " }riddance` }`; + +var c = classification; +verify.syntacticClassificationsAre( + c.keyword("var"), c.text("tiredOfCanonicalExamples"), c.operator("="), + c.stringLiteral("`goodbye \"${"), c.stringLiteral("`hello world`"), + c.stringLiteral("}\" \nand ${"), c.stringLiteral("`good${"), c.stringLiteral("\" \""), c.stringLiteral("}riddance`"), c.stringLiteral("}`"), c.punctuation(";")); \ No newline at end of file From 4aafe1d2bc2c645b6986752ac6a7e2804dc283e5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Oct 2014 14:55:52 -0700 Subject: [PATCH 08/15] Addressed CR feedback. --- src/compiler/checker.ts | 12 +++++++++--- src/compiler/emitter.ts | 19 ++++++++++++++++--- src/compiler/scanner.ts | 24 +++++++++++++----------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7275a5e95951f..7011df7e10d19 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5945,10 +5945,17 @@ module ts { return getUnionType([type1, type2]); } - function checkTemplateExpression(node: TemplateExpression): void { + function checkTemplateExpression(node: TemplateExpression): Type { + // We just want to check each expressions, but we are unconcerned with + // the type of each expression, as any value may be coerced into a string. + // It is worth asking whether this is what we really want though. + // A place where we actually *are* concerned with the expressions' types are + // in tagged templates. forEach((node).templateSpans, templateSpan => { checkExpression(templateSpan.expression); }); + + return stringType; } function checkExpressionWithContextualType(node: Expression, contextualType: Type, contextualMapper?: TypeMapper): Type { @@ -6005,8 +6012,7 @@ module ts { case SyntaxKind.NumericLiteral: return numberType; case SyntaxKind.TemplateExpression: - checkTemplateExpression(node); - // fall through + return checkTemplateExpression(node); case SyntaxKind.StringLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: return stringType; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e8550fbce3196..f2e984d18c1a1 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -806,12 +806,14 @@ module ts { } function getTemplateLiteralAsStringLiteral(node: LiteralExpression): string { - return "\"" + escapeString(node.text) + "\""; + return '"' + escapeString(node.text) + '"'; } function emitTemplateExpression(node: TemplateExpression): void { + // In ES6 mode and above, we can simply emit each portion of a template in order, but in + // ES3 & ES5 we must convert the template expression into a series of string concatenations. if (compilerOptions.target >= ScriptTarget.ES6) { - forEachChild(node, emitNode); + forEachChild(node, emit); return; } @@ -825,6 +827,15 @@ module ts { emitLiteral(node.head); forEach(node.templateSpans, templateSpan => { + // Check if the expression has operands and binds its operands less closely than binary '+'. + // If it does, we need to wrap the expression in parentheses. Otherwise, something like + // `abc${ 1 << 2}` + // becomes + // "abc" + 1 << 2 + "" + // which is really + // ("abc" + 1) << (2 + "") + // rather than + // "abc" + (1 << 2) + "" var needsParens = comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan; write(" + "); @@ -858,6 +869,7 @@ module ts { // // TODO (drosen): Note that we need to account for the upcoming 'yield' and // spread ('...') unary operators that are anticipated for ES6. + Debug.assert(compilerOptions.target <= ScriptTarget.ES5); switch (expression.kind) { case SyntaxKind.BinaryExpression: switch ((expression).operator) { @@ -880,7 +892,8 @@ module ts { } function emitTemplateSpan(span: TemplateSpan) { - forEachChild(span, emitNode); + emit(span.expression); + emit(span.literal); } // This function specifically handles numeric/string literals for enum and accessor 'identifiers'. diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 0d207b1ae92f0..fddfa8a7f338b 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -519,10 +519,10 @@ module ts { return +(text.substring(start, pos)); } - function scanHexDigits(count: number, useExactCount?: boolean): number { + function scanHexDigits(count: number, mustMatchCount?: boolean): number { var digits = 0; var value = 0; - while (digits < count || !useExactCount) { + while (digits < count || !mustMatchCount) { var ch = text.charCodeAt(pos); if (ch >= CharacterCodes._0 && ch <= CharacterCodes._9) { value = value * 16 + ch - CharacterCodes._0; @@ -582,18 +582,18 @@ module ts { * a literal component of a TemplateExpression. */ function scanTemplateAndSetTokenValue(): SyntaxKind { - var isStartOfTemplate = text.charCodeAt(pos) === CharacterCodes.backtick; + var startedWithBacktick = text.charCodeAt(pos) === CharacterCodes.backtick; pos++; var start = pos; var contents = "" - var resultingToken = SyntaxKind.Unknown; + var resultingToken: SyntaxKind; while (true) { if (pos >= len) { contents += text.substring(start, pos); error(Diagnostics.Unexpected_end_of_text); - resultingToken = isStartOfTemplate ? SyntaxKind.NoSubstitutionTemplateLiteral : SyntaxKind.TemplateTail; + resultingToken = startedWithBacktick ? SyntaxKind.NoSubstitutionTemplateLiteral : SyntaxKind.TemplateTail; break; } @@ -603,7 +603,7 @@ module ts { if (currChar === CharacterCodes.backtick) { contents += text.substring(start, pos); pos++; - resultingToken = isStartOfTemplate ? SyntaxKind.NoSubstitutionTemplateLiteral : SyntaxKind.TemplateTail; + resultingToken = startedWithBacktick ? SyntaxKind.NoSubstitutionTemplateLiteral : SyntaxKind.TemplateTail; break; } @@ -611,7 +611,7 @@ module ts { if (currChar === CharacterCodes.$ && pos + 1 < len && text.charCodeAt(pos + 1) === CharacterCodes.openBrace) { contents += text.substring(start, pos); pos += 2; - resultingToken = isStartOfTemplate ? SyntaxKind.TemplateHead : SyntaxKind.TemplateMiddle; + resultingToken = startedWithBacktick ? SyntaxKind.TemplateHead : SyntaxKind.TemplateMiddle; break; } @@ -641,6 +641,8 @@ module ts { pos++; } + Debug.assert(resultingToken !== undefined); + tokenValue = contents; return resultingToken; } @@ -673,7 +675,7 @@ module ts { return "\""; case CharacterCodes.x: case CharacterCodes.u: - var ch = scanHexDigits(ch === CharacterCodes.x ? 2 : 4, /*useExactCount*/ true); + var ch = scanHexDigits(ch === CharacterCodes.x ? 2 : 4, /*mustMatchCount*/ true); if (ch >= 0) { return String.fromCharCode(ch); } @@ -704,7 +706,7 @@ module ts { if (pos + 5 < len && text.charCodeAt(pos + 1) === CharacterCodes.u) { var start = pos; pos += 2; - var value = scanHexDigits(4, /*useExactCount*/ true); + var value = scanHexDigits(4, /*mustMatchCount*/ true); pos = start; return value; } @@ -922,7 +924,7 @@ module ts { case CharacterCodes._0: if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.X || text.charCodeAt(pos + 1) === CharacterCodes.x)) { pos += 2; - var value = scanHexDigits(1, /*useExactCount*/ false); + var value = scanHexDigits(1, /*mustMatchCount*/ false); if (value < 0) { error(Diagnostics.Hexadecimal_digit_expected); value = 0; @@ -1112,7 +1114,7 @@ module ts { * Unconditionally back up and scan a template expression portion. */ function reScanTemplateToken(): SyntaxKind { - Debug.assert("'reScanTemplateToken' should only be called on a '}'"); + Debug.assert(token === SyntaxKind.CloseBraceToken, "'reScanTemplateToken' should only be called on a '}'"); pos = tokenPos; return token = scanTemplateAndSetTokenValue(); } From 8786d30e9d4ba02caf3ac3f1757d705010f6eb4c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Oct 2014 15:04:08 -0700 Subject: [PATCH 09/15] Changed Debug.assert's first parameter to a boolean. --- src/compiler/checker.ts | 14 +++++++------- src/compiler/core.ts | 2 +- src/services/formatting/smartIndenter.ts | 2 +- src/services/services.ts | 18 +++++++++--------- src/services/signatureHelp.ts | 2 +- src/services/utilities.ts | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7011df7e10d19..696a0538a49fc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -424,7 +424,7 @@ module ts { if (result.flags & SymbolFlags.BlockScopedVariable) { // Block-scoped variables cannot be used before their definition var declaration = forEach(result.declarations, d => d.flags & NodeFlags.BlockScoped ? d : undefined); - Debug.assert(declaration, "Block-scoped variable declaration is undefined"); + Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); var declarationSourceFile = getSourceFileOfNode(declaration); var referenceSourceFile = getSourceFileOfNode(errorLocation); if (declarationSourceFile === referenceSourceFile) { @@ -469,7 +469,7 @@ module ts { function getSymbolOfPartOfRightHandSideOfImport(entityName: EntityName, importDeclaration?: ImportDeclaration): Symbol { if (!importDeclaration) { importDeclaration = getAncestor(entityName, SyntaxKind.ImportDeclaration); - Debug.assert(importDeclaration); + Debug.assert(importDeclaration !== undefined); } // There are three things we might try to look for. In the following examples, // the search term is enclosed in |...|: @@ -3345,7 +3345,7 @@ module ts { chainedMessage = chainedMessage || Diagnostics.Type_0_is_not_assignable_to_type_1_Colon; terminalMessage = terminalMessage || Diagnostics.Type_0_is_not_assignable_to_type_1; var diagnosticKey = errorInfo ? chainedMessage : terminalMessage; - Debug.assert(diagnosticKey); + Debug.assert(diagnosticKey !== undefined); reportError(diagnosticKey, typeToString(source), typeToString(target)); } return false; @@ -7342,17 +7342,17 @@ module ts { errorMessage = Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor; } else { - Debug.assert(derived.flags & SymbolFlags.Property); + Debug.assert((derived.flags & SymbolFlags.Property) !== 0); errorMessage = Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property; } } else if (base.flags & SymbolFlags.Property) { - Debug.assert(derived.flags & SymbolFlags.Method); + Debug.assert((derived.flags & SymbolFlags.Method) !== 0); errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function; } else { - Debug.assert(base.flags & SymbolFlags.Accessor); - Debug.assert(derived.flags & SymbolFlags.Method); + Debug.assert((base.flags & SymbolFlags.Accessor) !== 0); + Debug.assert((derived.flags & SymbolFlags.Method) !== 0); errorMessage = Diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 7f0f78dd2fb4e..56ca60a57443c 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -631,7 +631,7 @@ module ts { return currentAssertionLevel >= level; } - export function assert(expression: any, message?: string, verboseDebugInfo?: () => string): void { + export function assert(expression: boolean, message?: string, verboseDebugInfo?: () => string): void { if (!expression) { var verboseDebugString = ""; if (verboseDebugInfo) { diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 79b238c893dc3..62bb7cc93ec8b 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -175,7 +175,7 @@ module ts.formatting { function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: Node, childStartLine: number, sourceFile: SourceFile): boolean { if (parent.kind === SyntaxKind.IfStatement && (parent).elseStatement === child) { var elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile); - Debug.assert(elseKeyword); + Debug.assert(elseKeyword !== undefined); var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line; return elseKeywordStartLine === childStartLine; diff --git a/src/services/services.ts b/src/services/services.ts index 0eea836f5c8ec..c60a3355164f4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1656,7 +1656,7 @@ module ts { } if (syntaxTree !== null) { - Debug.assert(sourceFile); + Debug.assert(sourceFile !== undefined); // All done, ensure state is up to date this.currentFileVersion = version; this.currentFilename = filename; @@ -1864,9 +1864,9 @@ module ts { ): SourceFile { var bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ false); - Debug.assert(bucket); + Debug.assert(bucket !== undefined); var entry = lookUp(bucket, filename); - Debug.assert(entry); + Debug.assert(entry !== undefined); if (entry.sourceFile.isOpen === isOpen && entry.sourceFile.version === version) { return entry.sourceFile; @@ -1878,7 +1878,7 @@ module ts { function releaseDocument(filename: string, compilationSettings: CompilerOptions): void { var bucket = getBucketForCompilationSettings(compilationSettings, false); - Debug.assert(bucket); + Debug.assert(bucket !== undefined); var entry = lookUp(bucket, filename); entry.refCount--; @@ -2549,7 +2549,7 @@ module ts { mappedNode = precedingToken; } - Debug.assert(mappedNode, "Could not map a Fidelity node to an AST node"); + Debug.assert(mappedNode !== undefined, "Could not map a Fidelity node to an AST node"); // Get the completions activeCompletionSession = { @@ -2603,7 +2603,7 @@ module ts { if (containingObjectLiteral) { var objectLiteral = (mappedNode.kind === SyntaxKind.ObjectLiteral ? mappedNode : getAncestor(mappedNode, SyntaxKind.ObjectLiteral)); - Debug.assert(objectLiteral); + Debug.assert(objectLiteral !== undefined); isMemberCompletion = true; @@ -2656,7 +2656,7 @@ module ts { var symbol = lookUp(activeCompletionSession.symbols, entryName); if (symbol) { var type = session.typeChecker.getTypeOfSymbol(symbol); - Debug.assert(type, "Could not find type for symbol"); + Debug.assert(type !== undefined, "Could not find type for symbol"); var completionEntry = createCompletionEntry(symbol, session.typeChecker); // TODO(drosen): Right now we just permit *all* semantic meanings when calling 'getSymbolKind' // which is permissible given that it is backwards compatible; but really we should consider @@ -2755,7 +2755,7 @@ module ts { } if (rootSymbolFlags & SymbolFlags.GetAccessor) return ScriptElementKind.memberVariableElement; if (rootSymbolFlags & SymbolFlags.SetAccessor) return ScriptElementKind.memberVariableElement; - Debug.assert(rootSymbolFlags & SymbolFlags.Method); + Debug.assert((rootSymbolFlags & SymbolFlags.Method) !== undefined); }) || ScriptElementKind.memberFunctionElement; } return ScriptElementKind.memberVariableElement; @@ -5155,7 +5155,7 @@ module ts { descriptor = descriptors[i]; } } - Debug.assert(descriptor); + Debug.assert(descriptor !== undefined); // We don't want to match something like 'TODOBY', so we make sure a non // letter/digit follows the match. diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 86e378abb45d5..929325fcde3e1 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -219,7 +219,7 @@ module ts.SignatureHelp { // Find the list that starts right *after* the < or ( token. // If the user has just opened a list, consider this item 0. var list = getChildListThatStartsWithOpenerToken(parent, node, sourceFile); - Debug.assert(list); + Debug.assert(list !== undefined); return { list: list, listItemIndex: 0 diff --git a/src/services/utilities.ts b/src/services/utilities.ts index ca17b704d059e..87d5101331068 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -35,7 +35,7 @@ module ts { // syntaxList should not be undefined here. If it is, there is a problem. Find out if // there at least is a child that is a list. if (!syntaxList) { - Debug.assert(findChildOfKind(node.parent, SyntaxKind.SyntaxList), + Debug.assert(findChildOfKind(node.parent, SyntaxKind.SyntaxList) !== undefined, "Node of kind " + SyntaxKind[node.parent.kind] + " has no list children"); } @@ -194,7 +194,7 @@ module ts { } } - Debug.assert(startNode || n.kind === SyntaxKind.SourceFile); + Debug.assert(startNode !== undefined || n.kind === SyntaxKind.SourceFile); // Here we know that none of child token nodes embrace the position, // the only known case is when position is at the end of the file. From d45fb7769ab9d756ee17e7cc54f98aa18555c823 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Oct 2014 15:58:22 -0700 Subject: [PATCH 10/15] Renamed certain functions in the parser to more accurately reflect behavior. --- src/compiler/parser.ts | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index cd7f99b696423..d62da511aaf10 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1161,7 +1161,7 @@ module ts { case ParsingContext.SwitchClauses: return token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; case ParsingContext.TypeMembers: - return isTypeMember(); + return isStartOfTypeMember(); case ParsingContext.ClassMembers: return lookAhead(isClassMemberStart); case ParsingContext.EnumMembers: @@ -1173,14 +1173,14 @@ module ts { case ParsingContext.TypeParameters: return isIdentifier(); case ParsingContext.ArgumentExpressions: - return token === SyntaxKind.CommaToken || isExpression(); + return token === SyntaxKind.CommaToken || isStartOfExpression(); case ParsingContext.ArrayLiteralMembers: - return token === SyntaxKind.CommaToken || isExpression(); + return token === SyntaxKind.CommaToken || isStartOfExpression(); case ParsingContext.Parameters: - return isParameter(); + return isStartOfParameter(); case ParsingContext.TypeArguments: case ParsingContext.TupleElementTypes: - return token === SyntaxKind.CommaToken || isType(); + return token === SyntaxKind.CommaToken || isStartOfType(); } Debug.fail("Non-exhaustive case in 'isListElement'."); @@ -1505,7 +1505,7 @@ module ts { // user writes a constraint that is an expression and not an actual type, then parse // it out as an expression (so we can recover well), but report that a type is needed // instead. - if (isType() || !isExpression()) { + if (isStartOfType() || !isStartOfExpression()) { node.constraint = parseType(); } else { @@ -1541,7 +1541,7 @@ module ts { return parseOptional(SyntaxKind.ColonToken) ? token === SyntaxKind.StringLiteral ? parseStringLiteral() : parseType() : undefined; } - function isParameter(): boolean { + function isStartOfParameter(): boolean { return token === SyntaxKind.DotDotDotToken || isIdentifier() || isModifier(token); } @@ -1749,7 +1749,7 @@ module ts { return finishNode(node); } - function isTypeMember(): boolean { + function isStartOfTypeMember(): boolean { switch (token) { case SyntaxKind.OpenParenToken: case SyntaxKind.LessThanToken: @@ -1856,7 +1856,7 @@ module ts { return createMissingNode(); } - function isType(): boolean { + function isStartOfType(): boolean { switch (token) { case SyntaxKind.AnyKeyword: case SyntaxKind.StringKeyword: @@ -1874,7 +1874,7 @@ module ts { // or something that starts a type. We don't want to consider things like '(1)' a type. return lookAhead(() => { nextToken(); - return token === SyntaxKind.CloseParenToken || isParameter() || isType(); + return token === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType(); }); default: return isIdentifier(); @@ -1908,7 +1908,7 @@ module ts { return type; } - function isFunctionType(): boolean { + function isStartOfFunctionType(): boolean { return token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken && lookAhead(() => { nextToken(); if (token === SyntaxKind.CloseParenToken || token === SyntaxKind.DotDotDotToken) { @@ -1941,7 +1941,7 @@ module ts { } function parseType(): TypeNode { - if (isFunctionType()) { + if (isStartOfFunctionType()) { return parseFunctionType(SyntaxKind.CallSignature); } if (token === SyntaxKind.NewKeyword) { @@ -1956,7 +1956,7 @@ module ts { // EXPRESSIONS - function isExpression(): boolean { + function isStartOfExpression(): boolean { switch (token) { case SyntaxKind.ThisKeyword: case SyntaxKind.SuperKeyword: @@ -1991,9 +1991,9 @@ module ts { } } - function isExpressionStatement(): boolean { + function isStartOfExpressionStatement(): boolean { // As per the grammar, neither '{' nor 'function' can start an expression statement. - return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && isExpression(); + return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && isStartOfExpression(); } function parseExpression(noIn?: boolean): Expression { @@ -2014,7 +2014,7 @@ module ts { // it's more likely that a { would be a allowed (as an object literal). While this // is also allowed for parameters, the risk is that we consume the { as an object // literal when it really will be for the block following the parameter. - if (scanner.hasPrecedingLineBreak() || (inParameter && token === SyntaxKind.OpenBraceToken) || !isExpression()) { + if (scanner.hasPrecedingLineBreak() || (inParameter && token === SyntaxKind.OpenBraceToken) || !isStartOfExpression()) { // preceding line break, open brace in a parameter (likely a function body) or current token is not an expression - // do not try to parse initializer return undefined; @@ -2262,7 +2262,7 @@ module ts { if (token === SyntaxKind.OpenBraceToken) { body = parseBody(/* ignoreMissingOpenBrace */ false); } - else if (isStatement(/* inErrorRecovery */ true) && !isExpressionStatement() && token !== SyntaxKind.FunctionKeyword) { + else if (isStatement(/* inErrorRecovery */ true) && !isStartOfExpressionStatement() && token !== SyntaxKind.FunctionKeyword) { // Check if we got a plain statement (i.e. no expression-statements, no functions expressions/declarations) // // Here we try to recover from a potential error situation in the case where the @@ -3267,7 +3267,7 @@ module ts { case SyntaxKind.EnumKeyword: // When followed by an identifier, these do not start a statement but might // instead be following declarations - if (isDeclaration()) { + if (isDeclarationStart()) { return false; } case SyntaxKind.PublicKeyword: @@ -3280,7 +3280,7 @@ module ts { return false; } default: - return isExpression(); + return isStartOfExpression(); } } @@ -3993,7 +3993,7 @@ module ts { return finishNode(node); } - function isDeclaration(): boolean { + function isDeclarationStart(): boolean { switch (token) { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: @@ -4011,14 +4011,14 @@ module ts { return lookAhead(() => nextToken() >= SyntaxKind.Identifier || token === SyntaxKind.StringLiteral); case SyntaxKind.ExportKeyword: // Check for export assignment or modifier on source element - return lookAhead(() => nextToken() === SyntaxKind.EqualsToken || isDeclaration()); + return lookAhead(() => nextToken() === SyntaxKind.EqualsToken || isDeclarationStart()); case SyntaxKind.DeclareKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: // Check for modifier on source element - return lookAhead(() => { nextToken(); return isDeclaration(); }); + return lookAhead(() => { nextToken(); return isDeclarationStart(); }); } } @@ -4079,7 +4079,7 @@ module ts { } function isSourceElement(inErrorRecovery: boolean): boolean { - return isDeclaration() || isStatement(inErrorRecovery); + return isDeclarationStart() || isStatement(inErrorRecovery); } function parseSourceElement() { @@ -4091,7 +4091,7 @@ module ts { } function parseSourceElementOrModuleElement(modifierContext: ModifierContext): Statement { - if (isDeclaration()) { + if (isDeclarationStart()) { return parseDeclaration(modifierContext); } From 64097a3c6cf1eaf022f1c9e1438f3e70c0cda831 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Oct 2014 16:11:12 -0700 Subject: [PATCH 11/15] Missed a use when fixing Debug.assert --- src/harness/typeWriter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts index 5dfc75b29a5b4..6f7a7c335a03f 100644 --- a/src/harness/typeWriter.ts +++ b/src/harness/typeWriter.ts @@ -92,7 +92,7 @@ class TypeWriterWalker { private getTypeOfNode(node: ts.Node): ts.Type { var type = this.checker.getTypeOfNode(node); - ts.Debug.assert(type, "type doesn't exist"); + ts.Debug.assert(type !== undefined, "type doesn't exist"); return type; } } From aabfebd40e4842cf5a9f4989e1450d2303cceffd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Oct 2014 16:21:06 -0700 Subject: [PATCH 12/15] Fixed emit for parenthesized template expressions. --- src/compiler/emitter.ts | 10 +++++++--- .../baselines/reference/templateStringInParentheses.js | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f2e984d18c1a1..6d2ece71acf0a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -817,8 +817,11 @@ module ts { return; } - var templateNeedsParens = isExpression(node.parent) && - comparePrecedenceToBinaryPlus(node.parent) !== Comparison.LessThan; + Debug.assert(node.parent.kind !== SyntaxKind.TaggedTemplateExpression); + + var templateNeedsParens = isExpression(node.parent) + && node.parent.kind !== SyntaxKind.ParenExpression + && comparePrecedenceToBinaryPlus(node.parent) !== Comparison.LessThan; if (templateNeedsParens) { write("("); @@ -836,7 +839,8 @@ module ts { // ("abc" + 1) << (2 + "") // rather than // "abc" + (1 << 2) + "" - var needsParens = comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan; + var needsParens = templateSpan.expression.kind !== SyntaxKind.ParenExpression + && comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan; write(" + "); diff --git a/tests/baselines/reference/templateStringInParentheses.js b/tests/baselines/reference/templateStringInParentheses.js index 381e8ffd800e9..6c5c678bf4e85 100644 --- a/tests/baselines/reference/templateStringInParentheses.js +++ b/tests/baselines/reference/templateStringInParentheses.js @@ -2,4 +2,4 @@ var x = (`abc${0}abc`); //// [templateStringInParentheses.js] -var x = (("abc" + 0 + "abc")); +var x = ("abc" + 0 + "abc"); From b8535d339c6b4377b824c37e6ec448ab6538ea15 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Oct 2014 16:53:55 -0700 Subject: [PATCH 13/15] Omit empty template tail literals. --- src/compiler/emitter.ts | 9 ++++- .../reference/templateStringInInOperator.js | 2 +- .../templateStringWithEmptyLiteralPortions.js | 38 +++++++++++++++++++ ...mplateStringWithEmptyLiteralPortions.types | 37 ++++++++++++++++++ ...mplateStringWithEmptyLiteralPortionsES6.js | 38 +++++++++++++++++++ ...ateStringWithEmptyLiteralPortionsES6.types | 37 ++++++++++++++++++ .../templateStringWithEmptyLiteralPortions.ts | 23 +++++++++++ ...mplateStringWithEmptyLiteralPortionsES6.ts | 24 ++++++++++++ 8 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/templateStringWithEmptyLiteralPortions.js create mode 100644 tests/baselines/reference/templateStringWithEmptyLiteralPortions.types create mode 100644 tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js create mode 100644 tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts create mode 100644 tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6d2ece71acf0a..fe6258e0c3c44 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -852,8 +852,13 @@ module ts { write(")"); } - write(" + ") - emitLiteral(templateSpan.literal); + // Only emit if the literal is non-empty. + // The binary '+' operator is left-associative, so the first string concatenation will force + // the result up to this point to be a string. Emitting a '+ ""' has no semantic effect. + if (templateSpan.literal.text.length !== 0) { + write(" + ") + emitLiteral(templateSpan.literal); + } }); if (templateNeedsParens) { diff --git a/tests/baselines/reference/templateStringInInOperator.js b/tests/baselines/reference/templateStringInInOperator.js index 18890c9858a9d..c496e335dd434 100644 --- a/tests/baselines/reference/templateStringInInOperator.js +++ b/tests/baselines/reference/templateStringInInOperator.js @@ -2,4 +2,4 @@ var x = `${ "hi" }` in { hi: 10, hello: 20}; //// [templateStringInInOperator.js] -var x = "" + "hi" + "" in { hi: 10, hello: 20 }; +var x = "" + "hi" in { hi: 10, hello: 20 }; diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js new file mode 100644 index 0000000000000..8bc6e2c42065d --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.js @@ -0,0 +1,38 @@ +//// [templateStringWithEmptyLiteralPortions.ts] +var a = ``; + +var b = `${ 0 }`; + +var c = `1${ 0 }`; + +var d = `${ 0 }2`; + +var e = `1${ 0 }2`; + +var f = `${ 0 }${ 0 }`; + +var g = `1${ 0 }${ 0 }`; + +var h = `${ 0 }2${ 0 }`; + +var i = `1${ 0 }2${ 0 }`; + +var j = `${ 0 }${ 0 }3`; + +var k = `1${ 0 }${ 0 }3`; + +var l = `1${ 0 }2${ 0 }3`; + +//// [templateStringWithEmptyLiteralPortions.js] +var a = ""; +var b = "" + 0; +var c = "1" + 0; +var d = "" + 0 + "2"; +var e = "1" + 0 + "2"; +var f = "" + 0 + 0; +var g = "1" + 0 + 0; +var h = "" + 0 + "2" + 0; +var i = "1" + 0 + "2" + 0; +var j = "" + 0 + 0 + "3"; +var k = "1" + 0 + 0 + "3"; +var l = "1" + 0 + "2" + 0 + "3"; diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types new file mode 100644 index 0000000000000..a44bab8fe440e --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortions.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts === +var a = ``; +>a : string + +var b = `${ 0 }`; +>b : string + +var c = `1${ 0 }`; +>c : string + +var d = `${ 0 }2`; +>d : string + +var e = `1${ 0 }2`; +>e : string + +var f = `${ 0 }${ 0 }`; +>f : string + +var g = `1${ 0 }${ 0 }`; +>g : string + +var h = `${ 0 }2${ 0 }`; +>h : string + +var i = `1${ 0 }2${ 0 }`; +>i : string + +var j = `${ 0 }${ 0 }3`; +>j : string + +var k = `1${ 0 }${ 0 }3`; +>k : string + +var l = `1${ 0 }2${ 0 }3`; +>l : string + diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js new file mode 100644 index 0000000000000..f0e827cde639d --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.js @@ -0,0 +1,38 @@ +//// [templateStringWithEmptyLiteralPortionsES6.ts] +var a = ``; + +var b = `${ 0 }`; + +var c = `1${ 0 }`; + +var d = `${ 0 }2`; + +var e = `1${ 0 }2`; + +var f = `${ 0 }${ 0 }`; + +var g = `1${ 0 }${ 0 }`; + +var h = `${ 0 }2${ 0 }`; + +var i = `1${ 0 }2${ 0 }`; + +var j = `${ 0 }${ 0 }3`; + +var k = `1${ 0 }${ 0 }3`; + +var l = `1${ 0 }2${ 0 }3`; + +//// [templateStringWithEmptyLiteralPortionsES6.js] +var a = ``; +var b = `${0}`; +var c = `1${0}`; +var d = `${0}2`; +var e = `1${0}2`; +var f = `${0}${0}`; +var g = `1${0}${0}`; +var h = `${0}2${0}`; +var i = `1${0}2${0}`; +var j = `${0}${0}3`; +var k = `1${0}${0}3`; +var l = `1${0}2${0}3`; diff --git a/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types new file mode 100644 index 0000000000000..4074831d410ce --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmptyLiteralPortionsES6.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts === +var a = ``; +>a : string + +var b = `${ 0 }`; +>b : string + +var c = `1${ 0 }`; +>c : string + +var d = `${ 0 }2`; +>d : string + +var e = `1${ 0 }2`; +>e : string + +var f = `${ 0 }${ 0 }`; +>f : string + +var g = `1${ 0 }${ 0 }`; +>g : string + +var h = `${ 0 }2${ 0 }`; +>h : string + +var i = `1${ 0 }2${ 0 }`; +>i : string + +var j = `${ 0 }${ 0 }3`; +>j : string + +var k = `1${ 0 }${ 0 }3`; +>k : string + +var l = `1${ 0 }2${ 0 }3`; +>l : string + diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts new file mode 100644 index 0000000000000..11dca4caf7739 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortions.ts @@ -0,0 +1,23 @@ +var a = ``; + +var b = `${ 0 }`; + +var c = `1${ 0 }`; + +var d = `${ 0 }2`; + +var e = `1${ 0 }2`; + +var f = `${ 0 }${ 0 }`; + +var g = `1${ 0 }${ 0 }`; + +var h = `${ 0 }2${ 0 }`; + +var i = `1${ 0 }2${ 0 }`; + +var j = `${ 0 }${ 0 }3`; + +var k = `1${ 0 }${ 0 }3`; + +var l = `1${ 0 }2${ 0 }3`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts new file mode 100644 index 0000000000000..183da57dd4588 --- /dev/null +++ b/tests/cases/conformance/es6/templates/templateStringWithEmptyLiteralPortionsES6.ts @@ -0,0 +1,24 @@ +// @target: ES6 +var a = ``; + +var b = `${ 0 }`; + +var c = `1${ 0 }`; + +var d = `${ 0 }2`; + +var e = `1${ 0 }2`; + +var f = `${ 0 }${ 0 }`; + +var g = `1${ 0 }${ 0 }`; + +var h = `${ 0 }2${ 0 }`; + +var i = `1${ 0 }2${ 0 }`; + +var j = `${ 0 }${ 0 }3`; + +var k = `1${ 0 }${ 0 }3`; + +var l = `1${ 0 }2${ 0 }3`; \ No newline at end of file From ead3c1bde8f0d27addc5a20fe433fddafbad2ef4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 28 Oct 2014 13:55:56 -0700 Subject: [PATCH 14/15] Disabled completion list entries in template literal parts for the LS. --- src/services/services.ts | 31 ++++++++++++++++--- .../completionListInTemplateLiteralParts1.ts | 11 +++++++ ...ionListInTemplateLiteralPartsNegatives1.ts | 11 +++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/completionListInTemplateLiteralParts1.ts create mode 100644 tests/cases/fourslash/completionListInTemplateLiteralPartsNegatives1.ts diff --git a/src/services/services.ts b/src/services/services.ts index 8d233811c8151..8b20cdbe8ed3b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2498,25 +2498,48 @@ module ts { } function isInStringOrRegularExpressionLiteral(previousToken: Node): boolean { - if (previousToken.kind === SyntaxKind.StringLiteral) { + if (previousToken.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(previousToken.kind)) { // The position has to be either: 1. entirely within the token text, or // 2. at the end position, and the string literal is not terminated + var start = previousToken.getStart(); var end = previousToken.getEnd(); + if (start < position && position < end) { return true; } else if (position === end) { var width = end - start; var text = previousToken.getSourceFile().text; - return width <= 1 || - text.charCodeAt(start) !== text.charCodeAt(end - 1) || - text.charCodeAt(end - 2) === CharacterCodes.backslash; + + // If the token is a single character, or its second-to-last charcter indicates an escape code, + // then we can immediately say that we are in the middle of an unclosed string. + if (width <= 1 || text.charCodeAt(end - 2) === CharacterCodes.backslash) { + return true; + } + + // Now check if the last character is a closing character for the token. + switch (previousToken.kind) { + case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + return text.charCodeAt(start) !== text.charCodeAt(end - 1); + + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + return text.charCodeAt(end - 1) !== CharacterCodes.openBrace + || text.charCodeAt(end - 2) !== CharacterCodes.$; + + case SyntaxKind.TemplateTail: + return text.charCodeAt(end - 1) !== CharacterCodes.backtick; + } + + return false; } } else if (previousToken.kind === SyntaxKind.RegularExpressionLiteral) { return previousToken.getStart() < position && position < previousToken.getEnd(); } + return false; } diff --git a/tests/cases/fourslash/completionListInTemplateLiteralParts1.ts b/tests/cases/fourslash/completionListInTemplateLiteralParts1.ts new file mode 100644 index 0000000000000..a71584bdbdd2f --- /dev/null +++ b/tests/cases/fourslash/completionListInTemplateLiteralParts1.ts @@ -0,0 +1,11 @@ +/// + +/////*0*/` $ { ${/*1*/ 10/*2*/ + 1.1/*3*/ /*4*/} 12312`/*5*/ +//// +/////*6*/`asdasd${/*7*/ 2 + 1.1 /*8*/} 12312 { + +test.markers().forEach(marker => { + goTo.position(marker.position); + + verify.completionListItemsCountIsGreaterThan(0) +}} \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInTemplateLiteralPartsNegatives1.ts b/tests/cases/fourslash/completionListInTemplateLiteralPartsNegatives1.ts new file mode 100644 index 0000000000000..1624192057b3f --- /dev/null +++ b/tests/cases/fourslash/completionListInTemplateLiteralPartsNegatives1.ts @@ -0,0 +1,11 @@ +/// + +////`/*0*/ /*1*/$ /*2*/{ /*3*/$/*4*/{ 10 + 1.1 }/*5*/ 12312/*6*/` +//// +////`asdasd$/*7*/{ 2 + 1.1 }/*8*/ 12312 /*9*/{/*10*/ + +test.markers().forEach(marker => { + goTo.position(marker.position); + + verify.completionListIsEmpty() +} \ No newline at end of file From 63340a0d9441cf1218118760a960865ecdee3c5b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 31 Oct 2014 14:53:22 -0700 Subject: [PATCH 15/15] Addressed CR feedback. --- src/compiler/types.ts | 5 +++-- src/services/services.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ba5cdf044f339..ead8495773190 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -403,6 +403,8 @@ module ts { templateSpans: NodeArray; } + // Each of these corresponds to a substitution expression and a template literal, in that order. + // The template literal must have kind TemplateMiddleLiteral or TemplateTailLiteral. export interface TemplateSpan extends Node { expression: Expression; literal: LiteralExpression; @@ -440,8 +442,7 @@ module ts { export interface TaggedTemplateExpression extends Expression { tag: Expression; - // Either a LiteralExpression of kind NoSubstitutionTemplateLiteral, or a TemplateExpression - template: Expression; + template: LiteralExpression | TemplateExpression; } export interface TypeAssertion extends Expression { diff --git a/src/services/services.ts b/src/services/services.ts index 9b48900f9331b..d208eb87e96ea 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2471,12 +2471,12 @@ module ts { } function isCompletionListBlocker(previousToken: Node): boolean { - return isInStringOrRegularExpressionLiteral(previousToken) || + return isInStringOrRegularExpressionOrTemplateLiteral(previousToken) || isIdentifierDefinitionLocation(previousToken) || isRightOfIllegalDot(previousToken); } - function isInStringOrRegularExpressionLiteral(previousToken: Node): boolean { + function isInStringOrRegularExpressionOrTemplateLiteral(previousToken: Node): boolean { if (previousToken.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(previousToken.kind)) { // The position has to be either: 1. entirely within the token text, or // 2. at the end position, and the string literal is not terminated