Skip to content

Commit 8289c1a

Browse files
committed
Move checks from checker to binder
1 parent e266d5d commit 8289c1a

File tree

5 files changed

+21
-43
lines changed

5 files changed

+21
-43
lines changed

src/compiler/binder.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1401,10 +1401,28 @@ namespace ts {
14011401
}
14021402

14031403
function bindGlobalModuleExportDeclaration(node: GlobalModuleExportDeclaration) {
1404-
if (!file.externalModuleIndicator) {
1405-
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Global_module_exports_may_only_appear_in_module_files));
1404+
if (node.modifiers && node.modifiers.length) {
1405+
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Modifiers_cannot_appear_here));
1406+
}
1407+
1408+
if (node.parent.kind !== SyntaxKind.SourceFile) {
1409+
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Global_module_exports_may_only_appear_at_top_level));
14061410
return;
14071411
}
1412+
else {
1413+
const parent = node.parent as SourceFile;
1414+
1415+
if (!isExternalModule(<SourceFile>node.parent)) {
1416+
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Global_module_exports_may_only_appear_in_module_files));
1417+
return;
1418+
}
1419+
1420+
if (!parent.isDeclarationFile) {
1421+
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Global_module_exports_may_only_appear_in_declaration_files));
1422+
return;
1423+
}
1424+
}
1425+
14081426
file.symbol.globalExports = file.symbol.globalExports || {};
14091427
declareSymbol(file.symbol.globalExports, file.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
14101428
}

src/compiler/checker.ts

-20
Original file line numberDiff line numberDiff line change
@@ -15206,24 +15206,6 @@ namespace ts {
1520615206
}
1520715207
}
1520815208

15209-
function checkGlobalModuleExportDeclaration(node: GlobalModuleExportDeclaration) {
15210-
if (node.modifiers && node.modifiers.length) {
15211-
error(node, Diagnostics.Modifiers_cannot_appear_here);
15212-
}
15213-
15214-
if (node.parent.kind !== SyntaxKind.SourceFile) {
15215-
error(node, Diagnostics.Global_module_exports_may_only_appear_at_top_level);
15216-
}
15217-
else {
15218-
const parent = node.parent as SourceFile;
15219-
// Note: the binder handles the case where the declaration isn't in an external module
15220-
if (parent.externalModuleIndicator && !parent.isDeclarationFile) {
15221-
error(node, Diagnostics.Global_module_exports_may_only_appear_in_declaration_files);
15222-
}
15223-
}
15224-
15225-
}
15226-
1522715209
function checkSourceElement(node: Node): void {
1522815210
if (!node) {
1522915211
return;
@@ -15340,8 +15322,6 @@ namespace ts {
1534015322
return checkExportDeclaration(<ExportDeclaration>node);
1534115323
case SyntaxKind.ExportAssignment:
1534215324
return checkExportAssignment(<ExportAssignment>node);
15343-
case SyntaxKind.GlobalModuleExportDeclaration:
15344-
return checkGlobalModuleExportDeclaration(<GlobalModuleExportDeclaration>node);
1534515325
case SyntaxKind.EmptyStatement:
1534615326
checkGrammarStatementInAmbientContext(node);
1534715327
return;

tests/baselines/reference/umd-errors.errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
tests/cases/conformance/externalModules/err1.d.ts(3,1): error TS1314: Global module exports may only appear in module files.
2-
tests/cases/conformance/externalModules/err2.d.ts(3,2): error TS1314: Global module exports may only appear in module files.
32
tests/cases/conformance/externalModules/err2.d.ts(3,2): error TS1316: Global module exports may only appear at top level.
43
tests/cases/conformance/externalModules/err3.d.ts(3,1): error TS1184: Modifiers cannot appear here.
54
tests/cases/conformance/externalModules/err3.d.ts(4,1): error TS1184: Modifiers cannot appear here.
@@ -16,13 +15,11 @@ tests/cases/conformance/externalModules/err5.ts(3,1): error TS1315: Global modul
1615
~~~~~~~~~~~~~~~~~~~~~~~~
1716
!!! error TS1314: Global module exports may only appear in module files.
1817

19-
==== tests/cases/conformance/externalModules/err2.d.ts (2 errors) ====
18+
==== tests/cases/conformance/externalModules/err2.d.ts (1 errors) ====
2019
// Illegal, can't be in external ambient module
2120
declare module "Foo" {
2221
export as namespace Bar;
2322
~~~~~~~~~~~~~~~~~~~~~~~~
24-
!!! error TS1314: Global module exports may only appear in module files.
25-
~~~~~~~~~~~~~~~~~~~~~~~~
2623
!!! error TS1316: Global module exports may only appear at top level.
2724
}
2825

tests/baselines/reference/umd-errors.symbols

-8
This file was deleted.

tests/baselines/reference/umd-errors.types

-9
This file was deleted.

0 commit comments

Comments
 (0)