7
7
8
8
const RequireContextDependency = require ( "./RequireContextDependency" ) ;
9
9
10
+ /** @typedef {import("../Dependency").DependencyLocation } DependencyLocation */
11
+ /** @typedef {import("../javascript/JavascriptParser") } JavascriptParser */
12
+ /** @typedef {import("../javascript/JavascriptParser").Range } Range */
13
+
10
14
module . exports = class RequireContextDependencyParserPlugin {
15
+ /**
16
+ * @param {JavascriptParser } parser the parser
17
+ * @returns {void }
18
+ */
11
19
apply ( parser ) {
12
20
parser . hooks . call
13
21
. for ( "require.context" )
@@ -19,19 +27,19 @@ module.exports = class RequireContextDependencyParserPlugin {
19
27
case 4 : {
20
28
const modeExpr = parser . evaluateExpression ( expr . arguments [ 3 ] ) ;
21
29
if ( ! modeExpr . isString ( ) ) return ;
22
- mode = modeExpr . string ;
30
+ mode = /** @type { string } */ ( modeExpr . string ) ;
23
31
}
24
32
// falls through
25
33
case 3 : {
26
34
const regExpExpr = parser . evaluateExpression ( expr . arguments [ 2 ] ) ;
27
35
if ( ! regExpExpr . isRegExp ( ) ) return ;
28
- regExp = regExpExpr . regExp ;
36
+ regExp = /** @type { RegExp } */ ( regExpExpr . regExp ) ;
29
37
}
30
38
// falls through
31
39
case 2 : {
32
40
const recursiveExpr = parser . evaluateExpression ( expr . arguments [ 1 ] ) ;
33
41
if ( ! recursiveExpr . isBoolean ( ) ) return ;
34
- recursive = recursiveExpr . bool ;
42
+ recursive = /** @type { boolean } */ ( recursiveExpr . bool ) ;
35
43
}
36
44
// falls through
37
45
case 1 : {
@@ -45,9 +53,9 @@ module.exports = class RequireContextDependencyParserPlugin {
45
53
mode,
46
54
category : "commonjs"
47
55
} ,
48
- expr . range
56
+ /** @type { Range } */ ( expr . range )
49
57
) ;
50
- dep . loc = expr . loc ;
58
+ dep . loc = /** @type { DependencyLocation } */ ( expr . loc ) ;
51
59
dep . optional = ! ! parser . scope . inTry ;
52
60
parser . state . current . addDependency ( dep ) ;
53
61
return true ;
0 commit comments