Skip to content

Commit

Permalink
Make processTaggedTemplateExpression visit a returned node
Browse files Browse the repository at this point in the history
This problem was introduced in 70399e1 (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.
  • Loading branch information
elibarzilay committed May 15, 2020
1 parent d7dd06e commit 33c3e9e
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/transformers/taggedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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([""], [""]));
Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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
>`` : ""

11 changes: 11 additions & 0 deletions tests/cases/compiler/taggedTemplateStringsWithCurriedFunction.ts
Original file line number Diff line number Diff line change
@@ -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 } })``;

0 comments on commit 33c3e9e

Please sign in to comment.