solid-optimizer 0.2.0 → 0.4.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/README.md +294 -14
- package/dist/compile-BQuBDA0Q.d.mts +199 -0
- package/dist/compile-BQuBDA0Q.d.mts.map +1 -0
- package/dist/compile-D3caSUtw.mjs +4244 -0
- package/dist/compile-D3caSUtw.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/vite.d.mts +53 -0
- package/dist/vite.d.mts.map +1 -0
- package/dist/vite.mjs +1743 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +60 -58
- package/src/ast.ts +271 -0
- package/src/compile.ts +355 -0
- package/src/constants.ts +249 -0
- package/src/context.ts +116 -0
- package/src/fold.ts +850 -0
- package/src/index.ts +5 -107
- package/src/inline.ts +2237 -0
- package/src/jsx.ts +170 -0
- package/src/memo.ts +416 -0
- package/src/provider.ts +899 -0
- package/src/scope.ts +588 -0
- package/src/server.ts +275 -0
- package/src/size.ts +309 -0
- package/src/value.ts +386 -0
- package/src/vite/index.ts +1378 -0
- package/src/vite/inject.ts +350 -0
- package/src/vite/namespace.ts +66 -0
- package/src/vite/refs.ts +99 -0
- package/src/vite/report.ts +74 -0
- package/src/vite/runtime.ts +370 -0
- package/src/vite/usage.ts +405 -0
- package/dist/cjs/development/index.cjs +0 -228
- package/dist/cjs/development/index.cjs.map +0 -7
- package/dist/cjs/production/index.cjs +0 -1
- package/dist/esm/development/index.mjs +0 -197
- package/dist/esm/development/index.mjs.map +0 -7
- package/dist/esm/production/index.mjs +0 -1
- package/dist/types/checks.d.ts +0 -9
- package/dist/types/checks.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/path-references-import.d.ts +0 -3
- package/dist/types/path-references-import.d.ts.map +0 -1
- package/dist/types/unwrap-node.d.ts +0 -7
- package/dist/types/unwrap-node.d.ts.map +0 -1
- package/dist/types/unwrap-path.d.ts +0 -6
- package/dist/types/unwrap-path.d.ts.map +0 -1
- package/src/checks.ts +0 -42
- package/src/path-references-import.ts +0 -82
- package/src/unwrap-node.ts +0 -27
- package/src/unwrap-path.ts +0 -18
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import * as t2 from "@babel/types";
|
|
3
|
-
|
|
4
|
-
// src/path-references-import.ts
|
|
5
|
-
import * as t from "@babel/types";
|
|
6
|
-
|
|
7
|
-
// src/checks.ts
|
|
8
|
-
function isPathValid(path, key) {
|
|
9
|
-
return key(path.node);
|
|
10
|
-
}
|
|
11
|
-
function isNestedExpression(node) {
|
|
12
|
-
switch (node.type) {
|
|
13
|
-
case "ParenthesizedExpression":
|
|
14
|
-
case "TypeCastExpression":
|
|
15
|
-
case "TSAsExpression":
|
|
16
|
-
case "TSSatisfiesExpression":
|
|
17
|
-
case "TSNonNullExpression":
|
|
18
|
-
case "TSTypeAssertion":
|
|
19
|
-
case "TSInstantiationExpression":
|
|
20
|
-
return true;
|
|
21
|
-
default:
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// src/unwrap-path.ts
|
|
27
|
-
function unwrapPath(path, key) {
|
|
28
|
-
if (isPathValid(path, key)) {
|
|
29
|
-
return path;
|
|
30
|
-
}
|
|
31
|
-
if (isPathValid(path, isNestedExpression)) {
|
|
32
|
-
return unwrapPath(path.get("expression"), key);
|
|
33
|
-
}
|
|
34
|
-
return void 0;
|
|
35
|
-
}
|
|
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;
|
|
42
|
-
}
|
|
43
|
-
const binding = path.scope.getBinding(identifier.node.name);
|
|
44
|
-
if (!binding || binding.kind !== "module") {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
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("*");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
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);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
function pathReferencesImport(path, moduleSources, importNames) {
|
|
82
|
-
return pathReferencesImportIdentifier(path, moduleSources, importNames) || pathReferencesImportMember(path, moduleSources, importNames);
|
|
83
|
-
}
|
|
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;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/index.ts
|
|
105
|
-
function transformUntrackAndBatch(path) {
|
|
106
|
-
const arg = path.node.arguments[0];
|
|
107
|
-
if (t2.isExpression(arg)) {
|
|
108
|
-
const trueArrow = unwrapNode(arg, t2.isArrowFunctionExpression);
|
|
109
|
-
if (trueArrow) {
|
|
110
|
-
if (t2.isExpression(trueArrow.body)) {
|
|
111
|
-
path.replaceWith(trueArrow.body);
|
|
112
|
-
} else {
|
|
113
|
-
path.replaceWith(t2.callExpression(trueArrow, []));
|
|
114
|
-
}
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const trueFunc = unwrapNode(arg, t2.isFunctionExpression);
|
|
118
|
-
if (trueFunc) {
|
|
119
|
-
path.replaceWith(trueFunc.body);
|
|
120
|
-
}
|
|
121
|
-
} else if (t2.isSpreadElement(arg)) {
|
|
122
|
-
path.replaceWith(
|
|
123
|
-
t2.callExpression(
|
|
124
|
-
t2.memberExpression(arg.argument, t2.numericLiteral(0), true),
|
|
125
|
-
[]
|
|
126
|
-
)
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function transformStartTransition(path) {
|
|
131
|
-
const arg = path.node.arguments[0];
|
|
132
|
-
if (t2.isExpression(arg)) {
|
|
133
|
-
const trueArrow = unwrapNode(arg, t2.isArrowFunctionExpression);
|
|
134
|
-
if (trueArrow) {
|
|
135
|
-
if (t2.isExpression(trueArrow.body)) {
|
|
136
|
-
path.replaceWith(trueArrow.body);
|
|
137
|
-
} else {
|
|
138
|
-
path.replaceWith(t2.callExpression(trueArrow, []));
|
|
139
|
-
}
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const trueFunc = unwrapNode(arg, t2.isFunctionExpression);
|
|
143
|
-
if (trueFunc) {
|
|
144
|
-
path.replaceWith(trueFunc.body);
|
|
145
|
-
}
|
|
146
|
-
} else if (t2.isSpreadElement(arg)) {
|
|
147
|
-
path.replaceWith(
|
|
148
|
-
t2.callExpression(
|
|
149
|
-
t2.memberExpression(arg.argument, t2.numericLiteral(0), true),
|
|
150
|
-
[]
|
|
151
|
-
)
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function transformCreateDeferred(path) {
|
|
156
|
-
const arg = path.node.arguments[0];
|
|
157
|
-
if (t2.isExpression(arg)) {
|
|
158
|
-
path.replaceWith(arg);
|
|
159
|
-
} else if (t2.isSpreadElement(arg)) {
|
|
160
|
-
path.replaceWith(
|
|
161
|
-
t2.memberExpression(arg.argument, t2.numericLiteral(0), true)
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
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);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function solidOptimizerPlugin() {
|
|
181
|
-
return {
|
|
182
|
-
name: "solid-optimizer",
|
|
183
|
-
visitor: {
|
|
184
|
-
Program(program) {
|
|
185
|
-
program.traverse({
|
|
186
|
-
CallExpression(path) {
|
|
187
|
-
transformCallExpression(path);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
export {
|
|
195
|
-
solidOptimizerPlugin as default
|
|
196
|
-
};
|
|
197
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
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;AACzC,WAAO;AAAA,EACT;AACA,QAAM,aAAa,QAAQ;AAC3B,QAAM,eAAe,WAAW;AAChC,MACE,YAAY,cAAgB,qBAAmB,KAC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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};
|
package/dist/types/checks.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type * as t from '@babel/types';
|
|
2
|
-
type BroadTypeFilter<K extends t.Node> = (node: t.Node) => node is K;
|
|
3
|
-
type TypeCheck<K> = K extends BroadTypeFilter<infer U> ? U : never;
|
|
4
|
-
type TypeFilter = (node: t.Node) => boolean;
|
|
5
|
-
export default function unwrapNode<K extends TypeFilter>(node: t.Node, key: K): TypeCheck<K> | undefined;
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=unwrap-node.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unwrap-node.d.ts","sourceRoot":"","sources":["../../src/unwrap-node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,cAAc,CAAC;AAEvC,KAAK,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC;AACrE,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,eAAe,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEnE,KAAK,UAAU,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC;AAE5C,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,SAAS,UAAU,EACrD,IAAI,EAAE,CAAC,CAAC,IAAI,EACZ,GAAG,EAAE,CAAC,GACL,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAgB1B"}
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/src/checks.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type * as babel from '@babel/core';
|
|
2
|
-
import type * as t from '@babel/types';
|
|
3
|
-
|
|
4
|
-
export function getImportSpecifierKey(specifier: t.ImportSpecifier): string {
|
|
5
|
-
if (specifier.imported.type === 'Identifier') {
|
|
6
|
-
return specifier.imported.name;
|
|
7
|
-
}
|
|
8
|
-
return specifier.imported.value;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type TypeFilter<V extends t.Node> = (node: t.Node) => node is V;
|
|
12
|
-
|
|
13
|
-
export function isPathValid<V extends t.Node>(
|
|
14
|
-
path: unknown,
|
|
15
|
-
key: TypeFilter<V>,
|
|
16
|
-
): path is babel.NodePath<V> {
|
|
17
|
-
return key((path as babel.NodePath).node);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type NestedExpression =
|
|
21
|
-
| t.ParenthesizedExpression
|
|
22
|
-
| t.TypeCastExpression
|
|
23
|
-
| t.TSAsExpression
|
|
24
|
-
| t.TSSatisfiesExpression
|
|
25
|
-
| t.TSNonNullExpression
|
|
26
|
-
| t.TSInstantiationExpression
|
|
27
|
-
| t.TSTypeAssertion;
|
|
28
|
-
|
|
29
|
-
export function isNestedExpression(node: t.Node): node is NestedExpression {
|
|
30
|
-
switch (node.type) {
|
|
31
|
-
case 'ParenthesizedExpression':
|
|
32
|
-
case 'TypeCastExpression':
|
|
33
|
-
case 'TSAsExpression':
|
|
34
|
-
case 'TSSatisfiesExpression':
|
|
35
|
-
case 'TSNonNullExpression':
|
|
36
|
-
case 'TSTypeAssertion':
|
|
37
|
-
case 'TSInstantiationExpression':
|
|
38
|
-
return true;
|
|
39
|
-
default:
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from '@babel/core';
|
|
2
|
-
import * as t from '@babel/types';
|
|
3
|
-
import { isPathValid } from './checks';
|
|
4
|
-
import unwrapPath from './unwrap-path';
|
|
5
|
-
|
|
6
|
-
function pathReferencesImportIdentifier(
|
|
7
|
-
path: NodePath,
|
|
8
|
-
moduleSources: string[],
|
|
9
|
-
importNames: string[],
|
|
10
|
-
): boolean {
|
|
11
|
-
const identifier = unwrapPath(path, t.isIdentifier);
|
|
12
|
-
if (!identifier) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
const binding = path.scope.getBinding(identifier.node.name);
|
|
16
|
-
if (!binding || binding.kind !== 'module') {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
const importPath = binding.path;
|
|
20
|
-
const importParent = importPath.parentPath;
|
|
21
|
-
if (
|
|
22
|
-
isPathValid(importParent, t.isImportDeclaration) &&
|
|
23
|
-
moduleSources.includes(importParent.node.source.value)
|
|
24
|
-
) {
|
|
25
|
-
if (isPathValid(importPath, t.isImportSpecifier)) {
|
|
26
|
-
const key = t.isIdentifier(importPath.node.imported)
|
|
27
|
-
? importPath.node.imported.name
|
|
28
|
-
: importPath.node.imported.value;
|
|
29
|
-
return importNames.includes(key);
|
|
30
|
-
}
|
|
31
|
-
if (isPathValid(importPath, t.isImportDefaultSpecifier)) {
|
|
32
|
-
return importNames.includes('default');
|
|
33
|
-
}
|
|
34
|
-
if (isPathValid(importPath, t.isImportNamespaceSpecifier)) {
|
|
35
|
-
return importNames.includes('*');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const IMPORT_NAMESPACE = ['*'];
|
|
42
|
-
|
|
43
|
-
function pathReferencesImportMember(
|
|
44
|
-
path: NodePath,
|
|
45
|
-
moduleSources: string[],
|
|
46
|
-
importNames: string[],
|
|
47
|
-
): boolean {
|
|
48
|
-
const memberExpr =
|
|
49
|
-
unwrapPath(path, t.isMemberExpression) ||
|
|
50
|
-
unwrapPath(path, t.isOptionalMemberExpression);
|
|
51
|
-
if (memberExpr) {
|
|
52
|
-
const object = unwrapPath(memberExpr.get('object'), t.isIdentifier);
|
|
53
|
-
if (!object) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
const property = memberExpr.get('property');
|
|
57
|
-
if (isPathValid(property, t.isIdentifier)) {
|
|
58
|
-
return (
|
|
59
|
-
importNames.includes(property.node.name) &&
|
|
60
|
-
pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
if (isPathValid(property, t.isStringLiteral)) {
|
|
64
|
-
return (
|
|
65
|
-
importNames.includes(property.node.value) &&
|
|
66
|
-
pathReferencesImport(object, moduleSources, IMPORT_NAMESPACE)
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function pathReferencesImport(
|
|
74
|
-
path: NodePath,
|
|
75
|
-
moduleSources: string[],
|
|
76
|
-
importNames: string[],
|
|
77
|
-
): boolean {
|
|
78
|
-
return (
|
|
79
|
-
pathReferencesImportIdentifier(path, moduleSources, importNames) ||
|
|
80
|
-
pathReferencesImportMember(path, moduleSources, importNames)
|
|
81
|
-
);
|
|
82
|
-
}
|
package/src/unwrap-node.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type * as t from '@babel/types';
|
|
2
|
-
|
|
3
|
-
type BroadTypeFilter<K extends t.Node> = (node: t.Node) => node is K;
|
|
4
|
-
type TypeCheck<K> = K extends BroadTypeFilter<infer U> ? U : never;
|
|
5
|
-
|
|
6
|
-
type TypeFilter = (node: t.Node) => boolean;
|
|
7
|
-
|
|
8
|
-
export default function unwrapNode<K extends TypeFilter>(
|
|
9
|
-
node: t.Node,
|
|
10
|
-
key: K,
|
|
11
|
-
): TypeCheck<K> | undefined {
|
|
12
|
-
if (key(node)) {
|
|
13
|
-
return node as TypeCheck<K>;
|
|
14
|
-
}
|
|
15
|
-
switch (node.type) {
|
|
16
|
-
case 'ParenthesizedExpression':
|
|
17
|
-
case 'TypeCastExpression':
|
|
18
|
-
case 'TSAsExpression':
|
|
19
|
-
case 'TSSatisfiesExpression':
|
|
20
|
-
case 'TSNonNullExpression':
|
|
21
|
-
case 'TSTypeAssertion':
|
|
22
|
-
case 'TSInstantiationExpression':
|
|
23
|
-
return unwrapNode(node.expression, key);
|
|
24
|
-
default:
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/unwrap-path.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type * as babel from '@babel/core';
|
|
2
|
-
import type * as t from '@babel/types';
|
|
3
|
-
import { isNestedExpression, isPathValid } from './checks';
|
|
4
|
-
|
|
5
|
-
type TypeFilter<V extends t.Node> = (node: t.Node) => node is V;
|
|
6
|
-
|
|
7
|
-
export default function unwrapPath<V extends t.Node>(
|
|
8
|
-
path: unknown,
|
|
9
|
-
key: TypeFilter<V>,
|
|
10
|
-
): babel.NodePath<V> | undefined {
|
|
11
|
-
if (isPathValid(path, key)) {
|
|
12
|
-
return path;
|
|
13
|
-
}
|
|
14
|
-
if (isPathValid(path, isNestedExpression)) {
|
|
15
|
-
return unwrapPath(path.get('expression'), key);
|
|
16
|
-
}
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|