Skip to content

Commit 80165fa

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

File tree

3 files changed

+30
-57
lines changed

3 files changed

+30
-57
lines changed

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: 28 additions & 55 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,14 +642,14 @@ 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;
645+
let mainElement = this.moduleLevelExports.get("main");
646+
if (mainElement) {
653647
if (
654-
element.kind == ElementKind.FUNCTION_PROTOTYPE &&
655-
!(<FunctionPrototype>element).isAny(CommonFlags.GENERIC | CommonFlags.AMBIENT)
648+
mainElement.kind == ElementKind.FUNCTION_PROTOTYPE &&
649+
!(<FunctionPrototype>mainElement).isAny(CommonFlags.GENERIC | CommonFlags.AMBIENT)
656650
) {
657-
(<FunctionPrototype>element).set(CommonFlags.MAIN);
658-
this.mainFunction = <FunctionPrototype>element;
651+
(<FunctionPrototype>mainElement).set(CommonFlags.MAIN);
652+
this.mainFunction = <FunctionPrototype>mainElement;
659653
}
660654
}
661655

@@ -932,18 +926,15 @@ export class Program extends DiagnosticEmitter {
932926
this.currentFilespace.members.set(simpleName, prototype);
933927
if (prototype.is(CommonFlags.EXPORT) && declaration.range.source.isEntry) {
934928
if (this.moduleLevelExports.has(simpleName)) {
935-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
929+
let existingExport = this.moduleLevelExports.get(simpleName)!;
936930
this.error(
937931
DiagnosticCode.Export_declaration_conflicts_with_exported_declaration_of_0,
938-
declaration.name.range, existingExport.element.internalName
932+
declaration.name.range, existingExport.internalName
939933
);
940934
return;
941935
}
942936
prototype.set(CommonFlags.MODULE_EXPORT);
943-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
944-
element: prototype,
945-
identifier: declaration.name
946-
});
937+
this.moduleLevelExports.set(simpleName, prototype);
947938
}
948939
}
949940

@@ -1388,18 +1379,15 @@ export class Program extends DiagnosticEmitter {
13881379
this.currentFilespace.members.set(simpleName, element);
13891380
if (declaration.range.source.isEntry) {
13901381
if (this.moduleLevelExports.has(simpleName)) {
1391-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
1382+
let existingExport = this.moduleLevelExports.get(simpleName)!;
13921383
this.error(
13931384
DiagnosticCode.Export_declaration_conflicts_with_exported_declaration_of_0,
1394-
declaration.name.range, existingExport.element.internalName
1385+
declaration.name.range, existingExport.internalName
13951386
);
13961387
return;
13971388
}
13981389
element.set(CommonFlags.MODULE_EXPORT);
1399-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
1400-
element,
1401-
identifier: declaration.name
1402-
});
1390+
this.moduleLevelExports.set(simpleName, element);
14031391
}
14041392
}
14051393

@@ -1484,10 +1472,7 @@ export class Program extends DiagnosticEmitter {
14841472

14851473
// add module level export if a top-level export of an entry file
14861474
} else if (source.isEntry) {
1487-
this.moduleLevelExports.set(externalIdentifier.text, <ModuleExport>{
1488-
element,
1489-
identifier: externalIdentifier
1490-
});
1475+
this.moduleLevelExports.set(externalIdentifier.text, element);
14911476
}
14921477
}
14931478

@@ -1657,18 +1642,15 @@ export class Program extends DiagnosticEmitter {
16571642
this.currentFilespace.members.set(simpleName, prototype);
16581643
if (declaration.range.source.isEntry) {
16591644
if (this.moduleLevelExports.has(simpleName)) {
1660-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
1645+
let existingExport = this.moduleLevelExports.get(simpleName)!;
16611646
this.error(
16621647
DiagnosticCode.Duplicate_identifier_0,
1663-
declaration.name.range, existingExport.element.internalName
1648+
declaration.name.range, existingExport.internalName
16641649
);
16651650
return;
16661651
}
16671652
prototype.set(CommonFlags.MODULE_EXPORT);
1668-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
1669-
element: prototype,
1670-
identifier: declaration.name
1671-
});
1653+
this.moduleLevelExports.set(simpleName, prototype);
16721654
}
16731655
}
16741656

@@ -1822,18 +1804,15 @@ export class Program extends DiagnosticEmitter {
18221804
this.currentFilespace.members.set(simpleName, prototype);
18231805
if (declaration.range.source.isEntry) {
18241806
if (this.moduleLevelExports.has(simpleName)) {
1825-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
1807+
let existingExport = this.moduleLevelExports.get(simpleName)!;
18261808
this.error(
18271809
DiagnosticCode.Duplicate_identifier_0,
1828-
declaration.name.range, existingExport.element.internalName
1810+
declaration.name.range, existingExport.internalName
18291811
);
18301812
return;
18311813
}
18321814
prototype.set(CommonFlags.MODULE_EXPORT);
1833-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
1834-
element: prototype,
1835-
identifier: declaration.name
1836-
});
1815+
this.moduleLevelExports.set(simpleName, prototype);
18371816
}
18381817
}
18391818

@@ -1911,19 +1890,16 @@ export class Program extends DiagnosticEmitter {
19111890
this.currentFilespace.members.set(simpleName, namespace);
19121891
if (declaration.range.source.isEntry) {
19131892
if (this.moduleLevelExports.has(simpleName)) {
1914-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
1915-
if (existingExport.element !== namespace) { // not merged
1893+
let existingExport = this.moduleLevelExports.get(simpleName)!;
1894+
if (existingExport !== namespace) { // not merged
19161895
this.error(
19171896
DiagnosticCode.Duplicate_identifier_0,
1918-
declaration.name.range, existingExport.element.internalName
1897+
declaration.name.range, existingExport.internalName
19191898
);
19201899
return;
19211900
}
19221901
} else {
1923-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
1924-
element: namespace,
1925-
identifier: declaration.name
1926-
});
1902+
this.moduleLevelExports.set(simpleName, namespace);
19271903
}
19281904
namespace.set(CommonFlags.MODULE_EXPORT);
19291905
}
@@ -2055,18 +2031,15 @@ export class Program extends DiagnosticEmitter {
20552031
this.currentFilespace.members.set(simpleName, global);
20562032
if (declaration.range.source.isEntry) {
20572033
if (this.moduleLevelExports.has(simpleName)) {
2058-
let existingExport = <ModuleExport>this.moduleLevelExports.get(simpleName);
2034+
let existingExport = this.moduleLevelExports.get(simpleName)!;
20592035
this.error(
20602036
DiagnosticCode.Duplicate_identifier_0,
2061-
declaration.name.range, existingExport.element.internalName
2037+
declaration.name.range, existingExport.internalName
20622038
);
20632039
continue;
20642040
}
20652041
global.set(CommonFlags.MODULE_EXPORT);
2066-
this.moduleLevelExports.set(simpleName, <ModuleExport>{
2067-
element: global,
2068-
identifier: declaration.name
2069-
});
2042+
this.moduleLevelExports.set(simpleName, global);
20702043
}
20712044
}
20722045
this.checkGlobal(global, declaration);

0 commit comments

Comments
 (0)