solid-optimizer 0.1.1 → 0.2.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/LICENSE CHANGED
@@ -1,7 +1,21 @@
1
- MIT License Copyright (c) 2022 <author>
1
+ MIT License
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ Copyright (c) 2025 Alexis Munsayac
4
4
 
5
- The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
6
11
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -42,6 +42,9 @@ Passed argument is inlined.
42
42
 
43
43
  `getListener` calls are replaced with `null`.
44
44
 
45
+ ## Sponsors
46
+
47
+ ![Sponsors](https://github.com/lxsmnsyc/sponsors/blob/main/sponsors.svg?raw=true)
45
48
  ## License
46
49
 
47
50
  MIT © [lxsmnsyc](https://github.com/lxsmnsyc)
@@ -35,120 +35,108 @@ __export(src_exports, {
35
35
  module.exports = __toCommonJS(src_exports);
36
36
  var t2 = __toESM(require("@babel/types"), 1);
37
37
 
38
- // src/unwrap-node.ts
38
+ // src/path-references-import.ts
39
39
  var t = __toESM(require("@babel/types"), 1);
40
- function unwrapNode(node, key) {
41
- if (key(node)) {
42
- return node;
40
+
41
+ // src/checks.ts
42
+ function isPathValid(path, key) {
43
+ return key(path.node);
44
+ }
45
+ function isNestedExpression(node) {
46
+ switch (node.type) {
47
+ case "ParenthesizedExpression":
48
+ case "TypeCastExpression":
49
+ case "TSAsExpression":
50
+ case "TSSatisfiesExpression":
51
+ case "TSNonNullExpression":
52
+ case "TSTypeAssertion":
53
+ case "TSInstantiationExpression":
54
+ return true;
55
+ default:
56
+ return false;
43
57
  }
44
- if (t.isParenthesizedExpression(node) || t.isTypeCastExpression(node) || t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTSTypeAssertion(node) || t.isTSInstantiationExpression(node)) {
45
- return unwrapNode(node.expression, key);
58
+ }
59
+
60
+ // src/unwrap-path.ts
61
+ function unwrapPath(path, key) {
62
+ if (isPathValid(path, key)) {
63
+ return path;
64
+ }
65
+ if (isPathValid(path, isNestedExpression)) {
66
+ return unwrapPath(path.get("expression"), key);
46
67
  }
47
68
  return void 0;
48
69
  }
49
70
 
50
- // src/index.ts
51
- var TRACKED = {
52
- "solid-js": {
53
- createEffect: true,
54
- onMount: true,
55
- getListener: true,
56
- untrack: true,
57
- batch: true,
58
- startTransition: true,
59
- createDeferred: true
60
- },
61
- "solid-js/web": {
62
- createEffect: true,
63
- onMount: true,
64
- getListener: true,
65
- untrack: true,
66
- batch: true,
67
- startTransition: true,
68
- createDeferred: true
71
+ // src/path-references-import.ts
72
+ function pathReferencesImportIdentifier(path, moduleSources, importNames) {
73
+ const identifier = unwrapPath(path, t.isIdentifier);
74
+ if (!identifier) {
75
+ return false;
69
76
  }
70
- };
71
- var MODULES = new Set(Object.keys(TRACKED));
72
- function isValidSpecifier(specifier, name) {
73
- return t2.isIdentifier(specifier.imported) && specifier.imported.name === name || t2.isStringLiteral(specifier.imported) && specifier.imported.value === name;
74
- }
75
- function extractImportIdentifiers(ctx, path) {
76
- if (MODULES.has(path.node.source.value)) {
77
- const modulePath = path.node.source.value;
78
- for (let i = 0, len = path.node.specifiers.length; i < len; i += 1) {
79
- const specifier = path.node.specifiers[i];
80
- if (t2.isImportSpecifier(specifier)) {
81
- const ids = TRACKED[modulePath];
82
- for (const key of Object.keys(ids)) {
83
- if (isValidSpecifier(specifier, key)) {
84
- ctx.identifiers[modulePath][key].add(specifier.local);
85
- }
86
- }
87
- } else if (t2.isImportNamespaceSpecifier(specifier)) {
88
- ctx.namespaces[modulePath].add(specifier.local);
89
- }
90
- }
77
+ const binding = path.scope.getBinding(identifier.node.name);
78
+ if (!binding || binding.kind !== "module") {
79
+ return false;
91
80
  }
92
- }
93
- function checkValidIdentifierImport(ctx, identifier) {
94
- for (const mod of MODULES) {
95
- const identifiers = ctx.identifiers[mod];
96
- for (const key of Object.keys(identifiers)) {
97
- if (identifiers[key].has(identifier)) {
98
- return key;
99
- }
81
+ const importPath = binding.path;
82
+ const importParent = importPath.parentPath;
83
+ if (isPathValid(importParent, t.isImportDeclaration) && moduleSources.includes(importParent.node.source.value)) {
84
+ if (isPathValid(importPath, t.isImportSpecifier)) {
85
+ const key = t.isIdentifier(importPath.node.imported) ? importPath.node.imported.name : importPath.node.imported.value;
86
+ return importNames.includes(key);
87
+ }
88
+ if (isPathValid(importPath, t.isImportDefaultSpecifier)) {
89
+ return importNames.includes("default");
90
+ }
91
+ if (isPathValid(importPath, t.isImportNamespaceSpecifier)) {
92
+ return importNames.includes("*");
100
93
  }
101
94
  }
102
- return void 0;
95
+ return false;
103
96
  }
104
- function checkValidNamespaceImport(ctx, object, property) {
105
- for (const mod of MODULES) {
106
- const namespace = ctx.namespaces[mod];
107
- if (namespace.has(object) && property in TRACKED[mod]) {
108
- return true;
97
+ var IMPORT_NAMESPACE = ["*"];
98
+ function pathReferencesImportMember(path, moduleSources, importNames) {
99
+ const memberExpr = unwrapPath(path, t.isMemberExpression) || unwrapPath(path, t.isOptionalMemberExpression);
100
+ if (memberExpr) {
101
+ const object = unwrapPath(memberExpr.get("object"), t.isIdentifier);
102
+ if (!object) {
103
+ return false;
104
+ }
105
+ const property = memberExpr.get("property");
106
+ if (isPathValid(property, t.isIdentifier)) {
107
+ return importNames.includes(property.node.name) && pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE);
108
+ }
109
+ if (isPathValid(property, t.isStringLiteral)) {
110
+ return importNames.includes(property.node.value) && pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE);
109
111
  }
110
112
  }
111
113
  return false;
112
114
  }
113
- function transformCreateEffect(path) {
114
- path.remove();
115
- }
116
- function transformOnMount(path) {
117
- path.remove();
118
- }
119
- function transformGetListener(path) {
120
- path.replaceWith(t2.nullLiteral());
115
+ function pathReferencesImport(path, moduleSources, importNames) {
116
+ return pathReferencesImportIdentifier(path, moduleSources, importNames) || pathReferencesImportMember(path, moduleSources, importNames);
121
117
  }
122
- function transformBatch(path) {
123
- const arg = path.node.arguments[0];
124
- if (t2.isExpression(arg)) {
125
- const trueArrow = unwrapNode(arg, t2.isArrowFunctionExpression);
126
- if (trueArrow) {
127
- if (t2.isExpression(trueArrow.body)) {
128
- path.replaceWith(trueArrow.body);
129
- } else {
130
- path.replaceWith(t2.callExpression(trueArrow, []));
131
- }
132
- return;
133
- }
134
- const trueFunc = unwrapNode(arg, t2.isFunctionExpression);
135
- if (trueFunc) {
136
- path.replaceWith(trueFunc.body);
137
- }
138
- } else if (t2.isSpreadElement(arg)) {
139
- path.replaceWith(
140
- t2.callExpression(
141
- t2.memberExpression(
142
- arg.argument,
143
- t2.numericLiteral(0),
144
- true
145
- ),
146
- []
147
- )
148
- );
118
+
119
+ // src/unwrap-node.ts
120
+ function unwrapNode(node, key) {
121
+ if (key(node)) {
122
+ return node;
123
+ }
124
+ switch (node.type) {
125
+ case "ParenthesizedExpression":
126
+ case "TypeCastExpression":
127
+ case "TSAsExpression":
128
+ case "TSSatisfiesExpression":
129
+ case "TSNonNullExpression":
130
+ case "TSTypeAssertion":
131
+ case "TSInstantiationExpression":
132
+ return unwrapNode(node.expression, key);
133
+ default:
134
+ return void 0;
149
135
  }
150
136
  }
151
- function transformUntrack(path) {
137
+
138
+ // src/index.ts
139
+ function transformUntrackAndBatch(path) {
152
140
  const arg = path.node.arguments[0];
153
141
  if (t2.isExpression(arg)) {
154
142
  const trueArrow = unwrapNode(arg, t2.isArrowFunctionExpression);
@@ -167,11 +155,7 @@ function transformUntrack(path) {
167
155
  } else if (t2.isSpreadElement(arg)) {
168
156
  path.replaceWith(
169
157
  t2.callExpression(
170
- t2.memberExpression(
171
- arg.argument,
172
- t2.numericLiteral(0),
173
- true
174
- ),
158
+ t2.memberExpression(arg.argument, t2.numericLiteral(0), true),
175
159
  []
176
160
  )
177
161
  );
@@ -196,11 +180,7 @@ function transformStartTransition(path) {
196
180
  } else if (t2.isSpreadElement(arg)) {
197
181
  path.replaceWith(
198
182
  t2.callExpression(
199
- t2.memberExpression(
200
- arg.argument,
201
- t2.numericLiteral(0),
202
- true
203
- ),
183
+ t2.memberExpression(arg.argument, t2.numericLiteral(0), true),
204
184
  []
205
185
  )
206
186
  );
@@ -212,100 +192,35 @@ function transformCreateDeferred(path) {
212
192
  path.replaceWith(arg);
213
193
  } else if (t2.isSpreadElement(arg)) {
214
194
  path.replaceWith(
215
- t2.memberExpression(
216
- arg.argument,
217
- t2.numericLiteral(0),
218
- true
219
- )
195
+ t2.memberExpression(arg.argument, t2.numericLiteral(0), true)
220
196
  );
221
197
  }
222
198
  }
223
- function runTransform(path, targetName) {
224
- switch (targetName) {
225
- case "createEffect":
226
- transformCreateEffect(path);
227
- break;
228
- case "onMount":
229
- transformOnMount(path);
230
- break;
231
- case "getListener":
232
- transformGetListener(path);
233
- break;
234
- case "untrack":
235
- transformUntrack(path);
236
- break;
237
- case "batch":
238
- transformBatch(path);
239
- break;
240
- case "startTransition":
241
- transformStartTransition(path);
242
- break;
243
- case "createDeferred":
244
- transformCreateDeferred(path);
245
- break;
246
- default:
247
- break;
199
+ var MODULES = ["solid-js", "solid-js/web"];
200
+ function transformCallExpression(path) {
201
+ const callee = path.get("callee");
202
+ if (pathReferencesImport(callee, MODULES, ["createEffect", "onMount"])) {
203
+ path.remove();
204
+ } else if (pathReferencesImport(callee, MODULES, ["getListener"])) {
205
+ path.replaceWith(t2.nullLiteral());
206
+ } else if (pathReferencesImport(callee, MODULES, ["untrack", "batch"])) {
207
+ transformUntrackAndBatch(path);
208
+ } else if (pathReferencesImport(callee, MODULES, ["startTransition"])) {
209
+ transformStartTransition(path);
210
+ } else if (pathReferencesImport(callee, MODULES, ["createDeferred"])) {
211
+ transformCreateDeferred(path);
248
212
  }
249
213
  }
250
214
  function solidOptimizerPlugin() {
251
215
  return {
252
216
  name: "solid-optimizer",
253
- pre() {
254
- this.ctx = {
255
- hooks: /* @__PURE__ */ new Map(),
256
- identifiers: {
257
- "solid-js": {
258
- createEffect: /* @__PURE__ */ new Set(),
259
- onMount: /* @__PURE__ */ new Set(),
260
- getListener: /* @__PURE__ */ new Set(),
261
- untrack: /* @__PURE__ */ new Set(),
262
- batch: /* @__PURE__ */ new Set(),
263
- startTransition: /* @__PURE__ */ new Set(),
264
- createDeferred: /* @__PURE__ */ new Set()
265
- },
266
- "solid-js/web": {
267
- createEffect: /* @__PURE__ */ new Set(),
268
- onMount: /* @__PURE__ */ new Set(),
269
- getListener: /* @__PURE__ */ new Set(),
270
- untrack: /* @__PURE__ */ new Set(),
271
- batch: /* @__PURE__ */ new Set(),
272
- startTransition: /* @__PURE__ */ new Set(),
273
- createDeferred: /* @__PURE__ */ new Set()
274
- }
275
- },
276
- namespaces: {
277
- "solid-js": /* @__PURE__ */ new Set(),
278
- "solid-js/web": /* @__PURE__ */ new Set()
279
- }
280
- };
281
- },
282
217
  visitor: {
283
- ImportDeclaration(path, state) {
284
- extractImportIdentifiers(state.ctx, path);
285
- },
286
- CallExpression(path, state) {
287
- const trueIdentifier = unwrapNode(path.node.callee, t2.isIdentifier);
288
- if (trueIdentifier) {
289
- const binding = path.scope.getBindingIdentifier(trueIdentifier.name);
290
- if (binding) {
291
- const targetName = checkValidIdentifierImport(state.ctx, binding);
292
- if (targetName) {
293
- runTransform(path, targetName);
294
- }
295
- }
296
- return;
297
- }
298
- const trueMemberExpr = unwrapNode(path.node.callee, t2.isMemberExpression);
299
- if (trueMemberExpr && t2.isIdentifier(trueMemberExpr.property) && !trueMemberExpr.computed) {
300
- const source = unwrapNode(trueMemberExpr.object, t2.isIdentifier);
301
- if (source) {
302
- const targetName = trueMemberExpr.property.name;
303
- const binding = path.scope.getBindingIdentifier(source.name);
304
- if (binding && checkValidNamespaceImport(state.ctx, binding, targetName)) {
305
- runTransform(path, targetName);
306
- }
218
+ Program(program) {
219
+ program.traverse({
220
+ CallExpression(path) {
221
+ transformCallExpression(path);
307
222
  }
308
- }
223
+ });
309
224
  }
310
225
  }
311
226
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/index.ts", "../../../src/unwrap-node.ts"],
4
- "sourcesContent": ["import { NodePath, PluginObj, PluginPass } from '@babel/core';\nimport * as t from '@babel/types';\nimport unwrapNode from './unwrap-node';\n\nconst TRACKED: Record<string, Record<string, boolean>> = {\n 'solid-js': {\n createEffect: true,\n onMount: true,\n getListener: true,\n untrack: true,\n batch: true,\n startTransition: true,\n createDeferred: true,\n },\n 'solid-js/web': {\n createEffect: true,\n onMount: true,\n getListener: true,\n untrack: true,\n batch: true,\n startTransition: true,\n createDeferred: true,\n },\n};\n\nconst MODULES = new Set(Object.keys(TRACKED));\n\ninterface StateContext {\n hooks: Map<string, t.Identifier>;\n identifiers: Record<string, Record<string, Set<t.Identifier>>>;\n namespaces: Record<string, Set<t.Identifier>>;\n}\n\nfunction isValidSpecifier(\n specifier: t.ImportSpecifier,\n name: string,\n): boolean {\n return (\n (t.isIdentifier(specifier.imported) && specifier.imported.name === name)\n || (t.isStringLiteral(specifier.imported) && specifier.imported.value === name)\n );\n}\n\nfunction extractImportIdentifiers(\n ctx: StateContext,\n path: NodePath<t.ImportDeclaration>,\n) {\n if (MODULES.has(path.node.source.value)) {\n const modulePath = path.node.source.value;\n for (let i = 0, len = path.node.specifiers.length; i < len; i += 1) {\n const specifier = path.node.specifiers[i];\n if (t.isImportSpecifier(specifier)) {\n const ids = TRACKED[modulePath];\n\n for (const key of Object.keys(ids)) {\n if (isValidSpecifier(specifier, key)) {\n ctx.identifiers[modulePath][key].add(specifier.local);\n }\n }\n } else if (t.isImportNamespaceSpecifier(specifier)) {\n ctx.namespaces[modulePath].add(specifier.local);\n }\n }\n }\n}\n\nfunction checkValidIdentifierImport(\n ctx: StateContext,\n identifier: t.Identifier,\n) {\n for (const mod of MODULES) {\n const identifiers = ctx.identifiers[mod];\n for (const key of Object.keys(identifiers)) {\n if (identifiers[key].has(identifier)) {\n return key;\n }\n }\n }\n return undefined;\n}\n\nfunction checkValidNamespaceImport(\n ctx: StateContext,\n object: t.Identifier,\n property: string,\n) {\n for (const mod of MODULES) {\n const namespace = ctx.namespaces[mod];\n if (namespace.has(object) && property in TRACKED[mod]) {\n return true;\n }\n }\n return false;\n}\n\nfunction transformCreateEffect(\n path: NodePath<t.CallExpression>,\n) {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L78\n // Just remove it\n path.remove();\n}\n\nfunction transformOnMount(\n path: NodePath<t.CallExpression>,\n) {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L131\n // Just remove it\n path.remove();\n}\n\nfunction transformGetListener(\n path: NodePath<t.CallExpression>,\n) {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L157\n path.replaceWith(t.nullLiteral());\n}\n\nfunction transformBatch(\n path: NodePath<t.CallExpression>,\n) {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L107\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);\n if (trueArrow) {\n if (t.isExpression(trueArrow.body)) {\n path.replaceWith(trueArrow.body);\n } else {\n path.replaceWith(t.callExpression(trueArrow, []));\n }\n return;\n }\n const trueFunc = unwrapNode(arg, t.isFunctionExpression);\n if (trueFunc) {\n path.replaceWith(trueFunc.body);\n }\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.callExpression(\n t.memberExpression(\n arg.argument,\n t.numericLiteral(0),\n true,\n ),\n [],\n ),\n );\n }\n}\n\nfunction transformUntrack(\n path: NodePath<t.CallExpression>,\n) {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L111\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);\n if (trueArrow) {\n if (t.isExpression(trueArrow.body)) {\n path.replaceWith(trueArrow.body);\n } else {\n path.replaceWith(t.callExpression(trueArrow, []));\n }\n return;\n }\n const trueFunc = unwrapNode(arg, t.isFunctionExpression);\n if (trueFunc) {\n path.replaceWith(trueFunc.body);\n }\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.callExpression(\n t.memberExpression(\n arg.argument,\n t.numericLiteral(0),\n true,\n ),\n [],\n ),\n );\n }\n}\n\nfunction transformStartTransition(\n path: NodePath<t.CallExpression>,\n) {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/rendering.ts#L488\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);\n if (trueArrow) {\n if (t.isExpression(trueArrow.body)) {\n path.replaceWith(trueArrow.body);\n } else {\n path.replaceWith(t.callExpression(trueArrow, []));\n }\n return;\n }\n const trueFunc = unwrapNode(arg, t.isFunctionExpression);\n if (trueFunc) {\n path.replaceWith(trueFunc.body);\n }\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.callExpression(\n t.memberExpression(\n arg.argument,\n t.numericLiteral(0),\n true,\n ),\n [],\n ),\n );\n }\n}\n\nfunction transformCreateDeferred(\n path: NodePath<t.CallExpression>,\n) {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L99\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n path.replaceWith(arg);\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.memberExpression(\n arg.argument,\n t.numericLiteral(0),\n true,\n ),\n );\n }\n}\n\ninterface State extends PluginPass {\n ctx: StateContext;\n}\n\nfunction runTransform(path: NodePath<t.CallExpression>, targetName: string) {\n switch (targetName) {\n case 'createEffect':\n transformCreateEffect(path);\n break;\n case 'onMount':\n transformOnMount(path);\n break;\n case 'getListener':\n transformGetListener(path);\n break;\n case 'untrack':\n transformUntrack(path);\n break;\n case 'batch':\n transformBatch(path);\n break;\n case 'startTransition':\n transformStartTransition(path);\n break;\n case 'createDeferred':\n transformCreateDeferred(path);\n break;\n default:\n break;\n }\n}\n\nexport default function solidOptimizerPlugin(): PluginObj<State> {\n return {\n name: 'solid-optimizer',\n pre() {\n this.ctx = {\n hooks: new Map(),\n identifiers: {\n 'solid-js': {\n createEffect: new Set(),\n onMount: new Set(),\n getListener: new Set(),\n untrack: new Set(),\n batch: new Set(),\n startTransition: new Set(),\n createDeferred: new Set(),\n },\n 'solid-js/web': {\n createEffect: new Set(),\n onMount: new Set(),\n getListener: new Set(),\n untrack: new Set(),\n batch: new Set(),\n startTransition: new Set(),\n createDeferred: new Set(),\n },\n },\n namespaces: {\n 'solid-js': new Set(),\n 'solid-js/web': new Set(),\n },\n };\n },\n visitor: {\n ImportDeclaration(path, state) {\n extractImportIdentifiers(state.ctx, path);\n },\n CallExpression(path, state) {\n const trueIdentifier = unwrapNode(path.node.callee, t.isIdentifier);\n if (trueIdentifier) {\n const binding = path.scope.getBindingIdentifier(trueIdentifier.name);\n if (binding) {\n const targetName = checkValidIdentifierImport(state.ctx, binding);\n if (targetName) {\n runTransform(path, targetName);\n }\n }\n return;\n }\n const trueMemberExpr = unwrapNode(path.node.callee, t.isMemberExpression);\n if (\n trueMemberExpr\n && t.isIdentifier(trueMemberExpr.property)\n && !trueMemberExpr.computed\n ) {\n const source = unwrapNode(trueMemberExpr.object, t.isIdentifier);\n if (source) {\n const targetName = trueMemberExpr.property.name;\n const binding = path.scope.getBindingIdentifier(source.name);\n if (binding && checkValidNamespaceImport(state.ctx, binding, targetName)) {\n runTransform(path, targetName);\n }\n }\n }\n },\n },\n };\n}\n", "import * as t from '@babel/types';\n\ntype TypeCheck<K> =\n K extends (node: t.Node) => node is (infer U extends t.Node)\n ? U\n : never;\n\ntype TypeFilter = (node: t.Node) => boolean;\n\nexport default function unwrapNode<K extends TypeFilter>(\n node: t.Node,\n key: K,\n): TypeCheck<K> | undefined {\n if (key(node)) {\n return node as TypeCheck<K>;\n }\n if (\n t.isParenthesizedExpression(node)\n || t.isTypeCastExpression(node)\n || t.isTSAsExpression(node)\n || t.isTSSatisfiesExpression(node)\n || t.isTSNonNullExpression(node)\n || t.isTSTypeAssertion(node)\n || t.isTSInstantiationExpression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,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
3
+ "sources": ["../../../src/index.ts", "../../../src/path-references-import.ts", "../../../src/checks.ts", "../../../src/unwrap-path.ts", "../../../src/unwrap-node.ts"],
4
+ "sourcesContent": ["import type { NodePath, PluginObj } from '@babel/core';\nimport * as t from '@babel/types';\nimport { pathReferencesImport } from './path-references-import';\nimport unwrapNode from './unwrap-node';\n\nfunction transformUntrackAndBatch(path: NodePath<t.CallExpression>): void {\n // https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L130-L134\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);\n if (trueArrow) {\n if (t.isExpression(trueArrow.body)) {\n path.replaceWith(trueArrow.body);\n } else {\n path.replaceWith(t.callExpression(trueArrow, []));\n }\n return;\n }\n const trueFunc = unwrapNode(arg, t.isFunctionExpression);\n if (trueFunc) {\n path.replaceWith(trueFunc.body);\n }\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.callExpression(\n t.memberExpression(arg.argument, t.numericLiteral(0), true),\n [],\n ),\n );\n }\n}\n\nfunction transformStartTransition(path: NodePath<t.CallExpression>): void {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/rendering.ts#L488\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);\n if (trueArrow) {\n if (t.isExpression(trueArrow.body)) {\n path.replaceWith(trueArrow.body);\n } else {\n path.replaceWith(t.callExpression(trueArrow, []));\n }\n return;\n }\n const trueFunc = unwrapNode(arg, t.isFunctionExpression);\n if (trueFunc) {\n path.replaceWith(trueFunc.body);\n }\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.callExpression(\n t.memberExpression(arg.argument, t.numericLiteral(0), true),\n [],\n ),\n );\n }\n}\n\nfunction transformCreateDeferred(path: NodePath<t.CallExpression>): void {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L99\n const arg = path.node.arguments[0];\n if (t.isExpression(arg)) {\n path.replaceWith(arg);\n } else if (t.isSpreadElement(arg)) {\n path.replaceWith(\n t.memberExpression(arg.argument, t.numericLiteral(0), true),\n );\n }\n}\n\nconst MODULES = ['solid-js', 'solid-js/web'];\n\nfunction transformCallExpression(path: NodePath<t.CallExpression>): void {\n const callee = path.get('callee');\n\n if (pathReferencesImport(callee, MODULES, ['createEffect', 'onMount'])) {\n // https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L101\n // https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L154\n // Just remove it\n path.remove();\n } else if (pathReferencesImport(callee, MODULES, ['getListener'])) {\n // https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L188\n path.replaceWith(t.nullLiteral());\n } else if (pathReferencesImport(callee, MODULES, ['untrack', 'batch'])) {\n transformUntrackAndBatch(path);\n } else if (pathReferencesImport(callee, MODULES, ['startTransition'])) {\n transformStartTransition(path);\n } else if (pathReferencesImport(callee, MODULES, ['createDeferred'])) {\n transformCreateDeferred(path);\n }\n}\n\nexport default function solidOptimizerPlugin(): PluginObj {\n return {\n name: 'solid-optimizer',\n visitor: {\n Program(program) {\n program.traverse({\n CallExpression(path): void {\n transformCallExpression(path);\n },\n });\n },\n },\n };\n}\n", "import type { NodePath } from '@babel/core';\nimport * as t from '@babel/types';\nimport { isPathValid } from './checks';\nimport unwrapPath from './unwrap-path';\n\nfunction pathReferencesImportIdentifier(\n path: NodePath,\n moduleSources: string[],\n importNames: string[],\n): boolean {\n const identifier = unwrapPath(path, t.isIdentifier);\n if (!identifier) {\n return false;\n }\n const binding = path.scope.getBinding(identifier.node.name);\n if (!binding || binding.kind !== 'module') {\n return false;\n }\n const importPath = binding.path;\n const importParent = importPath.parentPath;\n if (\n isPathValid(importParent, t.isImportDeclaration) &&\n moduleSources.includes(importParent.node.source.value)\n ) {\n if (isPathValid(importPath, t.isImportSpecifier)) {\n const key = t.isIdentifier(importPath.node.imported)\n ? importPath.node.imported.name\n : importPath.node.imported.value;\n return importNames.includes(key);\n }\n if (isPathValid(importPath, t.isImportDefaultSpecifier)) {\n return importNames.includes('default');\n }\n if (isPathValid(importPath, t.isImportNamespaceSpecifier)) {\n return importNames.includes('*');\n }\n }\n return false;\n}\n\nconst IMPORT_NAMESPACE = ['*'];\n\nfunction pathReferencesImportMember(\n path: NodePath,\n moduleSources: string[],\n importNames: string[],\n): boolean {\n const memberExpr =\n unwrapPath(path, t.isMemberExpression) ||\n unwrapPath(path, t.isOptionalMemberExpression);\n if (memberExpr) {\n const object = unwrapPath(memberExpr.get('object'), t.isIdentifier);\n if (!object) {\n return false;\n }\n const property = memberExpr.get('property');\n if (isPathValid(property, t.isIdentifier)) {\n return (\n importNames.includes(property.node.name) &&\n pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE)\n );\n }\n if (isPathValid(property, t.isStringLiteral)) {\n return (\n importNames.includes(property.node.value) &&\n pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE)\n );\n }\n }\n return false;\n}\n\nexport function pathReferencesImport(\n path: NodePath,\n moduleSources: string[],\n importNames: string[],\n): boolean {\n return (\n pathReferencesImportIdentifier(path, moduleSources, importNames) ||\n pathReferencesImportMember(path, moduleSources, importNames)\n );\n}\n", "import type * as babel from '@babel/core';\nimport type * as t from '@babel/types';\n\nexport function getImportSpecifierKey(specifier: t.ImportSpecifier): string {\n if (specifier.imported.type === 'Identifier') {\n return specifier.imported.name;\n }\n return specifier.imported.value;\n}\n\ntype TypeFilter<V extends t.Node> = (node: t.Node) => node is V;\n\nexport function isPathValid<V extends t.Node>(\n path: unknown,\n key: TypeFilter<V>,\n): path is babel.NodePath<V> {\n return key((path as babel.NodePath).node);\n}\n\nexport type NestedExpression =\n | t.ParenthesizedExpression\n | t.TypeCastExpression\n | t.TSAsExpression\n | t.TSSatisfiesExpression\n | t.TSNonNullExpression\n | t.TSInstantiationExpression\n | t.TSTypeAssertion;\n\nexport function isNestedExpression(node: t.Node): node is NestedExpression {\n switch (node.type) {\n case 'ParenthesizedExpression':\n case 'TypeCastExpression':\n case 'TSAsExpression':\n case 'TSSatisfiesExpression':\n case 'TSNonNullExpression':\n case 'TSTypeAssertion':\n case 'TSInstantiationExpression':\n return true;\n default:\n return false;\n }\n}", "import type * as babel from '@babel/core';\nimport type * as t from '@babel/types';\nimport { isNestedExpression, isPathValid } from './checks';\n\ntype TypeFilter<V extends t.Node> = (node: t.Node) => node is V;\n\nexport default function unwrapPath<V extends t.Node>(\n path: unknown,\n key: TypeFilter<V>,\n): babel.NodePath<V> | undefined {\n if (isPathValid(path, key)) {\n return path;\n }\n if (isPathValid(path, isNestedExpression)) {\n return unwrapPath(path.get('expression'), key);\n }\n return undefined;\n}\n", "import type * as t from '@babel/types';\n\ntype BroadTypeFilter<K extends t.Node> = (node: t.Node) => node is K;\ntype TypeCheck<K> = K extends BroadTypeFilter<infer U> ? U : never;\n\ntype TypeFilter = (node: t.Node) => boolean;\n\nexport default function unwrapNode<K extends TypeFilter>(\n node: t.Node,\n key: K,\n): TypeCheck<K> | undefined {\n if (key(node)) {\n return node as TypeCheck<K>;\n }\n switch (node.type) {\n case 'ParenthesizedExpression':\n case 'TypeCastExpression':\n case 'TSAsExpression':\n case 'TSSatisfiesExpression':\n case 'TSNonNullExpression':\n case 'TSTypeAssertion':\n case 'TSInstantiationExpression':\n return unwrapNode(node.expression, key);\n default:\n return undefined;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,KAAmB;;;ACAnB,QAAmB;;;ACWZ,SAAS,YACd,MACA,KAC2B;AAC3B,SAAO,IAAK,KAA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AAQ;AAEhC,MAAI,qBAAqB,QAAQ,SAAS,CAAC,gBAAgB,SAAS,CAAC,GAAG;AAItE,SAAK,OAAO;AAAA,EACd,WAAW,qBAAqB,QAAQ,SAAS,CAAC,aAAa,CAAC,GAAG;AAEjE,SAAK,YAAc,eAAY,CAAC;AAAA,EAClC,WAAW,qBAAqB,QAAQ,SAAS,CAAC,WAAW,OAAO,CAAC,GAAG;AACtE,6BAAyB,IAAI;AAAA,EAC/B,WAAW,qBAAqB,QAAQ,SAAS,CAAC,iBAAiB,CAAC,GAAG;AACrE,6BAAyB,IAAI;AAAA,EAC/B,WAAW,qBAAqB,QAAQ,SAAS,CAAC,gBAAgB,CAAC,GAAG;AACpE,4BAAwB,IAAI;AAAA,EAC9B;AACF;AAEe,SAAR,uBAAmD;AACxD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,QAAQ,SAAS;AACf,gBAAQ,SAAS;AAAA,UACf,eAAe,MAAY;AACzB,oCAAwB,IAAI;AAAA,UAC9B;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": ["t"]
7
7
  }
@@ -1 +1 @@
1
- "use strict";var b=Object.create;var u=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var n in t)u(e,n,{get:t[n],enumerable:!0})},m=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of w(t))!y.call(e,s)&&s!==n&&u(e,s,{get:()=>t[s],enumerable:!(i=g(t,s))||i.enumerable});return e};var x=(e,t,n)=>(n=e!=null?b(k(e)):{},m(t||!e||!e.__esModule?u(n,"default",{value:e,enumerable:!0}):n,e)),N=e=>m(u({},"__esModule",{value:!0}),e);var O={};I(O,{default:()=>S});module.exports=N(O);var r=x(require("@babel/types"),1);var o=x(require("@babel/types"),1);function a(e,t){if(t(e))return e;if(o.isParenthesizedExpression(e)||o.isTypeCastExpression(e)||o.isTSAsExpression(e)||o.isTSSatisfiesExpression(e)||o.isTSNonNullExpression(e)||o.isTSTypeAssertion(e)||o.isTSInstantiationExpression(e))return a(e.expression,t)}var l={"solid-js":{createEffect:!0,onMount:!0,getListener:!0,untrack:!0,batch:!0,startTransition:!0,createDeferred:!0},"solid-js/web":{createEffect:!0,onMount:!0,getListener:!0,untrack:!0,batch:!0,startTransition:!0,createDeferred:!0}},d=new Set(Object.keys(l));function C(e,t){return r.isIdentifier(e.imported)&&e.imported.name===t||r.isStringLiteral(e.imported)&&e.imported.value===t}function T(e,t){if(d.has(t.node.source.value)){let n=t.node.source.value;for(let i=0,s=t.node.specifiers.length;i<s;i+=1){let c=t.node.specifiers[i];if(r.isImportSpecifier(c)){let f=l[n];for(let p of Object.keys(f))C(c,p)&&e.identifiers[n][p].add(c.local)}else r.isImportNamespaceSpecifier(c)&&e.namespaces[n].add(c.local)}}}function P(e,t){for(let n of d){let i=e.identifiers[n];for(let s of Object.keys(i))if(i[s].has(t))return s}}function h(e,t,n){for(let i of d)if(e.namespaces[i].has(t)&&n in l[i])return!0;return!1}function W(e){e.remove()}function L(e){e.remove()}function j(e){e.replaceWith(r.nullLiteral())}function F(e){let t=e.node.arguments[0];if(r.isExpression(t)){let n=a(t,r.isArrowFunctionExpression);if(n){r.isExpression(n.body)?e.replaceWith(n.body):e.replaceWith(r.callExpression(n,[]));return}let i=a(t,r.isFunctionExpression);i&&e.replaceWith(i.body)}else r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function M(e){let t=e.node.arguments[0];if(r.isExpression(t)){let n=a(t,r.isArrowFunctionExpression);if(n){r.isExpression(n.body)?e.replaceWith(n.body):e.replaceWith(r.callExpression(n,[]));return}let i=a(t,r.isFunctionExpression);i&&e.replaceWith(i.body)}else r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function D(e){let t=e.node.arguments[0];if(r.isExpression(t)){let n=a(t,r.isArrowFunctionExpression);if(n){r.isExpression(n.body)?e.replaceWith(n.body):e.replaceWith(r.callExpression(n,[]));return}let i=a(t,r.isFunctionExpression);i&&e.replaceWith(i.body)}else r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function A(e){let t=e.node.arguments[0];r.isExpression(t)?e.replaceWith(t):r.isSpreadElement(t)&&e.replaceWith(r.memberExpression(t.argument,r.numericLiteral(0),!0))}function E(e,t){switch(t){case"createEffect":W(e);break;case"onMount":L(e);break;case"getListener":j(e);break;case"untrack":M(e);break;case"batch":F(e);break;case"startTransition":D(e);break;case"createDeferred":A(e);break;default:break}}function S(){return{name:"solid-optimizer",pre(){this.ctx={hooks:new Map,identifiers:{"solid-js":{createEffect:new Set,onMount:new Set,getListener:new Set,untrack:new Set,batch:new Set,startTransition:new Set,createDeferred:new Set},"solid-js/web":{createEffect:new Set,onMount:new Set,getListener:new Set,untrack:new Set,batch:new Set,startTransition:new Set,createDeferred:new Set}},namespaces:{"solid-js":new Set,"solid-js/web":new Set}}},visitor:{ImportDeclaration(e,t){T(t.ctx,e)},CallExpression(e,t){let n=a(e.node.callee,r.isIdentifier);if(n){let s=e.scope.getBindingIdentifier(n.name);if(s){let c=P(t.ctx,s);c&&E(e,c)}return}let i=a(e.node.callee,r.isMemberExpression);if(i&&r.isIdentifier(i.property)&&!i.computed){let s=a(i.object,r.isIdentifier);if(s){let c=i.property.name,f=e.scope.getBindingIdentifier(s.name);f&&h(t.ctx,f,c)&&E(e,c)}}}}}}
1
+ "use strict";var g=Object.create;var u=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var i in t)u(e,i,{get:t[i],enumerable:!0})},x=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of S(t))!I.call(e,o)&&o!==i&&u(e,o,{get:()=>t[o],enumerable:!(s=P(t,o))||s.enumerable});return e};var E=(e,t,i)=>(i=e!=null?g(h(e)):{},x(t||!e||!e.__esModule?u(i,"default",{value:e,enumerable:!0}):i,e)),F=e=>x(u({},"__esModule",{value:!0}),e);var k={};C(k,{default:()=>T});module.exports=F(k);var r=E(require("@babel/types"),1);var n=E(require("@babel/types"),1);function p(e,t){return t(e.node)}function b(e){switch(e.type){case"ParenthesizedExpression":case"TypeCastExpression":case"TSAsExpression":case"TSSatisfiesExpression":case"TSNonNullExpression":case"TSTypeAssertion":case"TSInstantiationExpression":return!0;default:return!1}}function d(e,t){if(p(e,t))return e;if(p(e,b))return d(e.get("expression"),t)}function v(e,t,i){let s=d(e,n.isIdentifier);if(!s)return!1;let o=e.scope.getBinding(s.node.name);if(!o||o.kind!=="module")return!1;let a=o.path,m=a.parentPath;if(p(m,n.isImportDeclaration)&&t.includes(m.node.source.value)){if(p(a,n.isImportSpecifier)){let N=n.isIdentifier(a.node.imported)?a.node.imported.name:a.node.imported.value;return i.includes(N)}if(p(a,n.isImportDefaultSpecifier))return i.includes("default");if(p(a,n.isImportNamespaceSpecifier))return i.includes("*")}return!1}var y=["*"];function w(e,t,i){let s=d(e,n.isMemberExpression)||d(e,n.isOptionalMemberExpression);if(s){let o=d(s.get("object"),n.isIdentifier);if(!o)return!1;let a=s.get("property");if(p(a,n.isIdentifier))return i.includes(a.node.name)&&l(o,t,y);if(p(a,n.isStringLiteral))return i.includes(a.node.value)&&l(o,t,y)}return!1}function l(e,t,i){return v(e,t,i)||w(e,t,i)}function c(e,t){if(t(e))return e;switch(e.type){case"ParenthesizedExpression":case"TypeCastExpression":case"TSAsExpression":case"TSSatisfiesExpression":case"TSNonNullExpression":case"TSTypeAssertion":case"TSInstantiationExpression":return c(e.expression,t);default:return}}function A(e){let t=e.node.arguments[0];if(r.isExpression(t)){let i=c(t,r.isArrowFunctionExpression);if(i){r.isExpression(i.body)?e.replaceWith(i.body):e.replaceWith(r.callExpression(i,[]));return}let s=c(t,r.isFunctionExpression);s&&e.replaceWith(s.body)}else r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function V(e){let t=e.node.arguments[0];if(r.isExpression(t)){let i=c(t,r.isArrowFunctionExpression);if(i){r.isExpression(i.body)?e.replaceWith(i.body):e.replaceWith(r.callExpression(i,[]));return}let s=c(t,r.isFunctionExpression);s&&e.replaceWith(s.body)}else r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function W(e){let t=e.node.arguments[0];r.isExpression(t)?e.replaceWith(t):r.isSpreadElement(t)&&e.replaceWith(r.memberExpression(t.argument,r.numericLiteral(0),!0))}var f=["solid-js","solid-js/web"];function K(e){let t=e.get("callee");l(t,f,["createEffect","onMount"])?e.remove():l(t,f,["getListener"])?e.replaceWith(r.nullLiteral()):l(t,f,["untrack","batch"])?A(e):l(t,f,["startTransition"])?V(e):l(t,f,["createDeferred"])&&W(e)}function T(){return{name:"solid-optimizer",visitor:{Program(e){e.traverse({CallExpression(t){K(t)}})}}}}