Skip to content

Commit 707b856

Browse files
committed
ModuleExport#identifier never used, so just use Element directly
1 parent c769f65 commit 707b856

File tree

4 files changed

+32
-60
lines changed

4 files changed

+32
-60
lines changed

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ under the licensing terms detailed in LICENSE:
88
* Igor Sbitnev <[email protected]>
99
* Norton Wang <[email protected]>
1010
* Alan Pierce <[email protected]>
11+
* Andy Hanson <[email protected]>
1112

1213
Portions of this software are derived from third-party works licensed under
1314
the following terms:

src/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export class Compiler extends DiagnosticEmitter {
408408

409409
// set up module exports
410410
for (let [name, moduleExport] of program.moduleLevelExports) {
411-
this.makeModuleExport(name, moduleExport.element);
411+
this.makeModuleExport(name, moduleExport);
412412
}
413413

414414
// set up gc

src/definitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ abstract class ExportsWalker {
5656
walk(): void {
5757
for (let moduleExport of this.program.moduleLevelExports.values()) {
5858
// FIXME: doesn't honor the actual externally visible name
59-
this.visitElement(moduleExport.element);
59+
this.visitElement(moduleExport);
6060
}
6161
var todo = this.todo;
6262
for (let i = 0; i < todo.length; ) this.visitElement(todo[i]);

src/program.ts

Lines changed: 29 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,6 @@ class TypeAlias {
133133
type: CommonTypeNode;
134134
}
135135

136-
/** Represents a module-level export. */
137-
class ModuleExport {
138-
element: Element;
139-
identifier: IdentifierExpression;
140-
}
141-
142136
/** Represents the kind of an operator overload. */
143137
export enum OperatorKind {
144138
INVALID,
@@ -325,8 +319,8 @@ export class Program extends DiagnosticEmitter {
325319
typeAliases: Map<string,TypeAlias> = new Map();
326320
/** File-level exports by exported name. */
327321
fileLevelExports: Map<string,Element> = new Map();
328-
/** Module-level exports by exported name. */
329-
moduleLevelExports: Map<string,ModuleExport> = new Map();
322+
/** Module-level exports by exported name. (Not related to ES6 modules.) */
323+
moduleLevelExports: Map<string, Element> = new Map();
330324

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

650644
// register 'main' if present
651-
if (this.moduleLevelExports.has("main")) {
652-
let element = (<ModuleExport>this.moduleLevelExports.get("main")).element;
653-
if (
654-
element.kind == ElementKind.FUNCTION_PROTOTYPE &&
655-
!(<FunctionPrototype>element).isAny(CommonFlags.GENERIC | CommonFlags.AMBIENT)
656-
) {
657-
(<FunctionPrototype>element).set(CommonFlags.MAIN);
658-
this.mainFunction = <FunctionPrototype>element;
659-
}
645+
let mainElement = this.moduleLevelExports.get("main");
646+
if (mainElement &&
647+
mainElement.kind == ElementKind.FUNCTION_PROTOTYPE &&
648+
!(<FunctionPrototype>mainElement).isAny(CommonFlags.GENERIC | CommonFlags.AMBIENT)
649+
) {
650+
(<FunctionPrototype>mainElement).set(CommonFlags.MAIN);
651+
this.mainFunction = <FunctionPrototype>mainElement;
660652
}
661653

662654
// register 'abort' if present
@@ -932,18 +924,15 @@ export class Program extends DiagnosticEmitter {
932924
this.currentFilespace.members.set(simpleName, prototype);
933925
if (prototype.is(CommonFlags.EXPORT) && declaration.range.source.isEntry) {
934926
if (this.moduleLevelExports.has(simpleName)) {
935-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
927+
let existingExport = this.moduleLevelExports.get(simpleName)!;
936928
this.error(
937929
DiagnosticCode.Export_declaration_conflicts_with_exported_declaration_of_0,
938-
declaration.name.range, existingExport.element.internalName
930+
declaration.name.range, existingExport.internalName
939931
);
940932
return;
941933
}
942934
prototype.set(CommonFlags.MODULE_EXPORT);
943-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
944-
element: prototype,
945-
identifier: declaration.name
946-
});
935+
this.moduleLevelExports.set(simpleName, prototype);
947936
}
948937
}
949938

@@ -1388,18 +1377,15 @@ export class Program extends DiagnosticEmitter {
13881377
this.currentFilespace.members.set(simpleName, element);
13891378
if (declaration.range.source.isEntry) {
13901379
if (this.moduleLevelExports.has(simpleName)) {
1391-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
1380+
let existingExport = this.moduleLevelExports.get(simpleName)!;
13921381
this.error(
13931382
DiagnosticCode.Export_declaration_conflicts_with_exported_declaration_of_0,
1394-
declaration.name.range, existingExport.element.internalName
1383+
declaration.name.range, existingExport.internalName
13951384
);
13961385
return;
13971386
}
13981387
element.set(CommonFlags.MODULE_EXPORT);
1399-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
1400-
element,
1401-
identifier: declaration.name
1402-
});
1388+
this.moduleLevelExports.set(simpleName, element);
14031389
}
14041390
}
14051391

@@ -1484,10 +1470,7 @@ export class Program extends DiagnosticEmitter {
14841470

14851471
// add module level export if a top-level export of an entry file
14861472
} else if (source.isEntry) {
1487-
this.moduleLevelExports.set(externalIdentifier.text, <ModuleExport>{
1488-
element,
1489-
identifier: externalIdentifier
1490-
});
1473+
this.moduleLevelExports.set(externalIdentifier.text, element);
14911474
}
14921475
}
14931476

@@ -1657,18 +1640,15 @@ export class Program extends DiagnosticEmitter {
16571640
this.currentFilespace.members.set(simpleName, prototype);
16581641
if (declaration.range.source.isEntry) {
16591642
if (this.moduleLevelExports.has(simpleName)) {
1660-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
1643+
let existingExport = this.moduleLevelExports.get(simpleName)!;
16611644
this.error(
16621645
DiagnosticCode.Duplicate_identifier_0,
1663-
declaration.name.range, existingExport.element.internalName
1646+
declaration.name.range, existingExport.internalName
16641647
);
16651648
return;
16661649
}
16671650
prototype.set(CommonFlags.MODULE_EXPORT);
1668-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
1669-
element: prototype,
1670-
identifier: declaration.name
1671-
});
1651+
this.moduleLevelExports.set(simpleName, prototype);
16721652
}
16731653
}
16741654

