Make processTaggedTemplateExpression visit a returned node

This problem was introduced in 70399e146e2 (from PR #23801), which added
a `visitTaggedTemplateExpression` case for `TaggedTemplateExpression`,
before that, it would fallback to the default of `visitNode`.  So re-add
that happen in `processTaggedTemplateExpression`.

Since it doesn't hurt, I left a `Debug.checkDefined(property.name)`
instead of `!`-ing it.

Fixes #38558.
This commit is contained in:
Eli Barzilay 2020-05-14 23:19:52 -04:00
parent d7dd06e36d
commit 33c3e9e2c6
6 changed files with 160 additions and 3 deletions

View File

@ -2583,7 +2583,7 @@ namespace ts {
&& i < numInitialPropertiesWithoutYield) {
numInitialPropertiesWithoutYield = i;
}
if (property.name!.kind === SyntaxKind.ComputedPropertyName) {
if (Debug.checkDefined(property.name).kind === SyntaxKind.ComputedPropertyName) {
numInitialProperties = i;
break;
}

View File

@ -8,7 +8,7 @@ namespace ts {
export function processTaggedTemplateExpression(
context: TransformationContext,
node: TaggedTemplateExpression,
visitor: ((node: Node) => VisitResult<Node>) | undefined,
visitor: Visitor,
currentSourceFile: SourceFile,
recordTaggedTemplateString: (temp: Identifier) => void,
level: ProcessLevel) {
@ -24,7 +24,9 @@ namespace ts {
const rawStrings: Expression[] = [];
const template = node.template;
if (level === ProcessLevel.LiftRestriction && !hasInvalidEscape(template)) return node;
if (level === ProcessLevel.LiftRestriction && !hasInvalidEscape(template)) {
return visitEachChild(node, visitor, context);
}
if (isNoSubstitutionTemplateLiteral(template)) {
cookedStrings.push(createTemplateCooked(template));

View File

@ -0,0 +1,41 @@
//// [taggedTemplateStringsWithCurriedFunction.ts]
// Originated from #38558
const f = _ => (..._) => "";
f({ ...{ x: 0 } })``;
f({ ...{ x: 0 } })`x`;
f({ ...{ x: 0 } })`x${f}x`;
f({ ...{ x: 0 }, y: (() => 1)() })``;
f({ x: (() => 1)(), ...{ y: 1 } })``;
//// [taggedTemplateStringsWithCurriedFunction.js]
// Originated from #38558
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var f = function (_) { return function () {
var _ = [];
for (var _i = 0; _i < arguments.length; _i++) {
_[_i] = arguments[_i];
}
return "";
}; };
f(__assign({ x: 0 }))(__makeTemplateObject([""], [""]));
f(__assign({ x: 0 }))(__makeTemplateObject(["x"], ["x"]));
f(__assign({ x: 0 }))(__makeTemplateObject(["x", "x"], ["x", "x"]), f);
f(__assign({ x: 0 }, { y: (function () { return 1; })() }))(__makeTemplateObject([""], [""]));
f(__assign({ x: (function () { return 1; })() }, { y: 1 }))(__makeTemplateObject([""], [""]));

View File

@ -0,0 +1,31 @@
=== tests/cases/compiler/taggedTemplateStringsWithCurriedFunction.ts ===
// Originated from #38558
const f = _ => (..._) => "";
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
>_ : Symbol(_, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 9))
>_ : Symbol(_, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 16))
f({ ...{ x: 0 } })``;
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 4, 8))
f({ ...{ x: 0 } })`x`;
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 5, 8))
f({ ...{ x: 0 } })`x${f}x`;
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 6, 8))
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
f({ ...{ x: 0 }, y: (() => 1)() })``;
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 7, 8))
>y : Symbol(y, Decl(taggedTemplateStringsWithCurriedFunction.ts, 7, 16))
f({ x: (() => 1)(), ...{ y: 1 } })``;
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 8, 3))
>y : Symbol(y, Decl(taggedTemplateStringsWithCurriedFunction.ts, 8, 24))

View File

@ -0,0 +1,72 @@
=== tests/cases/compiler/taggedTemplateStringsWithCurriedFunction.ts ===
// Originated from #38558
const f = _ => (..._) => "";
>f : (_: any) => (..._: any[]) => string
>_ => (..._) => "" : (_: any) => (..._: any[]) => string
>_ : any
>(..._) => "" : (..._: any[]) => string
>_ : any[]
>"" : ""
f({ ...{ x: 0 } })``;
>f({ ...{ x: 0 } })`` : string
>f({ ...{ x: 0 } }) : (..._: any[]) => string
>f : (_: any) => (..._: any[]) => string
>{ ...{ x: 0 } } : { x: number; }
>{ x: 0 } : { x: number; }
>x : number
>0 : 0
>`` : ""
f({ ...{ x: 0 } })`x`;
>f({ ...{ x: 0 } })`x` : string
>f({ ...{ x: 0 } }) : (..._: any[]) => string
>f : (_: any) => (..._: any[]) => string
>{ ...{ x: 0 } } : { x: number; }
>{ x: 0 } : { x: number; }
>x : number
>0 : 0
>`x` : "x"
f({ ...{ x: 0 } })`x${f}x`;
>f({ ...{ x: 0 } })`x${f}x` : string
>f({ ...{ x: 0 } }) : (..._: any[]) => string
>f : (_: any) => (..._: any[]) => string
>{ ...{ x: 0 } } : { x: number; }
>{ x: 0 } : { x: number; }
>x : number
>0 : 0
>`x${f}x` : string
>f : (_: any) => (..._: any[]) => string
f({ ...{ x: 0 }, y: (() => 1)() })``;
>f({ ...{ x: 0 }, y: (() => 1)() })`` : string
>f({ ...{ x: 0 }, y: (() => 1)() }) : (..._: any[]) => string
>f : (_: any) => (..._: any[]) => string
>{ ...{ x: 0 }, y: (() => 1)() } : { y: number; x: number; }
>{ x: 0 } : { x: number; }
>x : number
>0 : 0
>y : number
>(() => 1)() : number
>(() => 1) : () => number
>() => 1 : () => number
>1 : 1
>`` : ""
f({ x: (() => 1)(), ...{ y: 1 } })``;
>f({ x: (() => 1)(), ...{ y: 1 } })`` : string
>f({ x: (() => 1)(), ...{ y: 1 } }) : (..._: any[]) => string
>f : (_: any) => (..._: any[]) => string
>{ x: (() => 1)(), ...{ y: 1 } } : { y: number; x: number; }
>x : number
>(() => 1)() : number
>(() => 1) : () => number
>() => 1 : () => number
>1 : 1
>{ y: 1 } : { y: number; }
>y : number
>1 : 1
>`` : ""

View File

@ -0,0 +1,11 @@
//@target: es3
// Originated from #38558
const f = _ => (..._) => "";
f({ ...{ x: 0 } })``;
f({ ...{ x: 0 } })`x`;
f({ ...{ x: 0 } })`x${f}x`;
f({ ...{ x: 0 }, y: (() => 1)() })``;
f({ x: (() => 1)(), ...{ y: 1 } })``;