@jsenv/ast 3.0.7 → 3.0.8

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.
@@ -1,17 +1,17 @@
1
1
  export const getTypePropertyNode = (node) => {
2
2
  if (node.type !== "ObjectExpression") {
3
- return null
3
+ return null;
4
4
  }
5
- const { properties } = node
5
+ const { properties } = node;
6
6
  return properties.find((property) => {
7
7
  return (
8
8
  property.type === "Property" &&
9
9
  property.key.type === "Identifier" &&
10
10
  property.key.name === "type"
11
- )
12
- })
13
- }
11
+ );
12
+ });
13
+ };
14
14
 
15
15
  export const isStringLiteralNode = (node) => {
16
- return node.type === "Literal" && typeof node.value === "string"
17
- }
16
+ return node.type === "Literal" && typeof node.value === "string";
17
+ };
@@ -1,8 +1,8 @@
1
- import { isStringLiteralNode } from "./helpers.js"
1
+ import { isStringLiteralNode } from "./helpers.js";
2
2
 
3
3
  export const analyzeImportDeclaration = (node, { onUrl }) => {
4
- const specifierNode = node.source
5
- const assertionInfo = extractImportAssertionsInfo(node)
4
+ const specifierNode = node.source;
5
+ const assertionInfo = extractImportAssertionsInfo(node);
6
6
  onUrl({
7
7
  type: "js_import",
8
8
  subtype: "import_static",
@@ -13,14 +13,14 @@ export const analyzeImportDeclaration = (node, { onUrl }) => {
13
13
  column: specifierNode.loc.start.column,
14
14
  expectedType: assertionInfo ? assertionInfo.assert.type : "js_module",
15
15
  ...assertionInfo,
16
- })
17
- }
16
+ });
17
+ };
18
18
  export const analyzeImportExpression = (node, { onUrl }) => {
19
- const specifierNode = node.source
19
+ const specifierNode = node.source;
20
20
  if (!isStringLiteralNode(specifierNode)) {
21
- return
21
+ return;
22
22
  }
23
- const assertionInfo = extractImportAssertionsInfo(node)
23
+ const assertionInfo = extractImportAssertionsInfo(node);
24
24
 
25
25
  onUrl({
26
26
  type: "js_import",
@@ -32,17 +32,17 @@ export const analyzeImportExpression = (node, { onUrl }) => {
32
32
  column: specifierNode.loc.start.column,
33
33
  expectedType: assertionInfo ? assertionInfo.assert.type : "js_module",
34
34
  ...assertionInfo,
35
- })
36
- }
35
+ });
36
+ };
37
37
  export const analyzeExportNamedDeclaration = (node, { onUrl }) => {
38
- const specifierNode = node.source
38
+ const specifierNode = node.source;
39
39
  if (!specifierNode) {
40
40
  // This export has no "source", so it's probably
41
41
  // a local variable or function, e.g.
42
42
  // export { varName }
43
43
  // export const constName = ...
44
44
  // export function funcName() {}
45
- return
45
+ return;
46
46
  }
47
47
  onUrl({
48
48
  type: "js_import",
@@ -52,10 +52,10 @@ export const analyzeExportNamedDeclaration = (node, { onUrl }) => {
52
52
  end: specifierNode.end,
53
53
  line: specifierNode.loc.start.line,
54
54
  column: specifierNode.loc.start.column,
55
- })
56
- }
55
+ });
56
+ };
57
57
  export const analyzeExportAllDeclaration = (node, { onUrl }) => {
58
- const specifierNode = node.source
58
+ const specifierNode = node.source;
59
59
  onUrl({
60
60
  type: "js_import",
61
61
  subtype: "export_all",
@@ -64,72 +64,72 @@ export const analyzeExportAllDeclaration = (node, { onUrl }) => {
64
64
  end: specifierNode.end,
65
65
  line: specifierNode.loc.start.line,
66
66
  column: specifierNode.loc.start.column,
67
- })
68
- }
67
+ });
68
+ };
69
69
 
