Merge branch 'master' into dynamicNames

This commit is contained in:
Ron Buckton 2017-10-03 12:44:17 -07:00
commit 1745e170bd
49 changed files with 731 additions and 177 deletions

View File

@ -505,7 +505,7 @@ const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js")
const tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile, typesMapJson], (done) => {
const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/ true));
const {js, dts}: { js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream } = serverLibraryProject.src()
.pipe(sourcemaps.init())
.pipe(newer(tsserverLibraryFile))

View File

@ -647,7 +647,7 @@ compileFile(
[builtLocalDirectory, copyright, builtLocalCompiler].concat(languageServiceLibrarySources).concat(libraryTargets),
/*prefixes*/[copyright],
/*useBuiltCompiler*/ true,
{ noOutFile: false, generateDeclarations: true, stripInternal: true, preserveConstEnums: true },
{ noOutFile: false, generateDeclarations: true, stripInternal: true, preserveConstEnums: true, keepComments: true },
/*callback*/ function () {
prependFile(copyright, tsserverLibraryDefinitionFile);

View File

@ -17116,6 +17116,9 @@ namespace ts {
}
function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type {
if (languageVersion < ScriptTarget.ES2015) {
checkExternalEmitHelpers(node, ExternalEmitHelpers.MakeTemplateObject);
}
return getReturnTypeOfSignature(getResolvedSignature(node));
}
@ -24540,6 +24543,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");
}
}

View File

@ -3881,15 +3881,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 (<NewExpression>emittedExpression).arguments
? <LeftHandSideExpression>expression
: createParen(expression);
return !(leftmostExpr as NewExpression).arguments
? createParen(expression)
: <LeftHandSideExpression>expression;
}
return parenthesizeForAccess(expression);
@ -3970,7 +3970,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);
}
@ -4016,7 +4016,7 @@ namespace ts {
}
}
function getLeftmostExpression(node: Expression): Expression {
function getLeftmostExpression(node: Expression, stopAtCallExpressions: boolean) {
while (true) {
switch (node.kind) {
case SyntaxKind.PostfixUnaryExpression:
@ -4032,6 +4032,10 @@ namespace ts {
continue;
case SyntaxKind.CallExpression:
if (stopAtCallExpressions) {
return node;
}
// falls through
case SyntaxKind.ElementAccessExpression:
case SyntaxKind.PropertyAccessExpression:
node = (<CallExpression | PropertyAccessExpression | ElementAccessExpression>node).expression;
@ -4044,10 +4048,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(<Expression>body), body);
}

View File

@ -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;
};`
};
}

View File

@ -4337,22 +4337,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,
@ -4369,8 +4372,6 @@ namespace ts {
// Helpers included by ES2015 spread
SpreadIncludes = Read | Spread,
FirstEmitHelper = Extends,
LastEmitHelper = ExportStar
}
export const enum EmitHint {

View File

@ -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,

View File

@ -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"]));

View File

@ -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;

View File

@ -11,6 +11,12 @@ class C {
method(@dec x: number) {
}
}
function id<T>(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<T>(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"]));

View File

@ -22,6 +22,20 @@ class C {
}
}
function id<T>(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<T>(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, --, --))

View File

@ -22,6 +22,22 @@ class C {
}
}
function id<T>(x: T) {
>id : <T>(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 : <T>(x: T) => T
>`hello world` : "hello world"
=== tests/cases/compiler/script.ts ===
class A { }
>A : A
@ -46,6 +62,22 @@ class C {
}
}
function id<T>(x: T) {
>id : <T>(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 : <T>(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

View File

@ -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");

View File

@ -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"]));

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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"]));

View File

@ -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)

View File

@ -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;

View File

@ -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); });

View File

@ -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);

View File

@ -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;

View File

@ -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"; });

View File

@ -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;

View File

@ -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 ");

View File

@ -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\\\\"]));

View File

@ -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!"]));

View File

@ -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!"]));

View File

@ -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!"]));

View File

@ -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<T>(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 { };

View File

@ -0,0 +1,22 @@
//// [tests/cases/compiler/taggedTemplateWithoutDeclaredHelper.ts] ////
//// [foo.ts]
function id<T>(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;

View File

@ -0,0 +1,19 @@
=== tests/cases/compiler/foo.ts ===
function id<T>(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.

View File

@ -0,0 +1,21 @@
=== tests/cases/compiler/foo.ts ===
function id<T>(x: T) {
>id : <T>(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 : <T>(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.

View File

@ -0,0 +1,55 @@
//// [tests/cases/compiler/taggedTemplatesInModuleAndGlobal.ts] ////
//// [global.ts]
namespace n {
function id<T>(x: T): T {
return x;
}
function templateObjectFactory() {
return id`hello world`;
}
let result = templateObjectFactory() === templateObjectFactory();
}
//// [module.ts]
export { }
function id<T>(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;

View File

@ -0,0 +1,50 @@
=== tests/cases/compiler/global.ts ===
namespace n {
>n : Symbol(n, Decl(global.ts, 0, 0))
function id<T>(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<T>(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))

View File

@ -0,0 +1,60 @@
=== tests/cases/compiler/global.ts ===
namespace n {
>n : typeof n
function id<T>(x: T): T {
>id : <T>(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 : <T>(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<T>(x: T): T {
>id : <T>(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 : <T>(x: T) => T
>`hello world` : "hello world"
}
let result = templateObjectFactory() === templateObjectFactory();
>result : boolean
>templateObjectFactory() === templateObjectFactory() : boolean
>templateObjectFactory() : TemplateStringsArray
>templateObjectFactory : () => TemplateStringsArray
>templateObjectFactory() : TemplateStringsArray
>templateObjectFactory : () => TemplateStringsArray

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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");

View File

@ -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);

View File

@ -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);

View File

@ -16,6 +16,12 @@ class C {
}
}
function id<T>(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<T>(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;

View File

@ -0,0 +1,14 @@
// @target: es5
// @module: commonjs
// @importHelpers: true
// @strict: true
// @filename: foo.ts
function id<T>(x: T) {
return x;
}
export const result = id `hello world`;
// @filename: ./node_modules/tslib/index.d.ts
export { };

View File

@ -0,0 +1,24 @@
// @module: commonjs
// @target: es5
// @filename: global.ts
namespace n {
function id<T>(x: T): T {
return x;
}
function templateObjectFactory() {
return id`hello world`;
}
let result = templateObjectFactory() === templateObjectFactory();
}
// @filename: module.ts
export { }
function id<T>(x: T): T {
return x;
}
function templateObjectFactory() {
return id`hello world`;
}
let result = templateObjectFactory() === templateObjectFactory();