Skip to content

Commit 8a3090b

Browse files
author
Andy
authored
Improve test for 'symbol.exports' (#25523)
* Improve test for 'symbol.exports' * Remove SymbolFlags.HasExports and SymbolFlags.HasMembers * Update baseline
1 parent 990d445 commit 8a3090b

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ namespace ts {
225225
node.symbol = symbol;
226226
symbol.declarations = append(symbol.declarations, node);
227227

228-
if (symbolFlags & SymbolFlags.HasExports && !symbol.exports) {
228+
if (symbolFlags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.Module | SymbolFlags.Variable) && !symbol.exports) {
229229
symbol.exports = createSymbolTable();
230230
}
231231

232-
if (symbolFlags & SymbolFlags.HasMembers && !symbol.members) {
232+
if (symbolFlags & (SymbolFlags.Class | SymbolFlags.Interface | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && !symbol.members) {
233233
symbol.members = createSymbolTable();
234234
}
235235

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,12 +2417,12 @@ namespace ts {
24172417
// The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example,
24182418
// module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error.
24192419
function visit(symbol: Symbol | undefined): SymbolTable | undefined {
2420-
if (!(symbol && symbol.flags & SymbolFlags.HasExports && pushIfUnique(visitedSymbols, symbol))) {
2420+
if (!(symbol && symbol.exports && pushIfUnique(visitedSymbols, symbol))) {
24212421
return;
24222422
}
2423-
const symbols = cloneMap(symbol.exports!);
2423+
const symbols = cloneMap(symbol.exports);
24242424
// All export * declarations are collected in an __export symbol by the binder
2425-
const exportStars = symbol.exports!.get(InternalSymbolName.ExportStar);
2425+
const exportStars = symbol.exports.get(InternalSymbolName.ExportStar);
24262426
if (exportStars) {
24272427
const nestedSymbols = createSymbolTable();
24282428
const lookupTable = createMap<ExportCollisionTracker>() as ExportCollisionTrackerTable;

src/compiler/symbolWalker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ namespace ts {
171171
}
172172
const t = getTypeOfSymbol(symbol);
173173
visitType(t); // Should handle members on classes and such
174-
if (symbol.flags & SymbolFlags.HasExports) {
175-
symbol.exports!.forEach(visitSymbol);
174+
if (symbol.exports) {
175+
symbol.exports.forEach(visitSymbol);
176176
}
177177
forEach(symbol.declarations, d => {
178178
// Type queries are too far resolved when we just visit the symbol's type

src/compiler/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,9 +3439,6 @@ namespace ts {
34393439

34403440
ExportHasLocal = Function | Class | Enum | ValueModule,
34413441

3442-
HasExports = Class | Enum | Module | Variable,
3443-
HasMembers = Class | Interface | TypeLiteral | ObjectLiteral,
3444-
34453442
BlockScoped = BlockScopedVariable | Class | Enum,
34463443

34473444
PropertyOrAccessor = Property | Accessor,

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,8 +2075,6 @@ declare namespace ts {
20752075
AliasExcludes = 2097152,
20762076
ModuleMember = 2623475,
20772077
ExportHasLocal = 944,
2078-
HasExports = 1955,
2079-
HasMembers = 6240,
20802078
BlockScoped = 418,
20812079
PropertyOrAccessor = 98308,
20822080
ClassMember = 106500

tests/baselines/reference/api/typescript.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,8 +2075,6 @@ declare namespace ts {
20752075
AliasExcludes = 2097152,
20762076
ModuleMember = 2623475,
20772077
ExportHasLocal = 944,
2078-
HasExports = 1955,
2079-
HasMembers = 6240,
20802078
BlockScoped = 418,
20812079
PropertyOrAccessor = 98308,
20822080
ClassMember = 106500

tests/baselines/reference/moduleExportWithExportPropertyAssignment4.errors.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ tests/cases/conformance/salsa/a.js(4,17): error TS2339: Property 'toFixed' does
22
Property 'toFixed' does not exist on type 'string'.
33
tests/cases/conformance/salsa/a.js(5,16): error TS2339: Property 'toFixed' does not exist on type 'string | number'.
44
Property 'toFixed' does not exist on type 'string'.
5+
tests/cases/conformance/salsa/mod1.js(2,1): error TS2323: Cannot redeclare exported variable 'bothBefore'.
6+
tests/cases/conformance/salsa/mod1.js(4,1): error TS2323: Cannot redeclare exported variable 'bothBefore'.
7+
tests/cases/conformance/salsa/mod1.js(5,1): error TS2323: Cannot redeclare exported variable 'bothAfter'.
8+
tests/cases/conformance/salsa/mod1.js(10,1): error TS2323: Cannot redeclare exported variable 'bothAfter'.
59

610

711
==== tests/cases/conformance/salsa/a.js (2 errors) ====
@@ -21,16 +25,24 @@ tests/cases/conformance/salsa/a.js(5,16): error TS2339: Property 'toFixed' does
2125
==== tests/cases/conformance/salsa/requires.d.ts (0 errors) ====
2226
declare var module: { exports: any };
2327
declare function require(name: string): any;
24-
==== tests/cases/conformance/salsa/mod1.js (0 errors) ====
28+
==== tests/cases/conformance/salsa/mod1.js (4 errors) ====
2529
/// <reference path='./requires.d.ts' />
2630
module.exports.bothBefore = 'string'
31+
~~~~~~~~~~~~~~~~~~~~~~~~~
32+
!!! error TS2323: Cannot redeclare exported variable 'bothBefore'.
2733
A.justExport = 4
2834
A.bothBefore = 2
35+
~~~~~~~~~~~~
36+
!!! error TS2323: Cannot redeclare exported variable 'bothBefore'.
2937
A.bothAfter = 3
38+
~~~~~~~~~~~
39+
!!! error TS2323: Cannot redeclare exported variable 'bothAfter'.
3040
module.exports = A
3141
function A() {
3242
this.p = 1
3343
}
3444
module.exports.bothAfter = 'string'
45+
~~~~~~~~~~~~~~~~~~~~~~~~
46+
!!! error TS2323: Cannot redeclare exported variable 'bothAfter'.
3547
module.exports.justProperty = 'string'
3648

0 commit comments

Comments
 (0)