@@ -91,6 +91,10 @@ class DependencyMapperInstance {
91
91
* @type {DependencyMap | undefined }
92
92
*/
93
93
#dependencies;
94
+ /**
95
+ * @type {PatternDependencyMap | undefined }
96
+ */
97
+ #patternDependencies;
94
98
/**
95
99
* @type {DependencyMapperInstance | null | undefined }
96
100
*/
@@ -107,14 +111,44 @@ class DependencyMapperInstance {
107
111
* @type {boolean }
108
112
*/
109
113
allowSameHREFScope ;
114
+ /**
115
+ *
116
+ * @param {string } parentHREF
117
+ * @param {DependencyMap | undefined } dependencies
118
+ * @param {boolean } cascade
119
+ * @param {boolean } allowSameHREFScope
120
+ */
110
121
constructor (
111
122
parentHREF ,
112
123
dependencies ,
113
124
cascade = false ,
114
125
allowSameHREFScope = false
115
126
) {
116
127
this . href = parentHREF ;
117
- this . #dependencies = dependencies ;
128
+ if ( dependencies === kFallThrough || dependencies === undefined ) {
129
+ this . #dependencies = dependencies ;
130
+ this . #patternDependencies = undefined ;
131
+ } else {
132
+ let patterns = [ ] ;
133
+ let direct = ObjectCreate ( null ) ;
134
+ for ( const [ key , value ] of Object . entries ( dependencies ) ) {
135
+ if ( key . endsWith ( '*' ) ) {
136
+ let target = / ^ ( [ ^ * ] * ) \* ( [ ^ * ] * ) $ / . exec ( value ) ;
137
+ if ( ! target ) {
138
+ throw new Error ( 'pattern needs to have a single "*" in target' ) ;
139
+ }
140
+ let prefix = target [ 1 ] ;
141
+ let suffix = target [ 2 ] ;
142
+ patterns . push ( [
143
+ target . slice ( 0 , - 1 ) ,
144
+ [ prefix , suffix ]
145
+ ] ) ;
146
+ }
147
+ }
148
+ patterns . sort ( ( a , b ) => a [ 0 ] < b [ 0 ] ? - 1 : 1 ) ;
149
+ this . #dependencies = dependencies ;
150
+ this . #patternDependencies = patterns ;
151
+ }
118
152
this . cascade = cascade ;
119
153
this . allowSameHREFScope = allowSameHREFScope ;
120
154
ObjectFreeze ( this ) ;
@@ -303,6 +337,7 @@ function findScopeHREF(href, scopeStore, allowSame) {
303
337
304
338
/**
305
339
* @typedef {Record<string, string> | typeof kFallThrough } DependencyMap
340
+ * @typedef {Array<[string, [string, string]]> } PatternDependencyMap
306
341
* @typedef {Record<string, string> | null | true } JSONDependencyMap
307
342
*/
308
343
/**
0 commit comments