solid-optimizer 0.1.0 → 0.1.2

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/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)
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -30,6 +34,27 @@ __export(src_exports, {
30
34
  });
31
35
  module.exports = __toCommonJS(src_exports);
32
36
  var t = __toESM(require("@babel/types"), 1);
37
+
38
+ // src/unwrap-node.ts
39
+ function unwrapNode(node, key) {
40
+ if (key(node)) {
41
+ return node;
42
+ }
43
+ switch (node.type) {
44
+ case "ParenthesizedExpression":
45
+ case "TypeCastExpression":
46
+ case "TSAsExpression":
47
+ case "TSSatisfiesExpression":
48
+ case "TSNonNullExpression":
49
+ case "TSTypeAssertion":
50
+ case "TSInstantiationExpression":
51
+ return unwrapNode(node.expression, key);
52
+ default:
53
+ return void 0;
54
+ }
55
+ }
56
+
57
+ // src/index.ts
33
58
  var TRACKED = {
34
59
  "solid-js": {
35
60
  createEffect: true,
@@ -39,6 +64,15 @@ var TRACKED = {
39
64
  batch: true,
40
65
  startTransition: true,
41
66
  createDeferred: true
67
+ },
68
+ "solid-js/web": {
69
+ createEffect: true,
70
+ onMount: true,
71
+ getListener: true,
72
+ untrack: true,
73
+ batch: true,
74
+ startTransition: true,
75
+ createDeferred: true
42
76
  }
43
77
  };
44
78
  var MODULES = new Set(Object.keys(TRACKED));
@@ -46,20 +80,21 @@ function isValidSpecifier(specifier, name) {
46
80
  return t.isIdentifier(specifier.imported) && specifier.imported.name === name || t.isStringLiteral(specifier.imported) && specifier.imported.value === name;
47
81
  }
48
82
  function extractImportIdentifiers(ctx, path) {
49
- if (MODULES.has(path.node.source.value)) {
50
- const modulePath = path.node.source.value;
51
- for (let i = 0, len = path.node.specifiers.length; i < len; i += 1) {
52
- const specifier = path.node.specifiers[i];
53
- if (t.isImportSpecifier(specifier)) {
54
- const ids = TRACKED[modulePath];
55
- for (const key of Object.keys(ids)) {
56
- if (isValidSpecifier(specifier, key)) {
57
- ctx.identifiers[modulePath][key].add(specifier.local);
58
- }
83
+ if (!MODULES.has(path.node.source.value)) {
84
+ return;
85
+ }
86
+ const modulePath = path.node.source.value;
87
+ for (let i = 0, len = path.node.specifiers.length; i < len; i += 1) {
88
+ const specifier = path.node.specifiers[i];
89
+ if (t.isImportSpecifier(specifier)) {
90
+ const ids = TRACKED[modulePath];
91
+ for (const key of Object.keys(ids)) {
92
+ if (isValidSpecifier(specifier, key)) {
93
+ ctx.identifiers[modulePath][key].add(specifier.local);
59
94
  }
60
- } else if (t.isImportNamespaceSpecifier(specifier)) {
61
- ctx.namespaces[modulePath].add(specifier.local);
62
95
  }
96
+ } else if (t.isImportNamespaceSpecifier(specifier)) {
97
+ ctx.namespaces[modulePath].add(specifier.local);
63
98
  }
64
99
  }
65
100
  }
@@ -95,19 +130,23 @@ function transformGetListener(path) {
95
130
  function transformBatch(path) {
96
131
  const arg = path.node.arguments[0];
97
132
  if (t.isExpression(arg)) {
98
- if (t.isArrowFunctionExpression(arg) && t.isExpression(arg.body)) {
99
- path.replaceWith(arg.body);
100
- } else {
101
- path.replaceWith(t.callExpression(arg, []));
133
+ const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);
134
+ if (trueArrow) {
135
+ if (t.isExpression(trueArrow.body)) {
136
+ path.replaceWith(trueArrow.body);
137
+ } else {
138
+ path.replaceWith(t.callExpression(trueArrow, []));
139
+ }
140
+ return;
141
+ }
142
+ const trueFunc = unwrapNode(arg, t.isFunctionExpression);
143
+ if (trueFunc) {
144
+ path.replaceWith(trueFunc.body);
102
145
  }
103
146
  } else if (t.isSpreadElement(arg)) {
104
147
  path.replaceWith(
105
148
  t.callExpression(
106
- t.memberExpression(
107
- arg.argument,
108
- t.numericLiteral(0),
109
- true
110
- ),
149
+ t.memberExpression(arg.argument, t.numericLiteral(0), true),
111
150
  []
112
151
  )
113
152
  );
@@ -116,19 +155,23 @@ function transformBatch(path) {
116
155
  function transformUntrack(path) {
117
156
  const arg = path.node.arguments[0];
118
157
  if (t.isExpression(arg)) {
119
- if (t.isArrowFunctionExpression(arg) && t.isExpression(arg.body)) {
120
- path.replaceWith(arg.body);
121
- } else {
122
- path.replaceWith(t.callExpression(arg, []));
158
+ const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);
159
+ if (trueArrow) {
160
+ if (t.isExpression(trueArrow.body)) {
161
+ path.replaceWith(trueArrow.body);
162
+ } else {
163
+ path.replaceWith(t.callExpression(trueArrow, []));
164
+ }
165
+ return;
166
+ }
167
+ const trueFunc = unwrapNode(arg, t.isFunctionExpression);
168
+ if (trueFunc) {
169
+ path.replaceWith(trueFunc.body);
123
170
  }
124
171
  } else if (t.isSpreadElement(arg)) {
125
172
  path.replaceWith(
126
173
  t.callExpression(
127
- t.memberExpression(
128
- arg.argument,
129
- t.numericLiteral(0),
130
- true
131
- ),
174
+ t.memberExpression(arg.argument, t.numericLiteral(0), true),
132
175
  []
133
176
  )
134
177
  );
@@ -137,19 +180,23 @@ function transformUntrack(path) {
137
180
  function transformStartTransition(path) {
138
181
  const arg = path.node.arguments[0];
139
182
  if (t.isExpression(arg)) {
140
- if (t.isArrowFunctionExpression(arg) && t.isExpression(arg.body)) {
141
- path.replaceWith(arg.body);
142
- } else {
143
- path.replaceWith(t.callExpression(arg, []));
183
+ const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);
184
+ if (trueArrow) {
185
+ if (t.isExpression(trueArrow.body)) {
186
+ path.replaceWith(trueArrow.body);
187
+ } else {
188
+ path.replaceWith(t.callExpression(trueArrow, []));
189
+ }
190
+ return;
191
+ }
192
+ const trueFunc = unwrapNode(arg, t.isFunctionExpression);
193
+ if (trueFunc) {
194
+ path.replaceWith(trueFunc.body);
144
195
  }
145
196
  } else if (t.isSpreadElement(arg)) {
146
197
  path.replaceWith(
147
198
  t.callExpression(
148
- t.memberExpression(
149
- arg.argument,
150
- t.numericLiteral(0),
151
- true
152
- ),
199
+ t.memberExpression(arg.argument, t.numericLiteral(0), true),
153
200
  []
154
201
  )
155
202
  );
@@ -161,84 +208,107 @@ function transformCreateDeferred(path) {
161
208
  path.replaceWith(arg);
162
209
  } else if (t.isSpreadElement(arg)) {
163
210
  path.replaceWith(
164
- t.memberExpression(
165
- arg.argument,
166
- t.numericLiteral(0),
167
- true
168
- )
211
+ t.memberExpression(arg.argument, t.numericLiteral(0), true)
169
212
  );
170
213
  }
171
214
  }
172
215
  function runTransform(path, targetName) {
173
216
  switch (targetName) {
174
- case "createEffect":
217
+ case "createEffect": {
175
218
  transformCreateEffect(path);
176
219
  break;
177
- case "onMount":
220
+ }
221
+ case "onMount": {
178
222
  transformOnMount(path);
179
223
  break;
180
- case "getListener":
224
+ }
225
+ case "getListener": {
181
226
  transformGetListener(path);
182
227
  break;
183
- case "untrack":
228
+ }
229
+ case "untrack": {
184
230
  transformUntrack(path);
185
231
  break;
186
- case "batch":
232
+ }
233
+ case "batch": {
187
234
  transformBatch(path);
188
235
  break;
189
- case "startTransition":
236
+ }
237
+ case "startTransition": {
190
238
  transformStartTransition(path);
191
239
  break;
192
- case "createDeferred":
240
+ }
241
+ case "createDeferred": {
193
242
  transformCreateDeferred(path);
194
243
  break;
195
- default:
196
- break;
244
+ }
245
+ }
246
+ }
247
+ function transformCallExpression(ctx, path) {
248
+ const trueIdentifier = unwrapNode(path.node.callee, t.isIdentifier);
249
+ if (trueIdentifier) {
250
+ const binding = path.scope.getBindingIdentifier(trueIdentifier.name);
251
+ if (binding) {
252
+ const targetName = checkValidIdentifierImport(ctx, binding);
253
+ if (targetName) {
254
+ runTransform(path, targetName);
255
+ }
256
+ }
257
+ return;
258
+ }
259
+ const trueMemberExpr = unwrapNode(path.node.callee, t.isMemberExpression);
260
+ if (trueMemberExpr && t.isIdentifier(trueMemberExpr.property) && !trueMemberExpr.computed) {
261
+ const source = unwrapNode(trueMemberExpr.object, t.isIdentifier);
262
+ if (source) {
263
+ const targetName = trueMemberExpr.property.name;
264
+ const binding = path.scope.getBindingIdentifier(source.name);
265
+ if (binding && checkValidNamespaceImport(ctx, binding, targetName)) {
266
+ runTransform(path, targetName);
267
+ }
268
+ }
197
269
  }
198
270
  }
199
271
  function solidOptimizerPlugin() {
200
272
  return {
201
273
  name: "solid-optimizer",
202
- pre() {
203
- this.ctx = {
204
- hooks: /* @__PURE__ */ new Map(),
205
- identifiers: {
206
- "solid-js": {
207
- createEffect: /* @__PURE__ */ new Set(),
208
- onMount: /* @__PURE__ */ new Set(),
209
- getListener: /* @__PURE__ */ new Set(),
210
- untrack: /* @__PURE__ */ new Set(),
211
- batch: /* @__PURE__ */ new Set(),
212
- startTransition: /* @__PURE__ */ new Set(),
213
- createDeferred: /* @__PURE__ */ new Set()
214
- }
215
- },
216
- namespaces: {
217
- "solid-js": /* @__PURE__ */ new Set()
218
- }
219
- };
220
- },
221
274
  visitor: {
222
- ImportDeclaration(path, state) {
223
- extractImportIdentifiers(state.ctx, path);
224
- },
225
- CallExpression(path, state) {
226
- const { callee } = path.node;
227
- if (t.isIdentifier(callee)) {
228
- const binding = path.scope.getBindingIdentifier(callee.name);
229
- if (binding) {
230
- const targetName = checkValidIdentifierImport(state.ctx, binding);
231
- if (targetName) {
232
- runTransform(path, targetName);
275
+ Program(program) {
276
+ const ctx = {
277
+ identifiers: {
278
+ "solid-js": {
279
+ createEffect: /* @__PURE__ */ new Set(),
280
+ onMount: /* @__PURE__ */ new Set(),
281
+ getListener: /* @__PURE__ */ new Set(),
282
+ untrack: /* @__PURE__ */ new Set(),
283
+ batch: /* @__PURE__ */ new Set(),
284
+ startTransition: /* @__PURE__ */ new Set(),
285
+ createDeferred: /* @__PURE__ */ new Set()
286
+ },
287
+ "solid-js/web": {
288
+ createEffect: /* @__PURE__ */ new Set(),
289
+ onMount: /* @__PURE__ */ new Set(),
290
+ getListener: /* @__PURE__ */ new Set(),
291
+ untrack: /* @__PURE__ */ new Set(),
292
+ batch: /* @__PURE__ */ new Set(),
293
+ startTransition: /* @__PURE__ */ new Set(),
294
+ createDeferred: /* @__PURE__ */ new Set()
233
295
  }
296
+ },
297
+ namespaces: {
298
+ "solid-js": /* @__PURE__ */ new Set(),
299
+ "solid-js/web": /* @__PURE__ */ new Set()
234
300
  }
235
- } else if (t.isMemberExpression(callee) && t.isIdentifier(callee.object) && t.isIdentifier(callee.property) && !callee.computed) {
236
- const targetName = callee.property.name;
237
- const binding = path.scope.getBindingIdentifier(callee.object.name);
238
- if (binding && checkValidNamespaceImport(state.ctx, binding, targetName)) {
239
- runTransform(path, targetName);
301
+ };
302
+ program.traverse({
303
+ ImportDeclaration(path) {
304
+ extractImportIdentifiers(ctx, path);
240
305
  }
241
- }
306
+ });
307
+ program.traverse({
308
+ CallExpression(path) {
309
+ transformCallExpression(ctx, path);
310
+ }
311
+ });
242
312
  }
243
313
  }
244
314
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/index.ts"],
4
- "sourcesContent": ["import { NodePath, PluginObj, PluginPass } from '@babel/core';\nimport * as t from '@babel/types';\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};\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 if (t.isArrowFunctionExpression(arg) && t.isExpression(arg.body)) {\n path.replaceWith(arg.body);\n } else {\n path.replaceWith(t.callExpression(arg, []));\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 if (t.isArrowFunctionExpression(arg) && t.isExpression(arg.body)) {\n path.replaceWith(arg.body);\n } else {\n path.replaceWith(t.callExpression(arg, []));\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 if (t.isArrowFunctionExpression(arg) && t.isExpression(arg.body)) {\n path.replaceWith(arg.body);\n } else {\n path.replaceWith(t.callExpression(arg, []));\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 },\n namespaces: {\n 'solid-js': new Set(),\n },\n };\n },\n visitor: {\n ImportDeclaration(path, state) {\n extractImportIdentifiers(state.ctx, path);\n },\n CallExpression(path, state) {\n const { callee } = path.node;\n if (t.isIdentifier(callee)) {\n const binding = path.scope.getBindingIdentifier(callee.name);\n if (binding) {\n const targetName = checkValidIdentifierImport(state.ctx, binding);\n if (targetName) {\n runTransform(path, targetName);\n }\n }\n } else if (\n t.isMemberExpression(callee)\n && t.isIdentifier(callee.object)\n && t.isIdentifier(callee.property)\n && !callee.computed\n ) {\n const targetName = callee.property.name;\n const binding = path.scope.getBindingIdentifier(callee.object.name);\n if (binding && checkValidNamespaceImport(state.ctx, binding, targetName)) {\n runTransform(path, targetName);\n }\n }\n },\n },\n };\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;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A,YACV,cAAc,oBAAI,IAAI;AAAA,YACtB,SAAS,oBAAI,IAAI;AAAA,YACjB,aAAa,oBAAI,IAAI;AAAA,YACrB,SAAS,oBAAI,IAAI;AAAA,YACjB,OAAO,oBAAI,IAAI;AAAA,YACf,iBAAiB,oBAAI,IAAI;AAAA,YACzB,gBAAgB,oBAAI,IAAI;AAAA,UAC1B;AAAA,QACF;AAAA,QACA,YAAY;AAAA,UACV,YAAY,oBAAI,IAAI;AAAA,QACtB;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,kBAAkB,MAAM,OAAO;AAC7B,iCAAyB,MAAM,KAAK,IAAI;AAAA,MAC1C;AAAA,MACA,eAAe,MAAM,OAAO;AAC1B,cAAM,EAAE,OAAO,IAAI,KAAK;AACxB,YAAM,eAAa,MAAM,GAAG;AAC1B,gBAAM,UAAU,KAAK,MAAM,qBAAqB,OAAO,IAAI;AAC3D,cAAI,SAAS;AACX,kBAAM,aAAa,2BAA2B,MAAM,KAAK,OAAO;AAChE,gBAAI,YAAY;AACd,2BAAa,MAAM,UAAU;AAAA,YAC/B;AAAA,UACF;AAAA,QACF,WACI,qBAAmB,MAAM,KACtB,eAAa,OAAO,MAAM,KAC1B,eAAa,OAAO,QAAQ,KAC9B,CAAC,OAAO,UACX;AACA,gBAAM,aAAa,OAAO,SAAS;AACnC,gBAAM,UAAU,KAAK,MAAM,qBAAqB,OAAO,OAAO,IAAI;AAClE,cAAI,WAAW,0BAA0B,MAAM,KAAK,SAAS,UAAU,GAAG;AACxE,yBAAa,MAAM,UAAU;AAAA,UAC/B;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
3
+ "sources": ["../../../src/index.ts", "../../../src/unwrap-node.ts"],
4
+ "sourcesContent": ["import type { 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 identifiers: Record<string, Record<string, Set<t.Identifier>>>;\n namespaces: Record<string, Set<t.Identifier>>;\n}\n\nfunction isValidSpecifier(specifier: t.ImportSpecifier, name: string): 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): void {\n if (!MODULES.has(path.node.source.value)) {\n return;\n }\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\nfunction checkValidIdentifierImport(\n ctx: StateContext,\n identifier: t.Identifier,\n): string | undefined {\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): boolean {\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(path: NodePath<t.CallExpression>): void {\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(path: NodePath<t.CallExpression>): void {\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(path: NodePath<t.CallExpression>): void {\n // https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L157\n path.replaceWith(t.nullLiteral());\n}\n\nfunction transformBatch(path: NodePath<t.CallExpression>): void {\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(arg.argument, t.numericLiteral(0), true),\n [],\n ),\n );\n }\n}\n\nfunction transformUntrack(path: NodePath<t.CallExpression>): void {\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(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\ninterface State extends PluginPass {\n ctx: StateContext;\n}\n\nfunction runTransform(\n path: NodePath<t.CallExpression>,\n targetName: string,\n): void {\n switch (targetName) {\n case 'createEffect': {\n transformCreateEffect(path);\n break;\n }\n case 'onMount': {\n transformOnMount(path);\n break;\n }\n case 'getListener': {\n transformGetListener(path);\n break;\n }\n case 'untrack': {\n transformUntrack(path);\n break;\n }\n case 'batch': {\n transformBatch(path);\n break;\n }\n case 'startTransition': {\n transformStartTransition(path);\n break;\n }\n case 'createDeferred': {\n transformCreateDeferred(path);\n break;\n }\n }\n}\n\nfunction transformCallExpression(\n ctx: StateContext,\n path: NodePath<t.CallExpression>,\n): void {\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(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(ctx, binding, targetName)) {\n runTransform(path, targetName);\n }\n }\n }\n}\n\nexport default function solidOptimizerPlugin(): PluginObj<State> {\n return {\n name: 'solid-optimizer',\n visitor: {\n Program(program) {\n const ctx: StateContext = {\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 program.traverse({\n ImportDeclaration(path): void {\n extractImportIdentifiers(ctx, path);\n },\n });\n program.traverse({\n CallExpression(path): void {\n transformCallExpression(ctx, path);\n },\n });\n },\n },\n };\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;A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B,KAAK,IAAI;AAAA,UACnC;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- "use strict";var x=Object.create;var a=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var i in t)a(e,i,{get:t[i],enumerable:!0})},d=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!S.call(e,s)&&s!==i&&a(e,s,{get:()=>t[s],enumerable:!(n=E(t,s))||n.enumerable});return e};var I=(e,t,i)=>(i=e!=null?x(b(e)):{},d(t||!e||!e.__esModule?a(i,"default",{value:e,enumerable:!0}):i,e)),P=e=>d(a({},"__esModule",{value:!0}),e);var v={};k(v,{default:()=>u});module.exports=P(v);var r=I(require("@babel/types"),1),c={"solid-js":{createEffect:!0,onMount:!0,getListener:!0,untrack:!0,batch:!0,startTransition:!0,createDeferred:!0}},l=new Set(Object.keys(c));function C(e,t){return r.isIdentifier(e.imported)&&e.imported.name===t||r.isStringLiteral(e.imported)&&e.imported.value===t}function w(e,t){if(l.has(t.node.source.value)){let i=t.node.source.value;for(let n=0,s=t.node.specifiers.length;n<s;n+=1){let o=t.node.specifiers[n];if(r.isImportSpecifier(o)){let p=c[i];for(let f of Object.keys(p))C(o,f)&&e.identifiers[i][f].add(o.local)}else r.isImportNamespaceSpecifier(o)&&e.namespaces[i].add(o.local)}}}function N(e,t){for(let i of l){let n=e.identifiers[i];for(let s of Object.keys(n))if(n[s].has(t))return s}}function h(e,t,i){for(let n of l)if(e.namespaces[n].has(t)&&i in c[n])return!0;return!1}function y(e){e.remove()}function W(e){e.remove()}function L(e){e.replaceWith(r.nullLiteral())}function j(e){let t=e.node.arguments[0];r.isExpression(t)?r.isArrowFunctionExpression(t)&&r.isExpression(t.body)?e.replaceWith(t.body):e.replaceWith(r.callExpression(t,[])):r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function D(e){let t=e.node.arguments[0];r.isExpression(t)?r.isArrowFunctionExpression(t)&&r.isExpression(t.body)?e.replaceWith(t.body):e.replaceWith(r.callExpression(t,[])):r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function M(e){let t=e.node.arguments[0];r.isExpression(t)?r.isArrowFunctionExpression(t)&&r.isExpression(t.body)?e.replaceWith(t.body):e.replaceWith(r.callExpression(t,[])):r.isSpreadElement(t)&&e.replaceWith(r.callExpression(r.memberExpression(t.argument,r.numericLiteral(0),!0),[]))}function O(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 m(e,t){switch(t){case"createEffect":y(e);break;case"onMount":W(e);break;case"getListener":L(e);break;case"untrack":D(e);break;case"batch":j(e);break;case"startTransition":M(e);break;case"createDeferred":O(e);break;default:break}}function u(){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}},namespaces:{"solid-js":new Set}}},visitor:{ImportDeclaration(e,t){w(t.ctx,e)},CallExpression(e,t){let{callee:i}=e.node;if(r.isIdentifier(i)){let n=e.scope.getBindingIdentifier(i.name);if(n){let s=N(t.ctx,n);s&&m(e,s)}}else if(r.isMemberExpression(i)&&r.isIdentifier(i.object)&&r.isIdentifier(i.property)&&!i.computed){let n=i.property.name,s=e.scope.getBindingIdentifier(i.object.name);s&&h(t.ctx,s,n)&&m(e,n)}}}}}
1
+ "use strict";var E=Object.create;var d=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var w=(e,t)=>{for(var n in t)d(e,n,{get:t[n],enumerable:!0})},p=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of S(t))!y.call(e,s)&&s!==n&&d(e,s,{get:()=>t[s],enumerable:!(i=b(t,s))||i.enumerable});return e};var C=(e,t,n)=>(n=e!=null?E(g(e)):{},p(t||!e||!e.__esModule?d(n,"default",{value:e,enumerable:!0}):n,e)),N=e=>p(d({},"__esModule",{value:!0}),e);var K={};w(K,{default:()=>x});module.exports=N(K);var r=C(require("@babel/types"),1);function o(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 o(e.expression,t);default:return}}var f={"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}},l=new Set(Object.keys(f));function k(e,t){return r.isIdentifier(e.imported)&&e.imported.name===t||r.isStringLiteral(e.imported)&&e.imported.value===t}function I(e,t){if(!l.has(t.node.source.value))return;let n=t.node.source.value;for(let i=0,s=t.node.specifiers.length;i<s;i+=1){let a=t.node.specifiers[i];if(r.isImportSpecifier(a)){let c=f[n];for(let u of Object.keys(c))k(a,u)&&e.identifiers[n][u].add(a.local)}else r.isImportNamespaceSpecifier(a)&&e.namespaces[n].add(a.local)}}function T(e,t){for(let n of l){let i=e.identifiers[n];for(let s of Object.keys(i))if(i[s].has(t))return s}}function v(e,t,n){for(let i of l)if(e.namespaces[i].has(t)&&n in f[i])return!0;return!1}function P(e){e.remove()}function h(e){e.remove()}function W(e){e.replaceWith(r.nullLiteral())}function F(e){let t=e.node.arguments[0];if(r.isExpression(t)){let n=o(t,r.isArrowFunctionExpression);if(n){r.isExpression(n.body)?e.replaceWith(n.body):e.replaceWith(r.callExpression(n,[]));return}let i=o(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 L(e){let t=e.node.arguments[0];if(r.isExpression(t)){let n=o(t,r.isArrowFunctionExpression);if(n){r.isExpression(n.body)?e.replaceWith(n.body):e.replaceWith(r.callExpression(n,[]));return}let i=o(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 j(e){let t=e.node.arguments[0];if(r.isExpression(t)){let n=o(t,r.isArrowFunctionExpression);if(n){r.isExpression(n.body)?e.replaceWith(n.body):e.replaceWith(r.callExpression(n,[]));return}let i=o(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];r.isExpression(t)?e.replaceWith(t):r.isSpreadElement(t)&&e.replaceWith(r.memberExpression(t.argument,r.numericLiteral(0),!0))}function m(e,t){switch(t){case"createEffect":{P(e);break}case"onMount":{h(e);break}case"getListener":{W(e);break}case"untrack":{L(e);break}case"batch":{F(e);break}case"startTransition":{j(e);break}case"createDeferred":{D(e);break}}}function A(e,t){let n=o(t.node.callee,r.isIdentifier);if(n){let s=t.scope.getBindingIdentifier(n.name);if(s){let a=T(e,s);a&&m(t,a)}return}let i=o(t.node.callee,r.isMemberExpression);if(i&&r.isIdentifier(i.property)&&!i.computed){let s=o(i.object,r.isIdentifier);if(s){let a=i.property.name,c=t.scope.getBindingIdentifier(s.name);c&&v(e,c,a)&&m(t,a)}}}function x(){return{name:"solid-optimizer",visitor:{Program(e){let t={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}};e.traverse({ImportDeclaration(n){I(t,n)}}),e.traverse({CallExpression(n){A(t,n)}})}}}}