Skip to content

Commit fb99d55

Browse files
authored
Merge pull request #29022 from mprobst/no-resolve-libref
Do not process library reference directives with noLib set.
2 parents c146d1f + f3f5877 commit fb99d55

9 files changed

+282
-3
lines changed

src/compiler/program.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,8 +2227,9 @@ namespace ts {
22272227
processReferencedFiles(file, isDefaultLib);
22282228
processTypeReferenceDirectives(file);
22292229
}
2230-
2231-
processLibReferenceDirectives(file);
2230+
if (!options.noLib) {
2231+
processLibReferenceDirectives(file);
2232+
}
22322233

22332234
modulesWithElidedImports.set(file.path, false);
22342235
processImportedModules(file);
@@ -2315,8 +2316,10 @@ namespace ts {
23152316
processReferencedFiles(file, isDefaultLib);
23162317
processTypeReferenceDirectives(file);
23172318
}
2319+
if (!options.noLib) {
2320+
processLibReferenceDirectives(file);
2321+
}
23182322

2319-
processLibReferenceDirectives(file);
23202323

23212324
// always process imported modules to record module name resolutions
23222325
processImportedModules(file);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//// [tests/cases/conformance/declarationEmit/libReferenceNoLib.ts] ////
2+
3+
//// [fakelib.ts]
4+
// Test that passing noLib disables <reference lib> resolution.
5+
6+
interface Object { }
7+
interface Array<T> { }
8+
interface String { }
9+
interface Boolean { }
10+
interface Number { }
11+
interface Function { }
12+
interface RegExp { }
13+
interface IArguments { }
14+
15+
16+
//// [file1.ts]
17+
/// <reference lib="dom" />
18+
export declare interface HTMLElement { field: string; }
19+
export const elem: HTMLElement = { field: 'a' };
20+
21+
22+
//// [fakelib.js]
23+
// Test that passing noLib disables <reference lib> resolution.
24+
//// [file1.js]
25+
"use strict";
26+
Object.defineProperty(exports, "__esModule", { value: true });
27+
exports.elem = { field: 'a' };
28+
29+
30+
//// [fakelib.d.ts]
31+
interface Object {
32+
}
33+
interface Array<T> {
34+
}
35+
interface String {
36+
}
37+
interface Boolean {
38+
}
39+
interface Number {
40+
}
41+
interface Function {
42+
}
43+
interface RegExp {
44+
}
45+
interface IArguments {
46+
}
47+
//// [file1.d.ts]
48+
export declare interface HTMLElement {
49+
field: string;
50+
}
51+
export declare const elem: HTMLElement;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== tests/cases/conformance/declarationEmit/fakelib.ts ===
2+
// Test that passing noLib disables <reference lib> resolution.
3+
4+
interface Object { }
5+
>Object : Symbol(Object, Decl(fakelib.ts, 0, 0))
6+
7+
interface Array<T> { }
8+
>Array : Symbol(Array, Decl(fakelib.ts, 2, 20))
9+
>T : Symbol(T, Decl(fakelib.ts, 3, 16))
10+
11+
interface String { }
12+
>String : Symbol(String, Decl(fakelib.ts, 3, 22))
13+
14+
interface Boolean { }
15+
>Boolean : Symbol(Boolean, Decl(fakelib.ts, 4, 20))
16+
17+
interface Number { }
18+
>Number : Symbol(Number, Decl(fakelib.ts, 5, 21))
19+
20+
interface Function { }
21+
>Function : Symbol(Function, Decl(fakelib.ts, 6, 20))
22+
23+
interface RegExp { }
24+
>RegExp : Symbol(RegExp, Decl(fakelib.ts, 7, 22))
25+
26+
interface IArguments { }
27+
>IArguments : Symbol(IArguments, Decl(fakelib.ts, 8, 20))
28+
29+
30+
=== tests/cases/conformance/declarationEmit/file1.ts ===
31+
/// <reference lib="dom" />
32+
export declare interface HTMLElement { field: string; }
33+
>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0))
34+
>field : Symbol(HTMLElement.field, Decl(file1.ts, 1, 38))
35+
36+
export const elem: HTMLElement = { field: 'a' };
37+
>elem : Symbol(elem, Decl(file1.ts, 2, 12))
38+
>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0))
39+
>field : Symbol(field, Decl(file1.ts, 2, 34))
40+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/conformance/declarationEmit/fakelib.ts ===
2+
// Test that passing noLib disables <reference lib> resolution.
3+
No type information for this code.
4+
No type information for this code.interface Object { }
5+
No type information for this code.interface Array<T> { }
6+
No type information for this code.interface String { }
7+
No type information for this code.interface Boolean { }
8+
No type information for this code.interface Number { }
9+
No type information for this code.interface Function { }
10+
No type information for this code.interface RegExp { }
11+
No type information for this code.interface IArguments { }
12+
No type information for this code.
13+
No type information for this code.
14+
No type information for this code.=== tests/cases/conformance/declarationEmit/file1.ts ===
15+
/// <reference lib="dom" />
16+
export declare interface HTMLElement { field: string; }
17+
>field : string
18+
19+
export const elem: HTMLElement = { field: 'a' };
20+
>elem : HTMLElement
21+
>{ field: 'a' } : { field: string; }
22+
>field : string
23+
>'a' : "a"
24+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//// [tests/cases/conformance/declarationEmit/libReferenceNoLibBundle.ts] ////
2+
3+
//// [fakelib.ts]
4+
// Test that passing noLib disables <reference lib> resolution.
5+
6+
interface Object { }
7+
interface Array<T> { }
8+
interface String { }
9+
interface Boolean { }
10+
interface Number { }
11+
interface Function { }
12+
interface RegExp { }
13+
interface IArguments { }
14+
15+
16+
//// [file1.ts]
17+
/// <reference lib="dom" />
18+
export declare interface HTMLElement { field: string; }
19+
export const elem: HTMLElement = { field: 'a' };
20+
21+
22+
//// [bundle.js]
23+
// Test that passing noLib disables <reference lib> resolution.
24+
define("file1", ["require", "exports"], function (require, exports) {
25+
"use strict";
26+
Object.defineProperty(exports, "__esModule", { value: true });
27+
exports.elem = { field: 'a' };
28+
});
29+
30+
31+
//// [bundle.d.ts]
32+
interface Object {
33+
}
34+
interface Array<T> {
35+
}
36+
interface String {
37+
}
38+
interface Boolean {
39+
}
40+
interface Number {
41+
}
42+
interface Function {
43+
}
44+
interface RegExp {
45+
}
46+
interface IArguments {
47+
}
48+
declare module "file1" {
49+
export interface HTMLElement {
50+
field: string;
51+
}
52+
export const elem: HTMLElement;
53+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== tests/cases/conformance/declarationEmit/fakelib.ts ===
2+
// Test that passing noLib disables <reference lib> resolution.
3+
4+
interface Object { }
5+
>Object : Symbol(Object, Decl(fakelib.ts, 0, 0))
6+
7+
interface Array<T> { }
8+
>Array : Symbol(Array, Decl(fakelib.ts, 2, 20))
9+
>T : Symbol(T, Decl(fakelib.ts, 3, 16))
10+
11+
interface String { }
12+
>String : Symbol(String, Decl(fakelib.ts, 3, 22))
13+
14+
interface Boolean { }
15+
>Boolean : Symbol(Boolean, Decl(fakelib.ts, 4, 20))
16+
17+
interface Number { }
18+
>Number : Symbol(Number, Decl(fakelib.ts, 5, 21))
19+
20+
interface Function { }
21+
>Function : Symbol(Function, Decl(fakelib.ts, 6, 20))
22+
23+
interface RegExp { }
24+
>RegExp : Symbol(RegExp, Decl(fakelib.ts, 7, 22))
25+
26+
interface IArguments { }
27+
>IArguments : Symbol(IArguments, Decl(fakelib.ts, 8, 20))
28+
29+
30+
=== tests/cases/conformance/declarationEmit/file1.ts ===
31+
/// <reference lib="dom" />
32+
export declare interface HTMLElement { field: string; }
33+
>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0))
34+
>field : Symbol(HTMLElement.field, Decl(file1.ts, 1, 38))
35+
36+
export const elem: HTMLElement = { field: 'a' };
37+
>elem : Symbol(elem, Decl(file1.ts, 2, 12))
38+
>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0))
39+
>field : Symbol(field, Decl(file1.ts, 2, 34))
40+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/conformance/declarationEmit/fakelib.ts ===
2+
// Test that passing noLib disables <reference lib> resolution.
3+
No type information for this code.
4+
No type information for this code.interface Object { }
5+
No type information for this code.interface Array<T> { }
6+
No type information for this code.interface String { }
7+
No type information for this code.interface Boolean { }
8+
No type information for this code.interface Number { }
9+
No type information for this code.interface Function { }
10+
No type information for this code.interface RegExp { }
11+
No type information for this code.interface IArguments { }
12+
No type information for this code.
13+
No type information for this code.
14+
No type information for this code.=== tests/cases/conformance/declarationEmit/file1.ts ===
15+
/// <reference lib="dom" />
16+
export declare interface HTMLElement { field: string; }
17+
>field : string
18+
19+
export const elem: HTMLElement = { field: 'a' };
20+
>elem : HTMLElement
21+
>{ field: 'a' } : { field: string; }
22+
>field : string
23+
>'a' : "a"
24+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @target: esnext
2+
// @module: commonjs
3+
// @noLib: true
4+
// @declaration: true
5+
// Test that passing noLib disables <reference lib> resolution.
6+
7+
// @filename: fakelib.ts
8+
interface Object { }
9+
interface Array<T> { }
10+
interface String { }
11+
interface Boolean { }
12+
interface Number { }
13+
interface Function { }
14+
interface RegExp { }
15+
interface IArguments { }
16+
17+
18+
// @filename: file1.ts
19+
/// <reference lib="dom" />
20+
export declare interface HTMLElement { field: string; }
21+
export const elem: HTMLElement = { field: 'a' };
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @target: esnext
2+
// @module: amd
3+
// @noLib: true
4+
// @declaration: true
5+
// @outFile: bundle.js
6+
7+
// Test that passing noLib disables <reference lib> resolution.
8+
9+
// @filename: fakelib.ts
10+
interface Object { }
11+
interface Array<T> { }
12+
interface String { }
13+
interface Boolean { }
14+
interface Number { }
15+
interface Function { }
16+
interface RegExp { }
17+
interface IArguments { }
18+
19+
20+
// @filename: file1.ts
21+
/// <reference lib="dom" />
22+
export declare interface HTMLElement { field: string; }
23+
export const elem: HTMLElement = { field: 'a' };

0 commit comments

Comments
 (0)