@@ -1822,18 +1802,15 @@ export class Program extends DiagnosticEmitter {
18221802
this.currentFilespace.members.set(simpleName, prototype);
18231803
if (declaration.range.source.isEntry) {
18241804
if (this.moduleLevelExports.has(simpleName)) {
1825-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
1805+
let existingExport = this.moduleLevelExports.get(simpleName)!;
18261806
this.error(
18271807
DiagnosticCode.Duplicate_identifier_0,
1828-
declaration.name.range, existingExport.element.internalName
1808+
declaration.name.range, existingExport.internalName
18291809
);
18301810
return;
18311811
}
18321812
prototype.set(CommonFlags.MODULE_EXPORT);
1833-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
1834-
element: prototype,
1835-
identifier: declaration.name
1836-
});
1813+
this.moduleLevelExports.set(simpleName, prototype);
18371814
}
18381815
}
18391816

@@ -1911,19 +1888,16 @@ export class Program extends DiagnosticEmitter {
19111888
this.currentFilespace.members.set(simpleName, namespace);
19121889
if (declaration.range.source.isEntry) {
19131890
if (this.moduleLevelExports.has(simpleName)) {
1914-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
1915-
if (existingExport.element !== namespace) { // not merged
1891+
let existingExport = this.moduleLevelExports.get(simpleName)!;
1892+
if (existingExport !== namespace) { // not merged
19161893
this.error(
19171894
DiagnosticCode.Duplicate_identifier_0,
1918-
declaration.name.range, existingExport.element.internalName
1895+
declaration.name.range, existingExport.internalName
19191896
);
19201897
return;
19211898
}
19221899
} else {
1923-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
1924-
element: namespace,
1925-
identifier: declaration.name
1926-
});
1900+
this.moduleLevelExports.set(simpleName, namespace);
19271901
}
19281902
namespace.set(CommonFlags.MODULE_EXPORT);
19291903
}
@@ -2055,18 +2029,15 @@ export class Program extends DiagnosticEmitter {
20552029
this.currentFilespace.members.set(simpleName, global);
20562030
if (declaration.range.source.isEntry) {
20572031
if (this.moduleLevelExports.has(simpleName)) {
2058-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
2032+
let existingExport = this.moduleLevelExports.get(simpleName)!;
20592033
this.error(
20602034
DiagnosticCode.Duplicate_identifier_0,
2061-
declaration.name.range, existingExport.element.internalName
2035+
declaration.name.range, existingExport.internalName
20622036
);
20632037
continue;
20642038
}
20652039
global.set(CommonFlags.MODULE_EXPORT);
2066-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
2067-
element: global,
2068-
identifier: declaration.name
2069-
});
2040+
this.moduleLevelExports.set(simpleName, global);
20702041
}
20712042
}
20722043
this.checkGlobal(global, declaration);

0 commit comments

Comments
 (0)