Extend the MetaProperty check to work for new.target too

This commit is contained in:
Eli Barzilay 2021-02-22 18:30:17 -05:00
parent d495957065
commit 67f55aabd7
5 changed files with 93 additions and 4 deletions

View file

@ -21322,10 +21322,8 @@ namespace ts {
switch (source.kind) {
case SyntaxKind.MetaProperty:
return target.kind === SyntaxKind.MetaProperty
&& (source as MetaProperty).keywordToken === SyntaxKind.ImportKeyword
&& (target as MetaProperty).keywordToken === SyntaxKind.ImportKeyword
&& (source as MetaProperty).name.escapedText === "meta"
&& (target as MetaProperty).name.escapedText === "meta";
&& (source as MetaProperty).keywordToken === (target as MetaProperty).keywordToken
&& (source as MetaProperty).name.escapedText === (target as MetaProperty).name.escapedText;
case SyntaxKind.Identifier:
case SyntaxKind.PrivateIdentifier:
return target.kind === SyntaxKind.Identifier && getResolvedSymbol(<Identifier>source) === getResolvedSymbol(<Identifier>target) ||

View file

@ -0,0 +1,21 @@
//// [newTargetNarrowing.ts]
function foo(x: true) { }
function f() {
if (new.target.marked === true) {
foo(new.target.marked);
}
}
f.marked = true;
//// [newTargetNarrowing.js]
"use strict";
function foo(x) { }
function f() {
if (new.target.marked === true) {
foo(new.target.marked);
}
}
f.marked = true;

View file

@ -0,0 +1,24 @@
=== tests/cases/conformance/es6/newTarget/newTargetNarrowing.ts ===
function foo(x: true) { }
>foo : Symbol(foo, Decl(newTargetNarrowing.ts, 0, 0))
>x : Symbol(x, Decl(newTargetNarrowing.ts, 0, 13))
function f() {
>f : Symbol(f, Decl(newTargetNarrowing.ts, 0, 25), Decl(newTargetNarrowing.ts, 6, 1))
if (new.target.marked === true) {
>new.target.marked : Symbol(f.marked, Decl(newTargetNarrowing.ts, 6, 1))
>marked : Symbol(f.marked, Decl(newTargetNarrowing.ts, 6, 1))
foo(new.target.marked);
>foo : Symbol(foo, Decl(newTargetNarrowing.ts, 0, 0))
>new.target.marked : Symbol(f.marked, Decl(newTargetNarrowing.ts, 6, 1))
>marked : Symbol(f.marked, Decl(newTargetNarrowing.ts, 6, 1))
}
}
f.marked = true;
>f.marked : Symbol(f.marked, Decl(newTargetNarrowing.ts, 6, 1))
>f : Symbol(f, Decl(newTargetNarrowing.ts, 0, 25), Decl(newTargetNarrowing.ts, 6, 1))
>marked : Symbol(f.marked, Decl(newTargetNarrowing.ts, 6, 1))

View file

@ -0,0 +1,34 @@
=== tests/cases/conformance/es6/newTarget/newTargetNarrowing.ts ===
function foo(x: true) { }
>foo : (x: true) => void
>x : true
>true : true
function f() {
>f : typeof f
if (new.target.marked === true) {
>new.target.marked === true : boolean
>new.target.marked : boolean
>new.target : typeof f
>target : any
>marked : boolean
>true : true
foo(new.target.marked);
>foo(new.target.marked) : void
>foo : (x: true) => void
>new.target.marked : true
>new.target : typeof f
>target : any
>marked : true
}
}
f.marked = true;
>f.marked = true : true
>f.marked : boolean
>f : typeof f
>marked : boolean
>true : true

View file

@ -0,0 +1,12 @@
// @target: es6
// @strict: true
function foo(x: true) { }
function f() {
if (new.target.marked === true) {
foo(new.target.marked);
}
}
f.marked = true;