22 MIT License http://www.opensource.org/licenses/mit-license.php
33 Author Tobias Koppers @sokra
44*/
5- var ConstDependency = require ( "./dependencies/ConstDependency" ) ;
6- var BasicEvaluatedExpression = require ( "./BasicEvaluatedExpression" ) ;
5+ "use strict" ;
76
8- var NullFactory = require ( "./NullFactory" ) ;
7+ const ConstDependency = require ( "./dependencies/ConstDependency" ) ;
8+ const BasicEvaluatedExpression = require ( "./BasicEvaluatedExpression" ) ;
99
10- function APIPlugin ( ) { }
11- module . exports = APIPlugin ;
10+ const NullFactory = require ( "./NullFactory" ) ;
1211
13- var REPLACEMENTS = {
12+ const REPLACEMENTS = {
1413 __webpack_require__ : "__webpack_require__" , // eslint-disable-line camelcase
1514 __webpack_public_path__ : "__webpack_require__.p" , // eslint-disable-line camelcase
1615 __webpack_modules__ : "__webpack_require__.m" , // eslint-disable-line camelcase
@@ -19,36 +18,41 @@ var REPLACEMENTS = {
1918 __webpack_nonce__ : "__webpack_require__.nc" , // eslint-disable-line camelcase
2019 "require.onError" : "__webpack_require__.oe" // eslint-disable-line camelcase
2120} ;
22- var REPLACEMENT_TYPES = {
21+ const REPLACEMENT_TYPES = {
2322 __webpack_public_path__ : "string" , // eslint-disable-line camelcase
2423 __webpack_require__ : "function" , // eslint-disable-line camelcase
2524 __webpack_modules__ : "object" , // eslint-disable-line camelcase
2625 __webpack_chunk_load__ : "function" , // eslint-disable-line camelcase
2726 __webpack_nonce__ : "string" // eslint-disable-line camelcase
2827} ;
29- var IGNORES = [ ] ;
30- APIPlugin . prototype . apply = function ( compiler ) {
31- compiler . plugin ( "compilation" , function ( compilation , params ) {
32- compilation . dependencyFactories . set ( ConstDependency , new NullFactory ( ) ) ;
33- compilation . dependencyTemplates . set ( ConstDependency , new ConstDependency . Template ( ) ) ;
34-
35- params . normalModuleFactory . plugin ( "parser" , function ( parser ) {
36- Object . keys ( REPLACEMENTS ) . forEach ( function ( key ) {
37- parser . plugin ( "expression " + key , function ( expr ) {
38- var dep = new ConstDependency ( REPLACEMENTS [ key ] , expr . range ) ;
39- dep . loc = expr . loc ;
40- this . state . current . addDependency ( dep ) ;
41- return true ;
42- } ) ;
43- parser . plugin ( "evaluate typeof " + key , function ( expr ) {
44- return new BasicEvaluatedExpression ( ) . setString ( REPLACEMENT_TYPES [ key ] ) . setRange ( expr . range ) ;
28+
29+ const IGNORES = [ ] ;
30+
31+ class APIPlugin {
32+
33+ apply ( compiler ) {
34+ compiler . plugin ( "compilation" , ( compilation , params ) => {
35+ compilation . dependencyFactories . set ( ConstDependency , new NullFactory ( ) ) ;
36+ compilation . dependencyTemplates . set ( ConstDependency , new ConstDependency . Template ( ) ) ;
37+
38+ params . normalModuleFactory . plugin ( "parser" , parser => {
39+ Object . keys ( REPLACEMENTS ) . forEach ( key => {
40+ parser . plugin ( `expression ${ key } ` , expr => {
41+ const dep = new ConstDependency ( REPLACEMENTS [ key ] , expr . range ) ;
42+ dep . loc = expr . loc ;
43+ parser . state . current . addDependency ( dep ) ;
44+ return true ;
45+ } ) ;
46+ parser . plugin ( `evaluate typeof ${ key } ` , expr => {
47+ return new BasicEvaluatedExpression ( ) . setString ( REPLACEMENT_TYPES [ key ] ) . setRange ( expr . range ) ;
48+ } ) ;
4549 } ) ;
46- } ) ;
47- IGNORES . forEach ( function ( key ) {
48- parser . plugin ( key , function ( ) {
49- return true ;
50+ IGNORES . forEach ( key => {
51+ parser . plugin ( key , ( ) => true ) ;
5052 } ) ;
5153 } ) ;
5254 } ) ;
53- } ) ;
54- } ;
55+ }
56+ }
57+
58+ module . exports = APIPlugin ;
0 commit comments