5
5
6
6
"use strict" ;
7
7
8
+ const { parsePathQueryFragment } = require ( "../util/identifier" ) ;
9
+
8
10
/** @typedef {import("../javascript/BasicEvaluatedExpression") } BasicEvaluatedExpression */
9
11
/** @typedef {import("../javascript/JavascriptParser") } JavascriptParser */
10
12
/** @typedef {import("./ContextDependency") } ContextDependency */
@@ -32,19 +34,6 @@ const splitContextFromPrefix = prefix => {
32
34
} ;
33
35
} ;
34
36
35
- const splitQueryFromPostfix = postfix => {
36
- const idx = postfix . indexOf ( "?" ) ;
37
- let query = "" ;
38
- if ( idx >= 0 ) {
39
- query = postfix . substr ( idx ) ;
40
- postfix = postfix . substr ( 0 , idx ) ;
41
- }
42
- return {
43
- postfix,
44
- query
45
- } ;
46
- } ;
47
-
48
37
// TODO Use Omit<> type for contextOptions when typescript >= 3.5
49
38
/** @typedef {Partial<Pick<ContextDependencyOptions, Exclude<keyof ContextDependencyOptions, "resource"|"recursive"|"regExp">>> } PartialContextDependencyOptions */
50
39
@@ -70,7 +59,9 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
70
59
71
60
const valueRange = param . range ;
72
61
const { context, prefix } = splitContextFromPrefix ( prefixRaw ) ;
73
- const { postfix, query } = splitQueryFromPostfix ( postfixRaw ) ;
62
+ const { path : postfix , query, fragment } = parsePathQueryFragment (
63
+ postfixRaw
64
+ ) ;
74
65
75
66
// When there are more than two quasis, the generated RegExp can be more precise
76
67
// We join the quasis with the expression regexp
@@ -81,20 +72,21 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
81
72
. map ( q => quoteMeta ( q . string ) + options . wrappedContextRegExp . source )
82
73
. join ( "" ) ;
83
74
84
- // Example: `./context/pre${e}inner${e}inner2${e}post?query`
75
+ // Example: `./context/pre${e}inner${e}inner2${e}post?query#frag `
85
76
// context: "./context"
86
77
// prefix: "./pre"
87
78
// innerQuasis: [BEE("inner"), BEE("inner2")]
88
79
// (BEE = BasicEvaluatedExpression)
89
80
// postfix: "post"
90
81
// query: "?query"
82
+ // fragment: "#frag"
91
83
// regExp: /^\.\/pre.*inner.*inner2.*post$/
92
84
const regExp = new RegExp (
93
85
`^${ quoteMeta ( prefix ) } ${ innerRegExp } ${ quoteMeta ( postfix ) } $`
94
86
) ;
95
87
const dep = new Dep (
96
88
{
97
- request : context + query ,
89
+ request : context + query + fragment ,
98
90
recursive : options . wrappedContextRecursive ,
99
91
regExp,
100
92
mode : "sync" ,
@@ -165,15 +157,17 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
165
157
param . postfix && param . postfix . isString ( ) ? param . postfix . range : null ;
166
158
const valueRange = param . range ;
167
159
const { context, prefix } = splitContextFromPrefix ( prefixRaw ) ;
168
- const { postfix, query } = splitQueryFromPostfix ( postfixRaw ) ;
160
+ const { path : postfix , query, fragment } = parsePathQueryFragment (
161
+ postfixRaw
162
+ ) ;
169
163
const regExp = new RegExp (
170
164
`^${ quoteMeta ( prefix ) } ${ options . wrappedContextRegExp . source } ${ quoteMeta (
171
165
postfix
172
166
) } $`
173
167
) ;
174
168
const dep = new Dep (
175
169
{
176
- request : context + query ,
170
+ request : context + query + fragment ,
177
171
recursive : options . wrappedContextRecursive ,
178
172
regExp,
179
173
mode : "sync" ,
0 commit comments