mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-23 10:04:47 -05:00
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.
This commit is contained in:
committed by
GitHub
parent
0abefeca73
commit
065e695a28
@@ -27705,6 +27705,9 @@ namespace ts {
|
||||
// Initialize global symbol table
|
||||
let augmentations: ReadonlyArray<StringLiteral | Identifier>[] | undefined;
|
||||
for (const file of host.getSourceFiles()) {
|
||||
if (file.redirectInfo) {
|
||||
continue;
|
||||
}
|
||||
if (!isExternalOrCommonJsModule(file)) {
|
||||
mergeSymbolTable(globals, file.locals!);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/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.
|
||||
/src/index.ts(1,24): error TS2306: File '/node_modules/@types/react/index.d.ts' is not a module.
|
||||
/tests/index.ts(1,24): error TS2306: File '/tests/node_modules/@types/react/index.d.ts' is not a module.
|
||||
|
||||
|
||||
==== /src/bug25410.ts (0 errors) ====
|
||||
import { x } from './index'
|
||||
import { y } from '../tests/index'
|
||||
|
||||
==== /src/index.ts (1 errors) ====
|
||||
import * as React from 'react';
|
||||
~~~~~~~
|
||||
!!! error TS2306: File '/node_modules/@types/react/index.d.ts' is not a module.
|
||||
export var x = 1
|
||||
==== /tests/index.ts (1 errors) ====
|
||||
import * as React from 'react';
|
||||
~~~~~~~
|
||||
!!! error TS2306: File '/tests/node_modules/@types/react/index.d.ts' is not a module.
|
||||
export var y = 2
|
||||
|
||||
==== /tests/node_modules/@types/react/package.json (0 errors) ====
|
||||
{ "name": "@types/react", "version": "16.4.6" }
|
||||
==== /tests/node_modules/@types/react/index.d.ts (0 errors) ====
|
||||
|
||||
==== /node_modules/@types/react/package.json (0 errors) ====
|
||||
{ "name": "@types/react", "version": "16.4.6" }
|
||||
==== /node_modules/@types/react/index.d.ts (1 errors) ====
|
||||
declare global { }
|
||||
~~~~~~
|
||||
!!! error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.
|
||||
|
||||
34
tests/baselines/reference/duplicatePackage_globalMerge.js
Normal file
34
tests/baselines/reference/duplicatePackage_globalMerge.js
Normal file
@@ -0,0 +1,34 @@
|
||||
//// [tests/cases/compiler/duplicatePackage_globalMerge.ts] ////
|
||||
|
||||
//// [index.ts]
|
||||
import * as React from 'react';
|
||||
export var x = 1
|
||||
//// [index.ts]
|
||||
import * as React from 'react';
|
||||
export var y = 2
|
||||
|
||||
//// [package.json]
|
||||
{ "name": "@types/react", "version": "16.4.6" }
|
||||
//// [index.d.ts]
|
||||
|
||||
//// [package.json]
|
||||
{ "name": "@types/react", "version": "16.4.6" }
|
||||
//// [index.d.ts]
|
||||
declare global { }
|
||||
|
||||
//// [bug25410.ts]
|
||||
import { x } from './index'
|
||||
import { y } from '../tests/index'
|
||||
|
||||
|
||||
//// [index.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.x = 1;
|
||||
//// [index.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.y = 2;
|
||||
//// [bug25410.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
@@ -0,0 +1,29 @@
|
||||
=== /src/bug25410.ts ===
|
||||
import { x } from './index'
|
||||
>x : Symbol(x, Decl(bug25410.ts, 0, 8))
|
||||
|
||||
import { y } from '../tests/index'
|
||||
>y : Symbol(y, Decl(bug25410.ts, 1, 8))
|
||||
|
||||
=== /src/index.ts ===
|
||||
import * as React from 'react';
|
||||
>React : Symbol(React, Decl(index.ts, 0, 6))
|
||||
|
||||
export var x = 1
|
||||
>x : Symbol(x, Decl(index.ts, 1, 10))
|
||||
|
||||
=== /tests/index.ts ===
|
||||
import * as React from 'react';
|
||||
>React : Symbol(React, Decl(index.ts, 0, 6))
|
||||
|
||||
export var y = 2
|
||||
>y : Symbol(y, Decl(index.ts, 1, 10))
|
||||
|
||||
=== /tests/node_modules/@types/react/index.d.ts ===
|
||||
|
||||
>global : Symbol(global, Decl(index.d.ts, 0, 0))
|
||||
|
||||
=== /node_modules/@types/react/index.d.ts ===
|
||||
declare global { }
|
||||
>global : Symbol(global, Decl(index.d.ts, 0, 0))
|
||||
|
||||
31
tests/baselines/reference/duplicatePackage_globalMerge.types
Normal file
31
tests/baselines/reference/duplicatePackage_globalMerge.types
Normal file
@@ -0,0 +1,31 @@
|
||||
=== /src/bug25410.ts ===
|
||||
import { x } from './index'
|
||||
>x : number
|
||||
|
||||
import { y } from '../tests/index'
|
||||
>y : number
|
||||
|
||||
=== /src/index.ts ===
|
||||
import * as React from 'react';
|
||||
>React : any
|
||||
|
||||
export var x = 1
|
||||
>x : number
|
||||
>1 : 1
|
||||
|
||||
=== /tests/index.ts ===
|
||||
import * as React from 'react';
|
||||
>React : any
|
||||
|
||||
export var y = 2
|
||||
>y : number
|
||||
>2 : 2
|
||||
|
||||
=== /tests/node_modules/@types/react/index.d.ts ===
|
||||
|
||||
>global : typeof global
|
||||
|
||||
=== /node_modules/@types/react/index.d.ts ===
|
||||
declare global { }
|
||||
>global : typeof global
|
||||
|
||||
21
tests/cases/compiler/duplicatePackage_globalMerge.ts
Normal file
21
tests/cases/compiler/duplicatePackage_globalMerge.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
// @noImplicitReferences: true
|
||||
|
||||
// @Filename: /src/index.ts
|
||||
import * as React from 'react';
|
||||
export var x = 1
|
||||
// @Filename: /tests/index.ts
|
||||
import * as React from 'react';
|
||||
export var y = 2
|
||||
|
||||
// @Filename: /tests/node_modules/@types/react/package.json
|
||||
{ "name": "@types/react", "version": "16.4.6" }
|
||||
// @Filename: /tests/node_modules/@types/react/index.d.ts
|
||||
|
||||
// @Filename: /node_modules/@types/react/package.json
|
||||
{ "name": "@types/react", "version": "16.4.6" }
|
||||
// @Filename: /node_modules/@types/react/index.d.ts
|
||||
declare global { }
|
||||
|
||||
// @Filename: /src/bug25410.ts
|
||||
import { x } from './index'
|
||||
import { y } from '../tests/index'
|
||||
Reference in New Issue
Block a user