@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,87 +1,87 @@
1
- import { getTypePropertyNode, isStringLiteralNode } from "./helpers.js"
2
- import { isNewUrlCall, analyzeNewUrlCall } from "./new_url.js"
1
+ import { getTypePropertyNode, isStringLiteralNode } from "./helpers.js";
2
+ import { isNewUrlCall, analyzeNewUrlCall } from "./new_url.js";
3
3
  import {
4
4
  isImportMetaResolveCall,
5
5
  analyzeImportMetaResolveCall,
6
- } from "./import_meta_resolve.js"
6
+ } from "./import_meta_resolve.js";
7
7
 
8
8
  export const isNewWorkerCall = (node) => {
9
9
  return (
10
10
  node.type === "NewExpression" &&
11
11
  node.callee.type === "Identifier" &&
12
12
  node.callee.name === "Worker"
13
- )
14
- }
13
+ );
14
+ };
15
15
  export const analyzeNewWorkerCall = (node, { isJsModule, onUrl }) => {
16
16
  analyzeWorkerCallArguments(node, {
17
17
  isJsModule,
18
18
  onUrl,
19
19
  referenceSubtype: "new_worker_first_arg",
20
20
  expectedSubtype: "worker",
21
- })
22
- }
21
+ });
22
+ };
23
23
 
24
24
  export const isNewSharedWorkerCall = (node) => {
25
25
  return (
26
26
  node.type === "NewExpression" &&
27
27
  node.callee.type === "Identifier" &&
28
28
  node.callee.name === "SharedWorker"
29
- )
30
- }
29
+ );
30
+ };
31
31
  export const analyzeNewSharedWorkerCall = (node, { isJsModule, onUrl }) => {
32
32
  analyzeWorkerCallArguments(node, {
33
33
  isJsModule,
34
34
  onUrl,
35
35
  referenceSubtype: "new_shared_worker_first_arg",
36
36
  expectedSubtype: "shared_worker",
37
- })
38
- }
37
+ });
38
+ };
39
39
 
40
40
  export const isServiceWorkerRegisterCall = (node) => {
41
41
  if (node.type !== "CallExpression") {
42
- return false
42
+ return false;
43
43
  }
44
- const callee = node.callee
44
+ const callee = node.callee;
45
45
  if (
46
46
  callee.type === "MemberExpression" &&
47
47
  callee.property.type === "Identifier" &&
48
48
  callee.property.name === "register"
49
49
  ) {
50
- const parentObject = callee.object
50
+ const parentObject = callee.object;
51
51
  if (parentObject.type === "MemberExpression") {
52
- const parentProperty = parentObject.property
52
+ const parentProperty = parentObject.property;
53
53
  if (
54
54
  parentProperty.type === "Identifier" &&
55
55
  parentProperty.name === "serviceWorker"
56
56
  ) {
57
- const grandParentObject = parentObject.object
57
+ const grandParentObject = parentObject.object;
58
58
  if (grandParentObject.type === "MemberExpression") {
59
59
  // window.navigator.serviceWorker.register
60
- const grandParentProperty = grandParentObject.property
60
+ const grandParentProperty = grandParentObject.property;
61
61
  if (
62
62
  grandParentProperty.type === "Identifier" &&
63
63
  grandParentProperty.name === "navigator"
64
64
  ) {
65
- const ancestorObject = grandParentObject.object
65
+ const ancestorObject = grandParentObject.object;
66
66
  if (
67
67
  ancestorObject.type === "Identifier" &&
68
68
  ancestorObject.name === "window"
69
69
  ) {
70
- return true
70
+ return true;
71
71
  }
72
72
  }
73
73
  }
74
74
  if (grandParentObject.type === "Identifier") {
75
75
  // navigator.serviceWorker.register
76
76
  if (grandParentObject.name === "navigator") {
77
- return true
77
+ return true;
78
78
  }
79
79
  }
80
80
  }
81
81
  }
82
82
  }
83
- return false
84
- }
83
+ return false;
84
+ };
85
85
  export const analyzeServiceWorkerRegisterCall = (
86
86
  node,
87
87
  { isJsModule, onUrl },
@@ -91,32 +91,32 @@ export const analyzeServiceWorkerRegisterCall = (
91
91
  onUrl,
92
92
  referenceSubtype: "service_worker_register_first_arg",
93
93
  expectedSubtype: "service_worker",
94
- })
95
- }
94
+ });
95
+ };
96
96
 
