Skip to content

Commit 574381b

Browse files
committed
wip
1 parent eaa22a7 commit 574381b

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

lib/internal/policy/manifest.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class DependencyMapperInstance {
9191
* @type {DependencyMap | undefined}
9292
*/
9393
#dependencies;
94+
/**
95+
* @type {PatternDependencyMap | undefined}
96+
*/
97+
#patternDependencies;
9498
/**
9599
* @type {DependencyMapperInstance | null | undefined}
96100
*/
@@ -107,14 +111,44 @@ class DependencyMapperInstance {
107111
* @type {boolean}
108112
*/
109113
allowSameHREFScope;
114+
/**
115+
*
116+
* @param {string} parentHREF
117+
* @param {DependencyMap | undefined} dependencies
118+
* @param {boolean} cascade
119+
* @param {boolean} allowSameHREFScope
120+
*/
110121
constructor(
111122
parentHREF,
112123
dependencies,
113124
cascade = false,
114125
allowSameHREFScope = false
115126
) {
116127
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+
}
118152
this.cascade = cascade;
119153
this.allowSameHREFScope = allowSameHREFScope;
120154
ObjectFreeze(this);
@@ -303,6 +337,7 @@ function findScopeHREF(href, scopeStore, allowSame) {
303337

304338
/**
305339
* @typedef {Record<string, string> | typeof kFallThrough} DependencyMap
340+
* @typedef {Array<[string, [string, string]]>} PatternDependencyMap
306341
* @typedef {Record<string, string> | null | true} JSONDependencyMap
307342
*/
308343
/**

0 commit comments

Comments
 (0)