Skip to content

Commit

Permalink
Always make "module" available for SystemJS and AMD formats if `impor…
Browse files Browse the repository at this point in the history
…t.meta` is accessed directly (#3282)
  • Loading branch information
lukastaegert committed Dec 13, 2019
1 parent 6d94f0e commit ab48a69
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 15 deletions.
17 changes: 8 additions & 9 deletions src/ast/nodes/MetaProperty.ts
Expand Up @@ -35,16 +35,15 @@ export default class MetaProperty extends NodeBase {
parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
? parent.propertyKey
: null);
if (metaProperty) {
if (
metaProperty.startsWith(FILE_PREFIX) ||
if (
metaProperty &&
(metaProperty.startsWith(FILE_PREFIX) ||
metaProperty.startsWith(ASSET_PREFIX) ||
metaProperty.startsWith(CHUNK_PREFIX)
) {
this.scope.addAccessedGlobalsByFormat(accessedFileUrlGlobals);
} else {
this.scope.addAccessedGlobalsByFormat(accessedMetaUrlGlobals);
}
metaProperty.startsWith(CHUNK_PREFIX))
) {
this.scope.addAccessedGlobalsByFormat(accessedFileUrlGlobals);
} else {
this.scope.addAccessedGlobalsByFormat(accessedMetaUrlGlobals);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/form/samples/import-meta/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'supports directly accessing import.meta'
};
5 changes: 5 additions & 0 deletions test/form/samples/import-meta/_expected/amd.js
@@ -0,0 +1,5 @@
define(['module'], function (module) { 'use strict';

console.log(({ url: new URL(module.uri, document.baseURI).href }));

});
3 changes: 3 additions & 0 deletions test/form/samples/import-meta/_expected/cjs.js
@@ -0,0 +1,3 @@
'use strict';

console.log(({ url: (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('cjs.js', document.baseURI).href)) }));
1 change: 1 addition & 0 deletions test/form/samples/import-meta/_expected/es.js
@@ -0,0 +1 @@
console.log(import.meta);
6 changes: 6 additions & 0 deletions test/form/samples/import-meta/_expected/iife.js
@@ -0,0 +1,6 @@
(function () {
'use strict';

console.log(({ url: (document.currentScript && document.currentScript.src || new URL('iife.js', document.baseURI).href) }));

}());
10 changes: 10 additions & 0 deletions test/form/samples/import-meta/_expected/system.js
@@ -0,0 +1,10 @@
System.register([], function (exports, module) {
'use strict';
return {
execute: function () {

console.log(module.meta);

}
};
});
8 changes: 8 additions & 0 deletions test/form/samples/import-meta/_expected/umd.js
@@ -0,0 +1,8 @@
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}((function () { 'use strict';

console.log(({ url: (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('umd.js', document.baseURI).href)) }));

})));
1 change: 1 addition & 0 deletions test/form/samples/import-meta/main.js
@@ -0,0 +1 @@
console.log(import.meta);
3 changes: 0 additions & 3 deletions test/form/samples/resolve-import-meta-url-export/resolved.js

This file was deleted.

This file was deleted.

0 comments on commit ab48a69

Please sign in to comment.