Skip to content

Commit 2552a7b

Browse files
Merge pull request #178 from microsoft/main
Create a new pull request by comparing changes
2 parents 996a62f + ce487e4 commit 2552a7b

28 files changed

+361
-12
lines changed

src/compiler/checker.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28946,10 +28946,17 @@ namespace ts {
2894628946
prop = getPropertyOfType(apparentType, right.escapedText);
2894728947
}
2894828948
// In `Foo.Bar.Baz`, 'Foo' is not referenced if 'Bar' is a const enum or a module containing only const enums.
28949+
// `Foo` is also not referenced in `enum FooCopy { Bar = Foo.Bar }`, because the enum member value gets inlined
28950+
// here even if `Foo` is not a const enum.
28951+
//
2894928952
// The exceptions are:
2895028953
// 1. if 'isolatedModules' is enabled, because the const enum value will not be inlined, and
2895128954
// 2. if 'preserveConstEnums' is enabled and the expression is itself an export, e.g. `export = Foo.Bar.Baz`.
28952-
if (isIdentifier(left) && parentSymbol && (compilerOptions.isolatedModules || !(prop && isConstEnumOrConstEnumOnlyModule(prop)) || shouldPreserveConstEnums(compilerOptions) && isExportOrExportExpression(node))) {
28955+
if (isIdentifier(left) && parentSymbol && (
28956+
compilerOptions.isolatedModules ||
28957+
!(prop && (isConstEnumOrConstEnumOnlyModule(prop) || prop.flags & SymbolFlags.EnumMember && node.parent.kind === SyntaxKind.EnumMember)) ||
28958+
shouldPreserveConstEnums(compilerOptions) && isExportOrExportExpression(node)
28959+
)) {
2895328960
markAliasReferenced(parentSymbol, node);
2895428961
}
2895528962

@@ -40224,7 +40231,7 @@ namespace ts {
4022440231

4022540232
function isConstantMemberAccess(node: Expression): node is AccessExpression {
4022640233
const type = getTypeOfExpression(node);
40227-
if(type === errorType) {
40234+
if (type === errorType) {
4022840235
return false;
4022940236
}
4023040237

@@ -41975,15 +41982,20 @@ namespace ts {
4197541982
return propertyDeclaration;
4197641983
}
4197741984
}
41978-
else if (isMetaProperty(parent)) {
41979-
const parentType = getTypeOfNode(parent);
41980-
const propertyDeclaration = getPropertyOfType(parentType, (node as Identifier).escapedText);
41981-
if (propertyDeclaration) {
41982-
return propertyDeclaration;
41983-
}
41984-
if (parent.keywordToken === SyntaxKind.NewKeyword) {
41985+
else if (isMetaProperty(parent) && parent.name === node) {
41986+
if (parent.keywordToken === SyntaxKind.NewKeyword && idText(node as Identifier) === "target") {
41987+
// `target` in `new.target`
4198541988
return checkNewTargetMetaProperty(parent).symbol;
4198641989
}
41990+
// The `meta` in `import.meta` could be given `getTypeOfNode(parent).symbol` (the `ImportMeta` interface symbol), but
41991+
// we have a fake expression type made for other reasons already, whose transient `meta`
41992+
// member should more exactly be the kind of (declarationless) symbol we want.
41993+
// (See #44364 and #45031 for relevant implementation PRs)
41994+
if (parent.keywordToken === SyntaxKind.ImportKeyword && idText(node as Identifier) === "meta") {
41995+
return getGlobalImportMetaExpressionType().members!.get("meta" as __String);
41996+
}
41997+
// no other meta properties are valid syntax, thus no others should have symbols
41998+
return undefined;
4198741999
}
4198842000
}
4198942001

src/compiler/transformers/es2015.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ namespace ts {
11461146
[
11471147
...existingPrologue,
11481148
...prologue,
1149-
...(superStatementIndex <= existingPrologue.length ? emptyArray : visitNodes(constructor.body.statements, visitor, isStatement, existingPrologue.length, superStatementIndex)),
1149+
...(superStatementIndex <= existingPrologue.length ? emptyArray : visitNodes(constructor.body.statements, visitor, isStatement, existingPrologue.length, superStatementIndex - existingPrologue.length)),
11501150
...statements
11511151
]
11521152
),
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//// [constructorWithSuperAndPrologue.es5.ts]
2+
// https://github.com/microsoft/TypeScript/issues/48761
3+
"use strict";
4+
5+
class A {
6+
public constructor() {
7+
console.log("A")
8+
}
9+
}
10+
11+
class B extends A {
12+
constructor() {
13+
"ngInject";
14+
console.log("B")
15+
super();
16+
}
17+
}
18+
19+
20+
//// [constructorWithSuperAndPrologue.es5.js]
21+
// https://github.com/microsoft/TypeScript/issues/48761
22+
"use strict";
23+
var __extends = (this && this.__extends) || (function () {
24+
var extendStatics = function (d, b) {
25+
extendStatics = Object.setPrototypeOf ||
26+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
27+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
28+
return extendStatics(d, b);
29+
};
30+
return function (d, b) {
31+
if (typeof b !== "function" && b !== null)
32+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
33+
extendStatics(d, b);
34+
function __() { this.constructor = d; }
35+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36+
};
37+
})();
38+
var A = /** @class */ (function () {
39+
function A() {
40+
console.log("A");
41+
}
42+
return A;
43+
}());
44+
var B = /** @class */ (function (_super) {
45+
__extends(B, _super);
46+
function B() {
47+
"ngInject";
48+
console.log("B");
49+
return _super.call(this) || this;
50+
}
51+
return B;
52+
}(A));
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/constructorWithSuperAndPrologue.es5.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/48761
3+
"use strict";
4+
5+
class A {
6+
>A : Symbol(A, Decl(constructorWithSuperAndPrologue.es5.ts, 1, 13))
7+
8+
public constructor() {
9+
console.log("A")
10+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
11+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
12+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
13+
}
14+
}
15+
16+
class B extends A {
17+
>B : Symbol(B, Decl(constructorWithSuperAndPrologue.es5.ts, 7, 1))
18+
>A : Symbol(A, Decl(constructorWithSuperAndPrologue.es5.ts, 1, 13))
19+
20+
constructor() {
21+
"ngInject";
22+
console.log("B")
23+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
24+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
25+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
26+
27+
super();
28+
>super : Symbol(A, Decl(constructorWithSuperAndPrologue.es5.ts, 1, 13))
29+
}
30+
}
31+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=== tests/cases/compiler/constructorWithSuperAndPrologue.es5.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/48761
3+
"use strict";
4+
>"use strict" : "use strict"
5+
6+
class A {
7+
>A : A
8+
9+
public constructor() {
10+
console.log("A")
11+
>console.log("A") : void
12+
>console.log : (...data: any[]) => void
13+
>console : Console
14+
>log : (...data: any[]) => void
15+
>"A" : "A"
16+
}
17+
}
18+
19+
class B extends A {
20+
>B : B
21+
>A : A
22+
23+
constructor() {
24+
"ngInject";
25+
>"ngInject" : "ngInject"
26+
27+
console.log("B")
28+
>console.log("B") : void
29+
>console.log : (...data: any[]) => void
30+
>console : Console
31+
>log : (...data: any[]) => void
32+
>"B" : "B"
33+
34+
super();
35+
>super() : void
36+
>super : typeof A
37+
}
38+
}
39+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//// [tests/cases/compiler/importElisionEnum.ts] ////
2+
3+
//// [enum.ts]
4+
export enum MyEnum {
5+
a = 0,
6+
b,
7+
c,
8+
d
9+
}
10+
11+
//// [index.ts]
12+
import { MyEnum as MyEnumFromModule } from "./enum";
13+
14+
enum MyEnum {
15+
a = MyEnumFromModule.a
16+
}
17+
18+
//// [enum.js]
19+
"use strict";
20+
exports.__esModule = true;
21+
exports.MyEnum = void 0;
22+
var MyEnum;
23+
(function (MyEnum) {
24+
MyEnum[MyEnum["a"] = 0] = "a";
25+
MyEnum[MyEnum["b"] = 1] = "b";
26+
MyEnum[MyEnum["c"] = 2] = "c";
27+
MyEnum[MyEnum["d"] = 3] = "d";
28+
})(MyEnum = exports.MyEnum || (exports.MyEnum = {}));
29+
//// [index.js]
30+
"use strict";
31+
exports.__esModule = true;
32+
var MyEnum;
33+
(function (MyEnum) {
34+
MyEnum[MyEnum["a"] = 0] = "a";
35+
})(MyEnum || (MyEnum = {}));
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/enum.ts ===
2+
export enum MyEnum {
3+
>MyEnum : Symbol(MyEnum, Decl(enum.ts, 0, 0))
4+
5+
a = 0,
6+
>a : Symbol(MyEnum.a, Decl(enum.ts, 0, 20))
7+
8+
b,
9+
>b : Symbol(MyEnum.b, Decl(enum.ts, 1, 8))
10+
11+
c,
12+
>c : Symbol(MyEnum.c, Decl(enum.ts, 2, 4))
13+
14+
d
15+
>d : Symbol(MyEnum.d, Decl(enum.ts, 3, 4))
16+
}
17+
18+
=== tests/cases/compiler/index.ts ===
19+
import { MyEnum as MyEnumFromModule } from "./enum";
20+
>MyEnum : Symbol(MyEnumFromModule, Decl(enum.ts, 0, 0))
21+
>MyEnumFromModule : Symbol(MyEnumFromModule, Decl(index.ts, 0, 8))
22+
23+
enum MyEnum {
24+
>MyEnum : Symbol(MyEnum, Decl(index.ts, 0, 52))
25+
26+
a = MyEnumFromModule.a
27+
>a : Symbol(MyEnum.a, Decl(index.ts, 2, 13))
28+
>MyEnumFromModule.a : Symbol(MyEnumFromModule.a, Decl(enum.ts, 0, 20))
29+
>MyEnumFromModule : Symbol(MyEnumFromModule, Decl(index.ts, 0, 8))
30+
>a : Symbol(MyEnumFromModule.a, Decl(enum.ts, 0, 20))
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/compiler/enum.ts ===
2+
export enum MyEnum {
3+
>MyEnum : MyEnum
4+
5+
a = 0,
6+
>a : MyEnum.a
7+
>0 : 0
8+
9+
b,
10+
>b : MyEnum.b
11+
12+
c,
13+
>c : MyEnum.c
14+
15+
d
16+
>d : MyEnum.d
17+
}
18+
19+
=== tests/cases/compiler/index.ts ===
20+
import { MyEnum as MyEnumFromModule } from "./enum";
21+
>MyEnum : typeof MyEnumFromModule
22+
>MyEnumFromModule : typeof MyEnumFromModule
23+
24+
enum MyEnum {
25+
>MyEnum : MyEnum
26+
27+
a = MyEnumFromModule.a
28+
>a : MyEnum
29+
>MyEnumFromModule.a : MyEnumFromModule.a
30+
>MyEnumFromModule : typeof MyEnumFromModule
31+
>a : MyEnumFromModule.a
32+
}

tests/baselines/reference/importMeta(module=commonjs,target=es5).symbols

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
>URL : Symbol(URL, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
99
>import.meta.url : Symbol(ImportMeta.url, Decl(lib.dom.d.ts, --, --))
1010
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
11+
>meta : Symbol(ImportMetaExpression.meta)
1112
>url : Symbol(ImportMeta.url, Decl(lib.dom.d.ts, --, --))
1213
>toString : Symbol(URL.toString, Decl(lib.dom.d.ts, --, --))
1314

@@ -20,6 +21,7 @@
2021
const size = import.meta.scriptElement.dataset.size || 300;
2122
>size : Symbol(size, Decl(example.ts, 5, 7))
2223
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
24+
>meta : Symbol(ImportMetaExpression.meta)
2325

2426
const image = new Image();
2527
>image : Symbol(image, Decl(example.ts, 7, 7))
@@ -57,6 +59,7 @@
5759
export let x = import.meta;
5860
>x : Symbol(x, Decl(moduleLookingFile01.ts, 0, 10))
5961
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
62+
>meta : Symbol(ImportMetaExpression.meta)
6063

6164
export let y = import.metal;
6265
>y : Symbol(y, Decl(moduleLookingFile01.ts, 1, 10))
@@ -68,6 +71,7 @@ export let z = import.import.import.malkovich;
6871
let globalA = import.meta;
6972
>globalA : Symbol(globalA, Decl(scriptLookingFile01.ts, 0, 3))
7073
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
74+
>meta : Symbol(ImportMetaExpression.meta)
7175

7276
let globalB = import.metal;
7377
>globalB : Symbol(globalB, Decl(scriptLookingFile01.ts, 1, 3))
@@ -80,11 +84,15 @@ export const foo: ImportMeta = import.meta.blah = import.meta.blue = import.meta
8084
>foo : Symbol(foo, Decl(assignmentTargets.ts, 0, 12))
8185
>ImportMeta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
8286
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
87+
>meta : Symbol(ImportMetaExpression.meta)
8388
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
89+
>meta : Symbol(ImportMetaExpression.meta)
8490
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
91+
>meta : Symbol(ImportMetaExpression.meta)
8592

8693
import.meta = foo;
8794
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
95+
>meta : Symbol(ImportMetaExpression.meta)
8896
>foo : Symbol(foo, Decl(assignmentTargets.ts, 0, 12))
8997

9098
// @Filename augmentations.ts
@@ -108,5 +116,6 @@ const { a, b, c } = import.meta.wellKnownProperty;
108116
>c : Symbol(c, Decl(assignmentTargets.ts, 10, 13))
109117
>import.meta.wellKnownProperty : Symbol(ImportMeta.wellKnownProperty, Decl(assignmentTargets.ts, 5, 24))
110118
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
119+
>meta : Symbol(ImportMetaExpression.meta)
111120
>wellKnownProperty : Symbol(ImportMeta.wellKnownProperty, Decl(assignmentTargets.ts, 5, 24))
112121

0 commit comments

Comments
 (0)