solid-optimizer 0.1.2 → 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.
@@ -1,11 +1,14 @@
1
1
  // src/index.ts
2
+ import * as t2 from "@babel/types";
3
+
4
+ // src/path-references-import.ts
2
5
  import * as t from "@babel/types";
3
6
 
4
- // src/unwrap-node.ts
5
- function unwrapNode(node, key) {
6
- if (key(node)) {
7
- return node;
8
- }
7
+ // src/checks.ts
8
+ function isPathValid(path, key) {
9
+ return key(path.node);
10
+ }
11
+ function isNestedExpression(node) {
9
12
  switch (node.type) {
10
13
  case "ParenthesizedExpression":
11
14
  case "TypeCastExpression":
@@ -14,130 +17,111 @@ function unwrapNode(node, key) {
14
17
  case "TSNonNullExpression":
15
18
  case "TSTypeAssertion":
16
19
  case "TSInstantiationExpression":
17
- return unwrapNode(node.expression, key);
20
+ return true;
18
21
  default:
19
- return void 0;
22
+ return false;
20
23
  }
21
24
  }
22
25
 
23
- // src/index.ts
24
- var TRACKED = {
25
- "solid-js": {
26
- createEffect: true,
27
- onMount: true,
28
- getListener: true,
29
- untrack: true,
30
- batch: true,
31
- startTransition: true,
32
- createDeferred: true
33
- },
34
- "solid-js/web": {
35
- createEffect: true,
36
- onMount: true,
37
- getListener: true,
38
- untrack: true,
39
- batch: true,
40
- startTransition: true,
41
- createDeferred: true
26
+ // src/unwrap-path.ts
27
+ function unwrapPath(path, key) {
28
+ if (isPathValid(path, key)) {
29
+ return path;
42
30
  }
43
- };
44
- var MODULES = new Set(Object.keys(TRACKED));
45
- function isValidSpecifier(specifier, name) {
46
- return t.isIdentifier(specifier.imported) && specifier.imported.name === name || t.isStringLiteral(specifier.imported) && specifier.imported.value === name;
31
+ if (isPathValid(path, isNestedExpression)) {
32
+ return unwrapPath(path.get("expression"), key);
33
+ }
34
+ return void 0;
47
35
  }
48
- function extractImportIdentifiers(ctx, path) {
49
- if (!MODULES.has(path.node.source.value)) {
50
- return;
36
+
37
+ // src/path-references-import.ts
38
+ function pathReferencesImportIdentifier(path, moduleSources, importNames) {
39
+ const identifier = unwrapPath(path, t.isIdentifier);
40
+ if (!identifier) {
41
+ return false;
51
42
  }
52
- const modulePath = path.node.source.value;
53
- for (let i = 0, len = path.node.specifiers.length; i < len; i += 1) {
54
- const specifier = path.node.specifiers[i];
55
- if (t.isImportSpecifier(specifier)) {
56
- const ids = TRACKED[modulePath];
57
- for (const key of Object.keys(ids)) {
58
- if (isValidSpecifier(specifier, key)) {
59
- ctx.identifiers[modulePath][key].add(specifier.local);
60
- }
61
- }
62
- } else if (t.isImportNamespaceSpecifier(specifier)) {
63
- ctx.namespaces[modulePath].add(specifier.local);
64
- }
43
+ const binding = path.scope.getBinding(identifier.node.name);
44
+ if (!binding || binding.kind !== "module") {
45
+ return false;
65
46
  }
66
- }
67
- function checkValidIdentifierImport(ctx, identifier) {
68
- for (const mod of MODULES) {
69
- const identifiers = ctx.identifiers[mod];
70
- for (const key of Object.keys(identifiers)) {
71
- if (identifiers[key].has(identifier)) {
72
- return key;
73
- }
47
+ const importPath = binding.path;
48
+ const importParent = importPath.parentPath;
49
+ if (isPathValid(importParent, t.isImportDeclaration) && moduleSources.includes(importParent.node.source.value)) {
50
+ if (isPathValid(importPath, t.isImportSpecifier)) {
51
+ const key = t.isIdentifier(importPath.node.imported) ? importPath.node.imported.name : importPath.node.imported.value;
52
+ return importNames.includes(key);
53
+ }
54
+ if (isPathValid(importPath, t.isImportDefaultSpecifier)) {
55
+ return importNames.includes("default");
56
+ }
57
+ if (isPathValid(importPath, t.isImportNamespaceSpecifier)) {
58
+ return importNames.includes("*");
74
59
  }
75
60
  }
76
- return void 0;
61
+ return false;
77
62
  }
78
- function checkValidNamespaceImport(ctx, object, property) {
79
- for (const mod of MODULES) {
80
- const namespace = ctx.namespaces[mod];
81
- if (namespace.has(object) && property in TRACKED[mod]) {
82
- return true;
63
+ var IMPORT_NAMESPACE = ["*"];
64
+ function pathReferencesImportMember(path, moduleSources, importNames) {
65
+ const memberExpr = unwrapPath(path, t.isMemberExpression) || unwrapPath(path, t.isOptionalMemberExpression);
66
+ if (memberExpr) {
67
+ const object = unwrapPath(memberExpr.get("object"), t.isIdentifier);
68
+ if (!object) {
69
+ return false;
70
+ }
71
+ const property = memberExpr.get("property");
72
+ if (isPathValid(property, t.isIdentifier)) {
73
+ return importNames.includes(property.node.name) && pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE);
74
+ }
75
+ if (isPathValid(property, t.isStringLiteral)) {
76
+ return importNames.includes(property.node.value) && pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE);
83
77
  }
84
78
  }
85
79
  return false;
86
80
  }
87
- function transformCreateEffect(path) {
88
- path.remove();
89
- }
90
- function transformOnMount(path) {
91
- path.remove();
92
- }
93
- function transformGetListener(path) {
94
- path.replaceWith(t.nullLiteral());
81
+ function pathReferencesImport(path, moduleSources, importNames) {
82
+ return pathReferencesImportIdentifier(path, moduleSources, importNames) || pathReferencesImportMember(path, moduleSources, importNames);
95
83
  }
96
- function transformBatch(path) {
97
- const arg = path.node.arguments[0];
98
- if (t.isExpression(arg)) {
99
- const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);
100
- if (trueArrow) {
101
- if (t.isExpression(trueArrow.body)) {
102
- path.replaceWith(trueArrow.body);
103
- } else {
104
- path.replaceWith(t.callExpression(trueArrow, []));
105
- }
106
- return;
107
- }
108
- const trueFunc = unwrapNode(arg, t.isFunctionExpression);
109
- if (trueFunc) {
110
- path.replaceWith(trueFunc.body);
111
- }
112
- } else if (t.isSpreadElement(arg)) {
113
- path.replaceWith(
114
- t.callExpression(
115
- t.memberExpression(arg.argument, t.numericLiteral(0), true),
116
- []
117
- )
118
- );
84
+
85
+ // src/unwrap-node.ts
86
+ function unwrapNode(node, key) {
87
+ if (key(node)) {
88
+ return node;
89
+ }
90
+ switch (node.type) {
91
+ case "ParenthesizedExpression":
92
+ case "TypeCastExpression":
93
+ case "TSAsExpression":
94
+ case "TSSatisfiesExpression":
95
+ case "TSNonNullExpression":
96
+ case "TSTypeAssertion":
97
+ case "TSInstantiationExpression":
98
+ return unwrapNode(node.expression, key);
99
+ default:
100
+ return void 0;
119
101
  }
120
102
  }
121
- function transformUntrack(path) {
103
+
104
+ // src/index.ts
105
+ function transformUntrackAndBatch(path) {
122
106
  const arg = path.node.arguments[0];
123
- if (t.isExpression(arg)) {
124
- const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);
107
+ if (t2.isExpression(arg)) {
108
+ const trueArrow = unwrapNode(arg, t2.isArrowFunctionExpression);
125
109
  if (trueArrow) {
126
- if (t.isExpression(trueArrow.body)) {
110
+ if (t2.isExpression(trueArrow.body)) {
127
111
  path.replaceWith(trueArrow.body);
128
112
  } else {
129
- path.replaceWith(t.callExpression(trueArrow, []));
113
+ path.replaceWith(t2.callExpression(trueArrow, []));
130
114
  }
131
115
  return;
132
116
  }
133
- const trueFunc = unwrapNode(arg, t.isFunctionExpression);
117
+ const trueFunc = unwrapNode(arg, t2.isFunctionExpression);
134
118
  if (trueFunc) {
135
119
  path.replaceWith(trueFunc.body);
136
120
  }
137
- } else if (t.isSpreadElement(arg)) {
121
+ } else if (t2.isSpreadElement(arg)) {
138
122
  path.replaceWith(
139
- t.callExpression(
140
- t.memberExpression(arg.argument, t.numericLiteral(0), true),
123
+ t2.callExpression(
124
+ t2.memberExpression(arg.argument, t2.numericLiteral(0), true),
141
125
  []
142
126
  )
143
127
  );
@@ -145,24 +129,24 @@ function transformUntrack(path) {
145
129
  }
146
130
  function transformStartTransition(path) {
147
131
  const arg = path.node.arguments[0];
148
- if (t.isExpression(arg)) {
149
- const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);
132
+ if (t2.isExpression(arg)) {
133
+ const trueArrow = unwrapNode(arg, t2.isArrowFunctionExpression);
150
134
  if (trueArrow) {
151
- if (t.isExpression(trueArrow.body)) {
135
+ if (t2.isExpression(trueArrow.body)) {
152
136
  path.replaceWith(trueArrow.body);
153
137
  } else {
154
- path.replaceWith(t.callExpression(trueArrow, []));
138
+ path.replaceWith(t2.callExpression(trueArrow, []));
155
139
  }
156
140
  return;
157
141
  }
158
- const trueFunc = unwrapNode(arg, t.isFunctionExpression);
142
+ const trueFunc = unwrapNode(arg, t2.isFunctionExpression);
159
143
  if (trueFunc) {
160
144
  path.replaceWith(trueFunc.body);
161
145
  }
162
- } else if (t.isSpreadElement(arg)) {
146
+ } else if (t2.isSpreadElement(arg)) {
163
147
  path.replaceWith(
164
- t.callExpression(
165
- t.memberExpression(arg.argument, t.numericLiteral(0), true),
148
+ t2.callExpression(
149
+ t2.memberExpression(arg.argument, t2.numericLiteral(0), true),
166
150
  []
167
151
  )
168
152
  );
@@ -170,68 +154,27 @@ function transformStartTransition(path) {
170
154
  }
171
155
  function transformCreateDeferred(path) {
172
156
  const arg = path.node.arguments[0];
173
- if (t.isExpression(arg)) {
157
+ if (t2.isExpression(arg)) {
174
158
  path.replaceWith(arg);
175
- } else if (t.isSpreadElement(arg)) {
159
+ } else if (t2.isSpreadElement(arg)) {
176
160
  path.replaceWith(
177
- t.memberExpression(arg.argument, t.numericLiteral(0), true)
161
+ t2.memberExpression(arg.argument, t2.numericLiteral(0), true)
178
162
  );
179
163
  }
180
164
  }
181
- function runTransform(path, targetName) {
182
- switch (targetName) {
183
- case "createEffect": {
184
- transformCreateEffect(path);
185
- break;
186
- }
187
- case "onMount": {
188
- transformOnMount(path);
189
- break;
190
- }
191
- case "getListener": {
192
- transformGetListener(path);
193
- break;
194
- }
195
- case "untrack": {
196
- transformUntrack(path);
197
- break;
198
- }
199
- case "batch": {
200
- transformBatch(path);
201
- break;
202
- }
203
- case "startTransition": {
204
- transformStartTransition(path);
205
- break;
206
- }
207
- case "createDeferred": {
208
- transformCreateDeferred(path);
209
- break;
210
- }
211
- }
212
- }
213
- function transformCallExpression(ctx, path) {
214
- const trueIdentifier = unwrapNode(path.node.callee, t.isIdentifier);
215
- if (trueIdentifier) {
216
- const binding = path.scope.getBindingIdentifier(trueIdentifier.name);
217
- if (binding) {
218
- const targetName = checkValidIdentifierImport(ctx, binding);
219
- if (targetName) {
220
- runTransform(path, targetName);
221
- }
222
- }
223
- return;
224
- }
225
- const trueMemberExpr = unwrapNode(path.node.callee, t.isMemberExpression);
226
- if (trueMemberExpr && t.isIdentifier(trueMemberExpr.property) && !trueMemberExpr.computed) {
227
- const source = unwrapNode(trueMemberExpr.object, t.isIdentifier);
228
- if (source) {
229
- const targetName = trueMemberExpr.property.name;
230
- const binding = path.scope.getBindingIdentifier(source.name);
231
- if (binding && checkValidNamespaceImport(ctx, binding, targetName)) {
232
- runTransform(path, targetName);
233
- }
234
- }
165
+ var MODULES = ["solid-js", "solid-js/web"];
166
+ function transformCallExpression(path) {
167
+ const callee = path.get("callee");
168
+ if (pathReferencesImport(callee, MODULES, ["createEffect", "onMount"])) {
169
+ path.remove();
170
+ } else if (pathReferencesImport(callee, MODULES, ["getListener"])) {
171
+ path.replaceWith(t2.nullLiteral());
172
+ } else if (pathReferencesImport(callee, MODULES, ["untrack", "batch"])) {
173
+ transformUntrackAndBatch(path);
174
+ } else if (pathReferencesImport(callee, MODULES, ["startTransition"])) {
175
+ transformStartTransition(path);
176
+ } else if (pathReferencesImport(callee, MODULES, ["createDeferred"])) {
177
+ transformCreateDeferred(path);
235
178
  }
236
179
  }
237
180
  function solidOptimizerPlugin() {
@@ -239,40 +182,9 @@ function solidOptimizerPlugin() {
239
182
  name: "solid-optimizer",
240
183
  visitor: {
241
184
  Program(program) {
242
- const ctx = {
243
- identifiers: {
244
- "solid-js": {
245
- createEffect: /* @__PURE__ */ new Set(),
246
- onMount: /* @__PURE__ */ new Set(),
247
- getListener: /* @__PURE__ */ new Set(),
248
- untrack: /* @__PURE__ */ new Set(),
249
- batch: /* @__PURE__ */ new Set(),
250
- startTransition: /* @__PURE__ */ new Set(),
251
- createDeferred: /* @__PURE__ */ new Set()
252
- },
253
- "solid-js/web": {
254
- createEffect: /* @__PURE__ */ new Set(),
255
- onMount: /* @__PURE__ */ new Set(),
256
- getListener: /* @__PURE__ */ new Set(),
257
- untrack: /* @__PURE__ */ new Set(),
258
- batch: /* @__PURE__ */ new Set(),
259
- startTransition: /* @__PURE__ */ new Set(),
260
- createDeferred: /* @__PURE__ */ new Set()
261
- }
262
- },
263
- namespaces: {
264
- "solid-js": /* @__PURE__ */ new Set(),
265
- "solid-js/web": /* @__PURE__ */ new Set()
266
- }
267
- };
268
- program.traverse({
269
- ImportDeclaration(path) {
270
- extractImportIdentifiers(ctx, path);
271
- }
272
- });
273
185
  program.traverse({
274
186
  CallExpression(path) {
275
- transformCallExpression(ctx, path);
187
+ transformCallExpression(path);
276
188
  }
277
189
  });
278
190
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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": ";AACA,YAAY,OAAO;;;ACMJ,SAAR,WACL,MACA,KAC0B;AAC1B,MAAI,IAAI,IAAI,GAAG;AACb,WAAO;AAAA,EACT;AACA,UAAQ,KAAK,MAAM;AAAA,IACjB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,WAAW,KAAK,YAAY,GAAG;AAAA,IACxC;AACE,aAAO;AAAA,EACX;AACF;;;ADtBA,IAAM,UAAmD;AAAA,EACvD,YAAY;AAAA,IACV,cAAc;AAAA,IACd,SAAS;AAAA,IACT,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,gBAAgB;AAAA,EAClB;AAAA,EACA,gBAAgB;AAAA,IACd,cAAc;AAAA,IACd,SAAS;AAAA,IACT,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,iBAAiB;AAAA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ACf,iBAAiB,oBAAI,IAAI;AAAA,cACzB,gBAAgB,oBAAI,IAAI;AAAA,YAC1B;AAAA,YACA,gBAAgB;AAAA,cACd,cAAc,oBAAI,IAAI;AAAA,cACtB,SAAS,oBAAI,IAAI;AAAA,cACjB,aAAa,oBAAI,IAAI;AAAA,cACrB,SAAS,oBAAI,IAAI;AAAA,cACjB,OAAO,oBAAI,IAAI;AAAA,cACf,iBAAiB,oBAAI,IAAI;AAAA,cACzB,gBAAgB,oBAAI,IAAI;AAAA,YAC1B;AAAA,UACF;AAAA,UACA,YAAY;AAAA,YACV,YAAY,oBAAI,IAAI;AAAA,YACpB,gBAAgB,oBAAI,IAAI;AAAA,UAC1B;AAAA,QACF;AACA,gBAAQ,SAAS;AAAA,UACf,kBAAkB,MAAY;AAC5B,qCAAyB,KAAK,IAAI;AAAA,UACpC;AAAA,QACF,CAAC;AACD,gBAAQ,SAAS;AAAA,UACf,eAAe,MAAY;AACzB,oCAAwB,KAAK,IAAI;AAAA,UACnC;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;",
6
- "names": []
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": ";AACA,YAAYA,QAAO;;;ACAnB,YAAY,OAAO;;;ACWZ,SAAS,YACd,MACA,KAC2B;AAC3B,SAAO,IAAK,KAAwB,IAAI;AAC1C;AAWO,SAAS,mBAAmB,MAAwC;AACzE,UAAQ,KAAK,MAAM;AAAA,IACjB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;;;ACnCe,SAAR,WACL,MACA,KAC+B;AAC/B,MAAI,YAAY,MAAM,GAAG,GAAG;AAC1B,WAAO;AAAA,EACT;AACA,MAAI,YAAY,MAAM,kBAAkB,GAAG;AACzC,WAAO,WAAW,KAAK,IAAI,YAAY,GAAG,GAAG;AAAA,EAC/C;AACA,SAAO;AACT;;;AFZA,SAAS,+BACP,MACA,eACA,aACS;AACT,QAAM,aAAa,WAAW,MAAQ,cAAY;AAClD,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AACA,QAAM,UAAU,KAAK,MAAM,WAAW,WAAW,KAAK,IAAI;AAC1D,MAAI,CAAC,WAAW,QAAQ,SAAS,UAAU;A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H;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": ["t"]
7
7
  }
@@ -1 +1 @@
1
- import*as t from"@babel/types";function s(e,r){if(r(e))return e;switch(e.type){case"ParenthesizedExpression":case"TypeCastExpression":case"TSAsExpression":case"TSSatisfiesExpression":case"TSNonNullExpression":case"TSTypeAssertion":case"TSInstantiationExpression":return s(e.expression,r);default:return}}var d={"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}},f=new Set(Object.keys(d));function p(e,r){return t.isIdentifier(e.imported)&&e.imported.name===r||t.isStringLiteral(e.imported)&&e.imported.value===r}function m(e,r){if(!f.has(r.node.source.value))return;let n=r.node.source.value;for(let i=0,o=r.node.specifiers.length;i<o;i+=1){let a=r.node.specifiers[i];if(t.isImportSpecifier(a)){let c=d[n];for(let l of Object.keys(c))p(a,l)&&e.identifiers[n][l].add(a.local)}else t.isImportNamespaceSpecifier(a)&&e.namespaces[n].add(a.local)}}function x(e,r){for(let n of f){let i=e.identifiers[n];for(let o of Object.keys(i))if(i[o].has(r))return o}}function E(e,r,n){for(let i of f)if(e.namespaces[i].has(r)&&n in d[i])return!0;return!1}function b(e){e.remove()}function S(e){e.remove()}function g(e){e.replaceWith(t.nullLiteral())}function y(e){let r=e.node.arguments[0];if(t.isExpression(r)){let n=s(r,t.isArrowFunctionExpression);if(n){t.isExpression(n.body)?e.replaceWith(n.body):e.replaceWith(t.callExpression(n,[]));return}let i=s(r,t.isFunctionExpression);i&&e.replaceWith(i.body)}else t.isSpreadElement(r)&&e.replaceWith(t.callExpression(t.memberExpression(r.argument,t.numericLiteral(0),!0),[]))}function w(e){let r=e.node.arguments[0];if(t.isExpression(r)){let n=s(r,t.isArrowFunctionExpression);if(n){t.isExpression(n.body)?e.replaceWith(n.body):e.replaceWith(t.callExpression(n,[]));return}let i=s(r,t.isFunctionExpression);i&&e.replaceWith(i.body)}else t.isSpreadElement(r)&&e.replaceWith(t.callExpression(t.memberExpression(r.argument,t.numericLiteral(0),!0),[]))}function C(e){let r=e.node.arguments[0];if(t.isExpression(r)){let n=s(r,t.isArrowFunctionExpression);if(n){t.isExpression(n.body)?e.replaceWith(n.body):e.replaceWith(t.callExpression(n,[]));return}let i=s(r,t.isFunctionExpression);i&&e.replaceWith(i.body)}else t.isSpreadElement(r)&&e.replaceWith(t.callExpression(t.memberExpression(r.argument,t.numericLiteral(0),!0),[]))}function N(e){let r=e.node.arguments[0];t.isExpression(r)?e.replaceWith(r):t.isSpreadElement(r)&&e.replaceWith(t.memberExpression(r.argument,t.numericLiteral(0),!0))}function u(e,r){switch(r){case"createEffect":{b(e);break}case"onMount":{S(e);break}case"getListener":{g(e);break}case"untrack":{w(e);break}case"batch":{y(e);break}case"startTransition":{C(e);break}case"createDeferred":{N(e);break}}}function k(e,r){let n=s(r.node.callee,t.isIdentifier);if(n){let o=r.scope.getBindingIdentifier(n.name);if(o){let a=x(e,o);a&&u(r,a)}return}let i=s(r.node.callee,t.isMemberExpression);if(i&&t.isIdentifier(i.property)&&!i.computed){let o=s(i.object,t.isIdentifier);if(o){let a=i.property.name,c=r.scope.getBindingIdentifier(o.name);c&&E(e,c,a)&&u(r,a)}}}function I(){return{name:"solid-optimizer",visitor:{Program(e){let r={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){m(r,n)}}),e.traverse({CallExpression(n){k(r,n)}})}}}}export{I as default};
1
+ import*as r from"@babel/types";import*as n from"@babel/types";function a(e,t){return t(e.node)}function m(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(a(e,t))return e;if(a(e,m))return d(e.get("expression"),t)}function b(e,t,i){let s=d(e,n.isIdentifier);if(!s)return!1;let l=e.scope.getBinding(s.node.name);if(!l||l.kind!=="module")return!1;let o=l.path,u=o.parentPath;if(a(u,n.isImportDeclaration)&&t.includes(u.node.source.value)){if(a(o,n.isImportSpecifier)){let E=n.isIdentifier(o.node.imported)?o.node.imported.name:o.node.imported.value;return i.includes(E)}if(a(o,n.isImportDefaultSpecifier))return i.includes("default");if(a(o,n.isImportNamespaceSpecifier))return i.includes("*")}return!1}var x=["*"];function y(e,t,i){let s=d(e,n.isMemberExpression)||d(e,n.isOptionalMemberExpression);if(s){let l=d(s.get("object"),n.isIdentifier);if(!l)return!1;let o=s.get("property");if(a(o,n.isIdentifier))return i.includes(o.node.name)&&p(l,t,x);if(a(o,n.isStringLiteral))return i.includes(o.node.value)&&p(l,t,x)}return!1}function p(e,t,i){return b(e,t,i)||y(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 T(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 N(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 g(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 P(e){let t=e.get("callee");p(t,f,["createEffect","onMount"])?e.remove():p(t,f,["getListener"])?e.replaceWith(r.nullLiteral()):p(t,f,["untrack","batch"])?T(e):p(t,f,["startTransition"])?N(e):p(t,f,["createDeferred"])&&g(e)}function S(){return{name:"solid-optimizer",visitor:{Program(e){e.traverse({CallExpression(t){P(t)}})}}}}export{S as default};
@@ -0,0 +1,9 @@
1
+ import type * as babel from '@babel/core';
2
+ import type * as t from '@babel/types';
3
+ export declare function getImportSpecifierKey(specifier: t.ImportSpecifier): string;
4
+ type TypeFilter<V extends t.Node> = (node: t.Node) => node is V;
5
+ export declare function isPathValid<V extends t.Node>(path: unknown, key: TypeFilter<V>): path is babel.NodePath<V>;
6
+ export type NestedExpression = t.ParenthesizedExpression | t.TypeCastExpression | t.TSAsExpression | t.TSSatisfiesExpression | t.TSNonNullExpression | t.TSInstantiationExpression | t.TSTypeAssertion;
7
+ export declare function isNestedExpression(node: t.Node): node is NestedExpression;
8
+ export {};
9
+ //# sourceMappingURL=checks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../../src/checks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,KAAK,CAAC,MAAM,cAAc,CAAC;AAEvC,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,CAAC,CAAC,eAAe,GAAG,MAAM,CAK1E;AAED,KAAK,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC;AAEhE,wBAAgB,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EAC1C,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GACjB,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAE3B;AAED,MAAM,MAAM,gBAAgB,GACxB,CAAC,CAAC,uBAAuB,GACzB,CAAC,CAAC,kBAAkB,GACpB,CAAC,CAAC,cAAc,GAChB,CAAC,CAAC,qBAAqB,GACvB,CAAC,CAAC,mBAAmB,GACrB,CAAC,CAAC,yBAAyB,GAC3B,CAAC,CAAC,eAAe,CAAC;AAEtB,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,GAAG,IAAI,IAAI,gBAAgB,CAazE"}
@@ -1,12 +1,3 @@
1
- import type { PluginObj, PluginPass } from '@babel/core';
2
- import * as t from '@babel/types';
3
- interface StateContext {
4
- identifiers: Record<string, Record<string, Set<t.Identifier>>>;
5
- namespaces: Record<string, Set<t.Identifier>>;
6
- }
7
- interface State extends PluginPass {
8
- ctx: StateContext;
9
- }
10
- export default function solidOptimizerPlugin(): PluginObj<State>;
11
- export {};
1
+ import type { PluginObj } from '@babel/core';
2
+ export default function solidOptimizerPlugin(): PluginObj;
12
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AA0BlC,UAAU,YAAY;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC/D,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CAC/C;AA4KD,UAAU,KAAM,SAAQ,UAAU;IAChC,GAAG,EAAE,YAAY,CAAC;CACnB;AAsED,MAAM,CAAC,OAAO,UAAU,oBAAoB,IAAI,SAAS,CAAC,KAAK,CAAC,CA4C/D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AA6FvD,MAAM,CAAC,OAAO,UAAU,oBAAoB,IAAI,SAAS,CAaxD"}
@@ -0,0 +1,3 @@
1
+ import type { NodePath } from '@babel/core';
2
+ export declare function pathReferencesImport(path: NodePath, moduleSources: string[], importNames: string[]): boolean;
3
+ //# sourceMappingURL=path-references-import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-references-import.d.ts","sourceRoot":"","sources":["../../src/path-references-import.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAwE5C,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,QAAQ,EACd,aAAa,EAAE,MAAM,EAAE,EACvB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAKT"}
@@ -0,0 +1,6 @@
1
+ import type * as babel from '@babel/core';
2
+ import type * as t from '@babel/types';
3
+ type TypeFilter<V extends t.Node> = (node: t.Node) => node is V;
4
+ export default function unwrapPath<V extends t.Node>(path: unknown, key: TypeFilter<V>): babel.NodePath<V> | undefined;
5
+ export {};
6
+ //# sourceMappingURL=unwrap-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrap-path.d.ts","sourceRoot":"","sources":["../../src/unwrap-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,KAAK,CAAC,MAAM,cAAc,CAAC;AAGvC,KAAK,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC;AAEhE,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EACjD,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GACjB,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAQ/B"}