97
97
  const analyzeWorkerCallArguments = (
98
98
  node,
99
99
  { isJsModule, onUrl, referenceSubtype, expectedSubtype },
100
100
  ) => {
101
- let expectedType = "js_classic"
102
- let typePropertyNode
103
- const secondArgNode = node.arguments[1]
101
+ let expectedType = "js_classic";
102
+ let typePropertyNode;
103
+ const secondArgNode = node.arguments[1];
104
104
  if (secondArgNode) {
105
- typePropertyNode = getTypePropertyNode(secondArgNode)
105
+ typePropertyNode = getTypePropertyNode(secondArgNode);
106
106
  if (typePropertyNode) {
107
- const typePropertyValueNode = typePropertyNode.value
107
+ const typePropertyValueNode = typePropertyNode.value;
108
108
  if (isStringLiteralNode(typePropertyValueNode)) {
109
- const typePropertyValue = typePropertyValueNode.value
109
+ const typePropertyValue = typePropertyValueNode.value;
110
110
  if (typePropertyValue === "module") {
111
- expectedType = "js_module"
111
+ expectedType = "js_module";
112
112
  }
113
113
  }
114
114
  }
115
115
  }
116
116
 
117
- const firstArgNode = node.arguments[0]
117
+ const firstArgNode = node.arguments[0];
118
118
  if (isStringLiteralNode(firstArgNode)) {
119
- const specifierNode = firstArgNode
119
+ const specifierNode = firstArgNode;
120
120
  onUrl({
121
121
  type: "js_url",
122
122
  subtype: referenceSubtype,
@@ -128,8 +128,8 @@ const analyzeWorkerCallArguments = (
128
128
  end: specifierNode.end,
129
129
  line: specifierNode.loc.start.line,
130
130
  column: specifierNode.loc.start.column,
131
- })
132
- return
131
+ });
132
+ return;
133
133
  }
134
134
  if (isNewUrlCall(firstArgNode)) {
135
135
  analyzeNewUrlCall(firstArgNode, {
@@ -139,11 +139,11 @@ const analyzeWorkerCallArguments = (
139
139
  expectedType,
140
140
  expectedSubtype,
141
141
  typePropertyNode,
142
- })
143
- onUrl(mention)
142
+ });
143
+ onUrl(mention);
144
144
  },
145
- })
146
- return
145
+ });
146
+ return;
147
147
  }
148
148
  if (isJsModule && isImportMetaResolveCall(firstArgNode)) {
149
149
  analyzeImportMetaResolveCall(firstArgNode, {
@@ -152,10 +152,10 @@ const analyzeWorkerCallArguments = (
152
152
  expectedType,
153
153
  expectedSubtype,
154
154
  typePropertyNode,
155
- })
156
- onUrl(mention)
155
+ });
156
+ onUrl(mention);
157
157
  },
158
- })
159
- return
158
+ });
159
+ return;
160
160
  }
161
- }
161
+ };
@@ -1,16 +1,16 @@
1
- import { ancestor } from "acorn-walk"
1
+ import { ancestor } from "acorn-walk";
2
2
 