70
70
  const extractImportAssertionsInfo = (node) => {
71
71
  if (node.type === "ImportDeclaration") {
72
72
  // static import
73
- const { assertions } = node
73
+ const { assertions } = node;
74
74
  if (!assertions) {
75
- return null
75
+ return null;
76
76
  }
77
77
  if (assertions.length === 0) {
78
- return null
78
+ return null;
79
79
  }
80
80
  const typeAssertionNode = assertions.find(
81
81
  (assertion) => assertion.key.name === "type",
82
- )
82
+ );
83
83
  if (!typeAssertionNode) {
84
- return null
84
+ return null;
85
85
  }
86
- const typeNode = typeAssertionNode.value
86
+ const typeNode = typeAssertionNode.value;
87
87
  if (!isStringLiteralNode(typeNode)) {
88
- return null
88
+ return null;
89
89
  }
90
90
  return {
91
91
  assertNode: typeAssertionNode,
92
92
  assert: {
93
93
  type: typeNode.value,
94
94
  },
95
- }
95
+ };
96
96
  }
97
97
  // dynamic import
98
- const args = node.arguments
98
+ const args = node.arguments;
99
99
  if (!args) {
100
100
  // acorn keeps node.arguments undefined for dynamic import without a second argument
101
- return null
101
+ return null;
102
102
  }
103
- const firstArgNode = args[0]
103
+ const firstArgNode = args[0];
104
104
  if (!firstArgNode) {
105
- return null
105
+ return null;
106
106
  }
107
- const { properties } = firstArgNode
107
+ const { properties } = firstArgNode;
108
108
  const assertProperty = properties.find((property) => {
109
- return property.key.name === "assert"
110
- })
109
+ return property.key.name === "assert";
110
+ });
111
111
  if (!assertProperty) {
112
- return null
112
+ return null;
113
113
  }
114
- const assertValueNode = assertProperty.value
114
+ const assertValueNode = assertProperty.value;
115
115
  if (assertValueNode.type !== "ObjectExpression") {
116
- return null
116
+ return null;
117
117
  }
118
- const assertValueProperties = assertValueNode.properties
118
+ const assertValueProperties = assertValueNode.properties;
119
119
  const typePropertyNode = assertValueProperties.find((property) => {
120
- return property.key.name === "type"
121
- })
120
+ return property.key.name === "type";
121
+ });
122
122
  if (!typePropertyNode) {
123
- return null
123
+ return null;
124
124
  }
125
- const typePropertyValue = typePropertyNode.value
125
+ const typePropertyValue = typePropertyNode.value;
126
126
  if (!isStringLiteralNode(typePropertyValue)) {
127
- return null
127
+ return null;
128
128
  }
129
129
  return {
130
130
  assertNode: firstArgNode,
131
131
  assert: {
132
132
  type: typePropertyValue.value,
133
133
  },
134
- }
135
- }
134
+ };
135
+ };
@@ -1,4 +1,4 @@
1
- import { isStringLiteralNode } from "./helpers.js"
1
+ import { isStringLiteralNode } from "./helpers.js";
2
2
 
3
3
  export const isImportMetaResolveCall = (node) => {
4
4
  return (
@@ -7,11 +7,11 @@ export const isImportMetaResolveCall = (node) => {
7
7
  node.callee.object.type === "MetaProperty" &&
8
8
  node.callee.property.type === "Identifier" &&
9
9
  node.callee.property.name === "resolve"
10
- )
11
- }
10
+ );
11
+ };
12
12
 
13
13
  export const analyzeImportMetaResolveCall = (node, { onUrl }) => {
14
- const firstArg = node.arguments[0]
14
+ const firstArg = node.arguments[0];
15
15
  if (firstArg && isStringLiteralNode(firstArg)) {
16
16
  onUrl({
17
17
  node,
@@ -22,6 +22,6 @@ export const analyzeImportMetaResolveCall = (node, { onUrl }) => {
22
22
  end: firstArg.end,
23
23
  line: firstArg.loc.start.line,
24
24
  column: firstArg.loc.start.column,
25
- })
25
+ });
26
26
  }
27
- }
27
+ };
@@ -1,18 +1,18 @@
1
- import { isStringLiteralNode } from "./helpers.js"
1
+ import { isStringLiteralNode } from "./helpers.js";
2
2
 
3
3
  export const isNewUrlCall = (node) => {
4
4
  return (
5
5
  node.type === "NewExpression" &&
6
6
  node.callee.type === "Identifier" &&
7
7
  node.callee.name === "URL"
8
- )
9
- }
8
+ );
9
+ };
10
10
  export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
