@jsenv/ast 6.0.7 → 6.1.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@jsenv/ast",
3
- "version": "6.0.7",
4
- "description": "Parse and transform HTML,CSS and JS",
3
+ "version": "6.1.1",
4
+ "description": "Parse and transform HTML, CSS and JS",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -36,7 +36,7 @@
36
36
  "@babel/parser": "7.24.7",
37
37
  "@jsenv/urls": "2.2.7",
38
38
  "acorn": "8.12.1",
39
- "acorn-import-assertions": "1.9.0",
39
+ "acorn-import-attributes": "1.9.5",
40
40
  "acorn-walk": "8.3.3",
41
41
  "parse5": "7.1.2",
42
42
  "postcss": "8.4.39",
@@ -283,7 +283,7 @@ const isImageSetFunctionNode = (node) => {
283
283
  };
284
284
 
285
285
  const isDataUrl = (url) => {
286
- return /data:[^\n\r;]+?(?:;charset=[^\n\r;]+?)?;base64,([\d+/A-Za-z]+={0,2})/.test(
286
+ return /data:[^\n\r;]+(?:;charset=[^\n\r;]+)?;base64,[\d+/A-Za-z]+={0,2}/.test(
287
287
  url,
288
288
  );
289
289
  };
@@ -33,7 +33,6 @@ export const parseHtml = ({
33
33
  const htmlParseError = new Error(
34
34
  `Unable to parse HTML; ${parse5Error.code}`,
35
35
  );
36
-
37
36
  htmlParseError.reasonCode = parse5Error.code;
38
37
  htmlParseError.code = "PARSE_ERROR";
39
38
  htmlParseError.url = url;
@@ -44,7 +44,7 @@ export const applyBabelPlugins = async ({
44
44
  plugins: [
45
45
  // "importMeta",
46
46
  // "topLevelAwait",
47
- ...(inputIsJsModule ? ["dynamicImport", "importAssertions"] : []),
47
+ ...(inputIsJsModule ? ["dynamicImport", "importAttributes"] : []),
48
48
  "jsx",
49
49
  "classProperties",
50
50
  "classPrivateProperties",
@@ -58,6 +58,7 @@ export const applyBabelPlugins = async ({
58
58
  generatorOpts: {
59
59
  compact: false,
60
60
  ...(options.generatorOpts || {}),
61
+ ...(inputIsJsModule ? { importAttributesKeyword: "with" } : {}),
61
62
  },
62
63
  };
63
64
  try {
@@ -2,7 +2,7 @@ import { isStringLiteralNode } from "./helpers.js";
2
2
 
3
3
  export const analyzeImportDeclaration = (node, { onUrl }) => {
4
4
  const specifierNode = node.source;
5
- const assertionInfo = extractImportAssertionsInfo(node);
5
+ const attributesInfo = extractImportAttributesInfo(node);
6
6
  const info = {
7
7
  type: "js_import",
8
8
  subtype: "import_static",
@@ -14,9 +14,9 @@ export const analyzeImportDeclaration = (node, { onUrl }) => {
14
14
  expectedType: "js_module",
15
15
  astInfo: { node: specifierNode },
16
16
  };
17
- if (assertionInfo) {
17
+ if (attributesInfo) {
18
18
  const { importAttributes, importNode, importTypeAttributeNode } =
19
- assertionInfo;
19
+ attributesInfo;
20
20
  info.expectedType = importAttributes.type;
21
21
  info.importAttributes = importAttributes;
22
22
  Object.assign(info.astInfo, { importNode, importTypeAttributeNode });
@@ -28,7 +28,7 @@ export const analyzeImportExpression = (node, { onUrl }) => {
28
28
  if (!isStringLiteralNode(specifierNode)) {
29
29
  return;
30
30
  }
31
- const assertionInfo = extractImportAssertionsInfo(node);
31
+ const attributesInfo = extractImportAttributesInfo(node);
32
32
  const info = {
33
33
  type: "js_import",
34
34
  subtype: "import_dynamic",
@@ -40,9 +40,9 @@ export const analyzeImportExpression = (node, { onUrl }) => {
40
40
  column: specifierNode.loc.start.column,
41
41
  astInfo: { node: specifierNode },
42
42
  };
43
- if (assertionInfo) {
43
+ if (attributesInfo) {
44
44
  const { importAttributes, importNode, importTypeAttributeNode } =
45
- assertionInfo;
45
+ attributesInfo;
46
46
  info.expectedType = importAttributes.type;
47
47
  info.importAttributes = importAttributes;
48
48
  Object.assign(info.astInfo, { importNode, importTypeAttributeNode });
@@ -84,23 +84,23 @@ export const analyzeExportAllDeclaration = (node, { onUrl }) => {
84
84
  });
85
85
  };
86
86
 
87
- const extractImportAssertionsInfo = (node) => {
87
+ const extractImportAttributesInfo = (node) => {
88
88
  if (node.type === "ImportDeclaration") {
89
89
  // static import
90
- const { assertions } = node;
91
- if (!assertions) {
90
+ const { attributes } = node;
91
+ if (!attributes) {
92
92
  return null;
93
93
  }
94
- if (assertions.length === 0) {
94
+ if (attributes.length === 0) {
95
95
  return null;
96
96
  }
97
- const typeAssertionNode = assertions.find(
98
- (assertion) => assertion.key.name === "type",
97
+ const typeAttributeNode = attributes.find(
98
+ (attributeNode) => attributeNode.key.name === "type",
99
99
  );
100
- if (!typeAssertionNode) {
100
+ if (!typeAttributeNode) {
101
101
  return null;
102
102
  }
103
- const typeNode = typeAssertionNode.value;
103
+ const typeNode = typeAttributeNode.value;
104
104
  if (!isStringLiteralNode(typeNode)) {
105
105
  return null;
106
106
  }
@@ -109,7 +109,7 @@ const extractImportAssertionsInfo = (node) => {
109
109
  type: typeNode.value,
110
110
  },
111
111
  importNode: node,
112
- importTypeAttributeNode: typeAssertionNode,
112
+ importTypeAttributeNode: typeAttributeNode,
113
113
  };
114
114
  }
115
115
  // dynamic import
@@ -123,18 +123,18 @@ const extractImportAssertionsInfo = (node) => {
123
123
  return null;
124
124
  }
125
125
  const { properties } = firstArgNode;
126
- const assertProperty = properties.find((property) => {
127
- return property.key.name === "assert";
126
+ const withProperty = properties.find((property) => {
127
+ return property.key.name === "with";
128
128
  });
129
- if (!assertProperty) {
129
+ if (!withProperty) {
130
130
  return null;
131
131
  }
132
- const assertValueNode = assertProperty.value;
133
- if (assertValueNode.type !== "ObjectExpression") {
132
+ const withValueNode = withProperty.value;
133
+ if (withValueNode.type !== "ObjectExpression") {
134
134
  return null;
135
135
  }
136
- const assertValueProperties = assertValueNode.properties;
137
- const typePropertyNode = assertValueProperties.find((property) => {
136
+ const withValueProperties = withValueNode.properties;
137
+ const typePropertyNode = withValueProperties.find((property) => {
138
138
  return property.key.name === "type";
139
139
  });
140
140
  if (!typePropertyNode) {
@@ -1,10 +1,10 @@
1
1
  import { Parser, getLineInfo } from "acorn";
2
- import { importAssertions } from "acorn-import-assertions";
2
+ import { importAttributes } from "acorn-import-attributes";
3
3
 
4
4
  import { createJsParseError } from "./js_parse_error.js";
5
5
 
6
6
  export const parseJsWithAcorn = ({ js, url, isJsModule }) => {
7
- const AcornParser = Parser.extend(importAssertions);
7
+ const AcornParser = Parser.extend(importAttributes);
8
8
  const comments = [];
9
9
 
10
10
  try {