forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove error for CommonJs/AMD in ESM
there are too many weird modules detect harmony modules before parsing exports is now undefined in ESM module.exports is now read-only in ESM and returns undefined define is now undefined in ESM webpack#3917
- Loading branch information
Showing
30 changed files
with
178 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = function(originalModule) { | ||
if(!originalModule.webpackPolyfill) { | ||
var module = Object.create(originalModule); | ||
// module.parent = undefined by default | ||
if(!module.children) module.children = []; | ||
Object.defineProperty(module, "loaded", { | ||
enumerable: true, | ||
configurable: false, | ||
get: function() { | ||
return module.l; | ||
} | ||
}); | ||
Object.defineProperty(module, "id", { | ||
enumerable: true, | ||
configurable: false, | ||
get: function() { | ||
return module.i; | ||
} | ||
}); | ||
Object.defineProperty(module, "exports", { | ||
enumerable: true, | ||
configurable: false, | ||
get: function() { | ||
return undefined; | ||
} | ||
}); | ||
module.webpackPolyfill = 1; | ||
} | ||
return module; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
lib/dependencies/CommonJsInHarmonyDependencyParserPlugin.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
"use strict"; | ||
|
||
const HarmonyCompatiblilityDependency = require("./HarmonyCompatiblilityDependency"); | ||
|
||
module.exports = class HarmonyDetectionParserPlugin { | ||
apply(parser) { | ||
parser.plugin("program", (ast) => { | ||
var isHarmony = ast.body.some(statement => { | ||
return /^(Import|Export).*Declaration$/.test(statement.type); | ||
}); | ||
if(isHarmony) { | ||
let module = parser.state.module; | ||
const dep = new HarmonyCompatiblilityDependency(module); | ||
dep.loc = { | ||
start: { | ||
line: -1, | ||
column: 0 | ||
}, | ||
end: { | ||
line: -1, | ||
column: 0 | ||
}, | ||
index: -2 | ||
}; | ||
module.addDependency(dep); | ||
module.meta.harmonyModule = true; | ||
module.strict = true; | ||
module.exportsArgument = "__webpack_exports__"; | ||
} | ||
}); | ||
var nonHarmonyIdentifiers = ["define", "exports"]; | ||
nonHarmonyIdentifiers.forEach(identifer => { | ||
parser.plugin(`evaluate typeof ${identifer}`, nullInHarmony); | ||
parser.plugin(`typeof ${identifer}`, skipInHarmony); | ||
parser.plugin(`evaluate ${identifer}`, nullInHarmony); | ||
parser.plugin(`expression ${identifer}`, skipInHarmony); | ||
parser.plugin(`call ${identifer}`, skipInHarmony); | ||
}); | ||
|
||
function skipInHarmony() { | ||
let module = this.state.module; | ||
if(module && module.meta && module.meta.harmonyModule) | ||
return true; | ||
} | ||
|
||
function nullInHarmony() { | ||
let module = this.state.module; | ||
if(module && module.meta && module.meta.harmonyModule) | ||
return null; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.