3
- import { parseJsWithAcorn } from "./parse_js_with_acorn.js"
3
+ import { parseJsWithAcorn } from "./parse_js_with_acorn.js";
4
4
  import {
5
5
  analyzeImportExpression,
6
6
  analyzeImportDeclaration,
7
7
  analyzeExportNamedDeclaration,
8
8
  analyzeExportAllDeclaration,
9
- } from "./js_static_analysis/import_export.js"
9
+ } from "./js_static_analysis/import_export.js";
10
10
  import {
11
11
  isImportMetaResolveCall,
12
12
  analyzeImportMetaResolveCall,
13
- } from "./js_static_analysis/import_meta_resolve.js"
13
+ } from "./js_static_analysis/import_meta_resolve.js";
14
14
  import {
15
15
  isNewWorkerCall,
16
16
  analyzeNewWorkerCall,
@@ -18,15 +18,15 @@ import {
18
18
  analyzeNewSharedWorkerCall,
19
19
  isServiceWorkerRegisterCall,
20
20
  analyzeServiceWorkerRegisterCall,
21
- } from "./js_static_analysis/web_worker_entry_point.js"
21
+ } from "./js_static_analysis/web_worker_entry_point.js";
22
22
  import {
23
23
  isImportScriptsCall,
24
24
  analyzeImportScriptCalls,
25
- } from "./js_static_analysis/web_worker.js"
25
+ } from "./js_static_analysis/web_worker.js";
26
26
  import {
27
27
  isNewUrlCall,
28
28
  analyzeNewUrlCall,
29
- } from "./js_static_analysis/new_url.js"
29
+ } from "./js_static_analysis/new_url.js";
30
30
  import {
31
31
  isSystemRegisterCall,
32
32
  analyzeSystemRegisterCall,
@@ -34,7 +34,7 @@ import {
34
34
  analyzeSystemImportCall,
35
35
  isSystemResolveCall,
36
36
  analyzeSystemResolveCall,
37
- } from "./js_static_analysis/system.js"
37
+ } from "./js_static_analysis/system.js";
38
38
 
39
39
  export const parseJsUrls = async ({
40
40
  js,
@@ -42,63 +42,63 @@ export const parseJsUrls = async ({
42
42
  isJsModule = false,
43
43
  isWebWorker = false,
44
44
  } = {}) => {
45
- const jsUrls = []
45
+ const jsUrls = [];
46
46
  const jsAst = await parseJsWithAcorn({
47
47
  js,
48
48
  url,
49
49
  isJsModule,
50
- })
50
+ });
51
51
  const onUrl = (jsUrl) => {
52
- jsUrls.push(jsUrl)
53
- }
52
+ jsUrls.push(jsUrl);
53
+ };
54
54
  ancestor(jsAst, {
55
55
  ImportDeclaration: (node) => {
56
- analyzeImportDeclaration(node, { onUrl })
56
+ analyzeImportDeclaration(node, { onUrl });
57
57
  },
58
58
  ImportExpression: (node) => {
59
- analyzeImportExpression(node, { onUrl })
59
+ analyzeImportExpression(node, { onUrl });
60
60
  },
61
61
  ExportNamedDeclaration: (node) => {
62
- analyzeExportNamedDeclaration(node, { onUrl })
62
+ analyzeExportNamedDeclaration(node, { onUrl });
63
63
  },
64
64
  ExportAllDeclaration: (node) => {
65
- analyzeExportAllDeclaration(node, { onUrl })
65
+ analyzeExportAllDeclaration(node, { onUrl });
66
66
  },
67
67
  CallExpression: (node) => {
68
68
  if (isJsModule && isImportMetaResolveCall(node)) {
69
- analyzeImportMetaResolveCall(node, { onUrl })
70
- return
69
+ analyzeImportMetaResolveCall(node, { onUrl });
70
+ return;
71
71
  }
72
72
  if (isServiceWorkerRegisterCall(node)) {
73
73
  analyzeServiceWorkerRegisterCall(node, {
74
74
  isJsModule,
75
75
  onUrl,
76
- })
77
- return
76
+ });
77
+ return;
78
78
  }
79
79
  if (isWebWorker && isImportScriptsCall(node)) {
80
80
  analyzeImportScriptCalls(node, {
81
81
  onUrl,
82
- })
83
- return
82
+ });
83
+ return;
84
84
  }
