@jsenv/ast 6.0.7 → 6.1.0
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
|
|
4
|
-
"description": "Parse and transform HTML,CSS and JS",
|
|
3
|
+
"version": "6.1.0",
|
|
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-
|
|
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",
|
package/src/html/html_parse.js
CHANGED
|
@@ -44,7 +44,7 @@ export const applyBabelPlugins = async ({
|
|
|
44
44
|
plugins: [
|
|
45
45
|
// "importMeta",
|
|
46
46
|
// "topLevelAwait",
|
|
47
|
-
...(inputIsJsModule ? ["dynamicImport", "
|
|
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
|
|
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 (
|
|
17
|
+
if (attributesInfo) {
|
|
18
18
|
const { importAttributes, importNode, importTypeAttributeNode } =
|
|
19
|
-
|
|
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
|
|
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 (
|
|
43
|
+
if (attributesInfo) {
|
|
44
44
|
const { importAttributes, importNode, importTypeAttributeNode } =
|
|
45
|
-
|
|
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
|
|
87
|
+
const extractImportAttributesInfo = (node) => {
|
|
88
88
|
if (node.type === "ImportDeclaration") {
|
|
89
89
|
// static import
|
|
90
|
-
const {
|
|
91
|
-
if (!
|
|
90
|
+
const { attributes } = node;
|
|
91
|
+
if (!attributes) {
|
|
92
92
|
return null;
|
|
93
93
|
}
|
|
94
|
-
if (
|
|
94
|
+
if (attributes.length === 0) {
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
97
|
-
const
|
|
98
|
-
(
|
|
97
|
+
const typeAttributeNode = attributes.find(
|
|
98
|
+
(attributeNode) => attributeNode.key.name === "type",
|
|
99
99
|
);
|
|
100
|
-
if (!
|
|
100
|
+
if (!typeAttributeNode) {
|
|
101
101
|
return null;
|
|
102
102
|
}
|
|
103
|
-
const typeNode =
|
|
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:
|
|
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
|
|
127
|
-
return property.key.name === "
|
|
126
|
+
const withProperty = properties.find((property) => {
|
|
127
|
+
return property.key.name === "with";
|
|
128
128
|
});
|
|
129
|
-
if (!
|
|
129
|
+
if (!withProperty) {
|
|
130
130
|
return null;
|
|
131
131
|
}
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
132
|
+
const withValueNode = withProperty.value;
|
|
133
|
+
if (withValueNode.type !== "ObjectExpression") {
|
|
134
134
|
return null;
|
|
135
135
|
}
|
|
136
|
-
const
|
|
137
|
-
const typePropertyNode =
|
|
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 {
|
|
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(
|
|
7
|
+
const AcornParser = Parser.extend(importAttributes);
|
|
8
8
|
const comments = [];
|
|
9
9
|
|
|
10
10
|
try {
|