source: trip-planner-front/node_modules/webpack/lib/dependencies/RequireIncludeDependencyParserPlugin.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const WebpackError = require("../WebpackError");
9const {
10 evaluateToString,
11 toConstantDependency
12} = require("../javascript/JavascriptParserHelpers");
13const makeSerializable = require("../util/makeSerializable");
14const RequireIncludeDependency = require("./RequireIncludeDependency");
15
16module.exports = class RequireIncludeDependencyParserPlugin {
17 constructor(warn) {
18 this.warn = warn;
19 }
20 apply(parser) {
21 const { warn } = this;
22 parser.hooks.call
23 .for("require.include")
24 .tap("RequireIncludeDependencyParserPlugin", expr => {
25 if (expr.arguments.length !== 1) return;
26 const param = parser.evaluateExpression(expr.arguments[0]);
27 if (!param.isString()) return;
28
29 if (warn) {
30 parser.state.module.addWarning(
31 new RequireIncludeDeprecationWarning(expr.loc)
32 );
33 }
34
35 const dep = new RequireIncludeDependency(param.string, expr.range);
36 dep.loc = expr.loc;
37 parser.state.current.addDependency(dep);
38 return true;
39 });
40 parser.hooks.evaluateTypeof
41 .for("require.include")
42 .tap("RequireIncludePlugin", expr => {
43 if (warn) {
44 parser.state.module.addWarning(
45 new RequireIncludeDeprecationWarning(expr.loc)
46 );
47 }
48 return evaluateToString("function")(expr);
49 });
50 parser.hooks.typeof
51 .for("require.include")
52 .tap("RequireIncludePlugin", expr => {
53 if (warn) {
54 parser.state.module.addWarning(
55 new RequireIncludeDeprecationWarning(expr.loc)
56 );
57 }
58 return toConstantDependency(parser, JSON.stringify("function"))(expr);
59 });
60 }
61};
62
63class RequireIncludeDeprecationWarning extends WebpackError {
64 constructor(loc) {
65 super("require.include() is deprecated and will be removed soon.");
66
67 this.name = "RequireIncludeDeprecationWarning";
68
69 this.loc = loc;
70 }
71}
72
73makeSerializable(
74 RequireIncludeDeprecationWarning,
75 "webpack/lib/dependencies/RequireIncludeDependencyParserPlugin",
76 "RequireIncludeDeprecationWarning"
77);
Note: See TracBrowser for help on using the repository browser.