(parser, parserOptions)
| 37 | * @param {JavascriptParserOptions} parserOptions the javascript parser options |
| 38 | */ |
| 39 | const handler = (parser, parserOptions) => { |
| 40 | parser.hooks.program.tap(PLUGIN_NAME, (ast) => { |
| 41 | const firstNode = ast.body[0]; |
| 42 | if ( |
| 43 | firstNode && |
| 44 | firstNode.type === "ExpressionStatement" && |
| 45 | firstNode.expression.type === "Literal" && |
| 46 | firstNode.expression.value === "use strict" |
| 47 | ) { |
| 48 | // Remove "use strict" expression. It will be added later by the renderer again. |
| 49 | // This is necessary in order to not break the strict mode when webpack prepends code. |
| 50 | // @see https://github.com/webpack/webpack/issues/1970 |
| 51 | const dep = new ConstDependency( |
| 52 | "", |
| 53 | /** @type {Range} */ (firstNode.range) |
| 54 | ); |
| 55 | dep.loc = /** @type {DependencyLocation} */ (firstNode.loc); |
| 56 | parser.state.module.addPresentationalDependency(dep); |
| 57 | /** @type {BuildInfo} */ |
| 58 | (parser.state.module.buildInfo).strict = true; |
| 59 | } |
| 60 | if (parserOptions.overrideStrict) { |
| 61 | /** @type {BuildInfo} */ |
| 62 | (parser.state.module.buildInfo).strict = |
| 63 | parserOptions.overrideStrict === "strict"; |
| 64 | } |
| 65 | }); |
| 66 | }; |
| 67 | |
| 68 | normalModuleFactory.hooks.parser |
| 69 | .for(JAVASCRIPT_MODULE_TYPE_AUTO) |
nothing calls this directly
no test coverage detected