mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:13:31 -06:00
fix(44725): handle this parameter in tagged template call (#44734)
This commit is contained in:
parent
fdc31baffe
commit
114f68cd3d
@ -28724,8 +28724,10 @@ namespace ts {
|
||||
* Returns the this argument in calls like x.f(...) and x[f](...). Undefined otherwise.
|
||||
*/
|
||||
function getThisArgumentOfCall(node: CallLikeExpression): LeftHandSideExpression | undefined {
|
||||
if (node.kind === SyntaxKind.CallExpression) {
|
||||
const callee = skipOuterExpressions(node.expression);
|
||||
const expression = node.kind === SyntaxKind.CallExpression ? node.expression :
|
||||
node.kind === SyntaxKind.TaggedTemplateExpression ? node.tag : undefined;
|
||||
if (expression) {
|
||||
const callee = skipOuterExpressions(expression);
|
||||
if (isAccessExpression(callee)) {
|
||||
return callee.expression;
|
||||
}
|
||||
|
||||
19
tests/baselines/reference/thisTypeInTaggedTemplateCall.js
Normal file
19
tests/baselines/reference/thisTypeInTaggedTemplateCall.js
Normal file
@ -0,0 +1,19 @@
|
||||
//// [thisTypeInTaggedTemplateCall.ts]
|
||||
class Foo {
|
||||
static m<T>(this: new () => T, strings: TemplateStringsArray | string) {
|
||||
return new this()
|
||||
}
|
||||
}
|
||||
|
||||
Foo.m`test`;
|
||||
(Foo.m)`test`;
|
||||
|
||||
|
||||
//// [thisTypeInTaggedTemplateCall.js]
|
||||
class Foo {
|
||||
static m(strings) {
|
||||
return new this();
|
||||
}
|
||||
}
|
||||
Foo.m `test`;
|
||||
(Foo.m) `test`;
|
||||
@ -0,0 +1,27 @@
|
||||
=== tests/cases/conformance/types/thisType/thisTypeInTaggedTemplateCall.ts ===
|
||||
class Foo {
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInTaggedTemplateCall.ts, 0, 0))
|
||||
|
||||
static m<T>(this: new () => T, strings: TemplateStringsArray | string) {
|
||||
>m : Symbol(Foo.m, Decl(thisTypeInTaggedTemplateCall.ts, 0, 11))
|
||||
>T : Symbol(T, Decl(thisTypeInTaggedTemplateCall.ts, 1, 13))
|
||||
>this : Symbol(this, Decl(thisTypeInTaggedTemplateCall.ts, 1, 16))
|
||||
>T : Symbol(T, Decl(thisTypeInTaggedTemplateCall.ts, 1, 13))
|
||||
>strings : Symbol(strings, Decl(thisTypeInTaggedTemplateCall.ts, 1, 34))
|
||||
>TemplateStringsArray : Symbol(TemplateStringsArray, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
return new this()
|
||||
>this : Symbol(this, Decl(thisTypeInTaggedTemplateCall.ts, 1, 16))
|
||||
}
|
||||
}
|
||||
|
||||
Foo.m`test`;
|
||||
>Foo.m : Symbol(Foo.m, Decl(thisTypeInTaggedTemplateCall.ts, 0, 11))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInTaggedTemplateCall.ts, 0, 0))
|
||||
>m : Symbol(Foo.m, Decl(thisTypeInTaggedTemplateCall.ts, 0, 11))
|
||||
|
||||
(Foo.m)`test`;
|
||||
>Foo.m : Symbol(Foo.m, Decl(thisTypeInTaggedTemplateCall.ts, 0, 11))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInTaggedTemplateCall.ts, 0, 0))
|
||||
>m : Symbol(Foo.m, Decl(thisTypeInTaggedTemplateCall.ts, 0, 11))
|
||||
|
||||
30
tests/baselines/reference/thisTypeInTaggedTemplateCall.types
Normal file
30
tests/baselines/reference/thisTypeInTaggedTemplateCall.types
Normal file
@ -0,0 +1,30 @@
|
||||
=== tests/cases/conformance/types/thisType/thisTypeInTaggedTemplateCall.ts ===
|
||||
class Foo {
|
||||
>Foo : Foo
|
||||
|
||||
static m<T>(this: new () => T, strings: TemplateStringsArray | string) {
|
||||
>m : <T>(this: new () => T, strings: TemplateStringsArray | string) => T
|
||||
>this : new () => T
|
||||
>strings : string | TemplateStringsArray
|
||||
|
||||
return new this()
|
||||
>new this() : T
|
||||
>this : new () => T
|
||||
}
|
||||
}
|
||||
|
||||
Foo.m`test`;
|
||||
>Foo.m`test` : Foo
|
||||
>Foo.m : <T>(this: new () => T, strings: string | TemplateStringsArray) => T
|
||||
>Foo : typeof Foo
|
||||
>m : <T>(this: new () => T, strings: string | TemplateStringsArray) => T
|
||||
>`test` : "test"
|
||||
|
||||
(Foo.m)`test`;
|
||||
>(Foo.m)`test` : Foo
|
||||
>(Foo.m) : <T>(this: new () => T, strings: string | TemplateStringsArray) => T
|
||||
>Foo.m : <T>(this: new () => T, strings: string | TemplateStringsArray) => T
|
||||
>Foo : typeof Foo
|
||||
>m : <T>(this: new () => T, strings: string | TemplateStringsArray) => T
|
||||
>`test` : "test"
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
// @target: esnext
|
||||
|
||||
class Foo {
|
||||
static m<T>(this: new () => T, strings: TemplateStringsArray | string) {
|
||||
return new this()
|
||||
}
|
||||
}
|
||||
|
||||
Foo.m`test`;
|
||||
(Foo.m)`test`;
|
||||
Loading…
x
Reference in New Issue
Block a user