webpack 2.3.3 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +148 -133
  2. package/lib/APIPlugin.js +0 -6
  3. package/lib/AsyncDependenciesBlock.js +1 -1
  4. package/lib/AutomaticPrefetchPlugin.js +2 -2
  5. package/lib/BannerPlugin.js +30 -8
  6. package/lib/CachePlugin.js +2 -2
  7. package/lib/CaseSensitiveModulesWarning.js +6 -3
  8. package/lib/ChunkRenderError.js +3 -1
  9. package/lib/ChunkTemplate.js +2 -2
  10. package/lib/Compilation.js +17 -17
  11. package/lib/Compiler.js +30 -25
  12. package/lib/ContextModule.js +4 -3
  13. package/lib/ContextModuleFactory.js +5 -5
  14. package/lib/DelegatedModule.js +69 -63
  15. package/lib/DependenciesBlock.js +65 -59
  16. package/lib/Dependency.js +1 -0
  17. package/lib/EntryModuleNotFoundError.js +16 -10
  18. package/lib/ExtendedAPIPlugin.js +7 -2
  19. package/lib/ExternalModule.js +1 -1
  20. package/lib/ExternalModuleFactoryPlugin.js +26 -23
  21. package/lib/FlagDependencyUsagePlugin.js +63 -75
  22. package/lib/HotModuleReplacement.runtime.js +25 -27
  23. package/lib/HotModuleReplacementPlugin.js +3 -5
  24. package/lib/IgnorePlugin.js +48 -17
  25. package/lib/JsonpChunkTemplatePlugin.js +24 -24
  26. package/lib/JsonpMainTemplatePlugin.js +182 -182
  27. package/lib/LibManifestPlugin.js +51 -46
  28. package/lib/MainTemplate.js +17 -18
  29. package/lib/Module.js +158 -160
  30. package/lib/ModuleBuildError.js +4 -2
  31. package/lib/ModuleDependencyError.js +2 -1
  32. package/lib/ModuleDependencyWarning.js +2 -1
  33. package/lib/ModuleError.js +2 -2
  34. package/lib/ModuleFilenameHelpers.js +27 -27
  35. package/lib/ModuleNotFoundError.js +3 -1
  36. package/lib/ModuleParseError.js +6 -4
  37. package/lib/ModuleWarning.js +2 -2
  38. package/lib/MultiCompiler.js +3 -4
  39. package/lib/MultiStats.js +3 -3
  40. package/lib/MultiWatching.js +2 -2
  41. package/lib/NamedChunksPlugin.js +30 -0
  42. package/lib/NodeStuffPlugin.js +80 -79
  43. package/lib/NormalModule.js +7 -3
  44. package/lib/NormalModuleFactory.js +244 -240
  45. package/lib/Parser.js +1256 -1079
  46. package/lib/ProgressPlugin.js +2 -2
  47. package/lib/RawModule.js +1 -1
  48. package/lib/RecordIdsPlugin.js +5 -9
  49. package/lib/SetVarMainTemplatePlugin.js +1 -1
  50. package/lib/SourceMapDevToolPlugin.js +153 -157
  51. package/lib/Stats.js +34 -6
  52. package/lib/TemplatedPathPlugin.js +1 -0
  53. package/lib/UnsupportedFeatureWarning.js +2 -1
  54. package/lib/WebpackError.js +11 -0
  55. package/lib/WebpackOptionsApply.js +4 -4
  56. package/lib/WebpackOptionsValidationError.js +2 -3
  57. package/lib/dependencies/AMDDefineDependency.js +10 -6
  58. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -1
  59. package/lib/dependencies/AMDPlugin.js +3 -3
  60. package/lib/dependencies/ContextDependencyHelpers.js +19 -16
  61. package/lib/dependencies/CriticalDependencyWarning.js +4 -1
  62. package/lib/dependencies/DepBlockHelpers.js +3 -3
  63. package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
  64. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  65. package/lib/dependencies/ImportContextDependency.js +2 -1
  66. package/lib/dependencies/ImportDependenciesBlock.js +2 -2
  67. package/lib/dependencies/ImportParserPlugin.js +16 -2
  68. package/lib/dependencies/RequireEnsureDependenciesBlock.js +11 -3
  69. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +42 -13
  70. package/lib/dependencies/RequireEnsureDependency.js +9 -2
  71. package/lib/formatLocation.js +44 -27
  72. package/lib/optimize/AggressiveSplittingPlugin.js +10 -17
  73. package/lib/optimize/CommonsChunkPlugin.js +2 -2
  74. package/lib/performance/AssetsOverSizeLimitWarning.js +4 -1
  75. package/lib/performance/EntrypointsOverSizeLimitWarning.js +5 -1
  76. package/lib/performance/NoAsyncChunksWarning.js +5 -1
  77. package/lib/removeAndDo.js +6 -4
  78. package/lib/util/identifier.js +16 -0
  79. package/lib/webpack.js +2 -1
  80. package/package.json +7 -4
  81. package/schemas/webpackOptionsSchema.json +35 -0
