From c6520db2bd84c4bf7914c6a9918a1baad0a81726 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 22 Aug 2012 23:04:26 +0200 Subject: [PATCH] fixes #20 --- buildin/__webpack_module.js | 4 +++- lib/parse.js | 2 +- templates/browserAsync.js | 5 ++++- templates/browserSingle.js | 5 ++++- test/browsertest/lib/index.web.js | 3 ++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/buildin/__webpack_module.js b/buildin/__webpack_module.js index 174ccb25d..9f2e81393 100644 --- a/buildin/__webpack_module.js +++ b/buildin/__webpack_module.js @@ -1,7 +1,9 @@ module.exports = function(module) { if(!module.webpackPolyfill) { module.deprecate = function() {}; - module.id = "webpack"; + module.paths = []; + // module.parent = undefined by default + module.children = []; module.webpackPolyfill = 1; } return module; diff --git a/lib/parse.js b/lib/parse.js index 15f517d2a..fb6076196 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -522,7 +522,7 @@ function walkExpression(context, expression) { if(expression.object.type === "Identifier" && expression.object.name === "module" && expression.property.type === "Identifier" && - expression.property.name === "exports") + {exports:1, id:1, loaded:1}.hasOwnProperty(expression.property.name)) break; if(expression.object.type === "Identifier" && expression.object.name === "require" && diff --git a/templates/browserAsync.js b/templates/browserAsync.js index 9b18516ee..d7b048c60 100644 --- a/templates/browserAsync.js +++ b/templates/browserAsync.js @@ -6,9 +6,12 @@ /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ var module = installedModules[moduleId] = { -/******/ exports: {} +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false /******/ }; /******/ modules[moduleId](module, module.exports, require); +/******/ module.loaded = true; /******/ return module.exports; /******/ } /******/ require.e = function(chunkId, callback) { diff --git a/templates/browserSingle.js b/templates/browserSingle.js index fddce3115..492404643 100644 --- a/templates/browserSingle.js +++ b/templates/browserSingle.js @@ -5,9 +5,12 @@ /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ var module = installedModules[moduleId] = { -/******/ exports: {} +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false /******/ }; /******/ modules[moduleId](module, module.exports, require); +/******/ module.loaded = true; /******/ return module.exports; /******/ } /******/ require.e = function(chunkId, callback) { diff --git a/test/browsertest/lib/index.web.js b/test/browsertest/lib/index.web.js index 1cf283e66..9d3ca0c57 100644 --- a/test/browsertest/lib/index.web.js +++ b/test/browsertest/lib/index.web.js @@ -61,7 +61,6 @@ require.ensure([], function(require) { window.test(contextRequire("./singluar").value === 2, "Context works in chunk"); var singl = "singl"; window.test(require("." + "/" + singl + "uar").value === 2, "Context works in chunk, when splitted"); - window.test(typeof module.id === "string", "module.id should be a string"); window.test(process.argv && process.argv.length > 1, "process.argv should be an array"); process.nextTick(function() { sum2++; @@ -80,6 +79,8 @@ require.ensure([], function(require) { window.test(module === 1233, "overwrite module via variable should be ok"); }()); }); +window.test(typeof module.id === "number", "module.id should be a number"); +window.test(module.id === require.resolve("./index.web.js"), "module.id should be a id of the module"); require.ensure([], function(require) { require("./acircular");