2015-07-01 06:19:52 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2017-01-12 04:03:10 +08:00
|
|
|
"use strict";
|
2015-07-07 06:11:13 +08:00
|
|
|
|
2017-01-12 04:03:10 +08:00
|
|
|
const ConstDependency = require("./ConstDependency");
|
|
|
|
const ParserHelpers = require("../ParserHelpers");
|
|
|
|
|
|
|
|
class SystemPlugin {
|
|
|
|
constructor(options) {
|
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
apply(compiler) {
|
|
|
|
compiler.plugin("compilation", (compilation, params) => {
|
|
|
|
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
|
|
|
|
|
|
|
|
if(typeof parserOptions.system !== "undefined" && !parserOptions.system)
|
|
|
|
return;
|
2015-07-01 06:19:52 +08:00
|
|
|
|
2017-01-12 04:03:10 +08:00
|
|
|
function setNotSupported(name) {
|
|
|
|
parser.plugin("evaluate typeof " + name, ParserHelpers.evaluateToString("undefined"));
|
|
|
|
parser.plugin("expression " + name,
|
|
|
|
ParserHelpers.expressionIsUnsupported(name + " is not supported by webpack.")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
parser.plugin("typeof System", ParserHelpers.toConstantDependency("object"));
|
|
|
|
parser.plugin("evaluate typeof System", ParserHelpers.evaluateToString("object"));
|
|
|
|
|
|
|
|
parser.plugin("typeof System.import", ParserHelpers.toConstantDependency("function"));
|
|
|
|
parser.plugin("evaluate typeof System.import", ParserHelpers.evaluateToString("function"));
|
|
|
|
|
|
|
|
setNotSupported("System.set");
|
|
|
|
setNotSupported("System.get");
|
|
|
|
setNotSupported("System.register");
|
|
|
|
parser.plugin("expression System", (expr) => {
|
|
|
|
const dep = new ConstDependency("{}", expr.range);
|
|
|
|
dep.loc = expr.loc;
|
|
|
|
parser.state.current.addDependency(dep);
|
|
|
|
return true;
|
|
|
|
});
|
2016-09-14 18:04:42 +08:00
|
|
|
});
|
|
|
|
});
|
2017-01-12 04:03:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = SystemPlugin;
|