@jsenv/ast 1.1.3 → 1.2.2

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": "1.1.3",
3
+ "version": "1.2.2",
4
4
  "description": "Parse and transform HTML,CSS and JS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,13 +33,13 @@
33
33
  "test": "node --conditions=development ./scripts/test.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@babel/parser": "7.18.8",
37
- "@parcel/css": "1.11.2",
38
- "acorn": "8.7.1",
36
+ "@babel/parser": "7.19.0",
37
+ "@parcel/css": "1.13.1",
38
+ "acorn": "8.8.0",
39
39
  "acorn-import-assertions": "1.8.0",
40
40
  "acorn-walk": "8.2.0",
41
- "parse5": "7.0.0",
42
- "postcss": "8.4.14",
41
+ "parse5": "7.1.1",
42
+ "postcss": "8.4.16",
43
43
  "postcss-value-parser": "4.2.0"
44
44
  }
45
45
  }
@@ -84,7 +84,7 @@ export const analyzeLinkNode = (linkNode) => {
84
84
  isStylesheet: true,
85
85
  }
86
86
  }
87
- const isRessourceHint = [
87
+ const isResourceHint = [
88
88
  "preconnect",
89
89
  "dns-prefetch",
90
90
  "prefetch",
@@ -92,7 +92,7 @@ export const analyzeLinkNode = (linkNode) => {
92
92
  "modulepreload",
93
93
  ].includes(rel)
94
94
  return {
95
- isRessourceHint,
95
+ isResourceHint,
96
96
  rel,
97
97
  }
98
98
  }
@@ -7,7 +7,7 @@ import { setHtmlNodeText } from "./html_node_text.js"
7
7
  export const inlineScriptNode = (script, textContent) => {
8
8
  const src = getHtmlNodeAttribute(script, "src")
9
9
  setHtmlNodeAttributes(script, {
10
- "generated-from-src": src,
10
+ "inlined-from-src": src,
11
11
  "src": undefined,
12
12
  "crossorigin": undefined,
13
13
  "integrity": undefined,
@@ -18,7 +18,7 @@ export const inlineScriptNode = (script, textContent) => {
18
18
  export const inlineLinkStylesheetNode = (link, textContent) => {
19
19
  const href = getHtmlNodeAttribute(link, "href")
20
20
  setHtmlNodeAttributes(link, {
21
- "generated-from-href": href,
21
+ "inlined-from-href": href,
22
22
  "href": undefined,
23
23
  "rel": undefined,
24
24
  "type": undefined,
@@ -34,7 +34,7 @@ export const inlineLinkStylesheetNode = (link, textContent) => {
34
34
  export const inlineImgNode = (img, contentAsBase64) => {
35
35
  const src = getHtmlNodeAttribute(img, "src")
36
36
  setHtmlNodeAttributes(img, {
37
- "generated-from-src": src,
37
+ "inlined-from-src": src,
38
38
  "src": contentAsBase64,
39
39
  })
40
40
  }
@@ -1,9 +1,6 @@
1
1
  import { parseFragment } from "parse5"
2
2
 
3
- import {
4
- getHtmlNodeAttribute,
5
- setHtmlNodeAttributes,
6
- } from "./html_node_attributes.js"
3
+ import { setHtmlNodeAttributes } from "./html_node_attributes.js"
7
4
  import { findHtmlNode } from "./html_search.js"
8
5
  import { analyzeScriptNode } from "./html_analysis.js"
9
6
 
@@ -20,13 +17,15 @@ export const createHtmlNode = ({ tagName, textContent = "", ...rest }) => {
20
17
  return fragment.childNodes[0]
21
18
  }
22
19
 
23
- export const injectScriptNodeAsEarlyAsPossible = (htmlAst, scriptNode) => {
24
- const injectedBy = getHtmlNodeAttribute(scriptNode, "injected-by")
25
- if (injectedBy === undefined) {
26
- setHtmlNodeAttributes(scriptNode, {
27
- "injected-by": "jsenv",
28
- })
29
- }
20
+ export const injectScriptNodeAsEarlyAsPossible = (
21
+ htmlAst,
22
+ scriptNode,
23
+ jsenvPluginName = "jsenv",
24
+ ) => {
25
+ setHtmlNodeAttributes(scriptNode, {
26
+ "jsenv-plugin-owner": jsenvPluginName,
27
+ "jsenv-plugin-action": "injected",
28
+ })
30
29
  const isJsModule = analyzeScriptNode(scriptNode).type === "js_module"
31
30
  if (isJsModule) {
32
31
  const firstImportmapScript = findHtmlNode(htmlAst, (node) => {
@@ -97,9 +97,9 @@ export const getHtmlNodeAttributePosition = (node, attributeName) => {
97
97
  }
98
98
  }
99
99
  const originalPositionAttributeName =
100
- attributeName === "generated-from-src"
100
+ attributeName === "inlined-from-src"
101
101
  ? "original-src-position"
102
- : attributeName === "generated-from-href"
102
+ : attributeName === "inlined-from-href"
103
103
  ? "original-href-position"
104
104
  : `original-${attributeName}-position`
105
105
  const originalPosition = getHtmlNodeAttribute(
@@ -45,9 +45,9 @@ export const parseHtmlString = (
45
45
 
46
46
  export const stringifyHtmlAst = (
47
47
  htmlAst,
48
- { removeOriginalPositionAttributes = false } = {},
48
+ { cleanupJsenvAttributes = false } = {},
49
49
  ) => {
50
- if (removeOriginalPositionAttributes) {
50
+ if (cleanupJsenvAttributes) {
51
51
  const htmlNode = findHtmlChildNode(
52
52
  htmlAst,
53
53
  (node) => node.nodeName === "html",
@@ -66,17 +66,17 @@ export const stringifyHtmlAst = (
66
66
  "original-position": undefined,
67
67
  "original-src-position": undefined,
68
68
  "original-href-position": undefined,
69
- "injected-by": undefined,
70
- "generated-by": undefined,
71
- "generated-from-src": undefined,
72
- "generated-from-href": undefined,
69
+ "inlined-from-src": undefined,
70
+ "inlined-from-href": undefined,
71
+ "jsenv-plugin-owner": undefined,
72
+ "jsenv-plugin-action": undefined,
73
+ "jsenv-debug": undefined,
73
74
  })
74
75
  },
75
76
  })
76
77
  }
77
78
  }
78
79
  const htmlString = serialize(htmlAst)
79
-
80
80
  return htmlString
81
81
  }
82
82