@jsenv/ast 1.4.4 → 1.4.6

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": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Parse and transform HTML,CSS and JS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,13 +33,13 @@
33
33
  "test": "node --conditions=development ./scripts/test.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@babel/parser": "7.20.1",
36
+ "@babel/parser": "7.20.3",
37
37
  "@parcel/css": "1.14.0",
38
38
  "acorn": "8.8.1",
39
39
  "acorn-import-assertions": "1.8.0",
40
40
  "acorn-walk": "8.2.0",
41
- "parse5": "7.1.1",
42
- "postcss": "8.4.18",
41
+ "parse5": "7.1.2",
42
+ "postcss": "8.4.19",
43
43
  "postcss-value-parser": "4.2.0"
44
44
  }
45
45
  }
@@ -4,7 +4,7 @@ export const analyzeImportDeclaration = (node, { onUrl }) => {
4
4
  const specifierNode = node.source
5
5
  const assertionInfo = extractImportAssertionsInfo(node)
6
6
  onUrl({
7
- type: "js_import_export",
7
+ type: "js_import",
8
8
  subtype: "import_static",
9
9
  specifier: specifierNode.value,
10
10
  specifierStart: specifierNode.start,
@@ -23,7 +23,7 @@ export const analyzeImportExpression = (node, { onUrl }) => {
23
23
  const assertionInfo = extractImportAssertionsInfo(node)
24
24
 
25
25
  onUrl({
26
- type: "js_import_export",
26
+ type: "js_import",
27
27
  subtype: "import_dynamic",
28
28
  specifier: specifierNode.value,
29
29
  specifierStart: specifierNode.start,
@@ -45,7 +45,7 @@ export const analyzeExportNamedDeclaration = (node, { onUrl }) => {
45
45
  return
46
46
  }
47
47
  onUrl({
48
- type: "js_import_export",
48
+ type: "js_import",
49
49
  subtype: "export_named",
50
50
  specifier: specifierNode.value,
51
51
  specifierStart: specifierNode.start,
@@ -57,7 +57,7 @@ export const analyzeExportNamedDeclaration = (node, { onUrl }) => {
57
57
  export const analyzeExportAllDeclaration = (node, { onUrl }) => {
58
58
  const specifierNode = node.source
59
59
  onUrl({
60
- type: "js_import_export",
60
+ type: "js_import",
61
61
  subtype: "export_all",
62
62
  specifier: specifierNode.value,
63
63
  specifierStart: specifierNode.start,
@@ -0,0 +1,27 @@
1
+ import { isStringLiteralNode } from "./helpers.js"
2
+
3
+ export const isImportMetaResolveCall = (node) => {
4
+ return (
5
+ node.type === "CallExpression" &&
6
+ node.callee.type === "MemberExpression" &&
7
+ node.callee.object.type === "MetaProperty" &&
8
+ node.callee.property.type === "Identifier" &&
9
+ node.callee.property.name === "resolve"
10
+ )
11
+ }
12
+
13
+ export const analyzeImportMetaResolveCall = (node, { onUrl }) => {
14
+ const firstArg = node.arguments[0]
15
+ if (firstArg && isStringLiteralNode(firstArg)) {
16
+ onUrl({
17
+ node,
18
+ type: "js_import",
19
+ subtype: "import_meta_resolve",
20
+ specifier: firstArg.value,
21
+ specifierStart: firstArg.start,
22
+ specifierEnd: firstArg.end,
23
+ specifierLine: firstArg.loc.start.line,
24
+ specifierColumn: firstArg.loc.start.column,
25
+ })
26
+ }
27
+ }
@@ -14,7 +14,7 @@ export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
14
14
  if (urlType === "StringLiteral") {
15
15
  const specifierNode = firstArgNode
16
16
  onUrl({
17
- type: "js_url_specifier",
17
+ type: "js_url",
18
18
  subtype: "new_url_first_arg",
19
19
  specifier: specifierNode.value,
20
20
  specifierStart: specifierNode.start,
@@ -43,7 +43,7 @@ export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
43
43
  // we can understand the first argument
44
44
  const specifierNode = firstArgNode
45
45
  onUrl({
46
- type: "js_url_specifier",
46
+ type: "js_url",
47
47
  subtype: "new_url_first_arg",
48
48
  specifier: specifierNode.value,
49
49
  specifierStart: specifierNode.start,
@@ -58,7 +58,7 @@ export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
58
58
  if (baseUrlType === "StringLiteral") {
59
59
  const specifierNode = secondArgNode
60
60
  onUrl({
61
- type: "js_url_specifier",
61
+ type: "js_url",
62
62
  subtype: "new_url_second_arg",
63
63
  specifier: specifierNode.value,
64
64
  specifierStart: specifierNode.start,
@@ -30,7 +30,7 @@ const analyzeSystemRegisterDeps = (node, { onUrl }) => {
30
30
  if (isStringLiteralNode(element)) {
31
31
  const specifierNode = element
32
32
  onUrl({
33
- type: "js_url_specifier",
33
+ type: "js_url",
34
34
  subtype: "system_register_arg",
35
35
  expectedType: "js_classic",
36
36
  specifier: specifierNode.value,
@@ -61,7 +61,7 @@ export const analyzeSystemImportCall = (node, { onUrl }) => {
61
61
  if (isStringLiteralNode(firstArgNode)) {
62
62
  const specifierNode = firstArgNode
63
63
  onUrl({
64
- type: "js_url_specifier",
64
+ type: "js_url",
65
65
  subtype: "system_import_arg",
66
66
  expectedType: "js_classic",
67
67
  specifier: specifierNode.value,
@@ -72,3 +72,35 @@ export const analyzeSystemImportCall = (node, { onUrl }) => {
72
72
  })
73
73
  }
74
74
  }
75
+
76
+ export const isSystemResolveCall = (node) => {
77
+ const callee = node.callee
78
+ return (
79
+ callee.type === "MemberExpression" &&
80
+ callee.object.type === "MemberExpression" &&
81
+ callee.object.object.type === "Identifier" &&
82
+ // because of minification we can't assume _context.
83
+ // so anything matching "*.meta.resolve()"
84
+ // will be assumed to be the equivalent to "meta.resolve()"
85
+ // callee.object.object.name === "_context" &&
86
+ callee.object.property.type === "Identifier" &&
87
+ callee.object.property.name === "meta" &&
88
+ callee.property.type === "Identifier" &&
89
+ callee.property.name === "resolve"
90
+ )
91
+ }
92
+ export const analyzeSystemResolveCall = (node, { onUrl }) => {
93
+ const firstArgNode = node.arguments[0]
94
+ if (isStringLiteralNode(firstArgNode)) {
95
+ const specifierNode = firstArgNode
96
+ onUrl({
97
+ type: "js_url",
98
+ subtype: "system_resolve_arg",
99
+ specifier: specifierNode.value,
100
+ specifierStart: specifierNode.start,
101
+ specifierEnd: specifierNode.end,
102
+ specifierLine: specifierNode.loc.start.line,
103
+ specifierColumn: specifierNode.loc.start.column,
104
+ })
105
+ }
106
+ }
@@ -18,7 +18,7 @@ export const analyzeImportScriptCalls = (node, { onUrl }) => {
18
18
  if (isStringLiteralNode(arg)) {
19
19
  const specifierNode = arg
20
20
  onUrl({
21
- type: "js_url_specifier",
21
+ type: "js_url",
22
22
  subtype: "self_import_scripts_arg",
23
23
  expectedType: "js_classic",
24
24
  specifier: specifierNode.value,
@@ -1,5 +1,9 @@
1
1
  import { getTypePropertyNode, isStringLiteralNode } from "./helpers.js"
2
2
  import { isNewUrlCall, analyzeNewUrlCall } from "./new_url.js"
3
+ import {
4
+ isImportMetaResolveCall,
5
+ analyzeImportMetaResolveCall,
6
+ } from "./import_meta_resolve.js"
3
7
 
4
8
  export const isNewWorkerCall = (node) => {
5
9
  return (
@@ -114,7 +118,7 @@ const analyzeWorkerCallArguments = (
114
118
  if (isStringLiteralNode(firstArgNode)) {
115
119
  const specifierNode = firstArgNode
116
120
  onUrl({
117
- type: "js_url_specifier",
121
+ type: "js_url",
118
122
  subtype: referenceSubtype,
119
123
  expectedType,
120
124
  expectedSubtype,
@@ -139,5 +143,19 @@ const analyzeWorkerCallArguments = (
139
143
  onUrl(mention)
140
144
  },
141
145
  })
146
+ return
147
+ }
148
+ if (isJsModule && isImportMetaResolveCall(firstArgNode)) {
149
+ analyzeImportMetaResolveCall(firstArgNode, {
150
+ onUrl: (mention) => {
151
+ Object.assign(mention, {
152
+ expectedType,
153
+ expectedSubtype,
154
+ typePropertyNode,
155
+ })
156
+ onUrl(mention)
157
+ },
158
+ })
159
+ return
142
160
  }
143
161
  }
@@ -7,6 +7,10 @@ import {
7
7
  analyzeExportNamedDeclaration,
8
8
  analyzeExportAllDeclaration,
9
9
  } from "./js_static_analysis/import_export.js"
10
+ import {
11
+ isImportMetaResolveCall,
12
+ analyzeImportMetaResolveCall,
13
+ } from "./js_static_analysis/import_meta_resolve.js"
10
14
  import {
11
15
  isNewWorkerCall,
12
16
  analyzeNewWorkerCall,
@@ -28,6 +32,8 @@ import {
28
32
  analyzeSystemRegisterCall,
29
33
  isSystemImportCall,
30
34
  analyzeSystemImportCall,
35
+ isSystemResolveCall,
36
+ analyzeSystemResolveCall,
31
37
  } from "./js_static_analysis/system.js"
32
38
 
33
39
  export const parseJsUrls = async ({
@@ -59,6 +65,10 @@ export const parseJsUrls = async ({
59
65
  analyzeExportAllDeclaration(node, { onUrl })
60
66
  },
61
67
  CallExpression: (node) => {
68
+ if (isJsModule && isImportMetaResolveCall(node)) {
69
+ analyzeImportMetaResolveCall(node, { onUrl })
70
+ return
71
+ }
62
72
  if (isServiceWorkerRegisterCall(node)) {
63
73
  analyzeServiceWorkerRegisterCall(node, {
64
74
  isJsModule,
@@ -84,6 +94,12 @@ export const parseJsUrls = async ({
84
94
  })
85
95
  return
86
96
  }
97
+ if (!isJsModule && isSystemResolveCall(node)) {
98
+ analyzeSystemResolveCall(node, {
99
+ onUrl,
100
+ })
101
+ return
102
+ }
87
103
  },
88
104
  NewExpression: (node, ancestors) => {
89
105
  if (isNewWorkerCall(node)) {