Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 21 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28946,10 +28946,17 @@ namespace ts {
prop = getPropertyOfType(apparentType, right.escapedText);
}
// In `Foo.Bar.Baz`, 'Foo' is not referenced if 'Bar' is a const enum or a module containing only const enums.
// `Foo` is also not referenced in `enum FooCopy { Bar = Foo.Bar }`, because the enum member value gets inlined
// here even if `Foo` is not a const enum.
//
// The exceptions are:
// 1. if 'isolatedModules' is enabled, because the const enum value will not be inlined, and
// 2. if 'preserveConstEnums' is enabled and the expression is itself an export, e.g. `export = Foo.Bar.Baz`.
if (isIdentifier(left) && parentSymbol && (compilerOptions.isolatedModules || !(prop && isConstEnumOrConstEnumOnlyModule(prop)) || shouldPreserveConstEnums(compilerOptions) && isExportOrExportExpression(node))) {
if (isIdentifier(left) && parentSymbol && (
compilerOptions.isolatedModules ||
!(prop && (isConstEnumOrConstEnumOnlyModule(prop) || prop.flags & SymbolFlags.EnumMember && node.parent.kind === SyntaxKind.EnumMember)) ||
shouldPreserveConstEnums(compilerOptions) && isExportOrExportExpression(node)
)) {
markAliasReferenced(parentSymbol, node);
}

Expand Down Expand Up @@ -40224,7 +40231,7 @@ namespace ts {

function isConstantMemberAccess(node: Expression): node is AccessExpression {
const type = getTypeOfExpression(node);
if(type === errorType) {
if (type === errorType) {
return false;
}

Expand Down Expand Up @@ -41975,15 +41982,20 @@ namespace ts {
return propertyDeclaration;
}
}
else if (isMetaProperty(parent)) {
const parentType = getTypeOfNode(parent);
const propertyDeclaration = getPropertyOfType(parentType, (node as Identifier).escapedText);
if (propertyDeclaration) {
return propertyDeclaration;
}
if (parent.keywordToken === SyntaxKind.NewKeyword) {
else if (isMetaProperty(parent) && parent.name === node) {
if (parent.keywordToken === SyntaxKind.NewKeyword && idText(node as Identifier) === "target") {
// `target` in `new.target`
return checkNewTargetMetaProperty(parent).symbol;
}
// The `meta` in `import.meta` could be given `getTypeOfNode(parent).symbol` (the `ImportMeta` interface symbol), but
// we have a fake expression type made for other reasons already, whose transient `meta`
// member should more exactly be the kind of (declarationless) symbol we want.
// (See #44364 and #45031 for relevant implementation PRs)
if (parent.keywordToken === SyntaxKind.ImportKeyword && idText(node as Identifier) === "meta") {
return getGlobalImportMetaExpressionType().members!.get("meta" as __String);
}
// no other meta properties are valid syntax, thus no others should have symbols
return undefined;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ namespace ts {
[
...existingPrologue,
...prologue,
...(superStatementIndex <= existingPrologue.length ? emptyArray : visitNodes(constructor.body.statements, visitor, isStatement, existingPrologue.length, superStatementIndex)),
...(superStatementIndex <= existingPrologue.length ? emptyArray : visitNodes(constructor.body.statements, visitor, isStatement, existingPrologue.length, superStatementIndex - existingPrologue.length)),
...statements
]
),
Expand Down
52 changes: 52 additions & 0 deletions tests/baselines/reference/constructorWithSuperAndPrologue.es5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//// [constructorWithSuperAndPrologue.es5.ts]
// https://github.com/microsoft/TypeScript/issues/48761
"use strict";

class A {
public constructor() {
console.log("A")
}
}

class B extends A {
constructor() {
"ngInject";
console.log("B")
super();
}
}


//// [constructorWithSuperAndPrologue.es5.js]
// https://github.com/microsoft/TypeScript/issues/48761
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var A = /** @class */ (function () {
function A() {
console.log("A");
}
return A;
}());
var B = /** @class */ (function (_super) {
__extends(B, _super);
function B() {
"ngInject";
console.log("B");
return _super.call(this) || this;
}
return B;
}(A));
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
=== tests/cases/compiler/constructorWithSuperAndPrologue.es5.ts ===
// https://github.com/microsoft/TypeScript/issues/48761
"use strict";

class A {
>A : Symbol(A, Decl(constructorWithSuperAndPrologue.es5.ts, 1, 13))

public constructor() {
console.log("A")
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
}
}

class B extends A {
>B : Symbol(B, Decl(constructorWithSuperAndPrologue.es5.ts, 7, 1))
>A : Symbol(A, Decl(constructorWithSuperAndPrologue.es5.ts, 1, 13))

constructor() {
"ngInject";
console.log("B")
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))

super();
>super : Symbol(A, Decl(constructorWithSuperAndPrologue.es5.ts, 1, 13))
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
=== tests/cases/compiler/constructorWithSuperAndPrologue.es5.ts ===
// https://github.com/microsoft/TypeScript/issues/48761
"use strict";
>"use strict" : "use strict"

class A {
>A : A

public constructor() {
console.log("A")
>console.log("A") : void
>console.log : (...data: any[]) => void
>console : Console
>log : (...data: any[]) => void
>"A" : "A"
}
}

class B extends A {
>B : B
>A : A

constructor() {
"ngInject";
>"ngInject" : "ngInject"

console.log("B")
>console.log("B") : void
>console.log : (...data: any[]) => void
>console : Console
>log : (...data: any[]) => void
>"B" : "B"

super();
>super() : void
>super : typeof A
}
}

35 changes: 35 additions & 0 deletions tests/baselines/reference/importElisionEnum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [tests/cases/compiler/importElisionEnum.ts] ////

//// [enum.ts]
export enum MyEnum {
a = 0,
b,
c,
d
}

//// [index.ts]
import { MyEnum as MyEnumFromModule } from "./enum";

enum MyEnum {
a = MyEnumFromModule.a
}

//// [enum.js]
"use strict";
exports.__esModule = true;
exports.MyEnum = void 0;
var MyEnum;
(function (MyEnum) {
MyEnum[MyEnum["a"] = 0] = "a";
MyEnum[MyEnum["b"] = 1] = "b";
MyEnum[MyEnum["c"] = 2] = "c";
MyEnum[MyEnum["d"] = 3] = "d";
})(MyEnum = exports.MyEnum || (exports.MyEnum = {}));
//// [index.js]
"use strict";
exports.__esModule = true;
var MyEnum;
(function (MyEnum) {
MyEnum[MyEnum["a"] = 0] = "a";
})(MyEnum || (MyEnum = {}));
31 changes: 31 additions & 0 deletions tests/baselines/reference/importElisionEnum.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
=== tests/cases/compiler/enum.ts ===
export enum MyEnum {
>MyEnum : Symbol(MyEnum, Decl(enum.ts, 0, 0))

a = 0,
>a : Symbol(MyEnum.a, Decl(enum.ts, 0, 20))

b,
>b : Symbol(MyEnum.b, Decl(enum.ts, 1, 8))

c,
>c : Symbol(MyEnum.c, Decl(enum.ts, 2, 4))

d
>d : Symbol(MyEnum.d, Decl(enum.ts, 3, 4))
}

=== tests/cases/compiler/index.ts ===
import { MyEnum as MyEnumFromModule } from "./enum";
>MyEnum : Symbol(MyEnumFromModule, Decl(enum.ts, 0, 0))
>MyEnumFromModule : Symbol(MyEnumFromModule, Decl(index.ts, 0, 8))

enum MyEnum {
>MyEnum : Symbol(MyEnum, Decl(index.ts, 0, 52))

a = MyEnumFromModule.a
>a : Symbol(MyEnum.a, Decl(index.ts, 2, 13))
>MyEnumFromModule.a : Symbol(MyEnumFromModule.a, Decl(enum.ts, 0, 20))
>MyEnumFromModule : Symbol(MyEnumFromModule, Decl(index.ts, 0, 8))
>a : Symbol(MyEnumFromModule.a, Decl(enum.ts, 0, 20))
}
32 changes: 32 additions & 0 deletions tests/baselines/reference/importElisionEnum.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
=== tests/cases/compiler/enum.ts ===
export enum MyEnum {
>MyEnum : MyEnum

a = 0,
>a : MyEnum.a
>0 : 0

b,
>b : MyEnum.b

c,
>c : MyEnum.c

d
>d : MyEnum.d
}

=== tests/cases/compiler/index.ts ===
import { MyEnum as MyEnumFromModule } from "./enum";
>MyEnum : typeof MyEnumFromModule
>MyEnumFromModule : typeof MyEnumFromModule

enum MyEnum {
>MyEnum : MyEnum

a = MyEnumFromModule.a
>a : MyEnum
>MyEnumFromModule.a : MyEnumFromModule.a
>MyEnumFromModule : typeof MyEnumFromModule
>a : MyEnumFromModule.a
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
>URL : Symbol(URL, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>import.meta.url : Symbol(ImportMeta.url, Decl(lib.dom.d.ts, --, --))
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
>meta : Symbol(ImportMetaExpression.meta)
>url : Symbol(ImportMeta.url, Decl(lib.dom.d.ts, --, --))
>toString : Symbol(URL.toString, Decl(lib.dom.d.ts, --, --))

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

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

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

let globalB = import.metal;
>globalB : Symbol(globalB, Decl(scriptLookingFile01.ts, 1, 3))
Expand All @@ -80,11 +84,15 @@ export const foo: ImportMeta = import.meta.blah = import.meta.blue = import.meta
>foo : Symbol(foo, Decl(assignmentTargets.ts, 0, 12))
>ImportMeta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
>meta : Symbol(ImportMetaExpression.meta)
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
>meta : Symbol(ImportMetaExpression.meta)
>import.meta : Symbol(ImportMeta, Decl(lib.es5.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(assignmentTargets.ts, 4, 16))
>meta : Symbol(ImportMetaExpression.meta)

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

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

Loading