|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -var ConstDependency = require("./ConstDependency"); |
6 | | -var ParserHelpers = require("../ParserHelpers"); |
| 5 | +"use strict"; |
7 | 6 |
|
8 | | -function SystemPlugin(options) { |
9 | | - this.options = options; |
10 | | -} |
11 | | -module.exports = SystemPlugin; |
| 7 | +const ConstDependency = require("./ConstDependency"); |
| 8 | +const ParserHelpers = require("../ParserHelpers"); |
| 9 | + |
| 10 | +class SystemPlugin { |
| 11 | + constructor(options) { |
| 12 | + this.options = options; |
| 13 | + } |
| 14 | + |
| 15 | + apply(compiler) { |
| 16 | + compiler.plugin("compilation", (compilation, params) => { |
| 17 | + params.normalModuleFactory.plugin("parser", (parser, parserOptions) => { |
| 18 | + |
| 19 | + if(typeof parserOptions.system !== "undefined" && !parserOptions.system) |
| 20 | + return; |
12 | 21 |
|
13 | | -SystemPlugin.prototype.apply = function(compiler) { |
14 | | - compiler.plugin("compilation", function(compilation, params) { |
15 | | - params.normalModuleFactory.plugin("parser", function(parser, parserOptions) { |
16 | | - |
17 | | - if(typeof parserOptions.system !== "undefined" && !parserOptions.system) |
18 | | - return; |
19 | | - |
20 | | - function setNotSupported(name) { |
21 | | - parser.plugin("evaluate typeof " + name, ParserHelpers.evaluateToString("undefined")); |
22 | | - parser.plugin("expression " + name, |
23 | | - ParserHelpers.expressionIsUnsupported(name + " is not supported by webpack.") |
24 | | - ); |
25 | | - } |
26 | | - |
27 | | - parser.plugin("typeof System", ParserHelpers.toConstantDependency("object")); |
28 | | - parser.plugin("evaluate typeof System", ParserHelpers.evaluateToString("object")); |
29 | | - |
30 | | - parser.plugin("typeof System.import", ParserHelpers.toConstantDependency("function")); |
31 | | - parser.plugin("evaluate typeof System.import", ParserHelpers.evaluateToString("function")); |
32 | | - |
33 | | - setNotSupported("System.set"); |
34 | | - setNotSupported("System.get"); |
35 | | - setNotSupported("System.register"); |
36 | | - parser.plugin("expression System", function(expr) { |
37 | | - var dep = new ConstDependency("{}", expr.range); |
38 | | - dep.loc = expr.loc; |
39 | | - this.state.current.addDependency(dep); |
40 | | - return true; |
| 22 | + function setNotSupported(name) { |
| 23 | + parser.plugin("evaluate typeof " + name, ParserHelpers.evaluateToString("undefined")); |
| 24 | + parser.plugin("expression " + name, |
| 25 | + ParserHelpers.expressionIsUnsupported(name + " is not supported by webpack.") |
| 26 | + ); |
| 27 | + } |
| 28 | + |
| 29 | + parser.plugin("typeof System", ParserHelpers.toConstantDependency("object")); |
| 30 | + parser.plugin("evaluate typeof System", ParserHelpers.evaluateToString("object")); |
| 31 | + |
| 32 | + parser.plugin("typeof System.import", ParserHelpers.toConstantDependency("function")); |
| 33 | + parser.plugin("evaluate typeof System.import", ParserHelpers.evaluateToString("function")); |
| 34 | + |
| 35 | + setNotSupported("System.set"); |
| 36 | + setNotSupported("System.get"); |
| 37 | + setNotSupported("System.register"); |
| 38 | + parser.plugin("expression System", (expr) => { |
| 39 | + const dep = new ConstDependency("{}", expr.range); |
| 40 | + dep.loc = expr.loc; |
| 41 | + parser.state.current.addDependency(dep); |
| 42 | + return true; |
| 43 | + }); |
41 | 44 | }); |
42 | 45 | }); |
43 | | - }); |
44 | | -}; |
| 46 | + } |
| 47 | +} |
| 48 | +module.exports = SystemPlugin; |
0 commit comments