Skip to content

Commit

Permalink
Update for new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanCavanaugh committed Mar 1, 2016
1 parent 0eba61c commit 96a3047
Show file tree
Hide file tree
Showing 28 changed files with 213 additions and 37 deletions.
4 changes: 4 additions & 0 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,10 @@ namespace ts {
}

function bindGlobalModuleExportDeclaration(node: GlobalModuleExportDeclaration) {
if (!file.externalModuleIndicator) {
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Global_module_exports_may_only_appear_in_module_files));
return;
}
file.symbol.globalExports = file.symbol.globalExports || {};
declareSymbol(file.symbol.globalExports, file.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
}
Expand Down
19 changes: 19 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15201,6 +15201,23 @@ namespace ts {
}
}

function checkGlobalModuleExportDeclaration(node: GlobalModuleExportDeclaration) {
if (node.modifiers && node.modifiers.length) {
error(node, Diagnostics.Modifiers_cannot_appear_here);
}

if (node.parent.kind !== SyntaxKind.SourceFile) {
error(node, Diagnostics.Global_module_exports_may_only_appear_at_top_level);
}
else {
const parent = node.parent as SourceFile;
// Note: missing external module indicator case checked in binder
if (parent.externalModuleIndicator && !parent.isDeclarationFile) {
error(node, Diagnostics.Global_module_exports_may_only_appear_in_declaration_files);
}
}

}