85
85
  if (!isJsModule && isSystemRegisterCall(node)) {
86
86
  analyzeSystemRegisterCall(node, {
87
87
  onUrl,
88
- })
89
- return
88
+ });
89
+ return;
90
90
  }
91
91
  if (!isJsModule && isSystemImportCall(node)) {
92
92
  analyzeSystemImportCall(node, {
93
93
  onUrl,
94
- })
95
- return
94
+ });
95
+ return;
96
96
  }
97
97
  if (!isJsModule && isSystemResolveCall(node)) {
98
98
  analyzeSystemResolveCall(node, {
99
99
  onUrl,
100
- })
101
- return
100
+ });
101
+ return;
102
102
  }
103
103
  },
104
104
  NewExpression: (node, ancestors) => {
@@ -106,33 +106,33 @@ export const parseJsUrls = async ({
106
106
  analyzeNewWorkerCall(node, {
107
107
  isJsModule,
108
108
  onUrl,
109
- })
110
- return
109
+ });
110
+ return;
111
111
  }
112
112
  if (isNewSharedWorkerCall(node)) {
113
113
  analyzeNewSharedWorkerCall(node, {
114
114
  isJsModule,
115
115
  onUrl,
116
- })
117
- return
116
+ });
117
+ return;
118
118
  }
119
119
  if (isNewUrlCall(node)) {
120
- const parent = ancestors[ancestors.length - 2]
120
+ const parent = ancestors[ancestors.length - 2];
121
121
  if (
122
122
  parent &&
123
123
  (isNewWorkerCall(parent) ||
124
124
  isNewSharedWorkerCall(parent) ||
125
125
  isServiceWorkerRegisterCall(parent))
126
126
  ) {
127
- return
127
+ return;
128
128
  }
129
129
  analyzeNewUrlCall(node, {
130
130
  isJsModule,
131
131
  onUrl,
132
- })
133
- return
132
+ });
133
+ return;
134
134
  }
135
135
  },
136
- })
137
- return jsUrls
138
- }
136
+ });
137
+ return jsUrls;
138
+ };
@@ -1,10 +1,10 @@
1
- import { createJsParseError } from "./js_parse_error.js"
1
+ import { createJsParseError } from "./js_parse_error.js";
2
2
 
3
- let AcornParser
4
- let _getLineInfo
3
+ let AcornParser;
4
+ let _getLineInfo;
5
5
 
6
6
  export const parseJsWithAcorn = async ({ js, url, isJsModule }) => {
7
- await initAcornParser()
7
+ await initAcornParser();
8
8
  try {
9
9
  // https://github.com/acornjs/acorn/tree/master/acorn#interface
10
10
  const jsAst = AcornParser.parse(js, {
@@ -12,30 +12,30 @@ export const parseJsWithAcorn = async ({ js, url, isJsModule }) => {
12
12
  allowAwaitOutsideFunction: true,
13
13
  sourceType: isJsModule ? "module" : "script",
14
14
  ecmaVersion: 2022,
15
- })
16
- return jsAst
15
+ });
16
+ return jsAst;
17
17
  } catch (e) {
18
18
  if (e && e.name === "SyntaxError") {
19
- const { line, column } = _getLineInfo(js, e.raisedAt)
19
+ const { line, column } = _getLineInfo(js, e.raisedAt);
20
20
  throw createJsParseError({
21
21
  message: e.message,
22
22
  reasonCode: e.message,
23
23
  url,
24
24
  line,
25
25
  column,
26
- })
26
+ });
27
27
  }
28
- throw e
28
+ throw e;
29
29
  }
30
- }
30
+ };
31
31
 
