@jsenv/ast 6.3.4 → 6.3.6
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": "6.3.
|
|
3
|
+
"version": "6.3.6",
|
|
4
4
|
"description": "Parse and transform HTML, CSS and JS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/parser": "7.26.2",
|
|
33
33
|
"@jsenv/humanize": "1.2.8",
|
|
34
|
-
"@jsenv/urls": "2.5.
|
|
34
|
+
"@jsenv/urls": "2.5.3",
|
|
35
35
|
"acorn": "8.14.0",
|
|
36
36
|
"acorn-import-attributes": "1.9.5",
|
|
37
37
|
"acorn-walk": "8.3.4",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { urlToFileSystemPath } from "@jsenv/urls";
|
|
2
2
|
import { createParseError } from "../parse_error.js";
|
|
3
3
|
|
|
4
4
|
export const applyPostCss = async ({
|
|
@@ -16,8 +16,8 @@ export const applyPostCss = async ({
|
|
|
16
16
|
const cssFileUrl = urlToFileUrl(url);
|
|
17
17
|
const result = await postcss(plugins).process(content, {
|
|
18
18
|
collectUrls: true,
|
|
19
|
-
from:
|
|
20
|
-
to:
|
|
19
|
+
from: urlToFileSystemPath(cssFileUrl),
|
|
20
|
+
to: urlToFileSystemPath(cssFileUrl),
|
|
21
21
|
map: {
|
|
22
22
|
annotation: sourcemaps === "file",
|
|
23
23
|
inline: sourcemaps === "inline",
|
package/src/html/html_node.js
CHANGED
|
@@ -130,9 +130,38 @@ const getJsenvScriptsNode = (htmlAst) => {
|
|
|
130
130
|
jsenvScripts = createHtmlNode({
|
|
131
131
|
tagName: "jsenv-scripts",
|
|
132
132
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
const headNode = findChild(htmlAst, (node) => node.nodeName === "html")
|
|
134
|
+
.childNodes[0];
|
|
135
|
+
let after = headNode.childNodes[0];
|
|
136
|
+
for (const child of headNode.childNodes) {
|
|
137
|
+
if (child.nodeName === "link") {
|
|
138
|
+
after = child;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (child.nodeName === "script") {
|
|
142
|
+
const { type } = analyzeScriptNode(child);
|
|
143
|
+
if (type === "js_classic") {
|
|
144
|
+
insertHtmlNodeBefore(jsenvScripts, child);
|
|
145
|
+
return jsenvScripts;
|
|
146
|
+
}
|
|
147
|
+
if (type === "importmap") {
|
|
148
|
+
insertHtmlNodeAfter(jsenvScripts, child);
|
|
149
|
+
return jsenvScripts;
|
|
150
|
+
}
|
|
151
|
+
if (type === "js_module") {
|
|
152
|
+
insertHtmlNodeBefore(jsenvScripts, child);
|
|
153
|
+
return jsenvScripts;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (child.nodeName === "meta") {
|
|
157
|
+
after = child;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (after) {
|
|
161
|
+
insertHtmlNodeAfter(jsenvScripts, after);
|
|
162
|
+
return jsenvScripts;
|
|
163
|
+
}
|
|
164
|
+
injectHtmlNode(htmlAst, jsenvScripts);
|
|
136
165
|
return jsenvScripts;
|
|
137
166
|
};
|
|
138
167
|
const stringifyParams = (params, prefix = "") => {
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* - https://astexplorer.net/
|
|
4
4
|
* - https://bvaughn.github.io/babel-repl
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { urlToFileSystemPath } from "@jsenv/urls";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
7
8
|
import { createParseError } from "../parse_error.js";
|
|
8
9
|
|
|
9
10
|
export const applyBabelPlugins = async ({
|
|
@@ -20,7 +21,7 @@ export const applyBabelPlugins = async ({
|
|
|
20
21
|
}
|
|
21
22
|
const { transformAsync, transformFromAstAsync } = await import("@babel/core");
|
|
22
23
|
const sourceFileName = inputUrl.startsWith("file:")
|
|
23
|
-
?
|
|
24
|
+
? urlToFileSystemPath(inputUrl)
|
|
24
25
|
: undefined;
|
|
25
26
|
options = {
|
|
26
27
|
ast: false,
|
|
@@ -29,7 +30,7 @@ export const applyBabelPlugins = async ({
|
|
|
29
30
|
sourceFileName,
|
|
30
31
|
filename: outputUrl
|
|
31
32
|
? outputUrl.startsWith("file:")
|
|
32
|
-
?
|
|
33
|
+
? urlToFileSystemPath(inputUrl)
|
|
33
34
|
: undefined
|
|
34
35
|
: sourceFileName,
|
|
35
36
|
configFile: false,
|