Skip to content

Commit 35d2952

Browse files
TypeScript Botdragomirtitian
andauthored
🤖 Pick PR #58750 (Preserve elided imports used in dec...) into release-5.5 (#58757)
Co-authored-by: Titian Cernicova-Dragomir <[email protected]>
1 parent 4ee5d05 commit 35d2952

File tree

5 files changed

+153
-11
lines changed

5 files changed

+153
-11
lines changed

‎src/compiler/checker.ts‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8522,10 +8522,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
85228522
}
85238523

85248524
function createRecoveryBoundary() {
8525+
let trackedSymbols: TrackedSymbol[];
85258526
let unreportedErrors: (() => void)[];
85268527
const oldTracker = context.tracker;
85278528
const oldTrackedSymbols = context.trackedSymbols;
8528-
context.trackedSymbols = [];
8529+
context.trackedSymbols = undefined;
85298530
const oldEncounteredError = context.encounteredError;
85308531
context.tracker = new SymbolTrackerImpl(context, {
85318532
...oldTracker.inner,
@@ -8545,11 +8546,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
85458546
markError(() => oldTracker.reportNonSerializableProperty(name));
85468547
},
85478548
trackSymbol(sym, decl, meaning) {
8548-
const accessibility = isSymbolAccessible(sym, decl, meaning, /*shouldComputeAliasesToMakeVisible*/ false);
8549-
if (accessibility.accessibility !== SymbolAccessibility.Accessible) {
8550-
(context.trackedSymbols ??= []).push([sym, decl, meaning]);
8551-
return true;
8552-
}
8549+
(trackedSymbols ??= []).push([sym, decl, meaning]);
85538550
return false;
85548551
},
85558552
moduleResolverHost: context.tracker.moduleResolverHost,
@@ -8566,13 +8563,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
85668563
}
85678564

85688565
function startRecoveryScope() {
8569-
const initialTrackedSymbolsTop = context.trackedSymbols?.length ?? 0;
8566+
const trackedSymbolsTop = trackedSymbols?.length ?? 0;
85708567
const unreportedErrorsTop = unreportedErrors?.length ?? 0;
85718568
return () => {
85728569
hadError = false;
85738570
// Reset the tracked symbols to before the error
8574-
if (context.trackedSymbols) {
8575-
context.trackedSymbols.length = initialTrackedSymbolsTop;
8571+
if (trackedSymbols) {
8572+
trackedSymbols.length = trackedSymbolsTop;
85768573
}
85778574
if (unreportedErrors) {
85788575
unreportedErrors.length = unreportedErrorsTop;
@@ -8582,15 +8579,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
85828579

85838580
function finalizeBoundary() {
85848581
context.tracker = oldTracker;
8585-
const newTrackedSymbols = context.trackedSymbols;
85868582
context.trackedSymbols = oldTrackedSymbols;
85878583
context.encounteredError = oldEncounteredError;
85888584

85898585
unreportedErrors?.forEach(fn => fn());
85908586
if (hadError) {
85918587
return false;
85928588
}
8593-
newTrackedSymbols?.forEach(
8589+
trackedSymbols?.forEach(
85948590
([symbol, enclosingDeclaration, meaning]) =>
85958591
context.tracker.trackSymbol(
85968592
symbol,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//// [tests/cases/compiler/declarationEmitPreserveReferencedImports.ts] ////
2+
3+
//// [utils.ts]
4+
export interface Evt { }
5+
6+
7+
//// [decl.ts]
8+
import {Evt} from './utils'
9+
export const o = <T>(o: T) => () : T => null!
10+
11+
//// [main.ts]
12+
import { o } from './decl'
13+
import { Evt } from './utils'
14+
15+
export const f = { o: o({ v: null! as Evt}) };
16+
17+
//// [utils.js]
18+
"use strict";
19+
Object.defineProperty(exports, "__esModule", { value: true });
20+
//// [decl.js]
21+
"use strict";
22+
Object.defineProperty(exports, "__esModule", { value: true });
23+
exports.o = void 0;
24+
var o = function (o) { return function () { return null; }; };
25+
exports.o = o;
26+
//// [main.js]
27+
"use strict";
28+
Object.defineProperty(exports, "__esModule", { value: true });
29+
exports.f = void 0;
30+
var decl_1 = require("./decl");
31+
exports.f = { o: (0, decl_1.o)({ v: null }) };
32+
33+
34+
//// [utils.d.ts]
35+
export interface Evt {
36+
}
37+
//// [decl.d.ts]
38+
export declare const o: <T>(o: T) => () => T;
39+
//// [main.d.ts]
40+
import { Evt } from './utils';
41+
export declare const f: {
42+
o: () => {
43+
v: Evt;
44+
};
45+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [tests/cases/compiler/declarationEmitPreserveReferencedImports.ts] ////
2+
3+
=== utils.ts ===
4+
export interface Evt { }
5+
>Evt : Symbol(Evt, Decl(utils.ts, 0, 0))
6+
7+
8+
=== decl.ts ===
9+
import {Evt} from './utils'
10+
>Evt : Symbol(Evt, Decl(decl.ts, 0, 8))
11+
12+
export const o = <T>(o: T) => () : T => null!
13+
>o : Symbol(o, Decl(decl.ts, 1, 12))
14+
>T : Symbol(T, Decl(decl.ts, 1, 18))
15+
>o : Symbol(o, Decl(decl.ts, 1, 21))
16+
>T : Symbol(T, Decl(decl.ts, 1, 18))
17+
>T : Symbol(T, Decl(decl.ts, 1, 18))
18+
19+
=== main.ts ===
20+
import { o } from './decl'
21+
>o : Symbol(o, Decl(main.ts, 0, 8))
22+
23+
import { Evt } from './utils'
24+
>Evt : Symbol(Evt, Decl(main.ts, 1, 8))
25+
26+
export const f = { o: o({ v: null! as Evt}) };
27+
>f : Symbol(f, Decl(main.ts, 3, 12))
28+
>o : Symbol(o, Decl(main.ts, 3, 18))
29+
>o : Symbol(o, Decl(main.ts, 0, 8))
30+
>v : Symbol(v, Decl(main.ts, 3, 25))
31+
>Evt : Symbol(Evt, Decl(main.ts, 1, 8))
32+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//// [tests/cases/compiler/declarationEmitPreserveReferencedImports.ts] ////
2+
3+
=== utils.ts ===
4+
5+
export interface Evt { }
6+
7+
8+
=== decl.ts ===
9+
import {Evt} from './utils'
10+
>Evt : any
11+
> : ^^^
12+
13+
export const o = <T>(o: T) => () : T => null!
14+
>o : <T>(o: T) => () => T
15+
> : ^ ^^ ^^ ^^^^^^^^^^^
16+
><T>(o: T) => () : T => null! : <T>(o: T) => () => T
17+
> : ^ ^^ ^^ ^^^^^^^^^^^
18+
>o : T
19+
> : ^
20+
>() : T => null! : () => T
21+
> : ^^^^^^
22+
>null! : never
23+
> : ^^^^^
24+
25+
=== main.ts ===
26+
import { o } from './decl'
27+
>o : <T>(o: T) => () => T
28+
> : ^ ^^ ^^ ^^^^^^^^^^^
29+
30+
import { Evt } from './utils'
31+
>Evt : any
32+
> : ^^^
33+
34+
export const f = { o: o({ v: null! as Evt}) };
35+
>f : { o: () => { v: Evt; }; }
36+
> : ^^^^^^^^^^^^^^^^ ^^^^^^
37+
>{ o: o({ v: null! as Evt}) } : { o: () => { v: Evt; }; }
38+
> : ^^^^^^^^^^^^^^^^ ^^^^^^
39+
>o : () => { v: Evt; }
40+
> : ^^^^^^^^^^^ ^^^
41+
>o({ v: null! as Evt}) : () => { v: Evt; }
42+
> : ^^^^^^^^^^^ ^^^
43+
>o : <T>(o: T) => () => T
44+
> : ^ ^^ ^^ ^^^^^^^^^^^
45+
>{ v: null! as Evt} : { v: Evt; }
46+
> : ^^^^^ ^^^
47+
>v : Evt
48+
> : ^^^
49+
>null! as Evt : Evt
50+
> : ^^^
51+
>null! : never
52+
> : ^^^^^
53+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @declaration: true
2+
// @strict: true
3+
4+
// @filename: utils.ts
5+
export interface Evt { }
6+
7+
8+
// @filename: decl.ts
9+
import {Evt} from './utils'
10+
export const o = <T>(o: T) => () : T => null!
11+
12+
// @filename: main.ts
13+
import { o } from './decl'
14+
import { Evt } from './utils'
15+
16+
export const f = { o: o({ v: null! as Evt}) };

0 commit comments

Comments
 (0)