Skip to content

Commit

Permalink
Feat: Support module.uri in AMD extra (#2485)
Browse files Browse the repository at this point in the history
* feat(amd): support module.uri

* test(amd-extra): add test case for passing context meta url as module.uri
  • Loading branch information
jackw committed Apr 27, 2024
1 parent f6648c4 commit 1f76d7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/extras/amd.js
Expand Up @@ -40,11 +40,12 @@ import { errMsg } from '../err-msg.js';
if (splice)
amdDefineDeps.length -= splice;
var amdExec = amdDefineExec;
return [amdDefineDeps, function (_export) {
return [amdDefineDeps, function (_export, _context) {
_export({ default: exports, __useDefault: true });
return {
setters: setters,
execute: function () {
module.uri = _context.meta.url;
var amdResult = amdExec.apply(exports, depModules);
if (amdResult !== undefined)
module.exports = amdResult;
Expand Down
7 changes: 7 additions & 0 deletions test/browser/amd.js
Expand Up @@ -90,6 +90,13 @@ suite('AMD tests', function () {
});
});

test('Has access to module.uri (context meta)', function () {
return System.import('fixtures/amd-module-meta.js').then(function (m) {
assert.ok(m.default);
assert.equal(m.default.uri, baseURL+'fixtures/browser/amd-module-meta.js');
});
});

test('Throws an error when define() is called incorrectly', () => {
try {
define("strings are invalid amd modules");
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/browser/amd-module-meta.js
@@ -0,0 +1,5 @@
define(["module"], function (module) {
return {
uri: module.uri,
};
});

0 comments on commit 1f76d7d

Please sign in to comment.