Skip to content

Commit d8d8609

Browse files
committed
Merge branch 'main' into timestamps
2 parents cb73874 + d81a976 commit d8d8609

21 files changed

+526
-16
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/checker.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15737,11 +15737,14 @@ namespace ts {
1573715737
return type[cache] = elementType;
1573815738
}
1573915739
}
15740-
// If the object type is a mapped type { [P in K]: E }, where K is generic, instantiate E using a mapper
15741-
// that substitutes the index type for P. For example, for an index access { [P in K]: Box<T[P]> }[X], we
15742-
// construct the type Box<T[X]>.
15743-
if (isGenericMappedType(objectType) && !objectType.declaration.nameType) {
15744-
return type[cache] = mapType(substituteIndexedMappedType(objectType, type.indexType), t => getSimplifiedType(t, writing));
15740+
// If the object type is a mapped type { [P in K]: E }, where K is generic, or { [P in K as N]: E }, where
15741+
// K is generic and N is assignable to P, instantiate E using a mapper that substitutes the index type for P.
15742+
// For example, for an index access { [P in K]: Box<T[P]> }[X], we construct the type Box<T[X]>.
15743+
if (isGenericMappedType(objectType)) {
15744+
const nameType = getNameTypeFromMappedType(objectType);
15745+
if (!nameType || isTypeAssignableTo(nameType, getTypeParameterFromMappedType(objectType))) {
15746+
return type[cache] = mapType(substituteIndexedMappedType(objectType, type.indexType), t => getSimplifiedType(t, writing));
15747+
}
1574515748
}
1574615749
return type[cache] = type;
1574715750
}
@@ -28943,10 +28946,17 @@ namespace ts {
2894328946
prop = getPropertyOfType(apparentType, right.escapedText);
2894428947
}
2894528948
// 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+
//
2894628952
// The exceptions are:
2894728953
// 1. if 'isolatedModules' is enabled, because the const enum value will not be inlined, and
2894828954
// 2. if 'preserveConstEnums' is enabled and the expression is itself an export, e.g. `export = Foo.Bar.Baz`.
28949-
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+
)) {
2895028960
markAliasReferenced(parentSymbol, node);
2895128961
}
2895228962

@@ -40221,7 +40231,7 @@ namespace ts {
4022140231

4022240232
function isConstantMemberAccess(node: Expression): node is AccessExpression {
4022340233
const type = getTypeOfExpression(node);
40224-
if(type === errorType) {
40234+
if (type === errorType) {
4022540235
return false;
4022640236
}
4022740237

src/compiler/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3189,7 +3189,8 @@ namespace ts {
31893189
const pos = getNodePos();
31903190
parseExpected(SyntaxKind.TypeOfKeyword);
31913191
const entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true);
3192-
const typeArguments = tryParseTypeArguments();
3192+
// Make sure we perform ASI to prevent parsing the next line's type arguments as part of an instantiation expression.
3193+
const typeArguments = !scanner.hasPrecedingLineBreak() ? tryParseTypeArguments() : undefined;
31933194
return finishNode(factory.createTypeQueryNode(entityName, typeArguments), pos);
31943195
}
31953196

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+
}

0 commit comments

Comments
 (0)