Skip to content

ModuleExport#identifier never used, so just use Element directly #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ under the licensing terms detailed in LICENSE:
* Igor Sbitnev <[email protected]>
* Norton Wang <[email protected]>
* Alan Pierce <[email protected]>
* Andy Hanson <[email protected]>

Portions of this software are derived from third-party works licensed under
the following terms:
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
87 changes: 29 additions & 58 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -325,8 +319,8 @@ export class Program extends DiagnosticEmitter {
typeAliases: Map<string,TypeAlias> = new Map();
/** File-level exports by exported name. */
fileLevelExports: Map<string,Element> = new Map();
/** Module-level exports by exported name. */
moduleLevelExports: Map<string,ModuleExport> = new Map();
/** Module-level exports by exported name. (Not related to ES6 modules.) */
moduleLevelExports: Map<string, Element> = new Map();

/** ArrayBuffer instance reference. */
arrayBufferInstance: Class | null = null;
Expand Down Expand Up @@ -648,15 +642,13 @@ export class Program extends DiagnosticEmitter {
}

// register 'main' if present
if (this.moduleLevelExports.has("main")) {
let element = (<ModuleExport>this.moduleLevelExports.get("main")).element;
if (
element.kind == ElementKind.FUNCTION_PROTOTYPE &&
!(<FunctionPrototype>element).isAny(CommonFlags.GENERIC | CommonFlags.AMBIENT)
) {
(<FunctionPrototype>element).set(CommonFlags.MAIN);
this.mainFunction = <FunctionPrototype>element;
}
let mainElement = this.moduleLevelExports.get("main");
if (mainElement &&
mainElement.kind == ElementKind.FUNCTION_PROTOTYPE &&
!(<FunctionPrototype>mainElement).isAny(CommonFlags.GENERIC | CommonFlags.AMBIENT)
) {
(<FunctionPrototype>mainElement).set(CommonFlags.MAIN);
this.mainFunction = <FunctionPrototype>mainElement;
}

// register 'abort' if present
Expand Down Expand Up @@ -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 = <ModuleExport>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, <ModuleExport>{
element: prototype,
identifier: declaration.name
});
this.moduleLevelExports.set(simpleName, prototype);
}
}

Expand Down Expand Up @@ -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 = <ModuleExport>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, <ModuleExport>{
element,
identifier: declaration.name
});
this.moduleLevelExports.set(simpleName, element);
}
}

Expand Down Expand Up @@ -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, <ModuleExport>{
element,
identifier: externalIdentifier
});
this.moduleLevelExports.set(externalIdentifier.text, element);
}
}

Expand Down Expand Up @@ -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 = <ModuleExport>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, <ModuleExport>{
element: prototype,
identifier: declaration.name
});
this.moduleLevelExports.set(simpleName, prototype);
}
}

Expand Down Expand Up @@ -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 = <ModuleExport>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, <ModuleExport>{
element: prototype,
identifier: declaration.name
});
this.moduleLevelExports.set(simpleName, prototype);
}
}

Expand Down Expand Up @@ -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 = <ModuleExport>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, <ModuleExport>{
element: namespace,
identifier: declaration.name
});
this.moduleLevelExports.set(simpleName, namespace);
}
namespace.set(CommonFlags.MODULE_EXPORT);
}
Expand Down Expand Up @@ -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 = <ModuleExport>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, <ModuleExport>{
element: global,
identifier: declaration.name
});
this.moduleLevelExports.set(simpleName, global);
}
}
this.checkGlobal(global, declaration);
Expand Down