@jsenv/ast 1.3.0 → 1.3.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 +3 -3
- package/src/html/html_node.js +29 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/ast",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Parse and transform HTML,CSS and JS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@babel/parser": "7.19.
|
|
37
|
-
"@parcel/css": "1.
|
|
36
|
+
"@babel/parser": "7.19.1",
|
|
37
|
+
"@parcel/css": "1.14.0",
|
|
38
38
|
"acorn": "8.8.0",
|
|
39
39
|
"acorn-import-assertions": "1.8.0",
|
|
40
40
|
"acorn-walk": "8.2.0",
|
package/src/html/html_node.js
CHANGED
|
@@ -29,23 +29,42 @@ export const injectScriptNodeAsEarlyAsPossible = (
|
|
|
29
29
|
const isJsModule = analyzeScriptNode(scriptNode).type === "js_module"
|
|
30
30
|
if (isJsModule) {
|
|
31
31
|
const firstImportmapScript = findHtmlNode(htmlAst, (node) => {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
return (
|
|
33
|
+
node.nodeName === "script" &&
|
|
34
|
+
analyzeScriptNode(node).type === "importmap"
|
|
35
|
+
)
|
|
34
36
|
})
|
|
37
|
+
|
|
35
38
|
if (firstImportmapScript) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
firstImportmapScript,
|
|
39
|
+
const importmapParent = firstImportmapScript.parentNode
|
|
40
|
+
const importmapSiblings = importmapParent.childNodes
|
|
41
|
+
const nextSiblings = importmapSiblings.slice(
|
|
42
|
+
importmapSiblings.indexOf(firstImportmapScript) + 1,
|
|
40
43
|
)
|
|
44
|
+
let after = firstImportmapScript
|
|
45
|
+
for (const nextSibling of nextSiblings) {
|
|
46
|
+
if (nextSibling.nodeName === "script") {
|
|
47
|
+
return insertBefore(scriptNode, importmapParent, nextSibling)
|
|
48
|
+
}
|
|
49
|
+
if (nextSibling.nodeName === "link") {
|
|
50
|
+
after = nextSibling
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return insertAfter(scriptNode, importmapParent, after)
|
|
41
54
|
}
|
|
42
55
|
}
|
|
43
56
|
const headNode = findChild(htmlAst, (node) => node.nodeName === "html")
|
|
44
57
|
.childNodes[0]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
let after = headNode.childNodes[0]
|
|
59
|
+
for (const child of headNode.childNodes) {
|
|
60
|
+
if (child.nodeName === "script") {
|
|
61
|
+
return insertBefore(scriptNode, headNode, child)
|
|
62
|
+
}
|
|
63
|
+
if (child.nodeName === "link") {
|
|
64
|
+
after = child
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return insertAfter(scriptNode, headNode, after)
|
|
49
68
|
}
|
|
50
69
|
|
|
51
70
|
const insertBefore = (nodeToInsert, futureParentNode, futureNextSibling) => {
|