Skip to content

Commit

Permalink
fix importing modules with path segments (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsDenBakker authored and guybedford committed Jul 17, 2019
1 parent 8594d85 commit 9422c03
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ if (typeof document !== 'undefined') {

const backslashRegEx = /\\/g;
export function resolveIfNotPlainOrUrl (relUrl, parentUrl) {
// strip off any trailing query params or hashes
parentUrl = parentUrl && parentUrl.split('#')[0].split('?')[0];
if (relUrl.indexOf('\\') !== -1)
relUrl = relUrl.replace(backslashRegEx, '/');
// protocol-relative
Expand Down
6 changes: 6 additions & 0 deletions test/browser-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ suite('Basic loading tests', () => {
assert(m);
assert.equal(m.asdf, 'asdf');
});

test('Should import a module with query parameters with path segments', async function () {
var m = await importShim('./fixtures/es-modules/query-param-a.js?foo=/foo/bar/');
assert(m);
assert.equal(m.a, 'ab');
});
});

suite('Circular dependencies', function() {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/es-modules/query-param-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { b } from './query-param-b.js';

export const a = 'a' + b;
1 change: 1 addition & 0 deletions test/fixtures/es-modules/query-param-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const b = 'b';

0 comments on commit 9422c03

Please sign in to comment.