happy-dom 9.16.0 → 9.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
- package/lib/nodes/html-link-element/HTMLLinkElement.d.ts.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.js +5 -68
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.d.ts +22 -0
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -0
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.js +70 -0
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.js.map +1 -0
- package/lib/nodes/html-script-element/HTMLScriptElement.js +3 -3
- package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
- package/lib/nodes/html-script-element/{ScriptUtility.d.ts → HTMLScriptElementUtility.d.ts} +9 -2
- package/lib/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -0
- package/lib/nodes/html-script-element/{ScriptUtility.js → HTMLScriptElementUtility.js} +35 -36
- package/lib/nodes/html-script-element/HTMLScriptElementUtility.js.map +1 -0
- package/lib/query-selector/ISelectorAttribute.d.ts +2 -0
- package/lib/query-selector/ISelectorAttribute.d.ts.map +1 -1
- package/lib/query-selector/SelectorItem.d.ts.map +1 -1
- package/lib/query-selector/SelectorItem.js +5 -42
- package/lib/query-selector/SelectorItem.js.map +1 -1
- package/lib/query-selector/SelectorParser.d.ts +10 -0
- package/lib/query-selector/SelectorParser.d.ts.map +1 -1
- package/lib/query-selector/SelectorParser.js +65 -20
- package/lib/query-selector/SelectorParser.js.map +1 -1
- package/package.json +1 -1
- package/src/nodes/html-link-element/HTMLLinkElement.ts +5 -83
- package/src/nodes/html-link-element/HTMLLinkElementUtility.ts +82 -0
- package/src/nodes/html-script-element/HTMLScriptElement.ts +3 -3
- package/src/nodes/html-script-element/HTMLScriptElementUtility.ts +94 -0
- package/src/query-selector/ISelectorAttribute.ts +2 -0
- package/src/query-selector/SelectorItem.ts +7 -43
- package/src/query-selector/SelectorParser.ts +72 -20
- package/lib/nodes/html-script-element/ScriptUtility.d.ts.map +0 -1
- package/lib/nodes/html-script-element/ScriptUtility.js.map +0 -1
- package/src/nodes/html-script-element/ScriptUtility.ts +0 -89
@@ -14,16 +14,17 @@ import ISelectorPseudo from './ISelectorPseudo';
|
|
14
14
|
* Group 6: Attribute name when there is a value using apostrophe (e.g. "attr1")
|
15
15
|
* Group 7: Attribute operator when using apostrophe (e.g. "~")
|
16
16
|
* Group 8: Attribute value when using apostrophe (e.g. "value1")
|
17
|
-
* Group 9: Attribute
|
18
|
-
* Group 10: Attribute
|
19
|
-
* Group 11: Attribute
|
20
|
-
* Group 12:
|
21
|
-
* Group 13:
|
22
|
-
* Group 14:
|
23
|
-
* Group 15:
|
17
|
+
* Group 9: Attribute modifier when using apostrophe (e.g. "i" or "s")
|
18
|
+
* Group 10: Attribute name when threre is a value not using apostrophe (e.g. "attr1")
|
19
|
+
* Group 11: Attribute operator when not using apostrophe (e.g. "~")
|
20
|
+
* Group 12: Attribute value when notusing apostrophe (e.g. "value1")
|
21
|
+
* Group 13: Pseudo name when arguments (e.g. "nth-child")
|
22
|
+
* Group 14: Arguments of pseudo (e.g. "2n + 1")
|
23
|
+
* Group 15: Pseudo name when no arguments (e.g. "empty")
|
24
|
+
* Group 16: Combinator.
|
24
25
|
*/
|
25
26
|
const SELECTOR_REGEXP =
|
26
|
-
/(\*)|([a-zA-Z0-9-]+)|#((?:[a-zA-Z0-9-_]|\\.)+)|\.((?:[a-zA-Z0-9-_]|\\.)+)|\[([a-zA-Z0-9-_]+)\]|\[([a-zA-Z0-9-_]+)([~|^$*]{0,1}) *= *["']{1}([^"']*)["']{1}\]|\[([a-zA-Z0-9-_]+)([~|^$*]{0,1}) *= *([^\]]*)\]|:([a-zA-Z-]+) *\(([^)]+)\)|:([a-zA-Z-]+)|([ ,+>]*)/g;
|
27
|
+
/(\*)|([a-zA-Z0-9-]+)|#((?:[a-zA-Z0-9-_]|\\.)+)|\.((?:[a-zA-Z0-9-_]|\\.)+)|\[([a-zA-Z0-9-_]+)\]|\[([a-zA-Z0-9-_]+) *([~|^$*]{0,1}) *= *["']{1}([^"']*)["']{1} *(s|i){0,1}\]|\[([a-zA-Z0-9-_]+) *([~|^$*]{0,1}) *= *([^\]]*)\]|:([a-zA-Z-]+) *\(([^)]+)\)|:([a-zA-Z-]+)|([ ,+>]*)/g;
|
27
28
|
|
28
29
|
/**
|
29
30
|
* Escaped Character RegExp.
|
@@ -117,30 +118,40 @@ export default class SelectorParser {
|
|
117
118
|
currentSelectorItem.attributes.push({
|
118
119
|
name: match[5].toLowerCase(),
|
119
120
|
operator: null,
|
120
|
-
value: null
|
121
|
+
value: null,
|
122
|
+
modifier: null,
|
123
|
+
regExp: null
|
121
124
|
});
|
122
125
|
} else if (match[6] && match[8] !== undefined) {
|
123
126
|
currentSelectorItem.attributes = currentSelectorItem.attributes || [];
|
124
127
|
currentSelectorItem.attributes.push({
|
125
128
|
name: match[6].toLowerCase(),
|
126
129
|
operator: match[7] || null,
|
127
|
-
value: match[8]
|
130
|
+
value: match[8],
|
131
|
+
modifier: match[9] || null,
|
132
|
+
regExp: this.getAttributeRegExp({
|
133
|
+
operator: match[7],
|
134
|
+
value: match[8],
|
135
|
+
modifier: match[9]
|
136
|
+
})
|
128
137
|
});
|
129
|
-
} else if (match[
|
138
|
+
} else if (match[10] && match[12] !== undefined) {
|
130
139
|
currentSelectorItem.attributes = currentSelectorItem.attributes || [];
|
131
140
|
currentSelectorItem.attributes.push({
|
132
|
-
name: match[
|
133
|
-
operator: match[
|
134
|
-
value: match[
|
141
|
+
name: match[10].toLowerCase(),
|
142
|
+
operator: match[11] || null,
|
143
|
+
value: match[12],
|
144
|
+
modifier: null,
|
145
|
+
regExp: this.getAttributeRegExp({ operator: match[7], value: match[8] })
|
135
146
|
});
|
136
|
-
} else if (match[
|
147
|
+
} else if (match[13] && match[14]) {
|
137
148
|
currentSelectorItem.pseudos = currentSelectorItem.pseudos || [];
|
138
|
-
currentSelectorItem.pseudos.push(this.getPseudo(match[
|
139
|
-
} else if (match[14]) {
|
140
|
-
currentSelectorItem.pseudos = currentSelectorItem.pseudos || [];
|
141
|
-
currentSelectorItem.pseudos.push(this.getPseudo(match[14]));
|
149
|
+
currentSelectorItem.pseudos.push(this.getPseudo(match[13], match[14]));
|
142
150
|
} else if (match[15]) {
|
143
|
-
|
151
|
+
currentSelectorItem.pseudos = currentSelectorItem.pseudos || [];
|
152
|
+
currentSelectorItem.pseudos.push(this.getPseudo(match[15]));
|
153
|
+
} else if (match[16]) {
|
154
|
+
switch (match[16].trim()) {
|
144
155
|
case ',':
|
145
156
|
currentSelectorItem = new SelectorItem({
|
146
157
|
combinator: SelectorCombinatorEnum.descendant
|
@@ -178,6 +189,47 @@ export default class SelectorParser {
|
|
178
189
|
return groups;
|
179
190
|
}
|
180
191
|
|
192
|
+
/**
|
193
|
+
* Returns attribute RegExp.
|
194
|
+
*
|
195
|
+
* @param attribute Attribute.
|
196
|
+
* @param attribute.value Attribute value.
|
197
|
+
* @param attribute.operator Attribute operator.
|
198
|
+
* @param attribute.modifier Attribute modifier.
|
199
|
+
* @returns Attribute RegExp.
|
200
|
+
*/
|
201
|
+
private static getAttributeRegExp(attribute: {
|
202
|
+
value?: string;
|
203
|
+
operator?: string;
|
204
|
+
modifier?: string;
|
205
|
+
}): RegExp | null {
|
206
|
+
const modifier = attribute.modifier === 'i' ? 'i' : '';
|
207
|
+
|
208
|
+
if (!attribute.operator || !attribute.value) {
|
209
|
+
return null;
|
210
|
+
}
|
211
|
+
|
212
|
+
switch (attribute.operator) {
|
213
|
+
// [attribute~="value"] - Contains a specified word.
|
214
|
+
case '~':
|
215
|
+
return new RegExp(`[- ]${attribute.value}|${attribute.value}[- ]`, modifier);
|
216
|
+
// [attribute|="value"] - Starts with the specified word.
|
217
|
+
case '|':
|
218
|
+
return new RegExp(`^${attribute.value}[- ]`, modifier);
|
219
|
+
// [attribute^="value"] - Begins with a specified value.
|
220
|
+
case '^':
|
221
|
+
return new RegExp(`^${attribute.value}`, modifier);
|
222
|
+
// [attribute$="value"] - Ends with a specified value.
|
223
|
+
case '$':
|
224
|
+
return new RegExp(`${attribute.value}$`, modifier);
|
225
|
+
// [attribute*="value"] - Contains a specified value.
|
226
|
+
case '*':
|
227
|
+
return new RegExp(`${attribute.value}`, modifier);
|
228
|
+
default:
|
229
|
+
return null;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
181
233
|
/**
|
182
234
|
* Returns pseudo.
|
183
235
|
*
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ScriptUtility.d.ts","sourceRoot":"","sources":["../../../src/nodes/html-script-element/ScriptUtility.ts"],"names":[],"mappings":"AAIA,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IACjC;;;;;;OAMG;WACiB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAuEjF"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ScriptUtility.js","sourceRoot":"","sources":["../../../src/nodes/html-script-element/ScriptUtility.ts"],"names":[],"mappings":";;;;;AACA,8DAAsC;AACtC,+EAAuD;AACvD,8EAAsD;AAGtD;;GAEG;AACH,MAAqB,aAAa;IACjC;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,OAA0B;QAChE,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;QAErD,IACC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,4BAA4B;YAChF,OAAO,CAAC,aAA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,GAAG,CAAC,CAAC;aAC3D;YAAC,OAAO,KAAK,EAAE;gBACf,OAAO,CAAC,aAAa,CACpB,IAAI,oBAAU,CAAC,OAAO,EAAE;oBACvB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,KAAK;iBACL,CAAC,CACF,CAAC;gBACF,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,aAAa,CAC9C,IAAI,oBAAU,CAAC,OAAO,EAAE;oBACvB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,KAAK;iBACL,CAAC,CACF,CAAC;gBACF,IACC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC;oBAC/B,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,EACxD;oBACD,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBACvD;aACD;YACD,IAAI,IAAI,EAAE;gBACT,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC7C,OAAO,CAAC,aAAa,CAAC,IAAI,eAAK,CAAC,MAAM,CAAC,CAAC,CAAC;aACzC;SACD;IACF,CAAC;CACD;AA/ED,gCA+EC"}
|
@@ -1,89 +0,0 @@
|
|
1
|
-
import { Document } from '../..';
|
2
|
-
import Event from '../../event/Event';
|
3
|
-
import ErrorEvent from '../../event/events/ErrorEvent';
|
4
|
-
import ResourceFetch from '../../fetch/ResourceFetch';
|
5
|
-
import HTMLScriptElement from './HTMLScriptElement';
|
6
|
-
|
7
|
-
/**
|
8
|
-
* Helper class for getting the URL relative to a Location object.
|
9
|
-
*/
|
10
|
-
export default class ScriptUtility {
|
11
|
-
/**
|
12
|
-
* Returns a URL relative to the given Location object.
|
13
|
-
*
|
14
|
-
* @param options Options.
|
15
|
-
* @param options.element Element.
|
16
|
-
* @param element
|
17
|
-
*/
|
18
|
-
public static async loadExternalScript(element: HTMLScriptElement): Promise<void> {
|
19
|
-
const src = element.getAttribute('src');
|
20
|
-
const async = element.getAttribute('async') !== null;
|
21
|
-
|
22
|
-
if (
|
23
|
-
element.ownerDocument.defaultView.happyDOM.settings.disableJavaScriptFileLoading ||
|
24
|
-
element.ownerDocument.defaultView.happyDOM.settings.disableJavaScriptEvaluation
|
25
|
-
) {
|
26
|
-
return;
|
27
|
-
}
|
28
|
-
|
29
|
-
if (async) {
|
30
|
-
let code = null;
|
31
|
-
(<Document>element.ownerDocument)._readyStateManager.startTask();
|
32
|
-
try {
|
33
|
-
code = await ResourceFetch.fetch(element.ownerDocument, src);
|
34
|
-
} catch (error) {
|
35
|
-
element.dispatchEvent(
|
36
|
-
new ErrorEvent('error', {
|
37
|
-
message: error.message,
|
38
|
-
error
|
39
|
-
})
|
40
|
-
);
|
41
|
-
element.ownerDocument.defaultView.dispatchEvent(
|
42
|
-
new ErrorEvent('error', {
|
43
|
-
message: error.message,
|
44
|
-
error
|
45
|
-
})
|
46
|
-
);
|
47
|
-
if (
|
48
|
-
!element['_listeners']['error'] &&
|
49
|
-
!element.ownerDocument.defaultView['_listeners']['error']
|
50
|
-
) {
|
51
|
-
element.ownerDocument.defaultView.console.error(error);
|
52
|
-
}
|
53
|
-
}
|
54
|
-
if (code) {
|
55
|
-
element.ownerDocument.defaultView.eval(code);
|
56
|
-
element.dispatchEvent(new Event('load'));
|
57
|
-
}
|
58
|
-
(<Document>element.ownerDocument)._readyStateManager.endTask();
|
59
|
-
} else {
|
60
|
-
let code = null;
|
61
|
-
try {
|
62
|
-
code = ResourceFetch.fetchSync(element.ownerDocument, src);
|
63
|
-
} catch (error) {
|
64
|
-
element.dispatchEvent(
|
65
|
-
new ErrorEvent('error', {
|
66
|
-
message: error.message,
|
67
|
-
error
|
68
|
-
})
|
69
|
-
);
|
70
|
-
element.ownerDocument.defaultView.dispatchEvent(
|
71
|
-
new ErrorEvent('error', {
|
72
|
-
message: error.message,
|
73
|
-
error
|
74
|
-
})
|
75
|
-
);
|
76
|
-
if (
|
77
|
-
!element['_listeners']['error'] &&
|
78
|
-
!element.ownerDocument.defaultView['_listeners']['error']
|
79
|
-
) {
|
80
|
-
element.ownerDocument.defaultView.console.error(error);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
if (code) {
|
84
|
-
element.ownerDocument.defaultView.eval(code);
|
85
|
-
element.dispatchEvent(new Event('load'));
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}
|