32
32
  const initAcornParser = async () => {
33
33
  if (AcornParser) {
34
- return
34
+ return;
35
35
  }
36
- const { Parser, getLineInfo } = await import("acorn")
37
- const { importAssertions } = await import("acorn-import-assertions")
36
+ const { Parser, getLineInfo } = await import("acorn");
37
+ const { importAssertions } = await import("acorn-import-assertions");
38
38
 
39
- AcornParser = Parser.extend(importAssertions)
40
- _getLineInfo = getLineInfo
41
- }
39
+ AcornParser = Parser.extend(importAssertions);
40
+ _getLineInfo = getLineInfo;
41
+ };
package/src/main.js CHANGED
@@ -4,41 +4,41 @@ export {
4
4
  stringifyHtmlAst,
5
5
  parseSvgString,
6
6
  stringifySvgAst,
7
- } from "./html/html_parse.js"
8
- export { visitHtmlNodes, findHtmlNode } from "./html/html_search.js"
9
- export { analyzeScriptNode, analyzeLinkNode } from "./html/html_analysis.js"
7
+ } from "./html/html_parse.js";
8
+ export { visitHtmlNodes, findHtmlNode } from "./html/html_search.js";
9
+ export { analyzeScriptNode, analyzeLinkNode } from "./html/html_analysis.js";
10
10
  export {
11
11
  getHtmlNodeText,
12
12
  removeHtmlNodeText,
13
13
  setHtmlNodeText,
14
- } from "./html/html_node_text.js"
15
- export { parseSrcSet, stringifySrcSet } from "./html/html_src_set.js"
14
+ } from "./html/html_node_text.js";
15
+ export { parseSrcSet, stringifySrcSet } from "./html/html_src_set.js";
16
16
  export {
17
17
  getHtmlNodeAttribute,
18
18
  setHtmlNodeAttributes,
19
- } from "./html/html_node_attributes.js"
19
+ } from "./html/html_node_attributes.js";
20
20
  export {
21
21
  removeHtmlNode,
22
22
  createHtmlNode,
23
23
  injectHtmlNode,
24
24
  injectHtmlNodeAsEarlyAsPossible,
25
25
  insertHtmlNodeAfter,
26
- } from "./html/html_node.js"
26
+ } from "./html/html_node.js";
27
27
  export {
28
28
  inlineScriptNode,
29
29
  inlineLinkStylesheetNode,
30
30
  inlineImgNode,
31
- } from "./html/html_inlining.js"
31
+ } from "./html/html_inlining.js";
32
32
  export {
33
33
  getHtmlNodePosition,
34
34
  getHtmlNodeAttributePosition,
35
- } from "./html/html_node_position.js"
35
+ } from "./html/html_node_position.js";
36
36
 
37
37
  // css
38
- export { parseCssUrls } from "./css/parse_css_urls.js"
38
+ export { parseCssUrls } from "./css/parse_css_urls.js";
39
39
 
40
40
  // js
41
- export { applyBabelPlugins } from "./js/apply_babel_plugins.js"
42
- export { injectJsImport } from "./js/babel_utils.js"
43
- export { parseJsWithAcorn } from "./js/parse_js_with_acorn.js"
44
- export { parseJsUrls } from "./js/parse_js_urls.js"
41
+ export { applyBabelPlugins } from "./js/apply_babel_plugins.js";
42
+ export { injectJsImport } from "./js/babel_utils.js";
43
+ export { parseJsWithAcorn } from "./js/parse_js_with_acorn.js";
44
+ export { parseJsUrls } from "./js/parse_js_urls.js";
package/src/require.js CHANGED
@@ -1,3 +1,3 @@
1
- import { createRequire } from "node:module"
1
+ import { createRequire } from "node:module";
2
2
 
3
- export const require = createRequire(import.meta.url)
3
+ export const require = createRequire(import.meta.url);