11
11
  if (node.arguments.length === 1) {
12
- const firstArgNode = node.arguments[0]
13
- const urlType = analyzeUrlNodeType(firstArgNode, { isJsModule })
12
+ const firstArgNode = node.arguments[0];
13
+ const urlType = analyzeUrlNodeType(firstArgNode, { isJsModule });
14
14
  if (urlType === "StringLiteral") {
15
- const specifierNode = firstArgNode
15
+ const specifierNode = firstArgNode;
16
16
  onUrl({
17
17
  type: "js_url",
18
18
  subtype: "new_url_first_arg",
@@ -21,14 +21,14 @@ 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
- })
24
+ });
25
25
  }
26
- return
26
+ return;
27
27
  }
28
28
  if (node.arguments.length === 2) {
29
- const firstArgNode = node.arguments[0]
30
- const secondArgNode = node.arguments[1]
31
- const baseUrlType = analyzeUrlNodeType(secondArgNode, { isJsModule })
29
+ const firstArgNode = node.arguments[0];
30
+ const secondArgNode = node.arguments[1];
31
+ const baseUrlType = analyzeUrlNodeType(secondArgNode, { isJsModule });
32
32
  if (baseUrlType) {
33
33
  // we can understand the second argument
34
34
  if (
@@ -36,12 +36,12 @@ export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
36
36
  secondArgNode.value === "file:///"
37
37
  ) {
38
38
  // ignore new URL(specifier, "file:///")
39
- return
39
+ return;
40
40
  }
41
- const urlType = analyzeUrlNodeType(firstArgNode, { isJsModule })
41
+ const urlType = analyzeUrlNodeType(firstArgNode, { isJsModule });
42
42
  if (urlType === "StringLiteral") {
43
43
  // we can understand the first argument
44
- const specifierNode = firstArgNode
44
+ const specifierNode = firstArgNode;
45
45
  onUrl({
46
46
  type: "js_url",
47
47
  subtype: "new_url_first_arg",
@@ -53,10 +53,10 @@ export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
53
53
  baseUrlType,
54
54
  baseUrl:
55
55
  baseUrlType === "StringLiteral" ? secondArgNode.value : undefined,
56
- })
56
+ });
57
57
  }
58
58
  if (baseUrlType === "StringLiteral") {
59
- const specifierNode = secondArgNode
59
+ const specifierNode = secondArgNode;
60
60
  onUrl({
61
61
  type: "js_url",
62
62
  subtype: "new_url_second_arg",
@@ -65,31 +65,31 @@ export const analyzeNewUrlCall = (node, { isJsModule, onUrl }) => {
65
65
  end: specifierNode.end,
66
66
  line: specifierNode.loc.start.line,
67
67
  column: specifierNode.loc.start.column,
68
- })
68
+ });
69
69
  }
70
70
  }
71
71
  }
72
- }
72
+ };
73
73
 
74
74
  const analyzeUrlNodeType = (secondArgNode, { isJsModule }) => {
75
75
  if (isStringLiteralNode(secondArgNode)) {
76
- return "StringLiteral"
76
+ return "StringLiteral";
77
77
  }
78
78
  if (isImportMetaUrl(secondArgNode)) {
79
- return "import.meta.url"
79
+ return "import.meta.url";
80
80
  }
81
81
  if (isWindowLocation(secondArgNode)) {
82
- return "window.location"
82
+ return "window.location";
83
83
  }
84
84
  if (isWindowOrigin(secondArgNode)) {
85
- return "window.origin"
85
+ return "window.origin";
86
86
  }
87
87
  if (!isJsModule && isContextMetaUrlFromSystemJs(secondArgNode)) {
88
- return "context.meta.url"
88
+ return "context.meta.url";
89
89
  }
90
90
  if (!isJsModule) {
91
91
  if (isDocumentCurrentScriptSrc(secondArgNode)) {
92
- return "document.currentScript.src"
92
+ return "document.currentScript.src";
93
93
  }
94
94
  // new URL('specifier', document.currentScript.src)
95
95
  // becomes
@@ -97,11 +97,11 @@ const analyzeUrlNodeType = (secondArgNode, { isJsModule }) => {
97
97
  // new URL('specifier', currentUrl)
98
98
  // (search for scope.generateUidIdentifier("currentUrl")
99
99
  if (secondArgNode.type === "Identifier") {
100
- return "document.currentScript.src"
100
+ return "document.currentScript.src";
101
101
  }
102
102
  }
103
- return null
104
- }
103
+ return null;
104
+ };
105
105
 
