@jsenv/ast 6.7.21 → 6.8.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 CHANGED
@@ -1,19 +1,21 @@
1
1
  {
2
2
  "name": "@jsenv/ast",
3
- "version": "6.7.21",
3
+ "version": "6.8.1",
4
+ "type": "module",
4
5
  "description": "Parse and transform HTML, CSS and JS",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/jsenv/core",
8
9
  "directory": "packages/internal/ast"
9
10
  },
10
- "license": "MIT",
11
11
  "author": {
12
12
  "name": "dmail",
13
13
  "email": "dmaillard06@gmail.com"
14
14
  },
15
- "sideEffects": false,
16
- "type": "module",
15
+ "license": "MIT",
16
+ "engines": {
17
+ "node": ">=16.14.0"
18
+ },
17
19
  "exports": {
18
20
  ".": {
19
21
  "import": "./src/main.js"
@@ -26,15 +28,15 @@
26
28
  "dependencies": {
27
29
  "@babel/core": "7.29.0",
28
30
  "@babel/helper-module-imports": "7.28.6",
29
- "@babel/parser": "7.29.0",
31
+ "@babel/parser": "7.29.3",
30
32
  "@jsenv/humanize": "1.7.6",
31
33
  "@jsenv/urls": "2.9.8",
32
34
  "@jsenv/utils": "2.3.1",
33
35
  "acorn": "8.16.0",
34
36
  "acorn-import-attributes": "1.9.5",
35
37
  "acorn-walk": "8.3.5",
36
- "parse5": "8.0.0",
37
- "postcss": "8.5.8",
38
+ "parse5": "8.0.1",
39
+ "postcss": "8.5.14",
38
40
  "postcss-value-parser": "4.2.0"
39
41
  },
40
42
  "devDependencies": {
@@ -43,10 +45,8 @@
43
45
  "@jsenv/filesystem": "../../tooling/filesystem",
44
46
  "@jsenv/snapshot": "../../tooling/snapshot"
45
47
  },
46
- "engines": {
47
- "node": ">=16.14.0"
48
- },
49
48
  "publishConfig": {
50
49
  "access": "public"
51
- }
50
+ },
51
+ "sideEffects": false
52
52
  }
@@ -58,7 +58,6 @@ export const injectJsenvScript = (
58
58
  if (type === "module") {
59
59
  if (src) {
60
60
  if (initCall) {
61
- const paramsSource = stringifyParams(initCall.params, " ");
62
61
  const inlineScriptNode = createHtmlNode({
63
62
  "tagName": "script",
64
63
  "type": "module",
@@ -66,9 +65,7 @@ export const injectJsenvScript = (
66
65
  ...attributes,
67
66
  "children": `import { ${initCall.callee} } from ${JSON.stringify(src)};
68
67
 
69
- ${initCall.callee}({
70
- ${paramsSource}
71
- });`,
68
+ ${stringifyCall(initCall)};`,
72
69
  });
73
70
  insertHtmlNodeInside(inlineScriptNode, jsenvScriptsNode);
74
71
  return;
@@ -102,13 +99,10 @@ ${initCall.callee}({
102
99
  });
103
100
  insertHtmlNodeInside(remoteScriptNode, jsenvScriptsNode);
104
101
  if (initCall) {
105
- const paramsSource = stringifyParams(initCall.params, " ");
106
102
  const inlineScriptNode = createHtmlNode({
107
103
  "tagName": "script",
108
104
  "jsenv-injected-by": pluginName,
109
- "children": `${initCall.callee}({
110
- ${paramsSource}
111
- });`,
105
+ "children": `${stringifyCall(initCall)};`,
112
106
  ...attributes,
113
107
  });
114
108
  insertHtmlNodeInside(inlineScriptNode, jsenvScriptsNode);
@@ -170,17 +164,21 @@ const getJsenvScriptsNode = (htmlAst) => {
170
164
  injectHtmlNode(htmlAst, jsenvScripts);
171
165
  return jsenvScripts;
172
166
  };
173
- const stringifyParams = (params, prefix = "") => {
174
- const source = JSON.stringify(params, null, prefix);
175
- if (prefix.length) {
176
- // remove leading "{\n"
177
- // remove leading prefix
167
+ const stringifyCall = (initCall, { pretty = true } = {}) => {
168
+ if (!Object.hasOwn(initCall, "params")) {
169
+ return `${initCall.callee}()`;
170
+ }
171
+ if (pretty) {
172
+ const prefix = " ";
173
+ const source = JSON.stringify(initCall.params, null, prefix);
174
+ // remove leading "{\n "
178
175
  // remove trailing "\n}"
179
- return source.slice(2 + prefix.length, -2);
176
+ const paramsSource = source.slice(2 + prefix.length, -2);
177
+ return `${initCall.callee}({
178
+ ${paramsSource}
179
+ })`;
180
180
  }
181
- // remove leading "{"
182
- // remove trailing "}"
183
- return source.slice(1, -1);
181
+ return `${initCall.callee}(${JSON.stringify(initCall.params)})`;
184
182
  };
185
183
 
186
184
  export const injectHtmlNodeAsEarlyAsPossible = (
@@ -1,5 +1,6 @@
1
1
  import { Parser, getLineInfo } from "acorn";
2
2
  import { importAttributes } from "acorn-import-attributes";
3
+
3
4
  import { createParseError } from "../parse_error.js";
4
5
 
5
6
  export const parseJsWithAcorn = ({ js, url, isJsModule }) => {
@@ -12,7 +13,7 @@ export const parseJsWithAcorn = ({ js, url, isJsModule }) => {
12
13
  locations: true,
13
14
  allowAwaitOutsideFunction: true,
14
15
  sourceType: isJsModule ? "module" : "script",
15
- ecmaVersion: 2023,
16
+ ecmaVersion: 2025,
16
17
  onComment: (block, text, start, end) => {
17
18
  comments.push({
18
19
  block,