Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Jan 28, 2022
1 parent c09e82f commit 17e8eed
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/dependencies/ImportMetaPlugin.js
Expand Up @@ -52,6 +52,7 @@ class ImportMetaPlugin {
const parserHandler = (parser, { importMeta }) => {
if (importMeta === false) {
const { importMetaName } = compilation.outputOptions;
if (importMetaName === "import.meta") return;

parser.hooks.expression
.for("import.meta")
Expand Down
1 change: 1 addition & 0 deletions test/configCases/output/import-meta-name/a.js
@@ -0,0 +1 @@
export const url = import.meta.url;
9 changes: 9 additions & 0 deletions test/configCases/output/import-meta-name/index.js
@@ -0,0 +1,9 @@
import { url } from "./a";

it("should evaluate import.meta to pseudoImport.meta", () => {
expect(url).toBe("http://test.co/path/index.js");
});

it("should evaluate import.meta in runtime", () => {
expect(url).toBe(import.meta.url);
});
5 changes: 5 additions & 0 deletions test/configCases/output/import-meta-name/test.config.js
@@ -0,0 +1,5 @@
module.exports = {
moduleScope(scope) {
scope.pseudoImport = { meta: { url: "http://test.co/path/index.js" } };
}
};
13 changes: 13 additions & 0 deletions test/configCases/output/import-meta-name/webpack.config.js
@@ -0,0 +1,13 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
output: {
importMetaName: "pseudoImport.meta"
},
module: {
parser: {
javascript: {
importMeta: false
}
}
}
};

0 comments on commit 17e8eed

Please sign in to comment.