106
106
  const isImportMetaUrl = (node) => {
107
107
  return (
@@ -109,8 +109,8 @@ const isImportMetaUrl = (node) => {
109
109
  node.object.type === "MetaProperty" &&
110
110
  node.property.type === "Identifier" &&
111
111
  node.property.name === "url"
112
- )
113
- }
112
+ );
113
+ };
114
114
 
115
115
  const isWindowLocation = (node) => {
116
116
  return (
@@ -119,8 +119,8 @@ const isWindowLocation = (node) => {
119
119
  node.object.name === "window" &&
120
120
  node.property.type === "Identifier" &&
121
121
  node.property.name === "location"
122
- )
123
- }
122
+ );
123
+ };
124
124
 
125
125
  const isWindowOrigin = (node) => {
126
126
  return (
@@ -129,8 +129,8 @@ const isWindowOrigin = (node) => {
129
129
  node.object.name === "window" &&
130
130
  node.property.type === "Identifier" &&
131
131
  node.property.name === "origin"
132
- )
133
- }
132
+ );
133
+ };
134
134
 
135
135
  const isContextMetaUrlFromSystemJs = (node) => {
136
136
  return (
@@ -145,8 +145,8 @@ const isContextMetaUrlFromSystemJs = (node) => {
145
145
  node.object.property.name === "meta" &&
146
146
  node.property.type === "Identifier" &&
147
147
  node.property.name === "url"
148
- )
149
- }
148
+ );
149
+ };
150
150
 
151
151
  const isDocumentCurrentScriptSrc = (node) => {
152
152
  return (
@@ -158,5 +158,5 @@ const isDocumentCurrentScriptSrc = (node) => {
158
158
  node.object.property.name === "currentScript" &&
159
159
  node.property.type === "Identifier" &&
160
160
  node.property.name === "src"
161
- )
162
- }
161
+ );
162
+ };
@@ -1,34 +1,34 @@
1
- import { isStringLiteralNode } from "./helpers.js"
1
+ import { isStringLiteralNode } from "./helpers.js";
2
2
 
3
3
  export const isSystemRegisterCall = (node) => {
4
- const callee = node.callee
4
+ const callee = node.callee;
5
5
  return (
6
6
  callee.type === "MemberExpression" &&
7
7
  callee.object.type === "Identifier" &&
8
8
  callee.object.name === "System" &&
9
9
  callee.property.type === "Identifier" &&
10
10
  callee.property.name === "register"
11
- )
12
- }
11
+ );
12
+ };
13
13
  export const analyzeSystemRegisterCall = (node, { onUrl }) => {
14
- const firstArgNode = node.arguments[0]
14
+ const firstArgNode = node.arguments[0];
15
15
  if (firstArgNode.type === "ArrayExpression") {
16
- analyzeSystemRegisterDeps(firstArgNode, { onUrl })
17
- return
16
+ analyzeSystemRegisterDeps(firstArgNode, { onUrl });
17
+ return;
18
18
  }
19
19
  if (isStringLiteralNode(firstArgNode)) {
20
- const secondArgNode = node.arguments[1]
20
+ const secondArgNode = node.arguments[1];
21
21
  if (secondArgNode.type === "ArrayExpression") {
22
- analyzeSystemRegisterDeps(secondArgNode, { onUrl })
23
- return
22
+ analyzeSystemRegisterDeps(secondArgNode, { onUrl });
23
+ return;
24
24
  }
25
25
  }
26
- }
26
+ };
27
27
  const analyzeSystemRegisterDeps = (node, { onUrl }) => {
28
- const elements = node.elements
28
+ const elements = node.elements;
29
29
  elements.forEach((element) => {
30
30
  if (isStringLiteralNode(element)) {
31
- const specifierNode = element
31
+ const specifierNode = element;
32
32
  onUrl({
33
33
  type: "js_url",
34
34
  subtype: "system_register_arg",
@@ -38,13 +38,13 @@ const analyzeSystemRegisterDeps = (node, { onUrl }) => {
38
38
  end: specifierNode.end,
39
39
  line: specifierNode.loc.start.line,
40
40
  column: specifierNode.loc.start.column,
41
- })
41
+ });
42
42
  }
43
- })
44
- }
43
+ });
44
+ };
45
45
 
