Skip to content
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

import.meta.resolve implementation #2230

Merged
merged 1 commit into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/system-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ systemJSPrototype.import = function (id, parentUrl) {

// Hookable createContext function -> allowing eg custom import meta
systemJSPrototype.createContext = function (parentId) {
var loader = this;
return {
url: parentId
url: parentId,
resolve: function (id, parentUrl) {
return Promise.resolve(loader.resolve(id, parentUrl || parentId));
}
};
};

Expand Down
47 changes: 47 additions & 0 deletions test/browser/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,51 @@ suite('SystemJS Standard Tests', function() {
});
});

test('import.meta.resolve package maps', function () {
return System.import('fixtures/resolve.js').then(function (m) {
return m.resolve('a')
})
.then(function (resolved) {
assert.equal(resolved, rootURL + 'b');
});
});

test('import.meta.resolve package maps paths', function () {
return System.import('fixtures/resolve.js').then(function (m) {
return m.resolve('a/')
})
.then(function (resolved) {
assert.equal(resolved, baseURL + 'fixtures/browser/a/');
});
});

test('Contextual package maps', function () {
return System.import('fixtures/scope-test/index.js')
.then(function (m) {
assert.equal(m.mapdep, 'mapdep');
});
});

test('import.meta.resolve contextual package maps', function () {
return System.import('fixtures/resolve.js').then(function (m) {
return m.resolve('maptest', baseURL + 'fixtures/browser/scope-test/index.js')
})
.then(function (resolved) {
assert.equal(resolved, baseURL + 'fixtures/browser/contextual-map-dep.js');
});
});

test('import.meta.resolve contextual package maps fail', function () {
return System.import('fixtures/resolve.js').then(function (m) {
return m.resolve('maptest')
})
.then(function (resolved) {
assert.ok(false);
}, function (error) {
assert.equal(error.message.indexOf('Unable to resolve'), 0);
});
});

test('Loading named System.register fails', function () {
return System.import('fixtures/named-register.js')
.then(function () {
Expand Down Expand Up @@ -219,6 +257,15 @@ suite('SystemJS Standard Tests', function() {
assert.equal(System.get(resolved).auto, 'import');
});

test('import.meta.resolve', function () {
return System.import('fixtures/resolve.js').then(function (m) {
return m.resolve('./test.js')
})
.then(function (resolved) {
assert.equal(resolved, baseURL + 'fixtures/browser/test.js');
});
});

test('non-enumerable __esModule property export (issue 2090)', function () {
return System.import('fixtures/__esModule.js').then(function (m) {
// Even though __esModule is not enumerable on the exported object, it should be preserved on the systemjs namespace
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/browser/resolve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
System.register([], function (_export, _context) {
return {
setters: [],
execute: function () {
_export({
url: _context.meta.url,
resolve: _context.meta.resolve
});
}
};
});