@jsenv/ast 6.6.11 → 6.7.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/ast",
3
- "version": "6.6.11",
3
+ "version": "6.7.1",
4
4
  "description": "Parse and transform HTML, CSS and JS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,6 +32,7 @@
32
32
  "dependencies": {
33
33
  "@babel/parser": "7.27.0",
34
34
  "@jsenv/humanize": "1.5.2",
35
+ "@jsenv/utils": "2.3.1",
35
36
  "@jsenv/urls": "2.7.4",
36
37
  "acorn": "8.14.1",
37
38
  "acorn-import-attributes": "1.9.5",
@@ -8,7 +8,7 @@ import { pathToFileURL } from "node:url";
8
8
  import { createParseError } from "../parse_error.js";
9
9
 
10
10
  export const applyBabelPlugins = async ({
11
- babelPlugins,
11
+ babelPlugins = [],
12
12
  input,
13
13
  inputIsJsModule,
14
14
  inputUrl,
@@ -16,9 +16,12 @@ export const applyBabelPlugins = async ({
16
16
  ast,
17
17
  options = {},
18
18
  }) => {
19
- if (babelPlugins.length === 0) {
19
+ if (babelPlugins.length === 0 && !optionsAreImpactingResult(options)) {
20
20
  return { code: input };
21
21
  }
22
+
23
+ const { parserOpts = {}, parserPlugins = [], generatorOpts = {} } = options;
24
+
22
25
  const { transformAsync, transformFromAstAsync } = await import("@babel/core");
23
26
  const sourceFileName = inputUrl.startsWith("file:")
24
27
  ? urlToFileSystemPath(inputUrl)
@@ -39,6 +42,7 @@ export const applyBabelPlugins = async ({
39
42
  // consider using startColumn and startLine for inline scripts?
40
43
  // see https://github.com/babel/babel/blob/3ee9db7afe741f4d2f7933c519d8e7672fccb08d/packages/babel-parser/src/options.js#L36-L39
41
44
  parserOpts: {
45
+ ...parserOpts,
42
46
  sourceType: inputIsJsModule ? "module" : "classic",
43
47
  // allowAwaitOutsideFunction: true,
44
48
  plugins: [
@@ -50,14 +54,14 @@ export const applyBabelPlugins = async ({
50
54
  "classPrivateProperties",
51
55
  "classPrivateMethods",
52
56
  ...(useTypeScriptExtension(inputUrl) ? ["typescript"] : []),
53
- ...(options.parserPlugins || []),
57
+ ...parserPlugins,
54
58
  ].filter(Boolean),
55
59
  },
56
60
  plugins: babelPlugins,
57
61
  ...options,
58
62
  generatorOpts: {
59
63
  compact: false,
60
- ...(options.generatorOpts || {}),
64
+ ...generatorOpts,
61
65
  ...(inputIsJsModule ? { importAttributesKeyword: "with" } : {}),
62
66
  },
63
67
  };
@@ -82,6 +86,15 @@ export const applyBabelPlugins = async ({
82
86
  }
83
87
  };
84
88
 
89
+ const optionsAreImpactingResult = ({ generatorOpts }) => {
90
+ if (generatorOpts) {
91
+ if (generatorOpts.comments === false) {
92
+ return true;
93
+ }
94
+ }
95
+ return false;
96
+ };
97
+
85
98
  const normalizeResult = (result) => {
86
99
  const { map } = result;
87
100
  if (map) {