mirror of https://github.com/webpack/webpack.git
fixed #2570
This commit is contained in:
parent
9fce4061f1
commit
d382b10683
|
@ -91,6 +91,10 @@ function MainTemplate(outputOptions) {
|
|||
buf.push("// expose the module cache");
|
||||
buf.push(this.requireFn + ".c = installedModules;");
|
||||
|
||||
buf.push("");
|
||||
buf.push("// identity function for calling harmory imports with the correct context");
|
||||
buf.push(this.requireFn + ".i = function(value) { return value; };");
|
||||
|
||||
var publicPath = this.getPublicPath({
|
||||
hash: hash
|
||||
});
|
||||
|
|
|
@ -42,19 +42,20 @@ HarmonyImportSpecifierDependency.Template = function HarmonyImportSpecifierDepen
|
|||
HarmonyImportSpecifierDependency.Template.prototype.apply = function(dep, source) {
|
||||
var content;
|
||||
var importedModule = dep.importDependency.module;
|
||||
if(dep.id === "default" && !(importedModule && importedModule.meta && importedModule.meta.harmonyModule)) {
|
||||
content = "/* harmony import */" + dep.importedVar + "_default.a";
|
||||
var defaultImport = dep.id === "default" && !(importedModule && importedModule.meta && importedModule.meta.harmonyModule);
|
||||
if(defaultImport) {
|
||||
content = dep.importedVar + "_default.a";
|
||||
} else if(dep.id) {
|
||||
var used = importedModule ? importedModule.isUsed(dep.id) : dep.id;
|
||||
content = "/* harmony import */" + dep.importedVar + "[" + JSON.stringify(used) + "]";
|
||||
content = dep.importedVar + "[" + JSON.stringify(used) + (dep.id !== used ? " /* " + dep.id + " */" : "") + "]";
|
||||
} else {
|
||||
content = "/* harmony namespace import */ " + dep.importedVar;
|
||||
content = dep.importedVar;
|
||||
}
|
||||
if(!dep.call) {
|
||||
source.replace(dep.range[0], dep.range[1] - 1, content);
|
||||
} else if(dep.callArgs.length > 0) {
|
||||
source.replace(dep.range[0], dep.callArgs[0].range[0] - 1, content + ".call(undefined, ");
|
||||
} else if(defaultImport) {
|
||||
source.replace(dep.range[0], dep.range[1] - 1, dep.importedVar + "_default()");
|
||||
} else {
|
||||
source.replace(dep.call.range[0], dep.call.range[1] - 1, content + ".call()");
|
||||
source.replace(dep.range[0], dep.range[1] - 1, "__webpack_require__.i(" + content + ")");
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export default function() { return [].slice.call(arguments); }
|
|
@ -0,0 +1,13 @@
|
|||
import fn from "./fn";
|
||||
|
||||
it("should generate valid code when calling a harmony import function with brackets", function() {
|
||||
var a = fn((1));
|
||||
var b = fn(2);
|
||||
var c = fn((3), (4));
|
||||
var d = fn(5, (6));
|
||||
|
||||
a.should.be.eql([1]);
|
||||
b.should.be.eql([2]);
|
||||
c.should.be.eql([3, 4]);
|
||||
d.should.be.eql([5, 6]);
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var dirs = fs.readdirSync(__dirname);
|
||||
dirs.forEach(function(dir) {
|
||||
var actual = path.join(__dirname, dir, "actual.txt");
|
||||
var expected = path.join(__dirname, dir, "expected.txt");
|
||||
if(fs.existsSync(actual)) {
|
||||
fs.unlinkSync(expected);
|
||||
fs.renameSync(actual, expected);
|
||||
}
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
Hash: 55b4e00b04fd0c502b1f
|
||||
Time: Xms
|
||||
Asset Size Chunks Chunk Names
|
||||
bundle.js 4.64 kB 0 [emitted] main
|
||||
bundle.js 4.8 kB 0 [emitted] main
|
||||
1.bundle.js 252 bytes 1 [emitted]
|
||||
2.bundle.js 107 bytes 2 [emitted]
|
||||
3.bundle.js 202 bytes 3 [emitted]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Hash: 0fca0b37055d42f98682
|
||||
Time: Xms
|
||||
Asset Size Chunks Chunk Names
|
||||
main.js 1.4 kB 0 [emitted] main
|
||||
main.js 1.55 kB 0 [emitted] main
|
||||
chunk {0} main.js (main) 0 bytes [rendered]
|
||||
[0] (webpack)/test/statsCases/color-disabled/index.js 0 bytes {0} [built]
|
|
@ -1,6 +1,6 @@
|
|||
Hash: <CLR=BOLD>0fca0b37055d42f98682</CLR>
|
||||
Time: <CLR=BOLD>X</CLR>ms
|
||||
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
|
||||
<CLR=32>main.js</CLR> 1.4 kB <CLR=BOLD>0</CLR> <CLR=32>[emitted]</CLR> main
|
||||
<CLR=32>main.js</CLR> 1.55 kB <CLR=BOLD>0</CLR> <CLR=32>[emitted]</CLR> main
|
||||
chunk {<CLR=33>0</CLR>} <CLR=32>main.js</CLR> (main) 0 bytes<CLR=32> [rendered]</CLR>
|
||||
[0] <CLR=BOLD>(webpack)/test/statsCases/color-enabled-custom/index.js</CLR> 0 bytes {<CLR=33>0</CLR>}<CLR=32> [built]</CLR>
|
|
@ -1,6 +1,6 @@
|
|||
Hash: <CLR=BOLD>0fca0b37055d42f98682</CLR>
|
||||
Time: <CLR=BOLD>X</CLR>ms
|
||||
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
|
||||
<CLR=32,BOLD>main.js</CLR> 1.4 kB <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR> main
|
||||
<CLR=32,BOLD>main.js</CLR> 1.55 kB <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR> main
|
||||
chunk {<CLR=33,BOLD>0</CLR>} <CLR=32,BOLD>main.js</CLR> (main) 0 bytes<CLR=32,BOLD> [rendered]</CLR>
|
||||
[0] <CLR=BOLD>(webpack)/test/statsCases/color-enabled/index.js</CLR> 0 bytes {<CLR=33,BOLD>0</CLR>}<CLR=32,BOLD> [built]</CLR>
|
|
@ -3,13 +3,13 @@ Child
|
|||
Hash: 9874287bb38ab21ad757
|
||||
Time: Xms
|
||||
Asset Size Chunks Chunk Names
|
||||
main.js 1.44 kB 0 [emitted] main
|
||||
main.js 1.6 kB 0 [emitted] main
|
||||
chunk {0} main.js (main) 24 bytes [rendered]
|
||||
[0] (webpack)/test/statsCases/define-plugin/index.js 24 bytes {0} [built]
|
||||
Child
|
||||
Hash: 1557d04931c0902dd6cd
|
||||
Time: Xms
|
||||
Asset Size Chunks Chunk Names
|
||||
main.js 1.44 kB 0 [emitted] main
|
||||
main.js 1.6 kB 0 [emitted] main
|
||||
chunk {0} main.js (main) 24 bytes [rendered]
|
||||
[0] (webpack)/test/statsCases/define-plugin/index.js 24 bytes {0} [built]
|
|
@ -1,7 +1,7 @@
|
|||
Hash: ea561aa543731a7f84b9
|
||||
Time: Xms
|
||||
Asset Size Chunks Chunk Names
|
||||
main.js 1.53 kB 0 [emitted] main
|
||||
main.js 1.69 kB 0 [emitted] main
|
||||
chunk {0} main.js (main) 59 bytes [rendered]
|
||||
[0] (webpack)/test/statsCases/external/index.js 17 bytes {0} [built]
|
||||
[1] external "test" 42 bytes {0} [not cacheable]
|
|
@ -4,7 +4,7 @@ Time: Xms
|
|||
0.js 245 bytes 0 [emitted] cir1
|
||||
1.js 215 bytes 1, 2 [emitted] abd
|
||||
2.js 131 bytes 2 [emitted] ab
|
||||
main.js 5.38 kB 3 [emitted] main
|
||||
main.js 5.53 kB 3 [emitted] main
|
||||
4.js 260 bytes 4 [emitted] cir2
|
||||
5.js 138 bytes 5, 7 [emitted] chunk
|
||||
6.js 319 bytes 6, 4 [emitted] cir2 from cir1
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Hash: 8ca45b6d16d1f1e8be32
|
||||
Time: Xms
|
||||
Asset Size Chunks Chunk Names
|
||||
main.js 4.63 kB 0 [emitted] main
|
||||
main.js 4.79 kB 0 [emitted] main
|
||||
1.js 252 bytes 1 [emitted]
|
||||
2.js 107 bytes 2 [emitted]
|
||||
3.js 202 bytes 3 [emitted]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Hash: b85ca8f6c28cbbc3320d
|
||||
Time: Xms
|
||||
Asset Size Chunks Chunk Names
|
||||
bundle.js 1.4 kB 0 [emitted] main
|
||||
bundle.js 1.55 kB 0 [emitted] main
|
||||
chunk {0} bundle.js (main) 0 bytes [rendered]
|
||||
> main [0] (webpack)/test/statsCases/simple-more-info/index.js
|
||||
[0] (webpack)/test/statsCases/simple-more-info/index.js 0 bytes {0} [built]
|
||||
|
|
Loading…
Reference in New Issue