Skip to content

Commit ea1e0ab

Browse files
committed
Make processTaggedTemplateExpression visit a returned node
This problem was introduced in 70399e1 (from PR microsoft#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 microsoft#38558.
1 parent 1a15717 commit ea1e0ab

6 files changed

+160
-3
lines changed

src/compiler/transformers/es2015.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2583,7 +2583,7 @@ namespace ts {
25832583
&& i < numInitialPropertiesWithoutYield) {
25842584
numInitialPropertiesWithoutYield = i;
25852585
}
2586-
if (property.name!.kind === SyntaxKind.ComputedPropertyName) {
2586+
if (Debug.checkDefined(property.name).kind === SyntaxKind.ComputedPropertyName) {
25872587
numInitialProperties = i;
25882588
break;
25892589
}

src/compiler/transformers/taggedTemplate.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ts {
88
export function processTaggedTemplateExpression(
99
context: TransformationContext,
1010
node: TaggedTemplateExpression,
11-
visitor: ((node: Node) => VisitResult<Node>) | undefined,
11+
visitor: Visitor,
1212
currentSourceFile: SourceFile,
1313
recordTaggedTemplateString: (temp: Identifier) => void,
1414
level: ProcessLevel) {
@@ -24,7 +24,9 @@ namespace ts {
2424
const rawStrings: Expression[] = [];
2525
const template = node.template;
2626

27-
if (level === ProcessLevel.LiftRestriction && !hasInvalidEscape(template)) return node;
27+
if (level === ProcessLevel.LiftRestriction && !hasInvalidEscape(template)) {
28+
return visitEachChild(node, visitor, context);
29+
}
2830

2931
if (isNoSubstitutionTemplateLiteral(template)) {
3032
cookedStrings.push(createTemplateCooked(template));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//// [taggedTemplateStringsWithCurriedFunction.ts]
2+
// Originated from #38558
3+
4+
const f = _ => (..._) => "";
5+
6+
f({ ...{ x: 0 } })``;
7+
f({ ...{ x: 0 } })`x`;
8+
f({ ...{ x: 0 } })`x${f}x`;
9+
f({ ...{ x: 0 }, y: (() => 1)() })``;
10+
f({ x: (() => 1)(), ...{ y: 1 } })``;
11+
12+
13+
//// [taggedTemplateStringsWithCurriedFunction.js]
14+
// Originated from #38558
15+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
16+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
17+
return cooked;
18+
};
19+
var __assign = (this && this.__assign) || function () {
20+
__assign = Object.assign || function(t) {
21+
for (var s, i = 1, n = arguments.length; i < n; i++) {
22+
s = arguments[i];
23+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
24+
t[p] = s[p];
25+
}
26+
return t;
27+
};
28+
return __assign.apply(this, arguments);
29+
};
30+
var f = function (_) { return function () {
31+
var _ = [];
32+
for (var _i = 0; _i < arguments.length; _i++) {
33+
_[_i] = arguments[_i];
34+
}
35+
return "";
36+
}; };
37+
f(__assign({ x: 0 }))(__makeTemplateObject([""], [""]));
38+
f(__assign({ x: 0 }))(__makeTemplateObject(["x"], ["x"]));
39+
f(__assign({ x: 0 }))(__makeTemplateObject(["x", "x"], ["x", "x"]), f);
40+
f(__assign({ x: 0 }, { y: (function () { return 1; })() }))(__makeTemplateObject([""], [""]));
41+
f(__assign({ x: (function () { return 1; })() }, { y: 1 }))(__makeTemplateObject([""], [""]));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/taggedTemplateStringsWithCurriedFunction.ts ===
2+
// Originated from #38558
3+
4+
const f = _ => (..._) => "";
5+
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
6+
>_ : Symbol(_, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 9))
7+
>_ : Symbol(_, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 16))
8+
9+
f({ ...{ x: 0 } })``;
10+
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
11+
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 4, 8))
12+
13+
f({ ...{ x: 0 } })`x`;
14+
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
15+
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 5, 8))
16+
17+
f({ ...{ x: 0 } })`x${f}x`;
18+
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
19+
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 6, 8))
20+
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
21+
22+
f({ ...{ x: 0 }, y: (() => 1)() })``;
23+
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
24+
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 7, 8))
25+
>y : Symbol(y, Decl(taggedTemplateStringsWithCurriedFunction.ts, 7, 16))
26+
27+
f({ x: (() => 1)(), ...{ y: 1 } })``;
28+
>f : Symbol(f, Decl(taggedTemplateStringsWithCurriedFunction.ts, 2, 5))
29+
>x : Symbol(x, Decl(taggedTemplateStringsWithCurriedFunction.ts, 8, 3))
30+
>y : Symbol(y, Decl(taggedTemplateStringsWithCurriedFunction.ts, 8, 24))
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
=== tests/cases/compiler/taggedTemplateStringsWithCurriedFunction.ts ===
2+
// Originated from #38558
3+
4+
const f = _ => (..._) => "";
5+
>f : (_: any) => (..._: any[]) => string
6+
>_ => (..._) => "" : (_: any) => (..._: any[]) => string
7+
>_ : any
8+
>(..._) => "" : (..._: any[]) => string
9+
>_ : any[]
10+
>"" : ""
11+
12+
f({ ...{ x: 0 } })``;
13+
>f({ ...{ x: 0 } })`` : string
14+
>f({ ...{ x: 0 } }) : (..._: any[]) => string
15+
>f : (_: any) => (..._: any[]) => string
16+
>{ ...{ x: 0 } } : { x: number; }
17+
>{ x: 0 } : { x: number; }
18+
>x : number
19+
>0 : 0
20+
>`` : ""
21+
22+
f({ ...{ x: 0 } })`x`;
23+
>f({ ...{ x: 0 } })`x` : string
24+
>f({ ...{ x: 0 } }) : (..._: any[]) => string
25+
>f : (_: any) => (..._: any[]) => string
26+
>{ ...{ x: 0 } } : { x: number; }
27+
>{ x: 0 } : { x: number; }
28+
>x : number
29+
>0 : 0
30+
>`x` : "x"
31+
32+
f({ ...{ x: 0 } })`x${f}x`;
33+
>f({ ...{ x: 0 } })`x${f}x` : string
34+
>f({ ...{ x: 0 } }) : (..._: any[]) => string
35+
>f : (_: any) => (..._: any[]) => string
36+
>{ ...{ x: 0 } } : { x: number; }
37+
>{ x: 0 } : { x: number; }
38+
>x : number
39+
>0 : 0
40+
>`x${f}x` : string
41+
>f : (_: any) => (..._: any[]) => string
42+
43+
f({ ...{ x: 0 }, y: (() => 1)() })``;
44+
>f({ ...{ x: 0 }, y: (() => 1)() })`` : string
45+
>f({ ...{ x: 0 }, y: (() => 1)() }) : (..._: any[]) => string
46+
>f : (_: any) => (..._: any[]) => string
47+
>{ ...{ x: 0 }, y: (() => 1)() } : { y: number; x: number; }
48+
>{ x: 0 } : { x: number; }
49+
>x : number
50+
>0 : 0
51+
>y : number
52+
>(() => 1)() : number
53+
>(() => 1) : () => number
54+
>() => 1 : () => number
55+
>1 : 1
56+
>`` : ""
57+
58+
f({ x: (() => 1)(), ...{ y: 1 } })``;
59+
>f({ x: (() => 1)(), ...{ y: 1 } })`` : string
60+
>f({ x: (() => 1)(), ...{ y: 1 } }) : (..._: any[]) => string
61+
>f : (_: any) => (..._: any[]) => string
62+
>{ x: (() => 1)(), ...{ y: 1 } } : { y: number; x: number; }
63+
>x : number
64+
>(() => 1)() : number
65+
>(() => 1) : () => number
66+
>() => 1 : () => number
67+
>1 : 1
68+
>{ y: 1 } : { y: number; }
69+
>y : number
70+
>1 : 1
71+
>`` : ""
72+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@target: es3
2+
3+
// Originated from #38558
4+
5+
const f = _ => (..._) => "";
6+
7+
f({ ...{ x: 0 } })``;
8+
f({ ...{ x: 0 } })`x`;
9+
f({ ...{ x: 0 } })`x${f}x`;
10+
f({ ...{ x: 0 }, y: (() => 1)() })``;
11+
f({ x: (() => 1)(), ...{ y: 1 } })``;

0 commit comments

Comments
 (0)