diff --git a/NOTICE b/NOTICE index 7f93b281a4..13f4ea79bc 100644 --- a/NOTICE +++ b/NOTICE @@ -8,6 +8,7 @@ under the licensing terms detailed in LICENSE: * Igor Sbitnev * Norton Wang * Alan Pierce +* Andy Hanson Portions of this software are derived from third-party works licensed under the following terms: diff --git a/src/compiler.ts b/src/compiler.ts index 77bdc5e8f4..aea699a2c7 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -408,7 +408,7 @@ export class Compiler extends DiagnosticEmitter { // set up module exports for (let [name, moduleExport] of program.moduleLevelExports) { - this.makeModuleExport(name, moduleExport.element); + this.makeModuleExport(name, moduleExport); } // set up gc diff --git a/src/definitions.ts b/src/definitions.ts index 593fc0588b..710d9fa9a2 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -56,7 +56,7 @@ abstract class ExportsWalker { walk(): void { for (let moduleExport of this.program.moduleLevelExports.values()) { // FIXME: doesn't honor the actual externally visible name - this.visitElement(moduleExport.element); + this.visitElement(moduleExport); } var todo = this.todo; for (let i = 0; i < todo.length; ) this.visitElement(todo[i]); diff --git a/src/program.ts b/src/program.ts index ad6d785c99..3c2d35f092 100644 --- a/src/program.ts +++ b/src/program.ts @@ -133,12 +133,6 @@ class TypeAlias { type: CommonTypeNode; } -/** Represents a module-level export. */ -class ModuleExport { - element: Element; - identifier: IdentifierExpression; -} - /** Represents the kind of an operator overload. */ export enum OperatorKind { INVALID, @@ -325,8 +319,8 @@ export class Program extends DiagnosticEmitter { typeAliases: Map = new Map(); /** File-level exports by exported name. */ fileLevelExports: Map = new Map(); - /** Module-level exports by exported name. */ - moduleLevelExports: Map = new Map(); + /** Module-level exports by exported name. (Not related to ES6 modules.) */ + moduleLevelExports: Map = new Map(); /** ArrayBuffer instance reference. */ arrayBufferInstance: Class | null = null; @@ -648,15 +642,13 @@ export class Program extends DiagnosticEmitter { } // register 'main' if present - if (this.moduleLevelExports.has("main")) { - let element = (this.moduleLevelExports.get("main")).element; - if ( - element.kind == ElementKind.FUNCTION_PROTOTYPE && - !(element).isAny(CommonFlags.GENERIC | CommonFlags.AMBIENT) - ) { - (element).set(CommonFlags.MAIN); - this.mainFunction = element; - } + let mainElement = this.moduleLevelExports.get("main"); + if (mainElement && + mainElement.kind == ElementKind.FUNCTION_PROTOTYPE && + !(mainElement).isAny(CommonFlags.GENERIC | CommonFlags.AMBIENT) + ) { + (mainElement).set(CommonFlags.MAIN); + this.mainFunction = mainElement; } // register 'abort' if present @@ -932,18 +924,15 @@ export class Program extends DiagnosticEmitter { this.currentFilespace.members.set(simpleName, prototype); if (prototype.is(CommonFlags.EXPORT) && declaration.range.source.isEntry) { if (this.moduleLevelExports.has(simpleName)) { - let existingExport = this.moduleLevelExports.get(simpleName); + let existingExport = this.moduleLevelExports.get(simpleName)!; this.error( DiagnosticCode.Export_declaration_conflicts_with_exported_declaration_of_0, - declaration.name.range, existingExport.element.internalName + declaration.name.range, existingExport.internalName ); return; } prototype.set(CommonFlags.MODULE_EXPORT); - this.moduleLevelExports.set(simpleName, { - element: prototype, - identifier: declaration.name - }); + this.moduleLevelExports.set(simpleName, prototype); } } @@ -1388,18 +1377,15 @@ export class Program extends DiagnosticEmitter { this.currentFilespace.members.set(simpleName, element); if (declaration.range.source.isEntry) { if (this.moduleLevelExports.has(simpleName)) { - let existingExport = this.moduleLevelExports.get(simpleName); + let existingExport = this.moduleLevelExports.get(simpleName)!; this.error( DiagnosticCode.Export_declaration_conflicts_with_exported_declaration_of_0, - declaration.name.range, existingExport.element.internalName + declaration.name.range, existingExport.internalName ); return; } element.set(CommonFlags.MODULE_EXPORT); - this.moduleLevelExports.set(simpleName, { - element, - identifier: declaration.name - }); + this.moduleLevelExports.set(simpleName, element); } } @@ -1484,10 +1470,7 @@ export class Program extends DiagnosticEmitter { // add module level export if a top-level export of an entry file } else if (source.isEntry) { - this.moduleLevelExports.set(externalIdentifier.text, { - element, - identifier: externalIdentifier - }); + this.moduleLevelExports.set(externalIdentifier.text, element); } } @@ -1657,18 +1640,15 @@ export class Program extends DiagnosticEmitter { this.currentFilespace.members.set(simpleName, prototype); if (declaration.range.source.isEntry) { if (this.moduleLevelExports.has(simpleName)) { - let existingExport = this.moduleLevelExports.get(simpleName); + let existingExport = this.moduleLevelExports.get(simpleName)!; this.error( DiagnosticCode.Duplicate_identifier_0, - declaration.name.range, existingExport.element.internalName + declaration.name.range, existingExport.internalName ); return; } prototype.set(CommonFlags.MODULE_EXPORT); - this.moduleLevelExports.set(simpleName, { - element: prototype, - identifier: declaration.name - }); + this.moduleLevelExports.set(simpleName, prototype); } } @@ -1822,18 +1802,15 @@ export class Program extends DiagnosticEmitter { this.currentFilespace.members.set(simpleName, prototype); if (declaration.range.source.isEntry) { if (this.moduleLevelExports.has(simpleName)) { - let existingExport = this.moduleLevelExports.get(simpleName); + let existingExport = this.moduleLevelExports.get(simpleName)!; this.error( DiagnosticCode.Duplicate_identifier_0, - declaration.name.range, existingExport.element.internalName + declaration.name.range, existingExport.internalName ); return; } prototype.set(CommonFlags.MODULE_EXPORT); - this.moduleLevelExports.set(simpleName, { - element: prototype, - identifier: declaration.name - }); + this.moduleLevelExports.set(simpleName, prototype); } } @@ -1911,19 +1888,16 @@ export class Program extends DiagnosticEmitter { this.currentFilespace.members.set(simpleName, namespace); if (declaration.range.source.isEntry) { if (this.moduleLevelExports.has(simpleName)) { - let existingExport = this.moduleLevelExports.get(simpleName); - if (existingExport.element !== namespace) { // not merged + let existingExport = this.moduleLevelExports.get(simpleName)!; + if (existingExport !== namespace) { // not merged this.error( DiagnosticCode.Duplicate_identifier_0, - declaration.name.range, existingExport.element.internalName + declaration.name.range, existingExport.internalName ); return; } } else { - this.moduleLevelExports.set(simpleName, { - element: namespace, - identifier: declaration.name - }); + this.moduleLevelExports.set(simpleName, namespace); } namespace.set(CommonFlags.MODULE_EXPORT); } @@ -2055,18 +2029,15 @@ export class Program extends DiagnosticEmitter { this.currentFilespace.members.set(simpleName, global); if (declaration.range.source.isEntry) { if (this.moduleLevelExports.has(simpleName)) { - let existingExport = this.moduleLevelExports.get(simpleName); + let existingExport = this.moduleLevelExports.get(simpleName)!; this.error( DiagnosticCode.Duplicate_identifier_0, - declaration.name.range, existingExport.element.internalName + declaration.name.range, existingExport.internalName ); continue; } global.set(CommonFlags.MODULE_EXPORT); - this.moduleLevelExports.set(simpleName, { - element: global, - identifier: declaration.name - }); + this.moduleLevelExports.set(simpleName, global); } } this.checkGlobal(global, declaration);