@jsenv/ast 4.1.0 → 5.0.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 +4 -4
- package/src/js/js_static_analysis/import_export.js +32 -13
- package/src/js/js_static_analysis/import_meta_resolve.js +1 -1
- package/src/js/js_static_analysis/json_parse.js +1 -1
- package/src/js/js_static_analysis/new_blob.js +1 -1
- package/src/js/js_static_analysis/new_inline_content.js +1 -1
- package/src/js/js_static_analysis/new_url.js +3 -0
- package/src/js/js_static_analysis/system.js +3 -0
- package/src/js/js_static_analysis/web_worker.js +1 -0
- package/src/js/js_static_analysis/web_worker_entry_point.js +12 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/ast",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Parse and transform HTML,CSS and JS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@babel/parser": "7.22.
|
|
37
|
-
"acorn": "8.
|
|
36
|
+
"@babel/parser": "7.22.7",
|
|
37
|
+
"acorn": "8.10.0",
|
|
38
38
|
"acorn-import-assertions": "1.9.0",
|
|
39
39
|
"acorn-walk": "8.2.0",
|
|
40
40
|
"parse5": "7.1.2",
|
|
41
|
-
"postcss": "8.4.
|
|
41
|
+
"postcss": "8.4.25",
|
|
42
42
|
"postcss-value-parser": "4.2.0"
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -3,7 +3,7 @@ import { isStringLiteralNode } from "./helpers.js";
|
|
|
3
3
|
export const analyzeImportDeclaration = (node, { onUrl }) => {
|
|
4
4
|
const specifierNode = node.source;
|
|
5
5
|
const assertionInfo = extractImportAssertionsInfo(node);
|
|
6
|
-
|
|
6
|
+
const info = {
|
|
7
7
|
type: "js_import",
|
|
8
8
|
subtype: "import_static",
|
|
9
9
|
specifier: specifierNode.value,
|
|
@@ -11,9 +11,17 @@ export const analyzeImportDeclaration = (node, { onUrl }) => {
|
|
|
11
11
|
end: specifierNode.end,
|
|
12
12
|
line: specifierNode.loc.start.line,
|
|
13
13
|
column: specifierNode.loc.start.column,
|
|
14
|
-
expectedType:
|
|
15
|
-
|
|
16
|
-
}
|
|
14
|
+
expectedType: "js_module",
|
|
15
|
+
astInfo: { node: specifierNode },
|
|
16
|
+
};
|
|
17
|
+
if (assertionInfo) {
|
|
18
|
+
const { importAttributes, importNode, importTypeAttributeNode } =
|
|
19
|
+
assertionInfo;
|
|
20
|
+
info.expectedType = importAttributes.type;
|
|
21
|
+
info.importAttributes = importAttributes;
|
|
22
|
+
Object.assign(info.astInfo, { importNode, importTypeAttributeNode });
|
|
23
|
+
}
|
|
24
|
+
onUrl(info);
|
|
17
25
|
};
|
|
18
26
|
export const analyzeImportExpression = (node, { onUrl }) => {
|
|
19
27
|
const specifierNode = node.source;
|
|
@@ -21,18 +29,25 @@ export const analyzeImportExpression = (node, { onUrl }) => {
|
|
|
21
29
|
return;
|
|
22
30
|
}
|
|
23
31
|
const assertionInfo = extractImportAssertionsInfo(node);
|
|
24
|
-
|
|
25
|
-
onUrl({
|
|
32
|
+
const info = {
|
|
26
33
|
type: "js_import",
|
|
27
34
|
subtype: "import_dynamic",
|
|
35
|
+
expectedType: "js_module",
|
|
28
36
|
specifier: specifierNode.value,
|
|
29
37
|
start: specifierNode.start,
|
|
30
38
|
end: specifierNode.end,
|
|
31
39
|
line: specifierNode.loc.start.line,
|
|
32
40
|
column: specifierNode.loc.start.column,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
astInfo: { node: specifierNode },
|
|
42
|
+
};
|
|
43
|
+
if (assertionInfo) {
|
|
44
|
+
const { importAttributes, importNode, importTypeAttributeNode } =
|
|
45
|
+
assertionInfo;
|
|
46
|
+
info.expectedType = importAttributes.type;
|
|
47
|
+
info.importAttributes = importAttributes;
|
|
48
|
+
Object.assign(info.astInfo, { importNode, importTypeAttributeNode });
|
|
49
|
+
}
|
|
50
|
+
onUrl(info);
|
|
36
51
|
};
|
|
37
52
|
export const analyzeExportNamedDeclaration = (node, { onUrl }) => {
|
|
38
53
|
const specifierNode = node.source;
|
|
@@ -52,6 +67,7 @@ export const analyzeExportNamedDeclaration = (node, { onUrl }) => {
|
|
|
52
67
|
end: specifierNode.end,
|
|
53
68
|
line: specifierNode.loc.start.line,
|
|
54
69
|
column: specifierNode.loc.start.column,
|
|
70
|
+
astInfo: { node: specifierNode },
|
|
55
71
|
});
|
|
56
72
|
};
|
|
57
73
|
export const analyzeExportAllDeclaration = (node, { onUrl }) => {
|
|
@@ -64,6 +80,7 @@ export const analyzeExportAllDeclaration = (node, { onUrl }) => {
|
|
|
64
80
|
end: specifierNode.end,
|
|
65
81
|
line: specifierNode.loc.start.line,
|
|
66
82
|
column: specifierNode.loc.start.column,
|
|
83
|
+
astInfo: { node: specifierNode },
|
|
67
84
|
});
|
|
68
85
|
};
|
|
69
86
|
|
|
@@ -88,10 +105,11 @@ const extractImportAssertionsInfo = (node) => {
|
|
|
88
105
|
return null;
|
|
89
106
|
}
|
|
90
107
|
return {
|
|
91
|
-
|
|
92
|
-
assert: {
|
|
108
|
+
importAttributes: {
|
|
93
109
|
type: typeNode.value,
|
|
94
110
|
},
|
|
111
|
+
importNode: node,
|
|
112
|
+
importTypeAttributeNode: typeAssertionNode,
|
|
95
113
|
};
|
|
96
114
|
}
|
|
97
115
|
// dynamic import
|
|
@@ -127,9 +145,10 @@ const extractImportAssertionsInfo = (node) => {
|
|
|
127
145
|
return null;
|
|
128
146
|
}
|
|
129
147
|
return {
|
|
130
|
-
|
|
131
|
-
assert: {
|
|
148
|
+
importAttributes: {
|
|
132
149
|
type: typePropertyValue.value,
|
|
133
150
|
},
|
|
151
|
+
importNode: node,
|
|
152
|
+
importTypeAttributeNode: typePropertyNode,
|
|
134
153
|
};
|
|
135
154
|
};
|
|
@@ -14,7 +14,6 @@ export const analyzeImportMetaResolveCall = (node, { onUrl }) => {
|
|
|
14
14
|
const firstArg = node.arguments[0];
|
|
15
15
|
if (firstArg && isStringLiteralNode(firstArg)) {
|
|
16
16
|
onUrl({
|
|
17
|
-
node,
|
|
18
17
|
type: "js_import",
|
|
19
18
|
subtype: "import_meta_resolve",
|
|
20
19
|
specifier: firstArg.value,
|
|
@@ -22,6 +21,7 @@ export const analyzeImportMetaResolveCall = (node, { onUrl }) => {
|
|
|
22
21
|
end: firstArg.end,
|
|
23
22
|
line: firstArg.loc.start.line,
|
|
24
23
|
column: firstArg.loc.start.column,
|
|
24
|
+
astInfo: { node },
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
};
|
|
@@ -16,7 +16,6 @@ export const analyzeJSONParseCall = (node, { onInlineContent }) => {
|
|
|
16
16
|
const contentInfo = extractContentInfo(nodeHoldingContent);
|
|
17
17
|
if (contentInfo) {
|
|
18
18
|
onInlineContent({
|
|
19
|
-
node: nodeHoldingContent,
|
|
20
19
|
type: "json_parse_first_arg",
|
|
21
20
|
contentType: "application/json",
|
|
22
21
|
start: nodeHoldingContent.start,
|
|
@@ -28,6 +27,7 @@ export const analyzeJSONParseCall = (node, { onInlineContent }) => {
|
|
|
28
27
|
nodeType: contentInfo.nodeType,
|
|
29
28
|
quote: contentInfo.quote,
|
|
30
29
|
content: contentInfo.content,
|
|
30
|
+
astInfo: { node: nodeHoldingContent },
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
};
|
|
@@ -38,7 +38,6 @@ export const analyzeNewBlobCall = (node, { onInlineContent }) => {
|
|
|
38
38
|
const contentInfo = extractContentInfo(nodeHoldingContent);
|
|
39
39
|
if (contentInfo) {
|
|
40
40
|
onInlineContent({
|
|
41
|
-
node: nodeHoldingContent,
|
|
42
41
|
type: "new_blob_first_arg",
|
|
43
42
|
contentType,
|
|
44
43
|
start: nodeHoldingContent.start,
|
|
@@ -50,6 +49,7 @@ export const analyzeNewBlobCall = (node, { onInlineContent }) => {
|
|
|
50
49
|
nodeType: contentInfo.nodeType,
|
|
51
50
|
quote: contentInfo.quote,
|
|
52
51
|
content: contentInfo.content,
|
|
52
|
+
astInfo: { node: nodeHoldingContent },
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
};
|
|
@@ -32,7 +32,6 @@ export const analyzeNewInlineContentCall = (node, { onInlineContent }) => {
|
|
|
32
32
|
const contentInfo = extractContentInfo(nodeHoldingContent);
|
|
33
33
|
if (contentInfo) {
|
|
34
34
|
onInlineContent({
|
|
35
|
-
node: nodeHoldingContent,
|
|
36
35
|
type: "new_inline_content_first_arg",
|
|
37
36
|
contentType,
|
|
38
37
|
start: nodeHoldingContent.start,
|
|
@@ -44,6 +43,7 @@ export const analyzeNewInlineContentCall = (node, { onInlineContent }) => {
|
|
|
44
43
|
nodeType: contentInfo.nodeType,
|
|
45
44
|
quote: contentInfo.quote,
|
|
46
45
|
content: contentInfo.content,
|
|
46
|
+
astInfo: { node: nodeHoldingContent },
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
};
|
|
@@ -21,6 +21,7 @@ export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
|
|
|
21
21
|
end: specifierNode.end,
|
|
22
22
|
line: specifierNode.loc.start.line,
|
|
23
23
|
column: specifierNode.loc.start.column,
|
|
24
|
+
astInfo: { node: specifierNode },
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
return;
|
|
@@ -53,6 +54,7 @@ export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
|
|
|
53
54
|
baseUrlType,
|
|
54
55
|
baseUrl:
|
|
55
56
|
baseUrlType === "StringLiteral" ? secondArgNode.value : undefined,
|
|
57
|
+
astInfo: { node: firstArgNode },
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
if (baseUrlType === "StringLiteral") {
|
|
@@ -65,6 +67,7 @@ export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
|
|
|
65
67
|
end: specifierNode.end,
|
|
66
68
|
line: specifierNode.loc.start.line,
|
|
67
69
|
column: specifierNode.loc.start.column,
|
|
70
|
+
astInfo: { node: specifierNode },
|
|
68
71
|
});
|
|
69
72
|
}
|
|
70
73
|
}
|
|
@@ -38,6 +38,7 @@ const analyzeSystemRegisterDeps = (node, { onUrl }) => {
|
|
|
38
38
|
end: specifierNode.end,
|
|
39
39
|
line: specifierNode.loc.start.line,
|
|
40
40
|
column: specifierNode.loc.start.column,
|
|
41
|
+
astInfo: { node: specifierNode },
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
});
|
|
@@ -69,6 +70,7 @@ export const analyzeSystemImportCall = (node, { onUrl }) => {
|
|
|
69
70
|
end: specifierNode.end,
|
|
70
71
|
line: specifierNode.loc.start.line,
|
|
71
72
|
column: specifierNode.loc.start.column,
|
|
73
|
+
astInfo: { node: specifierNode },
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
76
|
};
|
|
@@ -101,6 +103,7 @@ export const analyzeSystemResolveCall = (node, { onUrl }) => {
|
|
|
101
103
|
end: specifierNode.end,
|
|
102
104
|
line: specifierNode.loc.start.line,
|
|
103
105
|
column: specifierNode.loc.start.column,
|
|
106
|
+
astInfo: { node: specifierNode },
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
};
|
|
@@ -122,38 +122,41 @@ const analyzeWorkerCallArguments = (
|
|
|
122
122
|
subtype: referenceSubtype,
|
|
123
123
|
expectedType,
|
|
124
124
|
expectedSubtype,
|
|
125
|
-
typePropertyNode,
|
|
126
125
|
specifier: specifierNode.value,
|
|
127
126
|
start: specifierNode.start,
|
|
128
127
|
end: specifierNode.end,
|
|
129
128
|
line: specifierNode.loc.start.line,
|
|
130
129
|
column: specifierNode.loc.start.column,
|
|
130
|
+
astInfo: {
|
|
131
|
+
node,
|
|
132
|
+
typePropertyNode,
|
|
133
|
+
},
|
|
131
134
|
});
|
|
132
135
|
return;
|
|
133
136
|
}
|
|
134
137
|
if (isNewUrlCall(firstArgNode)) {
|
|
135
138
|
analyzeNewUrlCall(firstArgNode, {
|
|
136
139
|
isJsModule,
|
|
137
|
-
onUrl: (
|
|
138
|
-
|
|
140
|
+
onUrl: (info) => {
|
|
141
|
+
info.astInfo.typePropertyNode = typePropertyNode;
|
|
142
|
+
Object.assign(info, {
|
|
139
143
|
expectedType,
|
|
140
144
|
expectedSubtype,
|
|
141
|
-
typePropertyNode,
|
|
142
145
|
});
|
|
143
|
-
onUrl(
|
|
146
|
+
onUrl(info);
|
|
144
147
|
},
|
|
145
148
|
});
|
|
146
149
|
return;
|
|
147
150
|
}
|
|
148
151
|
if (isJsModule && isImportMetaResolveCall(firstArgNode)) {
|
|
149
152
|
analyzeImportMetaResolveCall(firstArgNode, {
|
|
150
|
-
onUrl: (
|
|
151
|
-
|
|
153
|
+
onUrl: (info) => {
|
|
154
|
+
info.astInfo.typePropertyNode = typePropertyNode;
|
|
155
|
+
Object.assign(info, {
|
|
152
156
|
expectedType,
|
|
153
157
|
expectedSubtype,
|
|
154
|
-
typePropertyNode,
|
|
155
158
|
});
|
|
156
|
-
onUrl(
|
|
159
|
+
onUrl(info);
|
|
157
160
|
},
|
|
158
161
|
});
|
|
159
162
|
return;
|