@@ -1,13 +1,15 @@
1
1
  /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- var async = require("async");
6
- var Tapable = require("tapable");
7
- var NormalModule = require("./NormalModule");
8
- var RawModule = require("./RawModule");
9
- var Parser = require("./Parser");
10
- var RuleSet = require("./RuleSet");
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const asyncLib = require("async");
8
+ const Tapable = require("tapable");
9
+ const NormalModule = require("./NormalModule");
10
+ const RawModule = require("./RawModule");
11
+ const Parser = require("./Parser");
12
+ const RuleSet = require("./RuleSet");
11
13
 
12
14
  function loaderToIdent(data) {
13
15
  if(!data.options)
@@ -22,8 +24,8 @@ function loaderToIdent(data) {
22
24
  }
23
25
 
24
26
  function identToLoaderRequest(resultString) {
25
- var idx = resultString.indexOf("?");
26
- var options;
27
+ const idx = resultString.indexOf("?");
28
+ let options;
27
29
 
28
30
  if(idx >= 0) {
29
31
  options = resultString.substr(idx + 1);
@@ -31,7 +33,7 @@ function identToLoaderRequest(resultString) {
31
33
 
32
34
  return {
33
35
  loader: resultString,
34
- options: options
36
+ options
35
37
  };
36
38
  } else {
37
39
  return {
@@ -40,261 +42,263 @@ function identToLoaderRequest(resultString) {
40
42
  }
41
43
  }
42
44
 
43
- function NormalModuleFactory(context, resolvers, options) {
44
- Tapable.call(this);
45
- this.resolvers = resolvers;
46
- this.ruleSet = new RuleSet(options.rules || options.loaders);
47
- this.cachePredicate = typeof options.unsafeCache === "function" ? options.unsafeCache : Boolean.bind(null, options.unsafeCache);
48
- this.context = context || "";
49
- this.parserCache = {};
50
- this.plugin("factory", function() {
51
- var _this = this;
52
- return function(result, callback) {
53
- var resolver = _this.applyPluginsWaterfall0("resolver", null);
54
-
55
- // Ignored
56
- if(!resolver) return callback();
57
-
58
- resolver(result, function onDoneResolving(err, data) {
59
- if(err) return callback(err);
45
+ class NormalModuleFactory extends Tapable {
46
+ constructor(context, resolvers, options) {
47
+ super();
48
+ this.resolvers = resolvers;
49
+ this.ruleSet = new RuleSet(options.rules || options.loaders);
50
+ this.cachePredicate = typeof options.unsafeCache === "function" ? options.unsafeCache : Boolean.bind(null, options.unsafeCache);
51
+ this.context = context || "";
52
+ this.parserCache = {};
53
+ this.plugin("factory", function() {
54
+ /* beautify preserve:start */
55
+ // js-beautify consider to concat "return" and "("
56
+ // but it сontradicts eslint rule (keyword-spacing)
57
+ return (result, callback) => {
58
+ /* beautify preserve:end */
59
+ let resolver = this.applyPluginsWaterfall0("resolver", null);
60
60
 
61
61
  // Ignored
62
- if(!data) return callback();
63
-
64
- // direct module
65
- if(typeof data.source === "function")
66
- return callback(null, data);
62
+ if(!resolver) return callback();
67
63
 
68
- _this.applyPluginsAsyncWaterfall("after-resolve", data, function(err, result) {
64
+ resolver(result, (err, data) => {
69
65
  if(err) return callback(err);
70
66
 
71
67
  // Ignored
72
- if(!result) return callback();
68
+ if(!data) return callback();
69
+
70
+ // direct module
71
+ if(typeof data.source === "function")
72
+ return callback(null, data);
73
+
74
+ this.applyPluginsAsyncWaterfall("after-resolve", data, (err, result) => {
75
+ if(err) return callback(err);
76
+
77
+ // Ignored
78
+ if(!result) return callback();
79
+
80
+ let createdModule = this.applyPluginsBailResult("create-module", result);
81
+ if(!createdModule) {
73
82
 
74
- var createdModule = _this.applyPluginsBailResult("create-module", result);
75
- if(!createdModule) {
83
+ if(!result.request) {
84
+ return callback(new Error("Empty dependency (no request)"));
85
+ }
76
86
 
77
- if(!result.request) {
78
- return callback(new Error("Empty dependency (no request)"));
87
+ createdModule = new NormalModule(
88
+ result.request,
89
+ result.userRequest,
90
+ result.rawRequest,
91
+ result.loaders,
92
+ result.resource,
93
+ result.parser
94
+ );
79
95
  }
80
96
 
81
- createdModule = new NormalModule(
82
- result.request,
83
- result.userRequest,
84
- result.rawRequest,
85
- result.loaders,
86
- result.resource,
87
- result.parser
97
+ createdModule = this.applyPluginsWaterfall0("module", createdModule);
98
+
99
+ return callback(null, createdModule);
100
+ });
101
+ });
102
+ };
103
+ });
104
+ this.plugin("resolver", function() {
105
+ /* beautify preserve:start */
106
+ // js-beautify consider to concat "return" and "("
107
+ // but it сontradicts eslint rule (keyword-spacing)
108
+ return (data, callback) => {
109
+ /* beautify preserve:end */
110
+ const contextInfo = data.contextInfo;
111
+ const context = data.context;
112
+ const request = data.request;
113
+
114
+ const noAutoLoaders = /^-?!/.test(request);
115
+ const noPrePostAutoLoaders = /^!!/.test(request);
116
+ const noPostAutoLoaders = /^-!/.test(request);
117
+ let elements = request.replace(/^-?!+/, "").replace(/!!+/g, "!").split("!");
118
+ let resource = elements.pop();
119
+ elements = elements.map(identToLoaderRequest);
120
+
121
+ asyncLib.parallel([
122
+ callback => this.resolveRequestArray(contextInfo, context, elements, this.resolvers.loader, callback),
123
+ callback => {
124
+ if(resource === "" || resource[0] === "?")
125
+ return callback(null, {
126
+ resource
127
+ });
128
+
129
+ this.resolvers.normal.resolve(contextInfo, context, resource, (err, resource, resourceResolveData) => {
130
+ if(err) return callback(err);
131
+ callback(null, {
132
+ resourceResolveData,
133
+ resource
134
+ });
135
+ });
136
+ }
137
+ ], (err, results) => {
138
+ if(err) return callback(err);
139
+ let loaders = results[0];
140
+ const resourceResolveData = results[1].resourceResolveData;
141
+ resource = results[1].resource;
142
+
143
+ // translate option idents
144
+ try {
145
+ loaders.forEach(item => {
146
+ if(typeof item.options === "string" && /^\?/.test(item.options)) {
147
+ item.options = this.ruleSet.findOptionsByIdent(item.options.substr(1));
148
+ }
149
+ });
150
+ } catch(e) {
151
+ return callback(e);
152
+ }
153
+
154
+ if(resource === false) {
155
+ // ignored
156
+ return callback(null,
157
+ new RawModule(
158
+ "/* (ignored) */",
159
+ `ignored ${context} ${request}`,
160
+ `${request} (ignored)`
161
+ )
88
162
  );
89
163
  }
90
164
 
91
- createdModule = _this.applyPluginsWaterfall0("module", createdModule);
165
+ const userRequest = loaders.map(loaderToIdent).concat([resource]).join("!");
92
166
 
93
- return callback(null, createdModule);
94
- });
95
- });
96
- };
97
- });
98
- this.plugin("resolver", function() {
99
- var _this = this;
100
- return function(data, callback) {
101
- var contextInfo = data.contextInfo;
102
- var context = data.context;
103
- var request = data.request;
104
- var resolveContextInfo = {};
105
-
106
- var noAutoLoaders = /^-?!/.test(request);
107
- var noPrePostAutoLoaders = /^!!/.test(request);
108
- var noPostAutoLoaders = /^-!/.test(request);
109
- var elements = request.replace(/^-?!+/, "").replace(/!!+/g, "!").split("!");
110
- var resource = elements.pop();
111
- elements = elements.map(identToLoaderRequest);
112
-
113
- async.parallel([
114
- function(callback) {
115
- _this.resolveRequestArray(resolveContextInfo, context, elements, _this.resolvers.loader, callback);
116
- },
117
- function(callback) {
118
- if(resource === "" || resource[0] === "?")
119
- return callback(null, {
120
- resource: resource
121
- });
167
+ let resourcePath = resource;
168
+ let resourceQuery = "";
169
+ const queryIndex = resourcePath.indexOf("?");
170
+ if(queryIndex >= 0) {
171
+ resourceQuery = resourcePath.substr(queryIndex);
172
+ resourcePath = resourcePath.substr(0, queryIndex);
173
+ }
122
174
 
123
- _this.resolvers.normal.resolve(resolveContextInfo, context, resource, function(err, resource, resourceResolveData) {
124
- if(err) return callback(err);
125
- callback(null, {
126
- resourceResolveData: resourceResolveData,
127
- resource: resource,
128
- });
175
+ const result = this.ruleSet.exec({
176
+ resource: resourcePath,
177
+ resourceQuery,
178
+ issuer: contextInfo.issuer,
179
+ compiler: contextInfo.compiler
129
180
  });
130
- }
131
- ], function(err, results) {
132
- if(err) return callback(err);
133
- var loaders = results[0];
134
- var resourceResolveData = results[1].resourceResolveData;
135
- resource = results[1].resource;
136
-
137
- // translate option idents
138
- try {
139
- loaders.forEach(function(item) {
140
- if(typeof item.options === "string" && /^\?/.test(item.options)) {
141
- item.options = _this.ruleSet.findOptionsByIdent(item.options.substr(1));
181
+ const settings = {};
182
+ const useLoadersPost = [];
183
+ const useLoaders = [];
184
+ const useLoadersPre = [];
185
+ result.forEach(r => {
186
+ if(r.type === "use") {
187
+ if(r.enforce === "post" && !noPostAutoLoaders && !noPrePostAutoLoaders)
188
+ useLoadersPost.push(r.value);
189
+ else if(r.enforce === "pre" && !noPrePostAutoLoaders)
190
+ useLoadersPre.push(r.value);
191
+ else if(!r.enforce && !noAutoLoaders && !noPrePostAutoLoaders)
192
+ useLoaders.push(r.value);
193
+ } else {
194
+ settings[r.type] = r.value;
142
195
  }
143
196
  });
144
- } catch(e) {
145
- return callback(e);
146
- }
147
-
148
- if(resource === false)
149
- return callback(null,
150
- new RawModule("/* (ignored) */",
151
- "ignored " + context + " " + request,
152
- request + " (ignored)")); // ignored
197
+ asyncLib.parallel([
198
+ this.resolveRequestArray.bind(this, contextInfo, this.context, useLoadersPost, this.resolvers.loader),
199
+ this.resolveRequestArray.bind(this, contextInfo, this.context, useLoaders, this.resolvers.loader),
200
+ this.resolveRequestArray.bind(this, contextInfo, this.context, useLoadersPre, this.resolvers.loader)
201
+ ], (err, results) => {
202
+ if(err) return callback(err);
203
+ loaders = results[0].concat(loaders, results[1], results[2]);
204
+ process.nextTick(() => {
205
+ callback(null, {
206
+ context: context,
207
+ request: loaders.map(loaderToIdent).concat([resource]).join("!"),
208
+ dependencies: data.dependencies,
209
+ userRequest,
210
+ rawRequest: request,
211
+ loaders,
212
+ resource,
213
+ resourceResolveData,
214
+ parser: this.getParser(settings.parser)
215
+ });
216
+ });
217
+ });
218
+ });
219
+ };
220
+ });
221
+ }
153
222
 
154
- var userRequest = loaders.map(loaderToIdent).concat([resource]).join("!");
223
+ create(data, callback) {
224
+ const dependencies = data.dependencies;
225
+ const cacheEntry = dependencies[0].__NormalModuleFactoryCache;
226
+ if(cacheEntry) return callback(null, cacheEntry);
227
+ const context = data.context || this.context;
228
+ const request = dependencies[0].request;
229
+ const contextInfo = data.contextInfo || {};
230
+ this.applyPluginsAsyncWaterfall("before-resolve", {
231
+ contextInfo,
232
+ context,
233
+ request,
234
+ dependencies
235
+ }, (err, result) => {
236
+ if(err) return callback(err);
155
237
 
156
- var resourcePath = resource;
157
- var resourceQuery = "";
158
- var queryIndex = resourcePath.indexOf("?");
159
- if(queryIndex >= 0) {
160
- resourceQuery = resourcePath.substr(queryIndex);
161
- resourcePath = resourcePath.substr(0, queryIndex);
162
- }
238
+ // Ignored
239
+ if(!result) return callback();
163
240
 
164
- var result = _this.ruleSet.exec({
165
- resource: resourcePath,
166
- resourceQuery: resourceQuery,
167
- issuer: contextInfo.issuer,
168
- compiler: contextInfo.compiler
169
- });
170
- var settings = {};
171
- var useLoadersPost = [];
172
- var useLoaders = [];
173
- var useLoadersPre = [];
174
- result.forEach(function(r) {
175
- if(r.type === "use") {
176
- if(r.enforce === "post" && !noPostAutoLoaders && !noPrePostAutoLoaders)
177
- useLoadersPost.push(r.value);
178
- else if(r.enforce === "pre" && !noPrePostAutoLoaders)
179
- useLoadersPre.push(r.value);
180
- else if(!r.enforce && !noAutoLoaders && !noPrePostAutoLoaders)
181
- useLoaders.push(r.value);
182
- } else {
183
- settings[r.type] = r.value;
184
- }
185
- });
186
- async.parallel([
187
- _this.resolveRequestArray.bind(_this, resolveContextInfo, _this.context, useLoadersPost, _this.resolvers.loader),
188
- _this.resolveRequestArray.bind(_this, resolveContextInfo, _this.context, useLoaders, _this.resolvers.loader),
189
- _this.resolveRequestArray.bind(_this, resolveContextInfo, _this.context, useLoadersPre, _this.resolvers.loader)
190
- ], function(err, results) {
191
- if(err) return callback(err);
192
- loaders = results[0].concat(loaders).concat(results[1]).concat(results[2]);
193
- process.nextTick(onDoneResolving);
194
- });
241
+ const factory = this.applyPluginsWaterfall0("factory", null);
195
242
 
196
- function onDoneResolving() {
197
- callback(null, {
198
- context: context,
199
- request: loaders.map(loaderToIdent).concat([resource]).join("!"),
200
- dependencies: data.dependencies,
201
- userRequest: userRequest,
202
- rawRequest: request,
203
- loaders: loaders,
204
- resource: resource,
205
- resourceResolveData: resourceResolveData,
206
- parser: _this.getParser(settings.parser)
207
- });
208
- }
209
- });
210
- };
211
- });
212
- }
213
- module.exports = NormalModuleFactory;
243
+ // Ignored
244
+ if(!factory) return callback();
214
245
 
215
- NormalModuleFactory.prototype = Object.create(Tapable.prototype);
216
- NormalModuleFactory.prototype.constructor = NormalModuleFactory;
217
-
218
- NormalModuleFactory.prototype.create = function(data, callback) {
219
- var _this = this;
220
- var dependencies = data.dependencies;
221
- var cacheEntry = dependencies[0].__NormalModuleFactoryCache;
222
- if(cacheEntry) return callback(null, cacheEntry);
223
- var context = data.context || this.context;
224
- var request = dependencies[0].request;
225
- var contextInfo = data.contextInfo || {};
226
- _this.applyPluginsAsyncWaterfall("before-resolve", {
227
- contextInfo: contextInfo,
228
- context: context,
229
- request: request,
230
- dependencies: dependencies
231
- }, function(err, result) {
232
- if(err) return callback(err);
233
-
234
- // Ignored
235
- if(!result) return callback();
236
-
237
- var factory = _this.applyPluginsWaterfall0("factory", null);
238
-
239
- // Ignored
240
- if(!factory) return callback();
241
-
242
- factory(result, function(err, module) {
243
- if(err) return callback(err);
246
+ factory(result, (err, module) => {
247
+ if(err) return callback(err);
244
248
 
245
- if(module && _this.cachePredicate(module)) {
246
- dependencies.forEach(function(d) {
247
- d.__NormalModuleFactoryCache = module;
248
- });
249
- }
249
+ if(module && this.cachePredicate(module)) {
250
+ dependencies.forEach(d => d.__NormalModuleFactoryCache = module);
251
+ }
250
252
 
251
- callback(null, module);
253
+ callback(null, module);
254
+ });
252
255
  });
256
+ }
253
257
 
254
- });
255
- };
256
-
257
- NormalModuleFactory.prototype.resolveRequestArray = function resolveRequestArray(contextInfo, context, array, resolver, callback) {
258
- if(array.length === 0) return callback(null, []);
259
- async.map(array, function(item, callback) {
260
- resolver.resolve(contextInfo, context, item.loader, function(err, result) {
261
- if(err && /^[^/]*$/.test(item.loader) && !/-loader$/.test(item.loader)) {
262
- return resolver.resolve(contextInfo, context, item.loader + "-loader", function(err2) {
263
- if(!err2) {
264
- err.message = err.message + "\n" +
265
- "BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.\n" +
266
- " You need to specify '" + item.loader + "-loader' instead of '" + item.loader + "',\n" +
267
- " see https://webpack.js.org/guides/migrating/#automatic-loader-module-name-extension-removed";
268
- }
269
- callback(err);
270
- });
271
- }
272
- if(err) return callback(err);
258
+ resolveRequestArray(contextInfo, context, array, resolver, callback) {
259
+ if(array.length === 0) return callback(null, []);
260
+ asyncLib.map(array, (item, callback) => {
261
+ resolver.resolve(contextInfo, context, item.loader, (err, result) => {
262
+ if(err && /^[^/]*$/.test(item.loader) && !/-loader$/.test(item.loader)) {
263
+ return resolver.resolve(contextInfo, context, item.loader + "-loader", err2 => {
264
+ if(!err2) {
265
+ err.message = err.message + "\n" +
266
+ "BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.\n" +
267
+ ` You need to specify '${item.loader}-loader' instead of '${item.loader}',\n` +
268
+ " see https://webpack.js.org/guides/migrating/#automatic-loader-module-name-extension-removed";
269
+ }
270
+ callback(err);
271
+ });
272
+ }
273
+ if(err) return callback(err);
273
274
 
274
- var optionsOnly = item.options ? {
275
- options: item.options
276
- } : undefined;
277
- return callback(null, Object.assign({}, item, identToLoaderRequest(result), optionsOnly));
278
- });
279
- }, callback);
280
- };
281
-
282
- NormalModuleFactory.prototype.getParser = function getParser(parserOptions) {
283
- var ident = "null";
284
- if(parserOptions) {
285
- if(parserOptions.ident)
286
- ident = parserOptions.ident;
287
- else
288
- ident = JSON.stringify(parserOptions);
275
+ const optionsOnly = item.options ? {
276
+ options: item.options
277
+ } : undefined;
278
+ return callback(null, Object.assign({}, item, identToLoaderRequest(result), optionsOnly));
279
+ });
280
+ }, callback);
289
281
  }
290
- var parser = this.parserCache[ident];
291
- if(parser)
282
+
283
+ getParser(parserOptions) {
284
+ let ident = "null";
285
+ if(parserOptions) {
286
+ if(parserOptions.ident)
287
+ ident = parserOptions.ident;
288
+ else
289
+ ident = JSON.stringify(parserOptions);
290
+ }
291
+ const parser = this.parserCache[ident];
292
+ if(parser)
293
+ return parser;
294
+ return this.parserCache[ident] = this.createParser(parserOptions);
295
+ }
296
+
297
+ createParser(parserOptions) {
298
+ const parser = new Parser();
299
+ this.applyPlugins2("parser", parser, parserOptions || {});
292
300
  return parser;
293
- return this.parserCache[ident] = this.createParser(parserOptions);
294
- };
295
-
296
- NormalModuleFactory.prototype.createParser = function createParser(parserOptions) {
297
- var parser = new Parser();
298
- this.applyPlugins2("parser", parser, parserOptions || {});
299
- return parser;
300
- };
301
+ }
302
+ }
303
+
304
+ module.exports = NormalModuleFactory;