Skip to content

Commit 065e695

Browse files
authored
No merge for redirected source files in initializeTypeChecker (#25463)
Previously, redirected source files merged the same way as other source files, effectively causing the target of the redirection to be merged twice. mergeSymbol now has an assert (`source===target`) that catches this condition, so this change makes sure to skip redirected source files. This change doesn't apply to the preceding binding loop, since the binder handles already-bound source files correctly.
1 parent 0abefec commit 065e695

6 files changed

+149
-0
lines changed

src/compiler/checker.ts

+3
Original file line numberDiff line numberDiff line change
@@ -27705,6 +27705,9 @@ namespace ts {
2770527705
// Initialize global symbol table
2770627706
let augmentations: ReadonlyArray<StringLiteral | Identifier>[] | undefined;
2770727707
for (const file of host.getSourceFiles()) {
27708+
if (file.redirectInfo) {
27709+
continue;
27710+
}
2770827711
if (!isExternalOrCommonJsModule(file)) {
2770927712
mergeSymbolTable(globals, file.locals!);
2771027713
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/node_modules/@types/react/index.d.ts(1,9): error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.
2+
/src/index.ts(1,24): error TS2306: File '/node_modules/@types/react/index.d.ts' is not a module.
3+
/tests/index.ts(1,24): error TS2306: File '/tests/node_modules/@types/react/index.d.ts' is not a module.
4+
5+
6+
==== /src/bug25410.ts (0 errors) ====
7+
import { x } from './index'
8+
import { y } from '../tests/index'
9+
10+
==== /src/index.ts (1 errors) ====
11+
import * as React from 'react';
12+
~~~~~~~
13+
!!! error TS2306: File '/node_modules/@types/react/index.d.ts' is not a module.
14+
export var x = 1
15+
==== /tests/index.ts (1 errors) ====
16+
import * as React from 'react';
17+
~~~~~~~
18+
!!! error TS2306: File '/tests/node_modules/@types/react/index.d.ts' is not a module.
19+
export var y = 2
20+
21+
==== /tests/node_modules/@types/react/package.json (0 errors) ====
22+
{ "name": "@types/react", "version": "16.4.6" }
23+
==== /tests/node_modules/@types/react/index.d.ts (0 errors) ====
24+
25+
==== /node_modules/@types/react/package.json (0 errors) ====
26+
{ "name": "@types/react", "version": "16.4.6" }
27+
==== /node_modules/@types/react/index.d.ts (1 errors) ====
28+
declare global { }
29+
~~~~~~
30+
!!! error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [tests/cases/compiler/duplicatePackage_globalMerge.ts] ////
2+
3+
//// [index.ts]
4+
import * as React from 'react';
5+
export var x = 1
6+
//// [index.ts]
7+
import * as React from 'react';
8+
export var y = 2
9+
10+
//// [package.json]
11+
{ "name": "@types/react", "version": "16.4.6" }
12+
//// [index.d.ts]
13+
14+
//// [package.json]
15+
{ "name": "@types/react", "version": "16.4.6" }
16+
//// [index.d.ts]
17+
declare global { }
18+
19+
//// [bug25410.ts]
20+
import { x } from './index'
21+
import { y } from '../tests/index'
22+
23+
24+
//// [index.js]
25+
"use strict";
26+
exports.__esModule = true;
27+
exports.x = 1;
28+
//// [index.js]
29+
"use strict";
30+
exports.__esModule = true;
31+
exports.y = 2;
32+
//// [bug25410.js]
33+
"use strict";
34+
exports.__esModule = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== /src/bug25410.ts ===
2+
import { x } from './index'
3+
>x : Symbol(x, Decl(bug25410.ts, 0, 8))
4+
5+
import { y } from '../tests/index'
6+
>y : Symbol(y, Decl(bug25410.ts, 1, 8))
7+
8+
=== /src/index.ts ===
9+
import * as React from 'react';
10+
>React : Symbol(React, Decl(index.ts, 0, 6))
11+
12+
export var x = 1
13+
>x : Symbol(x, Decl(index.ts, 1, 10))
14+
15+
=== /tests/index.ts ===
16+
import * as React from 'react';
17+
>React : Symbol(React, Decl(index.ts, 0, 6))
18+
19+
export var y = 2
20+
>y : Symbol(y, Decl(index.ts, 1, 10))
21+
22+
=== /tests/node_modules/@types/react/index.d.ts ===
23+
24+
>global : Symbol(global, Decl(index.d.ts, 0, 0))
25+
26+
=== /node_modules/@types/react/index.d.ts ===
27+
declare global { }
28+
>global : Symbol(global, Decl(index.d.ts, 0, 0))
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== /src/bug25410.ts ===
2+
import { x } from './index'
3+
>x : number
4+
5+
import { y } from '../tests/index'
6+
>y : number
7+
8+
=== /src/index.ts ===
9+
import * as React from 'react';
10+
>React : any
11+
12+
export var x = 1
13+
>x : number
14+
>1 : 1
15+
16+
=== /tests/index.ts ===
17+
import * as React from 'react';
18+
>React : any
19+
20+
export var y = 2
21+
>y : number
22+
>2 : 2
23+
24+
=== /tests/node_modules/@types/react/index.d.ts ===
25+
26+
>global : typeof global
27+
28+
=== /node_modules/@types/react/index.d.ts ===
29+
declare global { }
30+
>global : typeof global
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @noImplicitReferences: true
2+
3+
// @Filename: /src/index.ts
4+
import * as React from 'react';
5+
export var x = 1
6+
// @Filename: /tests/index.ts
7+
import * as React from 'react';
8+
export var y = 2
9+
10+
// @Filename: /tests/node_modules/@types/react/package.json
11+
{ "name": "@types/react", "version": "16.4.6" }
12+
// @Filename: /tests/node_modules/@types/react/index.d.ts
13+
14+
// @Filename: /node_modules/@types/react/package.json
15+
{ "name": "@types/react", "version": "16.4.6" }
16+
// @Filename: /node_modules/@types/react/index.d.ts
17+
declare global { }
18+
19+
// @Filename: /src/bug25410.ts
20+
import { x } from './index'
21+
import { y } from '../tests/index'

0 commit comments

Comments
 (0)