Skip to content

Commit

Permalink
Improve robustness of dependency inference
Browse files Browse the repository at this point in the history
Update the patterns used to detect module dependencies to tolerate
string literals which may appear on the same line as module specifiers.
Further improve the pattern so that it does not match all
U+0022-delimited string literals and so that it does not require a
trailing semicolon.
  • Loading branch information
jugglinmike authored and rwaldron committed May 4, 2021
1 parent 4770db2 commit 93445b9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function findModuleSpecifiers(source) {
let lines = source.split(/\r?\n/g);
return lines.reduce((accum, line) => {
if (line.includes('.js') || line.includes('.mjs')) {
let parsed = /(import|import\(|from)(\s*)'(.*)'|"(.*)";/g.exec(line);
let parsed = /(import|import\(|from)(\s*)('(.*?)'|"(.*?)")/g.exec(line);
if (parsed && parsed.length) {
for (let entry of parsed) {
if (entry &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 2;
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*---
description: Dynamic import assertions
info: |
This test approximates the "import assertions" syntax using code comments in
order to support improvements to ESHost's dependency inferrence logic while
still passing in runtimes which do not yet support the proposed language
extension.
esid: sec-moduleevaluation
flags: [module, async]
---*/

Promise.all([
import('./import-assertion-1_FIXTURE.js'),//, {'':''})
import("./import-assertion-2_FIXTURE.js"),//, {"":""})
]).then(function(values) {
assert.sameValue(values[0].default, 1);
assert.sameValue(values[1].default, 2);
}).then($DONE, $DONE);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*---
description: Static import assertions
info: |
This test approximates the "import assertions" syntax using code comments in
order to support improvements to ESHost's dependency inferrence logic while
still passing in runtimes which do not yet support the proposed language
extension.
esid: sec-moduleevaluation
flags: [module]
---*/

import one from './import-assertion-1_FIXTURE.js'// assert {'':''};
import two from "./import-assertion-2_FIXTURE.js"// assert {"":""};
import './import-assertion-3_FIXTURE.js'// assert {'':''};
import "./import-assertion-4_FIXTURE.js"// assert {"":""};

assert.sameValue(one, 1);
assert.sameValue(two, 2);

0 comments on commit 93445b9

Please sign in to comment.