@jsenv/ast 5.2.1 → 6.0.1
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.
- package/package.json +2 -2
- package/src/html/html_node_position.js +2 -2
- package/src/html/html_parse.js +30 -5
- package/src/js/babel_utils.js +2 -2
- package/src/main.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/ast",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Parse and transform HTML,CSS and JS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@babel/parser": "7.23.
|
|
36
|
+
"@babel/parser": "7.23.3",
|
|
37
37
|
"@jsenv/urls": "2.2.1",
|
|
38
38
|
"acorn": "8.11.2",
|
|
39
39
|
"acorn-import-assertions": "1.9.0",
|
|
@@ -100,8 +100,8 @@ export const getHtmlNodeAttributePosition = (node, attributeName) => {
|
|
|
100
100
|
attributeName === "inlined-from-src"
|
|
101
101
|
? "original-src-position"
|
|
102
102
|
: attributeName === "inlined-from-href"
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
? "original-href-position"
|
|
104
|
+
: `original-${attributeName}-position`;
|
|
105
105
|
const originalPosition = getHtmlNodeAttribute(
|
|
106
106
|
node,
|
|
107
107
|
originalPositionAttributeName,
|
package/src/html/html_parse.js
CHANGED
|
@@ -12,11 +12,36 @@ import {
|
|
|
12
12
|
import { findHtmlChildNode, visitHtmlNodes } from "./html_search.js";
|
|
13
13
|
import { getHtmlNodeText } from "./html_node_text.js";
|
|
14
14
|
|
|
15
|
-
export const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
export const parseHtml = ({
|
|
16
|
+
html,
|
|
17
|
+
url,
|
|
18
|
+
storeOriginalPositions = true,
|
|
19
|
+
} = {}) => {
|
|
20
|
+
const htmlAst = parse(html, {
|
|
21
|
+
sourceCodeLocationInfo: true,
|
|
22
|
+
onParseError: (parse5Error) => {
|
|
23
|
+
if (
|
|
24
|
+
[
|
|
25
|
+
"missing-doctype",
|
|
26
|
+
"abandoned-head-element-child",
|
|
27
|
+
"duplicate-attribute",
|
|
28
|
+
"non-void-html-element-start-tag-with-trailing-solidus",
|
|
29
|
+
].includes(parse5Error.code)
|
|
30
|
+
) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const htmlParseError = new Error(
|
|
34
|
+
`Unable to parse HTML; ${parse5Error.code}`,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
htmlParseError.reasonCode = parse5Error.code;
|
|
38
|
+
htmlParseError.code = "PARSE_ERROR";
|
|
39
|
+
htmlParseError.url = url;
|
|
40
|
+
htmlParseError.line = parse5Error.startLine;
|
|
41
|
+
htmlParseError.column = parse5Error.startCol;
|
|
42
|
+
throw htmlParseError;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
20
45
|
if (storeOriginalPositions) {
|
|
21
46
|
const htmlNode = findHtmlChildNode(
|
|
22
47
|
htmlAst,
|
package/src/js/babel_utils.js
CHANGED