diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d89247b70f978..3db7eb07e996e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16664,6 +16664,9 @@ namespace ts { } function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type { + if (languageVersion < ScriptTarget.ES2015) { + checkExternalEmitHelpers(node, ExternalEmitHelpers.MakeTemplateObject); + } return getReturnTypeOfSignature(getResolvedSignature(node)); } @@ -24019,6 +24022,7 @@ namespace ts { case ExternalEmitHelpers.AsyncDelegator: return "__asyncDelegator"; case ExternalEmitHelpers.AsyncValues: return "__asyncValues"; case ExternalEmitHelpers.ExportStar: return "__exportStar"; + case ExternalEmitHelpers.MakeTemplateObject: return "__makeTemplateObject"; default: Debug.fail("Unrecognized helper"); } } diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 2ba2408225eb6..816a093ef0916 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -3877,15 +3877,15 @@ namespace ts { * @param expression The Expression node. */ export function parenthesizeForNew(expression: Expression): LeftHandSideExpression { - const emittedExpression = skipPartiallyEmittedExpressions(expression); - switch (emittedExpression.kind) { + const leftmostExpr = getLeftmostExpression(expression, /*stopAtCallExpressions*/ true); + switch (leftmostExpr.kind) { case SyntaxKind.CallExpression: return createParen(expression); case SyntaxKind.NewExpression: - return (emittedExpression).arguments - ? expression - : createParen(expression); + return !(leftmostExpr as NewExpression).arguments + ? createParen(expression) + : expression; } return parenthesizeForAccess(expression); @@ -3966,7 +3966,7 @@ namespace ts { } } - const leftmostExpressionKind = getLeftmostExpression(emittedExpression).kind; + const leftmostExpressionKind = getLeftmostExpression(emittedExpression, /*stopAtCallExpressions*/ false).kind; if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) { return setTextRange(createParen(expression), expression); } @@ -4012,7 +4012,7 @@ namespace ts { } } - function getLeftmostExpression(node: Expression): Expression { + function getLeftmostExpression(node: Expression, stopAtCallExpressions: boolean) { while (true) { switch (node.kind) { case SyntaxKind.PostfixUnaryExpression: @@ -4028,6 +4028,10 @@ namespace ts { continue; case SyntaxKind.CallExpression: + if (stopAtCallExpressions) { + return node; + } + // falls through case SyntaxKind.ElementAccessExpression: case SyntaxKind.PropertyAccessExpression: node = (node).expression; @@ -4040,10 +4044,11 @@ namespace ts { return node; } + } export function parenthesizeConciseBody(body: ConciseBody): ConciseBody { - if (!isBlock(body) && getLeftmostExpression(body).kind === SyntaxKind.ObjectLiteralExpression) { + if (!isBlock(body) && getLeftmostExpression(body, /*stopAtCallExpressions*/ false).kind === SyntaxKind.ObjectLiteralExpression) { return setTextRange(createParen(body), body); } diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index e9c84be51766a..f6669e7c05ebe 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -279,6 +279,13 @@ namespace ts { let currentSourceFile: SourceFile; let currentText: string; let hierarchyFacts: HierarchyFacts; + let taggedTemplateStringDeclarations: VariableDeclaration[]; + + function recordTaggedTemplateString(temp: Identifier) { + taggedTemplateStringDeclarations = append( + taggedTemplateStringDeclarations, + createVariableDeclaration(temp)); + } /** * Used to track if we are emitting body of the converted loop @@ -307,6 +314,7 @@ namespace ts { currentSourceFile = undefined; currentText = undefined; + taggedTemplateStringDeclarations = undefined; hierarchyFacts = HierarchyFacts.None; return visited; } @@ -520,6 +528,11 @@ namespace ts { addCaptureThisForNodeIfNeeded(statements, node); statementOffset = addCustomPrologue(statements, node.statements, statementOffset, visitor); addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset)); + if (taggedTemplateStringDeclarations) { + statements.push( + createVariableStatement(/*modifiers*/ undefined, + createVariableDeclarationList(taggedTemplateStringDeclarations))); + } addRange(statements, endLexicalEnvironment()); exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None); return updateSourceFileNode( @@ -3636,11 +3649,10 @@ namespace ts { // Visit the tag expression const tag = visitNode(node.tag, visitor, isExpression); - // Allocate storage for the template site object - const temp = createTempVariable(hoistVariableDeclaration); - // Build up the template arguments and the raw and cooked strings for the template. - const templateArguments: Expression[] = [temp]; + // We start out with 'undefined' for the first argument and revisit later + // to avoid walking over the template string twice and shifting all our arguments over after the fact. + const templateArguments: Expression[] = [undefined]; const cookedStrings: Expression[] = []; const rawStrings: Expression[] = []; const template = node.template; @@ -3658,16 +3670,25 @@ namespace ts { } } - // NOTE: The parentheses here is entirely optional as we are now able to auto- - // parenthesize when rebuilding the tree. This should be removed in a - // future version. It is here for now to match our existing emit. - return createParen( - inlineExpressions([ - createAssignment(temp, createArrayLiteral(cookedStrings)), - createAssignment(createPropertyAccess(temp, "raw"), createArrayLiteral(rawStrings)), - createCall(tag, /*typeArguments*/ undefined, templateArguments) - ]) - ); + const helperCall = createTemplateObjectHelper(context, createArrayLiteral(cookedStrings), createArrayLiteral(rawStrings)); + + // Create a variable to cache the template object if we're in a module. + // Do not do this in the global scope, as any variable we currently generate could conflict with + // variables from outside of the current compilation. In the future, we can revisit this behavior. + if (isExternalModule(currentSourceFile)) { + const tempVar = createTempVariable(recordTaggedTemplateString); + templateArguments[0] = createLogicalOr( + tempVar, + createAssignment( + tempVar, + helperCall) + ); + } + else { + templateArguments[0] = helperCall; + } + + return createCall(tag, /*typeArguments*/ undefined, templateArguments); } /** @@ -4036,6 +4057,18 @@ namespace ts { ); } + function createTemplateObjectHelper(context: TransformationContext, cooked: ArrayLiteralExpression, raw: ArrayLiteralExpression) { + context.requestEmitHelper(templateObjectHelper); + return createCall( + getHelperName("__makeTemplateObject"), + /*typeArguments*/ undefined, + [ + cooked, + raw + ] + ); + } + const extendsHelper: EmitHelper = { name: "typescript:extends", scoped: false, @@ -4052,4 +4085,16 @@ namespace ts { }; })();` }; + + const templateObjectHelper: EmitHelper = { + name: "typescript:makeTemplateObject", + scoped: false, + priority: 0, + text: ` + var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; + };` + }; + } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7a120064a64cb..de463fee97d2f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4271,22 +4271,25 @@ namespace ts { */ /* @internal */ export const enum ExternalEmitHelpers { - Extends = 1 << 0, // __extends (used by the ES2015 class transformation) - Assign = 1 << 1, // __assign (used by Jsx and ESNext object spread transformations) - Rest = 1 << 2, // __rest (used by ESNext object rest transformation) - Decorate = 1 << 3, // __decorate (used by TypeScript decorators transformation) - Metadata = 1 << 4, // __metadata (used by TypeScript decorators transformation) - Param = 1 << 5, // __param (used by TypeScript decorators transformation) - Awaiter = 1 << 6, // __awaiter (used by ES2017 async functions transformation) - Generator = 1 << 7, // __generator (used by ES2015 generator transformation) - Values = 1 << 8, // __values (used by ES2015 for..of and yield* transformations) - Read = 1 << 9, // __read (used by ES2015 iterator destructuring transformation) - Spread = 1 << 10, // __spread (used by ES2015 array spread and argument list spread transformations) - Await = 1 << 11, // __await (used by ES2017 async generator transformation) - AsyncGenerator = 1 << 12, // __asyncGenerator (used by ES2017 async generator transformation) - AsyncDelegator = 1 << 13, // __asyncDelegator (used by ES2017 async generator yield* transformation) - AsyncValues = 1 << 14, // __asyncValues (used by ES2017 for..await..of transformation) - ExportStar = 1 << 15, // __exportStar (used by CommonJS/AMD/UMD module transformation) + Extends = 1 << 0, // __extends (used by the ES2015 class transformation) + Assign = 1 << 1, // __assign (used by Jsx and ESNext object spread transformations) + Rest = 1 << 2, // __rest (used by ESNext object rest transformation) + Decorate = 1 << 3, // __decorate (used by TypeScript decorators transformation) + Metadata = 1 << 4, // __metadata (used by TypeScript decorators transformation) + Param = 1 << 5, // __param (used by TypeScript decorators transformation) + Awaiter = 1 << 6, // __awaiter (used by ES2017 async functions transformation) + Generator = 1 << 7, // __generator (used by ES2015 generator transformation) + Values = 1 << 8, // __values (used by ES2015 for..of and yield* transformations) + Read = 1 << 9, // __read (used by ES2015 iterator destructuring transformation) + Spread = 1 << 10, // __spread (used by ES2015 array spread and argument list spread transformations) + Await = 1 << 11, // __await (used by ES2017 async generator transformation) + AsyncGenerator = 1 << 12, // __asyncGenerator (used by ES2017 async generator transformation) + AsyncDelegator = 1 << 13, // __asyncDelegator (used by ES2017 async generator yield* transformation) + AsyncValues = 1 << 14, // __asyncValues (used by ES2017 for..await..of transformation) + ExportStar = 1 << 15, // __exportStar (used by CommonJS/AMD/UMD module transformation) + MakeTemplateObject = 1 << 16, // __makeTemplateObject (used for constructing template string array objects) + FirstEmitHelper = Extends, + LastEmitHelper = MakeTemplateObject, // Helpers included by ES2015 for..of ForOfIncludes = Values, @@ -4303,8 +4306,6 @@ namespace ts { // Helpers included by ES2015 spread SpreadIncludes = Read | Spread, - FirstEmitHelper = Extends, - LastEmitHelper = ExportStar } export const enum EmitHint { diff --git a/src/harness/unittests/printer.ts b/src/harness/unittests/printer.ts index 2bbc19881a34c..4aaddce5c002b 100644 --- a/src/harness/unittests/printer.ts +++ b/src/harness/unittests/printer.ts @@ -110,6 +110,31 @@ namespace ts { createSourceFile("source.ts", "", ScriptTarget.ES2015) )); + printsCorrectly("newExpressionWithPropertyAccessOnCallExpression", {}, printer => printer.printNode( + EmitHint.Unspecified, + createNew( + createPropertyAccess( + createCall( + createIdentifier("f"), /*typeArguments*/ undefined, /*argumentsArray*/ undefined), + "x"), + /*typeArguments*/ undefined, + /*argumentsArray*/ undefined + ), + createSourceFile("source.ts", "", ScriptTarget.ESNext)) + ); + + printsCorrectly("newExpressionOnConditionalExpression", {}, printer => printer.printNode( + EmitHint.Unspecified, + createNew( + createConditional( + createIdentifier("x"), createToken(SyntaxKind.QuestionToken), + createIdentifier("y"), createToken(SyntaxKind.ColonToken), + createIdentifier("z")), + /*typeArguments*/ undefined, + /*argumentsArray*/ undefined + ), + createSourceFile("source.ts", "", ScriptTarget.ESNext)) + ); printsCorrectly("emptyGlobalAugmentation", {}, printer => printer.printNode( EmitHint.Unspecified, diff --git a/tests/baselines/reference/asOperator3.js b/tests/baselines/reference/asOperator3.js index 770a853ad25b8..7cbb277bb0339 100644 --- a/tests/baselines/reference/asOperator3.js +++ b/tests/baselines/reference/asOperator3.js @@ -11,12 +11,15 @@ var g = tag `Hello ${123} World` as string; var h = tag `Hello` as string; //// [asOperator3.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var a = "" + (123 + 456); var b = "leading " + (123 + 456); var c = 123 + 456 + " trailing"; var d = "Hello " + 123 + " World"; var e = "Hello"; var f = 1 + (1 + " end of string"); -var g = (_a = ["Hello ", " World"], _a.raw = ["Hello ", " World"], tag(_a, 123)); -var h = (_b = ["Hello"], _b.raw = ["Hello"], tag(_b)); -var _a, _b; +var g = tag(__makeTemplateObject(["Hello ", " World"], ["Hello ", " World"]), 123); +var h = tag(__makeTemplateObject(["Hello"], ["Hello"])); diff --git a/tests/baselines/reference/asOperatorASI.js b/tests/baselines/reference/asOperatorASI.js index 342dc03d2ef90..4a78b022c4fe7 100644 --- a/tests/baselines/reference/asOperatorASI.js +++ b/tests/baselines/reference/asOperatorASI.js @@ -12,6 +12,10 @@ as(Foo); // should emit //// [asOperatorASI.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var Foo = /** @class */ (function () { function Foo() { } @@ -19,8 +23,7 @@ var Foo = /** @class */ (function () { }()); // Example 1 var x = 10; -(_a = ["Hello world"], _a.raw = ["Hello world"], as(_a)); // should not error +as(__makeTemplateObject(["Hello world"], ["Hello world"])); // should not error // Example 2 var y = 20; as(Foo); // should emit -var _a; diff --git a/tests/baselines/reference/importHelpers.js b/tests/baselines/reference/importHelpers.js index fdf9b12ed521d..7bdd660a9ae7d 100644 --- a/tests/baselines/reference/importHelpers.js +++ b/tests/baselines/reference/importHelpers.js @@ -11,6 +11,12 @@ class C { method(@dec x: number) { } } + +function id(x: T) { + return x; +} + +export const result = id`hello world`; //// [script.ts] class A { } @@ -23,6 +29,12 @@ class C { method(@dec x: number) { } } + +function id(x: T) { + return x; +} + +const result = id`hello world`; //// [tslib.d.ts] export declare function __extends(d: Function, b: Function): void; @@ -31,6 +43,7 @@ export declare function __decorate(decorators: Function[], target: any, key?: st export declare function __param(paramIndex: number, decorator: Function): Function; export declare function __metadata(metadataKey: any, metadataValue: any): Function; export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +export declare function __makeTemplateObject(cooked: string[], raw: string[]): TemplateStringsArray; //// [external.js] @@ -67,6 +80,11 @@ var C = /** @class */ (function () { ], C); return C; }()); +function id(x) { + return x; +} +exports.result = id(_a || (_a = tslib_1.__makeTemplateObject(["hello world"], ["hello world"]))); +var _a; //// [script.js] var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || @@ -78,6 +96,10 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); @@ -118,3 +140,7 @@ var C = /** @class */ (function () { ], C); return C; }()); +function id(x) { + return x; +} +var result = id(__makeTemplateObject(["hello world"], ["hello world"])); diff --git a/tests/baselines/reference/importHelpers.symbols b/tests/baselines/reference/importHelpers.symbols index 55ca5153e32cc..7b2184f93c61f 100644 --- a/tests/baselines/reference/importHelpers.symbols +++ b/tests/baselines/reference/importHelpers.symbols @@ -22,6 +22,20 @@ class C { } } +function id(x: T) { +>id : Symbol(id, Decl(external.ts, 9, 1)) +>T : Symbol(T, Decl(external.ts, 11, 12)) +>x : Symbol(x, Decl(external.ts, 11, 15)) +>T : Symbol(T, Decl(external.ts, 11, 12)) + + return x; +>x : Symbol(x, Decl(external.ts, 11, 15)) +} + +export const result = id`hello world`; +>result : Symbol(result, Decl(external.ts, 15, 12)) +>id : Symbol(id, Decl(external.ts, 9, 1)) + === tests/cases/compiler/script.ts === class A { } >A : Symbol(A, Decl(script.ts, 0, 0)) @@ -46,6 +60,20 @@ class C { } } +function id(x: T) { +>id : Symbol(id, Decl(script.ts, 9, 1)) +>T : Symbol(T, Decl(script.ts, 11, 12)) +>x : Symbol(x, Decl(script.ts, 11, 15)) +>T : Symbol(T, Decl(script.ts, 11, 12)) + + return x; +>x : Symbol(x, Decl(script.ts, 11, 15)) +} + +const result = id`hello world`; +>result : Symbol(result, Decl(script.ts, 15, 5)) +>id : Symbol(id, Decl(script.ts, 9, 1)) + === tests/cases/compiler/tslib.d.ts === export declare function __extends(d: Function, b: Function): void; >__extends : Symbol(__extends, Decl(tslib.d.ts, --, --)) @@ -89,3 +117,9 @@ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, ge >generator : Symbol(generator, Decl(tslib.d.ts, --, --)) >Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +export declare function __makeTemplateObject(cooked: string[], raw: string[]): TemplateStringsArray; +>__makeTemplateObject : Symbol(__makeTemplateObject, Decl(tslib.d.ts, --, --)) +>cooked : Symbol(cooked, Decl(tslib.d.ts, --, --)) +>raw : Symbol(raw, Decl(tslib.d.ts, --, --)) +>TemplateStringsArray : Symbol(TemplateStringsArray, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/importHelpers.types b/tests/baselines/reference/importHelpers.types index 0ab8d40ee853f..06b851139cfcc 100644 --- a/tests/baselines/reference/importHelpers.types +++ b/tests/baselines/reference/importHelpers.types @@ -22,6 +22,22 @@ class C { } } +function id(x: T) { +>id : (x: T) => T +>T : T +>x : T +>T : T + + return x; +>x : T +} + +export const result = id`hello world`; +>result : TemplateStringsArray +>id`hello world` : TemplateStringsArray +>id : (x: T) => T +>`hello world` : "hello world" + === tests/cases/compiler/script.ts === class A { } >A : A @@ -46,6 +62,22 @@ class C { } } +function id(x: T) { +>id : (x: T) => T +>T : T +>x : T +>T : T + + return x; +>x : T +} + +const result = id`hello world`; +>result : TemplateStringsArray +>id`hello world` : TemplateStringsArray +>id : (x: T) => T +>`hello world` : "hello world" + === tests/cases/compiler/tslib.d.ts === export declare function __extends(d: Function, b: Function): void; >__extends : (d: Function, b: Function) => void @@ -89,3 +121,9 @@ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, ge >generator : Function >Function : Function +export declare function __makeTemplateObject(cooked: string[], raw: string[]): TemplateStringsArray; +>__makeTemplateObject : (cooked: string[], raw: string[]) => TemplateStringsArray +>cooked : string[] +>raw : string[] +>TemplateStringsArray : TemplateStringsArray + diff --git a/tests/baselines/reference/printerApi/printsNodeCorrectly.newExpressionOnConditionalExpression.js b/tests/baselines/reference/printerApi/printsNodeCorrectly.newExpressionOnConditionalExpression.js new file mode 100644 index 0000000000000..fe8f852f26fcd --- /dev/null +++ b/tests/baselines/reference/printerApi/printsNodeCorrectly.newExpressionOnConditionalExpression.js @@ -0,0 +1 @@ +new (x ? y : z) \ No newline at end of file diff --git a/tests/baselines/reference/printerApi/printsNodeCorrectly.newExpressionWithPropertyAccessOnCallExpression.js b/tests/baselines/reference/printerApi/printsNodeCorrectly.newExpressionWithPropertyAccessOnCallExpression.js new file mode 100644 index 0000000000000..e3d961ca702f8 --- /dev/null +++ b/tests/baselines/reference/printerApi/printsNodeCorrectly.newExpressionWithPropertyAccessOnCallExpression.js @@ -0,0 +1 @@ +new (f().x) \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js index 3df09abb2db8d..f771b886ea055 100644 --- a/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js +++ b/tests/baselines/reference/taggedTemplateStringsHexadecimalEscapes.js @@ -5,11 +5,14 @@ function f(...args: any[]) { f `\x0D${ "Interrupted CRLF" }\x0A`; //// [taggedTemplateStringsHexadecimalEscapes.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } } -(_a = ["\r", "\n"], _a.raw = ["\\x0D", "\\x0A"], f(_a, "Interrupted CRLF")); -var _a; +f(__makeTemplateObject(["\r", "\n"], ["\\x0D", "\\x0A"]), "Interrupted CRLF"); diff --git a/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js b/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js index 10610fb28a970..a355420452830 100644 --- a/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js +++ b/tests/baselines/reference/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js @@ -6,11 +6,14 @@ function f(...x: any[]) { f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n` //// [taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function f() { var x = []; for (var _i = 0; _i < arguments.length; _i++) { x[_i] = arguments[_i]; } } -(_a = ["0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n"], _a.raw = ["0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n"], f(_a)); -var _a; +f(__makeTemplateObject(["0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n"], ["0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n"])); diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js index e0427c28b87e8..7e50da9c06aaf 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js @@ -92,67 +92,70 @@ var arr: any[]; //// [taggedTemplateStringsTypeArgumentInference.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; // Generic tag with one parameter function noParams(n) { } -(_a = [""], _a.raw = [""], noParams(_a)); +noParams(__makeTemplateObject([""], [""])); // Generic tag with parameter which does not use type parameter function noGenericParams(n) { } -(_b = [""], _b.raw = [""], noGenericParams(_b)); +noGenericParams(__makeTemplateObject([""], [""])); // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n, m) { } -(_c = ["", ""], _c.raw = ["", ""], someGenerics1a(_c, 3)); +someGenerics1a(__makeTemplateObject(["", ""], ["", ""]), 3); function someGenerics1b(n, m) { } -(_d = ["", ""], _d.raw = ["", ""], someGenerics1b(_d, 3)); +someGenerics1b(__makeTemplateObject(["", ""], ["", ""]), 3); // Generic tag with argument of function type whose parameter is of type parameter type function someGenerics2a(strs, n) { } -(_e = ["", ""], _e.raw = ["", ""], someGenerics2a(_e, function (n) { return n; })); +someGenerics2a(__makeTemplateObject(["", ""], ["", ""]), function (n) { return n; }); function someGenerics2b(strs, n) { } -(_f = ["", ""], _f.raw = ["", ""], someGenerics2b(_f, function (n, x) { return n; })); +someGenerics2b(__makeTemplateObject(["", ""], ["", ""]), function (n, x) { return n; }); // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter function someGenerics3(strs, producer) { } -(_g = ["", ""], _g.raw = ["", ""], someGenerics3(_g, function () { return ''; })); -(_h = ["", ""], _h.raw = ["", ""], someGenerics3(_h, function () { return undefined; })); -(_j = ["", ""], _j.raw = ["", ""], someGenerics3(_j, function () { return 3; })); +someGenerics3(__makeTemplateObject(["", ""], ["", ""]), function () { return ''; }); +someGenerics3(__makeTemplateObject(["", ""], ["", ""]), function () { return undefined; }); +someGenerics3(__makeTemplateObject(["", ""], ["", ""]), function () { return 3; }); // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type function someGenerics4(strs, n, f) { } -(_k = ["", "", ""], _k.raw = ["", "", ""], someGenerics4(_k, 4, function () { return null; })); -(_l = ["", "", ""], _l.raw = ["", "", ""], someGenerics4(_l, '', function () { return 3; })); -(_m = ["", "", ""], _m.raw = ["", "", ""], someGenerics4(_m, null, null)); +someGenerics4(__makeTemplateObject(["", "", ""], ["", "", ""]), 4, function () { return null; }); +someGenerics4(__makeTemplateObject(["", "", ""], ["", "", ""]), '', function () { return 3; }); +someGenerics4(__makeTemplateObject(["", "", ""], ["", "", ""]), null, null); // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type function someGenerics5(strs, n, f) { } -(_o = ["", " ", ""], _o.raw = ["", " ", ""], someGenerics5(_o, 4, function () { return null; })); -(_p = ["", "", ""], _p.raw = ["", "", ""], someGenerics5(_p, '', function () { return 3; })); -(_q = ["", "", ""], _q.raw = ["", "", ""], someGenerics5(_q, null, null)); +someGenerics5(__makeTemplateObject(["", " ", ""], ["", " ", ""]), 4, function () { return null; }); +someGenerics5(__makeTemplateObject(["", "", ""], ["", "", ""]), '', function () { return 3; }); +someGenerics5(__makeTemplateObject(["", "", ""], ["", "", ""]), null, null); // Generic tag with multiple arguments of function types that each have parameters of the same generic type function someGenerics6(strs, a, b, c) { } -(_r = ["", "", "", ""], _r.raw = ["", "", "", ""], someGenerics6(_r, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); -(_s = ["", "", "", ""], _s.raw = ["", "", "", ""], someGenerics6(_s, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); -(_t = ["", "", "", ""], _t.raw = ["", "", "", ""], someGenerics6(_t, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); +someGenerics6(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), function (n) { return n; }, function (n) { return n; }, function (n) { return n; }); +someGenerics6(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), function (n) { return n; }, function (n) { return n; }, function (n) { return n; }); +someGenerics6(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), function (n) { return n; }, function (n) { return n; }, function (n) { return n; }); // Generic tag with multiple arguments of function types that each have parameters of different generic type function someGenerics7(strs, a, b, c) { } -(_u = ["", "", "", ""], _u.raw = ["", "", "", ""], someGenerics7(_u, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); -(_v = ["", "", "", ""], _v.raw = ["", "", "", ""], someGenerics7(_v, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); -(_w = ["", "", "", ""], _w.raw = ["", "", "", ""], someGenerics7(_w, function (n) { return n; }, function (n) { return n; }, function (n) { return n; })); +someGenerics7(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), function (n) { return n; }, function (n) { return n; }, function (n) { return n; }); +someGenerics7(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), function (n) { return n; }, function (n) { return n; }, function (n) { return n; }); +someGenerics7(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), function (n) { return n; }, function (n) { return n; }, function (n) { return n; }); // Generic tag with argument of generic function type function someGenerics8(strs, n) { return n; } -var x = (_x = ["", ""], _x.raw = ["", ""], someGenerics8(_x, someGenerics7)); -(_y = ["", "", "", ""], _y.raw = ["", "", "", ""], x(_y, null, null, null)); +var x = someGenerics8(__makeTemplateObject(["", ""], ["", ""]), someGenerics7); +x(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), null, null, null); // Generic tag with multiple parameters of generic type passed arguments with no best common type function someGenerics9(strs, a, b, c) { return null; } -var a9a = (_z = ["", "", "", ""], _z.raw = ["", "", "", ""], someGenerics9(_z, '', 0, [])); +var a9a = someGenerics9(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), '', 0, []); var a9a; -var a9e = (_0 = ["", "", "", ""], _0.raw = ["", "", "", ""], someGenerics9(_0, undefined, { x: 6, z: new Date() }, { x: 6, y: '' })); +var a9e = someGenerics9(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); var a9e; // Generic tag with multiple parameters of generic type passed arguments with a single best common type -var a9d = (_1 = ["", "", "", ""], _1.raw = ["", "", "", ""], someGenerics9(_1, { x: 3 }, { x: 6 }, { x: 6 })); +var a9d = someGenerics9(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), { x: 3 }, { x: 6 }, { x: 6 }); var a9d; // Generic tag with multiple parameters of generic type where one argument is of type 'any' var anyVar; -var a = (_2 = ["", "", "", ""], _2.raw = ["", "", "", ""], someGenerics9(_2, 7, anyVar, 4)); +var a = someGenerics9(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), 7, anyVar, 4); var a; // Generic tag with multiple parameters of generic type where one argument is [] and the other is not 'any' -var arr = (_3 = ["", "", "", ""], _3.raw = ["", "", "", ""], someGenerics9(_3, [], null, undefined)); +var arr = someGenerics9(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), [], null, undefined); var arr; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3; diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js index 16f1a3faea0a7..4e0c70e837a83 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js @@ -34,16 +34,19 @@ f.thisIsNotATag(`abc${1}def${2}ghi`); //// [taggedTemplateStringsWithIncompatibleTypedTags.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var f; -(_a = ["abc"], _a.raw = ["abc"], f(_a)); -(_b = ["abc", "def", "ghi"], _b.raw = ["abc", "def", "ghi"], f(_b, 1, 2)); -(_c = ["abc"], _c.raw = ["abc"], f(_c)).member; -(_d = ["abc", "def", "ghi"], _d.raw = ["abc", "def", "ghi"], f(_d, 1, 2)).member; -(_e = ["abc"], _e.raw = ["abc"], f(_e))["member"]; -(_f = ["abc", "def", "ghi"], _f.raw = ["abc", "def", "ghi"], f(_f, 1, 2))["member"]; -(_g = ["abc", "def", "ghi"], _g.raw = ["abc", "def", "ghi"], (_h = ["abc"], _h.raw = ["abc"], f(_h))[0].member(_g, 1, 2)); -(_j = ["abc", "def", "ghi"], _j.raw = ["abc", "def", "ghi"], (_k = ["abc", "def", "ghi"], _k.raw = ["abc", "def", "ghi"], f(_k, 1, 2))["member"].member(_j, 1, 2)); -(_l = ["abc", "def", "ghi"], _l.raw = ["abc", "def", "ghi"], (_m = ["abc", "def", "ghi"], _m.raw = ["abc", "def", "ghi"], f(_m, true, true))["member"].member(_l, 1, 2)); +f(__makeTemplateObject(["abc"], ["abc"])); +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); +f(__makeTemplateObject(["abc"], ["abc"])).member; +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2).member; +f(__makeTemplateObject(["abc"], ["abc"]))["member"]; +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2)["member"]; +f(__makeTemplateObject(["abc"], ["abc"]))[0].member(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2)["member"].member(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), true, true)["member"].member(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); f.thisIsNotATag("abc"); f.thisIsNotATag("abc" + 1 + "def" + 2 + "ghi"); -var _a, _b, _c, _d, _e, _f, _h, _g, _k, _j, _m, _l; diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js index a896a811ffbbe..01db59ee17c4b 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js @@ -16,6 +16,9 @@ var x = new new new f `abc${ 0 }def`.member("hello")(42) === true; //// [taggedTemplateStringsWithManyCallAndMemberExpressions.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var f; -var x = new new new (_a = ["abc", "def"], _a.raw = ["abc", "def"], f(_a, 0)).member("hello")(42) === true; -var _a; +var x = new new new (f(__makeTemplateObject(["abc", "def"], ["abc", "def"]), 0).member)("hello")(42) === true; diff --git a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js index 9ffc0cadfef09..d3e9e3d2c43ff 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js +++ b/tests/baselines/reference/taggedTemplateStringsWithMultilineTemplate.js @@ -8,11 +8,14 @@ f ` `; //// [taggedTemplateStringsWithMultilineTemplate.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } } -(_a = ["\n\n"], _a.raw = ["\n\\\n\n"], f(_a)); -var _a; +f(__makeTemplateObject(["\n\n"], ["\n\\\n\n"])); diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js index 19211c2fa8a3b..7299ea3cbbde2 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js @@ -23,6 +23,10 @@ var z = foo `${1}${2}${3}`; // any (with error) //// [taggedTemplateStringsWithOverloadResolution1.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function foo() { var stuff = []; for (var _i = 0; _i < arguments.length; _i++) { @@ -36,10 +40,9 @@ var c = foo([], 1, 2); // boolean var d = foo([], 1, true); // boolean (with error) var e = foo([], 1, "2"); // {} var f = foo([], 1, 2, 3); // any (with error) -var u = (_a = [""], _a.raw = [""], foo(_a)); // number -var v = (_b = ["", ""], _b.raw = ["", ""], foo(_b, 1)); // string -var w = (_c = ["", "", ""], _c.raw = ["", "", ""], foo(_c, 1, 2)); // boolean -var x = (_d = ["", "", ""], _d.raw = ["", "", ""], foo(_d, 1, true)); // boolean (with error) -var y = (_e = ["", "", ""], _e.raw = ["", "", ""], foo(_e, 1, "2")); // {} -var z = (_f = ["", "", "", ""], _f.raw = ["", "", "", ""], foo(_f, 1, 2, 3)); // any (with error) -var _a, _b, _c, _d, _e, _f; +var u = foo(__makeTemplateObject([""], [""])); // number +var v = foo(__makeTemplateObject(["", ""], ["", ""]), 1); // string +var w = foo(__makeTemplateObject(["", "", ""], ["", "", ""]), 1, 2); // boolean +var x = foo(__makeTemplateObject(["", "", ""], ["", "", ""]), 1, true); // boolean (with error) +var y = foo(__makeTemplateObject(["", "", ""], ["", "", ""]), 1, "2"); // {} +var z = foo(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), 1, 2, 3); // any (with error) diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js index 779585ac264d8..e393484eff6ac 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js @@ -18,6 +18,10 @@ var c = foo2 `${1}`; var d = foo2([], 1); //// [taggedTemplateStringsWithOverloadResolution2.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function foo1() { var stuff = []; for (var _i = 0; _i < arguments.length; _i++) { @@ -25,7 +29,7 @@ function foo1() { } return undefined; } -var a = (_a = ["", ""], _a.raw = ["", ""], foo1(_a, 1)); +var a = foo1(__makeTemplateObject(["", ""], ["", ""]), 1); var b = foo1([], 1); function foo2() { var stuff = []; @@ -34,6 +38,5 @@ function foo2() { } return undefined; } -var c = (_b = ["", ""], _b.raw = ["", ""], foo2(_b, 1)); +var c = foo2(__makeTemplateObject(["", ""], ["", ""]), 1); var d = foo2([], 1); -var _a, _b; diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js index df89f2aeea791..9ff4434734bb5 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.js @@ -73,42 +73,45 @@ fn5 `${ (n) => n.substr(0) }`; //// [taggedTemplateStringsWithOverloadResolution3.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function fn1() { return null; } -var s = (_a = ["", ""], _a.raw = ["", ""], fn1(_a, undefined)); +var s = fn1(__makeTemplateObject(["", ""], ["", ""]), undefined); // No candidate overloads found -(_b = ["", ""], _b.raw = ["", ""], fn1(_b, {})); // Error +fn1(__makeTemplateObject(["", ""], ["", ""]), {}); // Error function fn2() { return undefined; } -var d1 = (_c = ["", "", ""], _c.raw = ["", "", ""], fn2(_c, 0, undefined)); // contextually typed -var d2 = (_d = ["", "", ""], _d.raw = ["", "", ""], fn2(_d, 0, undefined)); // any +var d1 = fn2(__makeTemplateObject(["", "", ""], ["", "", ""]), 0, undefined); // contextually typed +var d2 = fn2(__makeTemplateObject(["", "", ""], ["", "", ""]), 0, undefined); // any d1.foo(); // error d2(); // no error (typed as any) // Generic and non-generic overload where generic overload is the only candidate -(_e = ["", "", ""], _e.raw = ["", "", ""], fn2(_e, 0, '')); // OK +fn2(__makeTemplateObject(["", "", ""], ["", "", ""]), 0, ''); // OK // Generic and non-generic overload where non-generic overload is the only candidate -(_f = ["", "", ""], _f.raw = ["", "", ""], fn2(_f, '', 0)); // OK +fn2(__makeTemplateObject(["", "", ""], ["", "", ""]), '', 0); // OK function fn3() { return null; } -var s = (_g = ["", ""], _g.raw = ["", ""], fn3(_g, 3)); -var s = (_h = ["", "", "", ""], _h.raw = ["", "", "", ""], fn3(_h, '', 3, '')); -var n = (_j = ["", "", "", ""], _j.raw = ["", "", "", ""], fn3(_j, 5, 5, 5)); +var s = fn3(__makeTemplateObject(["", ""], ["", ""]), 3); +var s = fn3(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), '', 3, ''); +var n = fn3(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), 5, 5, 5); var n; // Generic overloads with differing arity tagging with arguments matching each overload type parameter count -var s = (_k = ["", ""], _k.raw = ["", ""], fn3(_k, 4)); -var s = (_l = ["", "", "", ""], _l.raw = ["", "", "", ""], fn3(_l, '', '', '')); -var n = (_m = ["", "", "", ""], _m.raw = ["", "", "", ""], fn3(_m, '', '', 3)); +var s = fn3(__makeTemplateObject(["", ""], ["", ""]), 4); +var s = fn3(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), '', '', ''); +var n = fn3(__makeTemplateObject(["", "", "", ""], ["", "", "", ""]), '', '', 3); // Generic overloads with differing arity tagging with argument count that doesn't match any overload -(_o = [""], _o.raw = [""], fn3(_o)); // Error +fn3(__makeTemplateObject([""], [""])); // Error function fn4() { } // Generic overloads with constraints tagged with types that satisfy the constraints -(_p = ["", "", ""], _p.raw = ["", "", ""], fn4(_p, '', 3)); -(_q = ["", "", ""], _q.raw = ["", "", ""], fn4(_q, 3, '')); -(_r = ["", "", ""], _r.raw = ["", "", ""], fn4(_r, 3, undefined)); -(_s = ["", "", ""], _s.raw = ["", "", ""], fn4(_s, '', null)); +fn4(__makeTemplateObject(["", "", ""], ["", "", ""]), '', 3); +fn4(__makeTemplateObject(["", "", ""], ["", "", ""]), 3, ''); +fn4(__makeTemplateObject(["", "", ""], ["", "", ""]), 3, undefined); +fn4(__makeTemplateObject(["", "", ""], ["", "", ""]), '', null); // Generic overloads with constraints called with type arguments that do not satisfy the constraints -(_t = ["", "", ""], _t.raw = ["", "", ""], fn4(_t, null, null)); // Error +fn4(__makeTemplateObject(["", "", ""], ["", "", ""]), null, null); // Error // Generic overloads with constraints called without type arguments but with types that do not satisfy the constraints -(_u = ["", "", ""], _u.raw = ["", "", ""], fn4(_u, true, null)); -(_v = ["", "", ""], _v.raw = ["", "", ""], fn4(_v, null, true)); +fn4(__makeTemplateObject(["", "", ""], ["", "", ""]), true, null); +fn4(__makeTemplateObject(["", "", ""], ["", "", ""]), null, true); function fn5() { return undefined; } -(_w = ["", ""], _w.raw = ["", ""], fn5(_w, function (n) { return n.toFixed(); })); // will error; 'n' should have type 'string'. -(_x = ["", ""], _x.raw = ["", ""], fn5(_x, function (n) { return n.substr(0); })); -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; +fn5(__makeTemplateObject(["", ""], ["", ""]), function (n) { return n.toFixed(); }); // will error; 'n' should have type 'string'. +fn5(__makeTemplateObject(["", ""], ["", ""]), function (n) { return n.substr(0); }); diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.js b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.js index 7a96d4b5e4d86..d1801bdeb6e67 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.js @@ -5,11 +5,14 @@ function declare(x: any, ...ys: any[]) { declare `Hello ${0} world!`; //// [taggedTemplateStringsWithTagNamedDeclare.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function declare(x) { var ys = []; for (var _i = 1; _i < arguments.length; _i++) { ys[_i - 1] = arguments[_i]; } } -(_a = ["Hello ", " world!"], _a.raw = ["Hello ", " world!"], declare(_a, 0)); -var _a; +declare(__makeTemplateObject(["Hello ", " world!"], ["Hello ", " world!"]), 0); diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.js b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.js index cd3d8ba6701ff..af9fd2c9d443e 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.js @@ -26,17 +26,20 @@ f.thisIsNotATag(`abc`); f.thisIsNotATag(`abc${1}def${2}ghi`); //// [taggedTemplateStringsWithTagsTypedAsAny.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var f; -(_a = ["abc"], _a.raw = ["abc"], f(_a)); -(_b = ["abc", "def", "ghi"], _b.raw = ["abc", "def", "ghi"], f(_b, 1, 2)); -(_c = ["abc"], _c.raw = ["abc"], f.g.h(_c)); -(_d = ["abc", "def", "ghi"], _d.raw = ["abc", "def", "ghi"], f.g.h(_d, 1, 2)); -(_e = ["abc"], _e.raw = ["abc"], f(_e)).member; -(_f = ["abc", "def", "ghi"], _f.raw = ["abc", "def", "ghi"], f(_f, 1, 2)).member; -(_g = ["abc"], _g.raw = ["abc"], f(_g))["member"]; -(_h = ["abc", "def", "ghi"], _h.raw = ["abc", "def", "ghi"], f(_h, 1, 2))["member"]; -(_j = ["abc", "def", "ghi"], _j.raw = ["abc", "def", "ghi"], (_k = ["abc"], _k.raw = ["abc"], f(_k))["member"].someOtherTag(_j, 1, 2)); -(_l = ["abc", "def", "ghi"], _l.raw = ["abc", "def", "ghi"], (_m = ["abc", "def", "ghi"], _m.raw = ["abc", "def", "ghi"], f(_m, 1, 2))["member"].someOtherTag(_l, 1, 2)); +f(__makeTemplateObject(["abc"], ["abc"])); +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); +f.g.h(__makeTemplateObject(["abc"], ["abc"])); +f.g.h(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); +f(__makeTemplateObject(["abc"], ["abc"])).member; +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2).member; +f(__makeTemplateObject(["abc"], ["abc"]))["member"]; +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2)["member"]; +f(__makeTemplateObject(["abc"], ["abc"]))["member"].someOtherTag(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2)["member"].someOtherTag(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); f.thisIsNotATag("abc"); f.thisIsNotATag("abc" + 1 + "def" + 2 + "ghi"); -var _a, _b, _c, _d, _e, _f, _g, _h, _k, _j, _m, _l; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js index 3e2889ce1f35e..c93dce9340f71 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js @@ -5,11 +5,14 @@ function foo(...rest: any[]) { foo `${function (x: number) { x = "bad"; } }`; //// [taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function foo() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { rest[_i] = arguments[_i]; } } -(_a = ["", ""], _a.raw = ["", ""], foo(_a, function (x) { x = "bad"; })); -var _a; +foo(__makeTemplateObject(["", ""], ["", ""]), function (x) { x = "bad"; }); diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js index 5f3409a1e5878..c6509f1ca8676 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js @@ -32,15 +32,18 @@ f.thisIsNotATag(`abc${1}def${2}ghi`); //// [taggedTemplateStringsWithTypedTags.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var f; -(_a = ["abc"], _a.raw = ["abc"], f(_a)); -(_b = ["abc", "def", "ghi"], _b.raw = ["abc", "def", "ghi"], f(_b, 1, 2)); -(_c = ["abc"], _c.raw = ["abc"], f(_c)).member; -(_d = ["abc", "def", "ghi"], _d.raw = ["abc", "def", "ghi"], f(_d, 1, 2)).member; -(_e = ["abc"], _e.raw = ["abc"], f(_e))["member"]; -(_f = ["abc", "def", "ghi"], _f.raw = ["abc", "def", "ghi"], f(_f, 1, 2))["member"]; -(_g = ["abc", "def", "ghi"], _g.raw = ["abc", "def", "ghi"], (_h = ["abc"], _h.raw = ["abc"], f(_h))[0].member(_g, 1, 2)); -(_j = ["abc", "def", "ghi"], _j.raw = ["abc", "def", "ghi"], (_k = ["abc", "def", "ghi"], _k.raw = ["abc", "def", "ghi"], f(_k, 1, 2))["member"].member(_j, 1, 2)); +f(__makeTemplateObject(["abc"], ["abc"])); +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); +f(__makeTemplateObject(["abc"], ["abc"])).member; +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2).member; +f(__makeTemplateObject(["abc"], ["abc"]))["member"]; +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2)["member"]; +f(__makeTemplateObject(["abc"], ["abc"]))[0].member(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); +f(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2)["member"].member(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 1, 2); f.thisIsNotATag("abc"); f.thisIsNotATag("abc" + 1 + "def" + 2 + "ghi"); -var _a, _b, _c, _d, _e, _f, _h, _g, _k, _j; diff --git a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js index 6a04b082e1f08..a5c35947db718 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js +++ b/tests/baselines/reference/taggedTemplateStringsWithUnicodeEscapes.js @@ -5,11 +5,14 @@ function f(...args: any[]) { f `'\u{1f4a9}'${ " should be converted to " }'\uD83D\uDCA9'`; //// [taggedTemplateStringsWithUnicodeEscapes.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } } -(_a = ["'\uD83D\uDCA9'", "'\uD83D\uDCA9'"], _a.raw = ["'\\u{1f4a9}'", "'\\uD83D\\uDCA9'"], f(_a, " should be converted to ")); -var _a; +f(__makeTemplateObject(["'\uD83D\uDCA9'", "'\uD83D\uDCA9'"], ["'\\u{1f4a9}'", "'\\uD83D\\uDCA9'"]), " should be converted to "); diff --git a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js index e8f219fd12582..73aa63931a66f 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js +++ b/tests/baselines/reference/taggedTemplateStringsWithWhitespaceEscapes.js @@ -5,11 +5,14 @@ function f(...args: any[]) { f `\t\n\v\f\r\\`; //// [taggedTemplateStringsWithWhitespaceEscapes.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function f() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } } -(_a = ["\t\n\v\f\r\\"], _a.raw = ["\\t\\n\\v\\f\\r\\\\"], f(_a)); -var _a; +f(__makeTemplateObject(["\t\n\v\f\r\\"], ["\\t\\n\\v\\f\\r\\\\"])); diff --git a/tests/baselines/reference/taggedTemplateUntypedTagCall01.js b/tests/baselines/reference/taggedTemplateUntypedTagCall01.js index e0d16eec39db9..1fd5168cda150 100644 --- a/tests/baselines/reference/taggedTemplateUntypedTagCall01.js +++ b/tests/baselines/reference/taggedTemplateUntypedTagCall01.js @@ -3,6 +3,9 @@ var tag: Function; tag `Hello world!`; //// [taggedTemplateUntypedTagCall01.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var tag; -(_a = ["Hello world!"], _a.raw = ["Hello world!"], tag(_a)); -var _a; +tag(__makeTemplateObject(["Hello world!"], ["Hello world!"])); diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag01.js b/tests/baselines/reference/taggedTemplateWithConstructableTag01.js index dacae2f529e15..ce2376d4d3107 100644 --- a/tests/baselines/reference/taggedTemplateWithConstructableTag01.js +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag01.js @@ -4,10 +4,13 @@ class CtorTag { } CtorTag `Hello world!`; //// [taggedTemplateWithConstructableTag01.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var CtorTag = /** @class */ (function () { function CtorTag() { } return CtorTag; }()); -(_a = ["Hello world!"], _a.raw = ["Hello world!"], CtorTag(_a)); -var _a; +CtorTag(__makeTemplateObject(["Hello world!"], ["Hello world!"])); diff --git a/tests/baselines/reference/taggedTemplateWithConstructableTag02.js b/tests/baselines/reference/taggedTemplateWithConstructableTag02.js index 6c38d508bd2c9..9cf0611aafdff 100644 --- a/tests/baselines/reference/taggedTemplateWithConstructableTag02.js +++ b/tests/baselines/reference/taggedTemplateWithConstructableTag02.js @@ -7,6 +7,9 @@ var tag: I; tag `Hello world!`; //// [taggedTemplateWithConstructableTag02.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var tag; -(_a = ["Hello world!"], _a.raw = ["Hello world!"], tag(_a)); -var _a; +tag(__makeTemplateObject(["Hello world!"], ["Hello world!"])); diff --git a/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.errors.txt b/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.errors.txt new file mode 100755 index 0000000000000..c0931c50bb576 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/foo.ts(5,23): error TS2343: This syntax requires an imported helper named '__makeTemplateObject', but module 'tslib' has no exported member '__makeTemplateObject'. + + +==== tests/cases/compiler/foo.ts (1 errors) ==== + function id(x: T) { + return x; + } + + export const result = id `hello world`; + ~~~~~~~~~~~~~~~~ +!!! error TS2343: This syntax requires an imported helper named '__makeTemplateObject', but module 'tslib' has no exported member '__makeTemplateObject'. + +==== tests/cases/compiler/node_modules/tslib/index.d.ts (0 errors) ==== + export { }; + \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.js b/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.js new file mode 100755 index 0000000000000..453b35d98ba84 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.js @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/taggedTemplateWithoutDeclaredHelper.ts] //// + +//// [foo.ts] +function id(x: T) { + return x; +} + +export const result = id `hello world`; + +//// [index.d.ts] +export { }; + + +//// [foo.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var tslib_1 = require("tslib"); +function id(x) { + return x; +} +exports.result = id(_a || (_a = tslib_1.__makeTemplateObject(["hello world"], ["hello world"]))); +var _a; diff --git a/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.symbols b/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.symbols new file mode 100755 index 0000000000000..dcba750c89076 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/foo.ts === +function id(x: T) { +>id : Symbol(id, Decl(foo.ts, 0, 0)) +>T : Symbol(T, Decl(foo.ts, 0, 12)) +>x : Symbol(x, Decl(foo.ts, 0, 15)) +>T : Symbol(T, Decl(foo.ts, 0, 12)) + + return x; +>x : Symbol(x, Decl(foo.ts, 0, 15)) +} + +export const result = id `hello world`; +>result : Symbol(result, Decl(foo.ts, 4, 12)) +>id : Symbol(id, Decl(foo.ts, 0, 0)) + +=== tests/cases/compiler/node_modules/tslib/index.d.ts === +export { }; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.types b/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.types new file mode 100755 index 0000000000000..7e8486e3ecc9f --- /dev/null +++ b/tests/baselines/reference/taggedTemplateWithoutDeclaredHelper.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/foo.ts === +function id(x: T) { +>id : (x: T) => T +>T : T +>x : T +>T : T + + return x; +>x : T +} + +export const result = id `hello world`; +>result : TemplateStringsArray +>id `hello world` : TemplateStringsArray +>id : (x: T) => T +>`hello world` : "hello world" + +=== tests/cases/compiler/node_modules/tslib/index.d.ts === +export { }; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplatesInModuleAndGlobal.js b/tests/baselines/reference/taggedTemplatesInModuleAndGlobal.js new file mode 100644 index 0000000000000..737bdec55dc43 --- /dev/null +++ b/tests/baselines/reference/taggedTemplatesInModuleAndGlobal.js @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/taggedTemplatesInModuleAndGlobal.ts] //// + +//// [global.ts] +namespace n { + function id(x: T): T { + return x; + } + + function templateObjectFactory() { + return id`hello world`; + } + let result = templateObjectFactory() === templateObjectFactory(); +} +//// [module.ts] +export { } +function id(x: T): T { + return x; +} + +function templateObjectFactory() { + return id`hello world`; +} +let result = templateObjectFactory() === templateObjectFactory(); + + +//// [global.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; +var n; +(function (n) { + function id(x) { + return x; + } + function templateObjectFactory() { + return id(__makeTemplateObject(["hello world"], ["hello world"])); + } + var result = templateObjectFactory() === templateObjectFactory(); +})(n || (n = {})); +//// [module.js] +"use strict"; +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +function id(x) { + return x; +} +function templateObjectFactory() { + return id(_a || (_a = __makeTemplateObject(["hello world"], ["hello world"]))); +} +var result = templateObjectFactory() === templateObjectFactory(); +var _a; diff --git a/tests/baselines/reference/taggedTemplatesInModuleAndGlobal.symbols b/tests/baselines/reference/taggedTemplatesInModuleAndGlobal.symbols new file mode 100644 index 0000000000000..b33ff869734ec --- /dev/null +++ b/tests/baselines/reference/taggedTemplatesInModuleAndGlobal.symbols @@ -0,0 +1,50 @@ +=== tests/cases/compiler/global.ts === +namespace n { +>n : Symbol(n, Decl(global.ts, 0, 0)) + + function id(x: T): T { +>id : Symbol(id, Decl(global.ts, 0, 13)) +>T : Symbol(T, Decl(global.ts, 1, 16)) +>x : Symbol(x, Decl(global.ts, 1, 19)) +>T : Symbol(T, Decl(global.ts, 1, 16)) +>T : Symbol(T, Decl(global.ts, 1, 16)) + + return x; +>x : Symbol(x, Decl(global.ts, 1, 19)) + } + + function templateObjectFactory() { +>templateObjectFactory : Symbol(templateObjectFactory, Decl(global.ts, 3, 5)) + + return id`hello world`; +>id : Symbol(id, Decl(global.ts, 0, 13)) + } + let result = templateObjectFactory() === templateObjectFactory(); +>result : Symbol(result, Decl(global.ts, 8, 7)) +>templateObjectFactory : Symbol(templateObjectFactory, Decl(global.ts, 3, 5)) +>templateObjectFactory : Symbol(templateObjectFactory, Decl(global.ts, 3, 5)) +} +=== tests/cases/compiler/module.ts === +export { } +function id(x: T): T { +>id : Symbol(id, Decl(module.ts, 0, 10)) +>T : Symbol(T, Decl(module.ts, 1, 12)) +>x : Symbol(x, Decl(module.ts, 1, 15)) +>T : Symbol(T, Decl(module.ts, 1, 12)) +>T : Symbol(T, Decl(module.ts, 1, 12)) + + return x; +>x : Symbol(x, Decl(module.ts, 1, 15)) +} + +function templateObjectFactory() { +>templateObjectFactory : Symbol(templateObjectFactory, Decl(module.ts, 3, 1)) + + return id`hello world`; +>id : Symbol(id, Decl(module.ts, 0, 10)) +} +let result = templateObjectFactory() === templateObjectFactory(); +>result : Symbol(result, Decl(module.ts, 8, 3)) +>templateObjectFactory : Symbol(templateObjectFactory, Decl(module.ts, 3, 1)) +>templateObjectFactory : Symbol(templateObjectFactory, Decl(module.ts, 3, 1)) + diff --git a/tests/baselines/reference/taggedTemplatesInModuleAndGlobal.types b/tests/baselines/reference/taggedTemplatesInModuleAndGlobal.types new file mode 100644 index 0000000000000..14550acb6b07c --- /dev/null +++ b/tests/baselines/reference/taggedTemplatesInModuleAndGlobal.types @@ -0,0 +1,60 @@ +=== tests/cases/compiler/global.ts === +namespace n { +>n : typeof n + + function id(x: T): T { +>id : (x: T) => T +>T : T +>x : T +>T : T +>T : T + + return x; +>x : T + } + + function templateObjectFactory() { +>templateObjectFactory : () => TemplateStringsArray + + return id`hello world`; +>id`hello world` : TemplateStringsArray +>id : (x: T) => T +>`hello world` : "hello world" + } + let result = templateObjectFactory() === templateObjectFactory(); +>result : boolean +>templateObjectFactory() === templateObjectFactory() : boolean +>templateObjectFactory() : TemplateStringsArray +>templateObjectFactory : () => TemplateStringsArray +>templateObjectFactory() : TemplateStringsArray +>templateObjectFactory : () => TemplateStringsArray +} +=== tests/cases/compiler/module.ts === +export { } +function id(x: T): T { +>id : (x: T) => T +>T : T +>x : T +>T : T +>T : T + + return x; +>x : T +} + +function templateObjectFactory() { +>templateObjectFactory : () => TemplateStringsArray + + return id`hello world`; +>id`hello world` : TemplateStringsArray +>id : (x: T) => T +>`hello world` : "hello world" +} +let result = templateObjectFactory() === templateObjectFactory(); +>result : boolean +>templateObjectFactory() === templateObjectFactory() : boolean +>templateObjectFactory() : TemplateStringsArray +>templateObjectFactory : () => TemplateStringsArray +>templateObjectFactory() : TemplateStringsArray +>templateObjectFactory : () => TemplateStringsArray + diff --git a/tests/baselines/reference/templateStringInModuleName.js b/tests/baselines/reference/templateStringInModuleName.js index 36f619176e435..fa11d39ff16af 100644 --- a/tests/baselines/reference/templateStringInModuleName.js +++ b/tests/baselines/reference/templateStringInModuleName.js @@ -6,12 +6,15 @@ declare module `M${2}` { } //// [templateStringInModuleName.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; declare; -(_a = ["M1"], _a.raw = ["M1"], module(_a)); +module(__makeTemplateObject(["M1"], ["M1"])); { } declare; -(_b = ["M", ""], _b.raw = ["M", ""], module(_b, 2)); +module(__makeTemplateObject(["M", ""], ["M", ""]), 2); { } -var _a, _b; diff --git a/tests/baselines/reference/templateStringInObjectLiteral.js b/tests/baselines/reference/templateStringInObjectLiteral.js index 0381e9a95e7c9..e007ff7b7e745 100644 --- a/tests/baselines/reference/templateStringInObjectLiteral.js +++ b/tests/baselines/reference/templateStringInObjectLiteral.js @@ -5,8 +5,11 @@ var x = { } //// [templateStringInObjectLiteral.js] -var x = (_a = ["b"], _a.raw = ["b"], { +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; +var x = { a: "abc" + 123 + "def" -}(_a)); +}(__makeTemplateObject(["b"], ["b"])); 321; -var _a; diff --git a/tests/baselines/reference/templateStringInPropertyName1.js b/tests/baselines/reference/templateStringInPropertyName1.js index 239ba78d82739..701400b0f2953 100644 --- a/tests/baselines/reference/templateStringInPropertyName1.js +++ b/tests/baselines/reference/templateStringInPropertyName1.js @@ -4,6 +4,9 @@ var x = { } //// [templateStringInPropertyName1.js] -var x = (_a = ["a"], _a.raw = ["a"], {}(_a)); +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; +var x = {}(__makeTemplateObject(["a"], ["a"])); 321; -var _a; diff --git a/tests/baselines/reference/templateStringInPropertyName2.js b/tests/baselines/reference/templateStringInPropertyName2.js index 8a71a6e30be5c..5f41ed7bfb201 100644 --- a/tests/baselines/reference/templateStringInPropertyName2.js +++ b/tests/baselines/reference/templateStringInPropertyName2.js @@ -4,6 +4,9 @@ var x = { } //// [templateStringInPropertyName2.js] -var x = (_a = ["abc", "def", "ghi"], _a.raw = ["abc", "def", "ghi"], {}(_a, 123, 456)); +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; +var x = {}(__makeTemplateObject(["abc", "def", "ghi"], ["abc", "def", "ghi"]), 123, 456); 321; -var _a; diff --git a/tests/baselines/reference/templateStringInTaggedTemplate.js b/tests/baselines/reference/templateStringInTaggedTemplate.js index 3ba70ba84b637..29b85bf71ea5d 100644 --- a/tests/baselines/reference/templateStringInTaggedTemplate.js +++ b/tests/baselines/reference/templateStringInTaggedTemplate.js @@ -2,5 +2,8 @@ `I AM THE ${ `${ `TAG` } ` } PORTION` `I ${ "AM" } THE TEMPLATE PORTION` //// [templateStringInTaggedTemplate.js] -(_a = ["I ", " THE TEMPLATE PORTION"], _a.raw = ["I ", " THE TEMPLATE PORTION"], ("I AM THE " + "TAG" + " " + " PORTION")(_a, "AM")); -var _a; +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; +("I AM THE " + "TAG" + " " + " PORTION")(__makeTemplateObject(["I ", " THE TEMPLATE PORTION"], ["I ", " THE TEMPLATE PORTION"]), "AM"); diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.js b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.js index 517383f6f2906..1176c97a6a2ec 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.js +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.js @@ -10,6 +10,10 @@ f({}, 10, 10); f `abcdef${ 1234 }${ 5678 }ghijkl`; //// [templateStringsArrayTypeDefinedInES5Mode.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; var TemplateStringsArray = /** @class */ (function () { function TemplateStringsArray() { } @@ -18,5 +22,4 @@ var TemplateStringsArray = /** @class */ (function () { function f(x, y, z) { } f({}, 10, 10); -(_a = ["abcdef", "", "ghijkl"], _a.raw = ["abcdef", "", "ghijkl"], f(_a, 1234, 5678)); -var _a; +f(__makeTemplateObject(["abcdef", "", "ghijkl"], ["abcdef", "", "ghijkl"]), 1234, 5678); diff --git a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.js b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.js index 6daa46d037b5c..f6db54aeb8f08 100644 --- a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.js +++ b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.js @@ -7,8 +7,11 @@ f({}, 10, 10); f `abcdef${ 1234 }${ 5678 }ghijkl`; //// [templateStringsArrayTypeNotDefinedES5Mode.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; function f(x, y, z) { } f({}, 10, 10); -(_a = ["abcdef", "", "ghijkl"], _a.raw = ["abcdef", "", "ghijkl"], f(_a, 1234, 5678)); -var _a; +f(__makeTemplateObject(["abcdef", "", "ghijkl"], ["abcdef", "", "ghijkl"]), 1234, 5678); diff --git a/tests/cases/compiler/importHelpers.ts b/tests/cases/compiler/importHelpers.ts index 2e15eb6352b88..becbc2eb715d0 100644 --- a/tests/cases/compiler/importHelpers.ts +++ b/tests/cases/compiler/importHelpers.ts @@ -16,6 +16,12 @@ class C { } } +function id(x: T) { + return x; +} + +export const result = id`hello world`; + // @filename: script.ts class A { } class B extends A { } @@ -28,6 +34,12 @@ class C { } } +function id(x: T) { + return x; +} + +const result = id`hello world`; + // @filename: tslib.d.ts export declare function __extends(d: Function, b: Function): void; export declare function __assign(t: any, ...sources: any[]): any; @@ -35,3 +47,4 @@ export declare function __decorate(decorators: Function[], target: any, key?: st export declare function __param(paramIndex: number, decorator: Function): Function; export declare function __metadata(metadataKey: any, metadataValue: any): Function; export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +export declare function __makeTemplateObject(cooked: string[], raw: string[]): TemplateStringsArray; diff --git a/tests/cases/compiler/taggedTemplateWithoutDeclaredHelper.ts b/tests/cases/compiler/taggedTemplateWithoutDeclaredHelper.ts new file mode 100755 index 0000000000000..5e5bea3fd6a9a --- /dev/null +++ b/tests/cases/compiler/taggedTemplateWithoutDeclaredHelper.ts @@ -0,0 +1,14 @@ +// @target: es5 +// @module: commonjs +// @importHelpers: true +// @strict: true + +// @filename: foo.ts +function id(x: T) { + return x; +} + +export const result = id `hello world`; + +// @filename: ./node_modules/tslib/index.d.ts +export { }; diff --git a/tests/cases/compiler/taggedTemplatesInModuleAndGlobal.ts b/tests/cases/compiler/taggedTemplatesInModuleAndGlobal.ts new file mode 100644 index 0000000000000..b96b869704a97 --- /dev/null +++ b/tests/cases/compiler/taggedTemplatesInModuleAndGlobal.ts @@ -0,0 +1,24 @@ +// @module: commonjs +// @target: es5 + +// @filename: global.ts +namespace n { + function id(x: T): T { + return x; + } + + function templateObjectFactory() { + return id`hello world`; + } + let result = templateObjectFactory() === templateObjectFactory(); +} +// @filename: module.ts +export { } +function id(x: T): T { + return x; +} + +function templateObjectFactory() { + return id`hello world`; +} +let result = templateObjectFactory() === templateObjectFactory();