function checkSourceElement(node: Node): void {
if (!node) {
Expand Down Expand Up @@ -15318,6 +15335,8 @@ namespace ts {
return checkExportDeclaration(<ExportDeclaration>node);
case SyntaxKind.ExportAssignment:
return checkExportAssignment(<ExportAssignment>node);
case SyntaxKind.GlobalModuleExportDeclaration:
return checkGlobalModuleExportDeclaration(<GlobalModuleExportDeclaration>node);
case SyntaxKind.EmptyStatement:
checkGrammarStatementInAmbientContext(node);
return;
Expand Down
12 changes: 12 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,18 @@
"category": "Error",
"code": 1313
},
"Global module exports may only appear in module files.": {
"category": "Error",
"code": 1314
},
"Global module exports may only appear in declaration files.": {
"category": "Error",
"code": 1315
},
"Global module exports may only appear at top level.": {
"category": "Error",
"code": 1316
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
Expand Down
33 changes: 15 additions & 18 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ namespace ts {
if (token === SyntaxKind.DefaultKeyword) {
return lookAhead(nextTokenIsClassOrFunction);
}
return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.OpenBraceToken && canFollowModifier();
return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.AsKeyword && token !== SyntaxKind.OpenBraceToken && canFollowModifier();
}
if (token === SyntaxKind.DefaultKeyword) {
return nextTokenIsClassOrFunction();
Expand Down Expand Up @@ -4431,7 +4431,8 @@ namespace ts {
case SyntaxKind.ExportKeyword:
nextToken();
if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken ||
token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword) {
token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword ||
token === SyntaxKind.AsKeyword) {
return true;
}
continue;
Expand Down Expand Up @@ -4608,22 +4609,23 @@ namespace ts {
case SyntaxKind.EnumKeyword:
return parseEnumDeclaration(fullStart, decorators, modifiers);
case SyntaxKind.GlobalKeyword:
if (lookAhead(isGlobalModuleExportDeclaration)) {
return parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers);
}
else {
return parseModuleDeclaration(fullStart, decorators, modifiers);
}
return parseModuleDeclaration(fullStart, decorators, modifiers);
case SyntaxKind.ModuleKeyword:
case SyntaxKind.NamespaceKeyword:
return parseModuleDeclaration(fullStart, decorators, modifiers);
case SyntaxKind.ImportKeyword:
return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers);
case SyntaxKind.ExportKeyword:
nextToken();
return token === SyntaxKind.DefaultKeyword || token === SyntaxKind.EqualsToken ?
parseExportAssignment(fullStart, decorators, modifiers) :
parseExportDeclaration(fullStart, decorators, modifiers);
switch (token) {
case SyntaxKind.DefaultKeyword:
case SyntaxKind.EqualsToken:
return parseExportAssignment(fullStart, decorators, modifiers);
case SyntaxKind.AsKeyword:
return parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers);
default:
return parseExportDeclaration(fullStart, decorators, modifiers);
}
default:
if (decorators || modifiers) {
// We reached this point because we encountered decorators and/or modifiers and assumed a declaration
Expand All @@ -4637,11 +4639,6 @@ namespace ts {
}
}

function isGlobalModuleExportDeclaration() {
nextToken();
return token === SyntaxKind.ExportKeyword;
}

function nextTokenIsIdentifierOrStringLiteralOnSameLine() {
nextToken();
return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral);
Expand Down Expand Up @@ -5301,8 +5298,8 @@ namespace ts {
const exportDeclaration = <GlobalModuleExportDeclaration>createNode(SyntaxKind.GlobalModuleExportDeclaration, fullStart);
exportDeclaration.decorators = decorators;
exportDeclaration.modifiers = modifiers;
parseExpected(SyntaxKind.GlobalKeyword);
parseExpected(SyntaxKind.ExportKeyword);
parseExpected(SyntaxKind.AsKeyword);
parseExpected(SyntaxKind.NamespaceKeyword);

exportDeclaration.name = parseIdentifier();

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ namespace ts {
}

function processRootFile(fileName: string, isDefaultLib: boolean) {
processSourceFile(normalizePath(fileName), isDefaultLib, true);
processSourceFile(normalizePath(fileName), isDefaultLib, /*isReference*/ true);
}

function fileReferenceIsEqualTo(a: FileReference, b: FileReference): boolean {
Expand Down
60 changes: 60 additions & 0 deletions tests/baselines/reference/umd-errors.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
tests/cases/conformance/externalModules/err1.d.ts(3,1): error TS1314: Global module exports may only appear in module files.
tests/cases/conformance/externalModules/err2.d.ts(3,2): error TS1314: Global module exports may only appear in module files.
tests/cases/conformance/externalModules/err2.d.ts(3,2): error TS1316: Global module exports may only appear at top level.
tests/cases/conformance/externalModules/err3.d.ts(3,1): error TS1184: Modifiers cannot appear here.
tests/cases/conformance/externalModules/err3.d.ts(4,1): error TS1184: Modifiers cannot appear here.
tests/cases/conformance/externalModules/err3.d.ts(5,1): error TS1184: Modifiers cannot appear here.
tests/cases/conformance/externalModules/err3.d.ts(6,7): error TS1134: Variable declaration expected.
tests/cases/conformance/externalModules/err4.d.ts(3,2): error TS1316: Global module exports may only appear at top level.
tests/cases/conformance/externalModules/err5.ts(3,1): error TS1315: Global module exports may only appear in declaration files.


==== tests/cases/conformance/externalModules/err1.d.ts (1 errors) ====

// Illegal, can't be in script file
export as namespace Foo;
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1314: Global module exports may only appear in module files.

==== tests/cases/conformance/externalModules/err2.d.ts (2 errors) ====
// Illegal, can't be in external ambient module
declare module "Foo" {
export as namespace Bar;
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1314: Global module exports may only appear in module files.
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1316: Global module exports may only appear at top level.
}

==== tests/cases/conformance/externalModules/err3.d.ts (4 errors) ====
// Illegal, can't have modifiers
export var p;
static export as namespace oo1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1184: Modifiers cannot appear here.
declare export as namespace oo2;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1184: Modifiers cannot appear here.
public export as namespace oo3;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1184: Modifiers cannot appear here.
const export as namespace oo4;
~~~~~~
!!! error TS1134: Variable declaration expected.

==== tests/cases/conformance/externalModules/err4.d.ts (1 errors) ====
// Illegal, must be at top-level
export namespace B {
export as namespace C1;
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1316: Global module exports may only appear at top level.
}

==== tests/cases/conformance/externalModules/err5.ts (1 errors) ====
// Illegal, may not appear in implementation files
export var v;
export as namespace C2;
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1315: Global module exports may only appear in declaration files.


36 changes: 36 additions & 0 deletions tests/baselines/reference/umd-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//// [tests/cases/conformance/externalModules/umd-errors.ts] ////

//// [err1.d.ts]

// Illegal, can't be in script file
export as namespace Foo;

//// [err2.d.ts]
// Illegal, can't be in external ambient module
declare module "Foo" {
export as namespace Bar;
}

//// [err3.d.ts]
// Illegal, can't have modifiers
export var p;
static export as namespace oo1;
declare export as namespace oo2;
public export as namespace oo3;
const export as namespace oo4;

//// [err4.d.ts]
// Illegal, must be at top-level
export namespace B {
export as namespace C1;
}

//// [err5.ts]
// Illegal, may not appear in implementation files
export var v;
export as namespace C2;



//// [err5.js]
"use strict";
8 changes: 8 additions & 0 deletions tests/baselines/reference/umd-errors.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/conformance/externalModules/err5.d.ts ===
// Illegal, may not appear in implementation files
export var v;
>v : Symbol(v, Decl(err5.d.ts, 1, 10))

export as namespace C;


9 changes: 9 additions & 0 deletions tests/baselines/reference/umd-errors.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/conformance/externalModules/err5.d.ts ===
// Illegal, may not appear in implementation files
export var v;
>v : any

export as namespace C;
>C : any


2 changes: 1 addition & 1 deletion tests/baselines/reference/umd1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
declare global export Foo;
export as namespace Foo;

//// [a.ts]
/// <reference path="foo.d.ts" />
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/umd1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ export interface Thing { n: typeof x }
>n : Symbol(n, Decl(foo.d.ts, 3, 24))
>x : Symbol(x, Decl(foo.d.ts, 1, 10))

declare global export Foo;
export as namespace Foo;

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd1.types
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ export interface Thing { n: typeof x }
>n : number
>x : number

declare global export Foo;
export as namespace Foo;
>Foo : any

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ tests/cases/conformance/externalModules/a.ts(2,8): error TS2503: Cannot find nam

export var x: number;
export function fn(): void;
declare global export Foo;
export as namespace Foo;

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

export var x: number;
export function fn(): void;
declare global export Foo;
export as namespace Foo;

//// [a.ts]
Foo.fn();
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/umd3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
declare global export Foo;
export as namespace Foo;

//// [a.ts]
import * as Foo from './foo';
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/umd3.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export interface Thing { n: typeof x }
>n : Symbol(n, Decl(foo.d.ts, 3, 24))
>x : Symbol(x, Decl(foo.d.ts, 1, 10))

declare global export Foo;
export as namespace Foo;

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd3.types
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ export interface Thing { n: typeof x }
>n : number
>x : number

declare global export Foo;
export as namespace Foo;
>Foo : any

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd4.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
declare global export Foo;
export as namespace Foo;

//// [a.ts]
import * as Bar from './foo';
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/umd4.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export interface Thing { n: typeof x }
>n : Symbol(n, Decl(foo.d.ts, 3, 24))
>x : Symbol(x, Decl(foo.d.ts, 1, 10))

declare global export Foo;
export as namespace Foo;

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd4.types
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ export interface Thing { n: typeof x }
>n : number
>x : number

declare global export Foo;
export as namespace Foo;
>Foo : any

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd5.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ tests/cases/conformance/externalModules/a.ts(6,9): error TS2304: Cannot find nam
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
declare global export Foo;
export as namespace Foo;

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd5.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export var x: number;
export function fn(): void;
export interface Thing { n: typeof x }
declare global export Foo;
export as namespace Foo;

//// [a.ts]
import * as Bar from './foo';
Expand Down
Loading

0 comments on commit 96a3047

Please sign in to comment.