@@ -8,8 +8,6 @@ const asyncLib = require("async");
88const Tapable = require ( "tapable" ) ;
99const NormalModule = require ( "./NormalModule" ) ;
1010const RawModule = require ( "./RawModule" ) ;
11- const Parser = require ( "./Parser" ) ;
12- const WebAssemblyParser = require ( "./WebAssemblyParser" ) ;
1311const RuleSet = require ( "./RuleSet" ) ;
1412
1513const loaderToIdent = data => {
@@ -287,24 +285,16 @@ class NormalModuleFactory extends Tapable {
287285 }
288286
289287 createParser ( type , parserOptions ) {
290- // TODO move to plugin
291- // const parser = this.applyPluginsBailResult1(`create-parser ${type}`);
292- let parser ;
293- switch ( type ) {
294- case "javascript/auto" :
295- parser = new Parser ( ) ;
296- break ;
297- case "webassembly/experimental" :
298- parser = new WebAssemblyParser ( ) ;
299- break ;
300- default :
301- throw new Error ( "Unknown module type" ) ;
288+ parserOptions = parserOptions || { } ;
289+ const parser = this . applyPluginsBailResult1 ( `create-parser ${ type } ` , parserOptions ) ;
290+ if ( ! parser ) {
291+ throw new Error ( `No parser registered for ${ type } ` ) ;
302292 }
303293 if ( type === "javascript/auto" ) {
304294 // TODO: remove backward compat in webpack 5
305- this . applyPlugins2 ( "parser" , parser , parserOptions || { } ) ;
295+ this . applyPlugins2 ( "parser" , parser , parserOptions ) ;
306296 }
307- this . applyPlugins2 ( `parser ${ type } ` , parser , parserOptions || { } ) ;
297+ this . applyPlugins2 ( `parser ${ type } ` , parser , parserOptions ) ;
308298 return parser ;
309299 }
310300}
0 commit comments