Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.5 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 |
|
---|
8 | const RequireContextDependency = require("./RequireContextDependency");
|
---|
9 |
|
---|
10 | module.exports = class RequireContextDependencyParserPlugin {
|
---|
11 | apply(parser) {
|
---|
12 | parser.hooks.call
|
---|
13 | .for("require.context")
|
---|
14 | .tap("RequireContextDependencyParserPlugin", expr => {
|
---|
15 | let regExp = /^\.\/.*$/;
|
---|
16 | let recursive = true;
|
---|
17 | let mode = "sync";
|
---|
18 | switch (expr.arguments.length) {
|
---|
19 | case 4: {
|
---|
20 | const modeExpr = parser.evaluateExpression(expr.arguments[3]);
|
---|
21 | if (!modeExpr.isString()) return;
|
---|
22 | mode = modeExpr.string;
|
---|
23 | }
|
---|
24 | // falls through
|
---|
25 | case 3: {
|
---|
26 | const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
|
---|
27 | if (!regExpExpr.isRegExp()) return;
|
---|
28 | regExp = regExpExpr.regExp;
|
---|
29 | }
|
---|
30 | // falls through
|
---|
31 | case 2: {
|
---|
32 | const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
|
---|
33 | if (!recursiveExpr.isBoolean()) return;
|
---|
34 | recursive = recursiveExpr.bool;
|
---|
35 | }
|
---|
36 | // falls through
|
---|
37 | case 1: {
|
---|
38 | const requestExpr = parser.evaluateExpression(expr.arguments[0]);
|
---|
39 | if (!requestExpr.isString()) return;
|
---|
40 | const dep = new RequireContextDependency(
|
---|
41 | {
|
---|
42 | request: requestExpr.string,
|
---|
43 | recursive,
|
---|
44 | regExp,
|
---|
45 | mode,
|
---|
46 | category: "commonjs"
|
---|
47 | },
|
---|
48 | expr.range
|
---|
49 | );
|
---|
50 | dep.loc = expr.loc;
|
---|
51 | dep.optional = !!parser.scope.inTry;
|
---|
52 | parser.state.current.addDependency(dep);
|
---|
53 | return true;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | });
|
---|
57 | }
|
---|
58 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.