Skip to content

Remove unnecessary 'queuedImports.splice()' calls #232

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
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
9 changes: 1 addition & 8 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,40 +490,33 @@ export class Program extends DiagnosticEmitter {
}

// queued imports should be resolvable now through traversing exports and queued exports
for (let i = 0; i < queuedImports.length;) {
let queuedImport = queuedImports[i];
for (const queuedImport of queuedImports) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but can we keep the plain for-loop here? Just to be sure, because for-of isn't yet supported when compiling to WASM (somewhat due to the lack of iterators), even though we don't compile the compiler itself to WASM yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What to do about for-of loops over maps?

let declaration = queuedImport.declaration;
if (declaration) { // named
let element = this.tryLocateImport(queuedImport.externalName, queuedExports);
if (element) {
this.elementsLookup.set(queuedImport.localName, element);
queuedImports.splice(i, 1);
} else {
if (element = this.tryLocateImport(queuedImport.externalNameAlt, queuedExports)) {
this.elementsLookup.set(queuedImport.localName, element);
queuedImports.splice(i, 1);
} else {
this.error(
DiagnosticCode.Module_0_has_no_exported_member_1,
declaration.range,
(<ImportStatement>declaration.parent).path.value,
declaration.externalName.text
);
++i;
}
}
} else { // filespace
let element = this.elementsLookup.get(queuedImport.externalName);
if (element) {
this.elementsLookup.set(queuedImport.localName, element);
queuedImports.splice(i, 1);
} else {
if (element = this.elementsLookup.get(queuedImport.externalNameAlt)) {
this.elementsLookup.set(queuedImport.localName, element);
queuedImports.splice(i, 1);
} else {
assert(false); // already reported by the parser not finding the file
++i;
}
}
}
Expand Down