From a358791d3e584000c38be80719acf02d6f0dedc0 Mon Sep 17 00:00:00 2001 From: "Kazunori \"Hassy\" Hashikuchi" Date: Thu, 5 Jul 2018 16:24:25 +1200 Subject: [PATCH 1/2] Add the new test cases Add the new test cases of the module name including an exclamation mark. --- test/node_modules/h!.js | 3 +++ test/node_modules/i.js | 3 +++ test/test.js | 8 ++++++++ 3 files changed, 14 insertions(+) create mode 100644 test/node_modules/h!.js create mode 100644 test/node_modules/i.js diff --git a/test/node_modules/h!.js b/test/node_modules/h!.js new file mode 100644 index 0000000..a90cdc5 --- /dev/null +++ b/test/node_modules/h!.js @@ -0,0 +1,3 @@ +define(["exports", "moduleId!a"], function(exports, a) { + exports.A = a.A; +}); diff --git a/test/node_modules/i.js b/test/node_modules/i.js new file mode 100644 index 0000000..ddaeca7 --- /dev/null +++ b/test/node_modules/i.js @@ -0,0 +1,3 @@ +define(["exports", "h!"], function(exports, h) { + exports.A = h.A; +}); diff --git a/test/test.js b/test/test.js index 770b155..5401025 100644 --- a/test/test.js +++ b/test/test.js @@ -38,3 +38,11 @@ assert.equal(g.G, "G"); // TODO // node_modules + package // async require + +console.log("resolve the module name which includes '!'"); +var h = require("h!"); +assert.equal(h.A, "A"); + +var i = require("i"); +console.log("resolve the module name which ends with '!'"); +assert.equal(i.A, "A"); From 92cc747d8a07dea5e35b1860615a49121bc3a736 Mon Sep 17 00:00:00 2001 From: "Kazunori \"Hassy\" Hashikuchi" Date: Thu, 5 Jul 2018 16:24:57 +1200 Subject: [PATCH 2/2] Fix the issue that module which ends with ! cannot be loaded Filter out the empty strings from the chunks so that the module whose name ends with '!' is properly recognized. --- amd-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amd-loader.js b/amd-loader.js index 6ac4a54..b84c42f 100644 --- a/amd-loader.js +++ b/amd-loader.js @@ -45,7 +45,7 @@ global.define = function (id, deps, factory) { return callback.apply(this, relativeId.map(req)) } - var chunks = relativeId.split("!"); + var chunks = relativeId.split("!").filter(chunk => chunk.length > 0); var prefix; if (chunks.length >= 2) { prefix = chunks[0];