46
46
  export const isSystemImportCall = (node) => {
47
- const callee = node.callee
47
+ const callee = node.callee;
48
48
  return (
49
49
  callee.type === "MemberExpression" &&
50
50
  callee.object.type === "Identifier" &&
@@ -54,12 +54,12 @@ export const isSystemImportCall = (node) => {
54
54
  // callee.object.name === "_context" &&
55
55
  callee.property.type === "Identifier" &&
56
56
  callee.property.name === "import"
57
- )
58
- }
57
+ );
58
+ };
59
59
  export const analyzeSystemImportCall = (node, { onUrl }) => {
60
- const firstArgNode = node.arguments[0]
60
+ const firstArgNode = node.arguments[0];
61
61
  if (isStringLiteralNode(firstArgNode)) {
62
- const specifierNode = firstArgNode
62
+ const specifierNode = firstArgNode;
63
63
  onUrl({
64
64
  type: "js_url",
65
65
  subtype: "system_import_arg",
@@ -69,12 +69,12 @@ export const analyzeSystemImportCall = (node, { onUrl }) => {
69
69
  end: specifierNode.end,
70
70
  line: specifierNode.loc.start.line,
71
71
  column: specifierNode.loc.start.column,
72
- })
72
+ });
73
73
  }
74
- }
74
+ };
75
75
 
76
76
  export const isSystemResolveCall = (node) => {
77
- const callee = node.callee
77
+ const callee = node.callee;
78
78
  return (
79
79
  callee.type === "MemberExpression" &&
80
80
  callee.object.type === "MemberExpression" &&
@@ -87,12 +87,12 @@ export const isSystemResolveCall = (node) => {
87
87
  callee.object.property.name === "meta" &&
88
88
  callee.property.type === "Identifier" &&
89
89
  callee.property.name === "resolve"
90
- )
91
- }
90
+ );
91
+ };
92
92
  export const analyzeSystemResolveCall = (node, { onUrl }) => {
93
- const firstArgNode = node.arguments[0]
93
+ const firstArgNode = node.arguments[0];
94
94
  if (isStringLiteralNode(firstArgNode)) {
95
- const specifierNode = firstArgNode
95
+ const specifierNode = firstArgNode;
96
96
  onUrl({
97
97
  type: "js_url",
98
98
  subtype: "system_resolve_arg",
@@ -101,6 +101,6 @@ export const analyzeSystemResolveCall = (node, { onUrl }) => {
101
101
  end: specifierNode.end,
102
102
  line: specifierNode.loc.start.line,
103
103
  column: specifierNode.loc.start.column,
104
- })
104
+ });
105
105
  }
106
- }
106
+ };
@@ -1,9 +1,9 @@
1
- import { isStringLiteralNode } from "./helpers.js"
1
+ import { isStringLiteralNode } from "./helpers.js";
2
2
 
3
3
  export const isImportScriptsCall = (node) => {
4
- const callee = node.callee
4
+ const callee = node.callee;
5
5
  if (callee.type === "Identifier" && callee.name === "importScripts") {
6
- return true
6
+ return true;
7
7
  }
8
8
  return (
9
9
  callee.type === "MemberExpression" &&
@@ -11,12 +11,12 @@ export const isImportScriptsCall = (node) => {
11
11
  callee.object.name === "self" &&
12
12
  callee.property.type === "Identifier" &&
13
13
  callee.property.name === "importScripts"
14
- )
15
- }
14
+ );
15
+ };
16
16
  export const analyzeImportScriptCalls = (node, { onUrl }) => {
17
17
  node.arguments.forEach((arg) => {
18
18
  if (isStringLiteralNode(arg)) {
19
- const specifierNode = arg
19
+ const specifierNode = arg;
20
20
  onUrl({
21
21
  type: "js_url",
22
22
  subtype: "self_import_scripts_arg",
@@ -26,7 +26,7 @@ export const analyzeImportScriptCalls = (node, { onUrl }) => {
26
26
  end: specifierNode.end,
27
27
  line: specifierNode.loc.start.line,
28
28
  column: specifierNode.loc.start.column,
29
- })
29
+ });
30
30
  }
31
- })
32
- }
31
+ });
32
+ };