solid-optimizer 0.2.0 → 0.3.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 +269 -14
- package/dist/compile-BroGlagZ.d.mts +172 -0
- package/dist/compile-BroGlagZ.d.mts.map +1 -0
- package/dist/compile-ocDYvJUW.mjs +3910 -0
- package/dist/compile-ocDYvJUW.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/vite.d.mts +35 -0
- package/dist/vite.d.mts.map +1 -0
- package/dist/vite.mjs +1465 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +60 -58
- package/src/ast.ts +263 -0
- package/src/compile.ts +304 -0
- package/src/constants.ts +249 -0
- package/src/context.ts +87 -0
- package/src/fold.ts +850 -0
- package/src/index.ts +4 -107
- package/src/inline.ts +2028 -0
- package/src/jsx.ts +170 -0
- package/src/memo.ts +383 -0
- package/src/provider.ts +842 -0
- package/src/scope.ts +588 -0
- package/src/server.ts +275 -0
- package/src/size.ts +307 -0
- package/src/value.ts +386 -0
- package/src/vite/index.ts +1135 -0
- package/src/vite/inject.ts +311 -0
- package/src/vite/namespace.ts +66 -0
- package/src/vite/runtime.ts +390 -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
package/src/index.ts
CHANGED
|
@@ -1,107 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function transformUntrackAndBatch(path: NodePath<t.CallExpression>): void {
|
|
7
|
-
// https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L130-L134
|
|
8
|
-
const arg = path.node.arguments[0];
|
|
9
|
-
if (t.isExpression(arg)) {
|
|
10
|
-
const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);
|
|
11
|
-
if (trueArrow) {
|
|
12
|
-
if (t.isExpression(trueArrow.body)) {
|
|
13
|
-
path.replaceWith(trueArrow.body);
|
|
14
|
-
} else {
|
|
15
|
-
path.replaceWith(t.callExpression(trueArrow, []));
|
|
16
|
-
}
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const trueFunc = unwrapNode(arg, t.isFunctionExpression);
|
|
20
|
-
if (trueFunc) {
|
|
21
|
-
path.replaceWith(trueFunc.body);
|
|
22
|
-
}
|
|
23
|
-
} else if (t.isSpreadElement(arg)) {
|
|
24
|
-
path.replaceWith(
|
|
25
|
-
t.callExpression(
|
|
26
|
-
t.memberExpression(arg.argument, t.numericLiteral(0), true),
|
|
27
|
-
[],
|
|
28
|
-
),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function transformStartTransition(path: NodePath<t.CallExpression>): void {
|
|
34
|
-
// https://github.com/solidjs/solid/blob/main/packages/solid/src/server/rendering.ts#L488
|
|
35
|
-
const arg = path.node.arguments[0];
|
|
36
|
-
if (t.isExpression(arg)) {
|
|
37
|
-
const trueArrow = unwrapNode(arg, t.isArrowFunctionExpression);
|
|
38
|
-
if (trueArrow) {
|
|
39
|
-
if (t.isExpression(trueArrow.body)) {
|
|
40
|
-
path.replaceWith(trueArrow.body);
|
|
41
|
-
} else {
|
|
42
|
-
path.replaceWith(t.callExpression(trueArrow, []));
|
|
43
|
-
}
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const trueFunc = unwrapNode(arg, t.isFunctionExpression);
|
|
47
|
-
if (trueFunc) {
|
|
48
|
-
path.replaceWith(trueFunc.body);
|
|
49
|
-
}
|
|
50
|
-
} else if (t.isSpreadElement(arg)) {
|
|
51
|
-
path.replaceWith(
|
|
52
|
-
t.callExpression(
|
|
53
|
-
t.memberExpression(arg.argument, t.numericLiteral(0), true),
|
|
54
|
-
[],
|
|
55
|
-
),
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function transformCreateDeferred(path: NodePath<t.CallExpression>): void {
|
|
61
|
-
// https://github.com/solidjs/solid/blob/main/packages/solid/src/server/reactive.ts#L99
|
|
62
|
-
const arg = path.node.arguments[0];
|
|
63
|
-
if (t.isExpression(arg)) {
|
|
64
|
-
path.replaceWith(arg);
|
|
65
|
-
} else if (t.isSpreadElement(arg)) {
|
|
66
|
-
path.replaceWith(
|
|
67
|
-
t.memberExpression(arg.argument, t.numericLiteral(0), true),
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const MODULES = ['solid-js', 'solid-js/web'];
|
|
73
|
-
|
|
74
|
-
function transformCallExpression(path: NodePath<t.CallExpression>): void {
|
|
75
|
-
const callee = path.get('callee');
|
|
76
|
-
|
|
77
|
-
if (pathReferencesImport(callee, MODULES, ['createEffect', 'onMount'])) {
|
|
78
|
-
// https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L101
|
|
79
|
-
// https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L154
|
|
80
|
-
// Just remove it
|
|
81
|
-
path.remove();
|
|
82
|
-
} else if (pathReferencesImport(callee, MODULES, ['getListener'])) {
|
|
83
|
-
// https://github.com/solidjs/solid/blob/41fa6c14b4bf71eed593303cd63b32d53e3515e9/packages/solid/src/server/reactive.ts#L188
|
|
84
|
-
path.replaceWith(t.nullLiteral());
|
|
85
|
-
} else if (pathReferencesImport(callee, MODULES, ['untrack', 'batch'])) {
|
|
86
|
-
transformUntrackAndBatch(path);
|
|
87
|
-
} else if (pathReferencesImport(callee, MODULES, ['startTransition'])) {
|
|
88
|
-
transformStartTransition(path);
|
|
89
|
-
} else if (pathReferencesImport(callee, MODULES, ['createDeferred'])) {
|
|
90
|
-
transformCreateDeferred(path);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export default function solidOptimizerPlugin(): PluginObj {
|
|
95
|
-
return {
|
|
96
|
-
name: 'solid-optimizer',
|
|
97
|
-
visitor: {
|
|
98
|
-
Program(program) {
|
|
99
|
-
program.traverse({
|
|
100
|
-
CallExpression(path): void {
|
|
101
|
-
transformCallExpression(path);
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
1
|
+
export type { CompileOptions, CompileResult, ModuleConstants } from './compile';
|
|
2
|
+
export { compile, readModuleConstants } from './compile';
|
|
3
|
+
export type { ImportedConstants } from './constants';
|
|
4
|
+
export type { Primitive } from './value';
|