@jsenv/ast 5.2.0 → 6.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/ast",
3
- "version": "5.2.0",
3
+ "version": "6.0.0",
4
4
  "description": "Parse and transform HTML,CSS and JS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,9 +35,9 @@
35
35
  "dependencies": {
36
36
  "@babel/parser": "7.23.0",
37
37
  "@jsenv/urls": "2.2.1",
38
- "acorn": "8.10.0",
38
+ "acorn": "8.11.2",
39
39
  "acorn-import-assertions": "1.9.0",
40
- "acorn-walk": "8.2.0",
40
+ "acorn-walk": "8.3.0",
41
41
  "parse5": "7.1.2",
42
42
  "postcss": "8.4.31",
43
43
  "postcss-value-parser": "4.2.0"
@@ -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 parseHtmlString = (
16
- htmlString,
17
- { storeOriginalPositions = true } = {},
18
- ) => {
19
- const htmlAst = parse(htmlString, { sourceCodeLocationInfo: true });
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/main.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // html
2
2
  export {
3
- parseHtmlString,
3
+ parseHtml,
4
4
  stringifyHtmlAst,
5
5
  parseSvgString,
6
6
  stringifySvgAst,