-
-
Notifications
You must be signed in to change notification settings - Fork 664
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
Keep resolving queued imports while there is progress #1415
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1020,50 +1020,69 @@ export class Program extends DiagnosticEmitter { | |
} | ||
} | ||
|
||
// queued imports should be resolvable now through traversing exports and queued exports | ||
for (let i = 0, k = queuedImports.length; i < k; ++i) { | ||
let queuedImport = queuedImports[i]; | ||
let localIdentifier = queuedImport.localIdentifier; | ||
let foreignIdentifier = queuedImport.foreignIdentifier; | ||
if (foreignIdentifier) { // i.e. import { foo [as bar] } from "./baz" | ||
let element = this.lookupForeign( | ||
foreignIdentifier.text, | ||
queuedImport.foreignPath, | ||
queuedImport.foreignPathAlt, | ||
queuedExports | ||
); | ||
if (element) { | ||
queuedImport.localFile.add( | ||
localIdentifier.text, | ||
element, | ||
localIdentifier // isImport | ||
); | ||
} else { | ||
// FIXME: file not found is not reported if this happens? | ||
this.error( | ||
DiagnosticCode.Module_0_has_no_exported_member_1, | ||
foreignIdentifier.range, queuedImport.foreignPath, foreignIdentifier.text | ||
// queued imports should be resolvable now through traversing exports and queued exports. | ||
// note that imports may depend upon imports, so repeat until there's no more progress. | ||
do { | ||
let i = 0, madeProgress = false; | ||
while (i < queuedImports.length) { | ||
let queuedImport = queuedImports[i]; | ||
let localIdentifier = queuedImport.localIdentifier; | ||
let foreignIdentifier = queuedImport.foreignIdentifier; | ||
if (foreignIdentifier) { // i.e. import { foo [as bar] } from "./baz" | ||
let element = this.lookupForeign( | ||
foreignIdentifier.text, | ||
queuedImport.foreignPath, | ||
queuedImport.foreignPathAlt, | ||
queuedExports | ||
); | ||
} | ||
} else { // i.e. import * as bar from "./bar" | ||
let foreignFile = this.lookupForeignFile(queuedImport.foreignPath, queuedImport.foreignPathAlt); | ||
if (foreignFile) { | ||
let localFile = queuedImport.localFile; | ||
let localName = localIdentifier.text; | ||
localFile.add( | ||
localName, | ||
foreignFile.asImportedNamespace( | ||
if (element) { | ||
queuedImport.localFile.add( | ||
localIdentifier.text, | ||
element, | ||
localIdentifier // isImport | ||
); | ||
queuedImports.splice(i, 1); | ||
madeProgress = true; | ||
} else { | ||
++i; | ||
} | ||
} else { // i.e. import * as bar from "./bar" | ||
let foreignFile = this.lookupForeignFile(queuedImport.foreignPath, queuedImport.foreignPathAlt); | ||
if (foreignFile) { | ||
let localFile = queuedImport.localFile; | ||
let localName = localIdentifier.text; | ||
localFile.add( | ||
localName, | ||
localFile, | ||
localIdentifier | ||
), | ||
localIdentifier // isImport | ||
); | ||
} else { | ||
assert(false); // already reported by the parser not finding the file | ||
foreignFile.asImportedNamespace( | ||
localName, | ||
localFile, | ||
localIdentifier | ||
), | ||
localIdentifier // isImport | ||
); | ||
queuedImports.splice(i, 1); | ||
madeProgress = true; | ||
} else { | ||
++i; | ||
assert(false); // already reported by the parser not finding the file | ||
} | ||
} | ||
} | ||
} | ||
if (!madeProgress) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhhhh! I had a feeling it may have been an ordering issue where one import had to resolve before others 😄 👍 |
||
// report queued imports we were unable to resolve | ||
for (let j = 0, l = queuedImports.length; j < l; ++j) { | ||
let queuedImport = queuedImports[j]; | ||
let foreignIdentifier = queuedImport.foreignIdentifier; | ||
if (foreignIdentifier) { | ||
this.error( | ||
DiagnosticCode.Module_0_has_no_exported_member_1, | ||
foreignIdentifier.range, queuedImport.foreignPath, foreignIdentifier.text | ||
); | ||
} | ||
} | ||
break; | ||
} | ||
} while (true); | ||
|
||
// queued exports should be resolvable now that imports are finalized | ||
// TODO: for (let [file, exports] of queuedExports) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(module | ||
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) | ||
(type $none_=>_none (func)) | ||
(memory $0 0) | ||
(global $export/a i32 (i32.const 1)) | ||
(global $export/b i32 (i32.const 2)) | ||
(global $export/c i32 (i32.const 3)) | ||
(export "memory" (memory $0)) | ||
(export "a" (global $export/a)) | ||
(export "renamed_a" (global $export/a)) | ||
(export "renamed_b" (global $export/b)) | ||
(export "renamed_renamed_b" (global $export/b)) | ||
(export "default" (func $export-default/theDefault)) | ||
(export "renamed_default" (func $export-default/theDefault)) | ||
(export "exportstar.add" (func $export/add)) | ||
(export "exportstar.sub" (func $export/sub)) | ||
(export "exportstar.renamed_mul" (func $export/mul)) | ||
(export "exportstar.a" (global $export/a)) | ||
(export "exportstar.b" (global $export/b)) | ||
(export "exportstar.renamed_c" (global $export/c)) | ||
(export "exportstar.ns.two" (func $export-default/theDefault)) | ||
(export "exportstar.default.two" (func $export-default/theDefault)) | ||
(func $export/add (param $0 i32) (param $1 i32) (result i32) | ||
local.get $0 | ||
local.get $1 | ||
i32.add | ||
) | ||
(func $export/mul (param $0 i32) (param $1 i32) (result i32) | ||
local.get $0 | ||
local.get $1 | ||
i32.mul | ||
) | ||
(func $export-default/theDefault | ||
nop | ||
) | ||
(func $export/sub (param $0 i32) (param $1 i32) (result i32) | ||
local.get $0 | ||
local.get $1 | ||
i32.sub | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
(module | ||
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) | ||
(type $none_=>_none (func)) | ||
(memory $0 0) | ||
(global $export/a i32 (i32.const 1)) | ||
(global $export/b i32 (i32.const 2)) | ||
(global $export/c i32 (i32.const 3)) | ||
(export "memory" (memory $0)) | ||
(export "a" (global $export/a)) | ||
(export "renamed_a" (global $export/a)) | ||
(export "renamed_b" (global $export/b)) | ||
(export "renamed_renamed_b" (global $export/b)) | ||
(export "default" (func $export-default/theDefault)) | ||
(export "renamed_default" (func $export-default/theDefault)) | ||
(export "exportstar.add" (func $export/add)) | ||
(export "exportstar.sub" (func $export/sub)) | ||
(export "exportstar.renamed_mul" (func $export/mul)) | ||
(export "exportstar.a" (global $export/a)) | ||
(export "exportstar.b" (global $export/b)) | ||
(export "exportstar.renamed_c" (global $export/c)) | ||
(export "exportstar.ns.two" (func $export-default/theDefault)) | ||
(export "exportstar.default.two" (func $export-default/theDefault)) | ||
(func $export/add (param $0 i32) (param $1 i32) (result i32) | ||
local.get $0 | ||
local.get $1 | ||
i32.add | ||
) | ||
(func $export/mul (param $0 i32) (param $1 i32) (result i32) | ||
local.get $0 | ||
local.get $1 | ||
i32.mul | ||
) | ||
(func $export-default/theDefault | ||
nop | ||
) | ||
(func $export/sub (param $0 i32) (param $1 i32) (result i32) | ||
local.get $0 | ||
local.get $1 | ||
i32.sub | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ export { | |
default, | ||
default as renamed_default | ||
} from "./reexport"; | ||
|
||
import { exportstar } from "./reexport"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding a test as well! 👍 |
||
export { exportstar }; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for adding this for console log debuggers like me 😂