@solidjs/start 2.0.0-beta.1 → 2.0.0-beta.3

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.
Files changed (231) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/client/StartClient.d.ts +7 -0
  3. package/{src/client/StartClient.tsx → dist/client/StartClient.jsx} +7 -15
  4. package/dist/client/index.jsx +2 -0
  5. package/dist/client/mount.d.ts +1 -0
  6. package/dist/client/mount.js +1 -0
  7. package/dist/client/spa/index.d.ts +4 -0
  8. package/dist/client/spa/index.jsx +5 -0
  9. package/dist/config/constants.d.ts +16 -0
  10. package/dist/config/constants.js +16 -0
  11. package/dist/config/dev-server.d.ts +2 -0
  12. package/dist/config/dev-server.js +128 -0
  13. package/dist/config/env.d.ts +19 -0
  14. package/dist/config/env.js +81 -0
  15. package/dist/config/fs-router.d.ts +37 -0
  16. package/dist/config/fs-router.js +141 -0
  17. package/dist/config/fs-routes/fs-watcher.d.ts +3 -0
  18. package/dist/config/fs-routes/fs-watcher.js +53 -0
  19. package/dist/config/fs-routes/index.d.ts +7 -0
  20. package/dist/config/fs-routes/index.js +107 -0
  21. package/dist/config/fs-routes/router.d.ts +42 -0
  22. package/dist/config/fs-routes/router.js +148 -0
  23. package/dist/config/fs-routes/tree-shake.d.ts +2 -0
  24. package/dist/config/fs-routes/tree-shake.js +305 -0
  25. package/dist/config/index.d.ts +25 -0
  26. package/dist/config/index.js +224 -0
  27. package/dist/config/lazy.d.ts +3 -0
  28. package/dist/config/lazy.js +114 -0
  29. package/dist/config/manifest.d.ts +3 -0
  30. package/dist/config/manifest.js +109 -0
  31. package/dist/config/utils.d.ts +4 -0
  32. package/dist/config/utils.js +6 -0
  33. package/dist/config/vite-utils.d.ts +21 -0
  34. package/dist/config/vite-utils.js +85 -0
  35. package/dist/directives/bubble-function-declaration.d.ts +3 -0
  36. package/dist/directives/bubble-function-declaration.js +23 -0
  37. package/dist/directives/compile.d.ts +9 -0
  38. package/dist/directives/compile.js +40 -0
  39. package/dist/directives/generate-unique-name.d.ts +3 -0
  40. package/dist/directives/generate-unique-name.js +16 -0
  41. package/dist/directives/get-descriptive-name.d.ts +2 -0
  42. package/dist/directives/get-descriptive-name.js +37 -0
  43. package/dist/directives/get-import-identifier.d.ts +4 -0
  44. package/dist/directives/get-import-identifier.js +19 -0
  45. package/dist/directives/get-root-statement-path.d.ts +2 -0
  46. package/dist/directives/get-root-statement-path.js +12 -0
  47. package/dist/directives/index.d.ts +14 -0
  48. package/dist/directives/index.js +170 -0
  49. package/dist/directives/is-statement-top-level.d.ts +3 -0
  50. package/dist/directives/is-statement-top-level.js +9 -0
  51. package/dist/directives/paths.d.ts +9 -0
  52. package/dist/directives/paths.js +36 -0
  53. package/dist/directives/plugin.d.ts +21 -0
  54. package/dist/directives/plugin.js +302 -0
  55. package/dist/directives/remove-unused-variables.d.ts +3 -0
  56. package/dist/directives/remove-unused-variables.js +66 -0
  57. package/{src/directives/types.ts → dist/directives/types.d.ts} +5 -7
  58. package/dist/directives/types.js +1 -0
  59. package/dist/directives/xxhash32.d.ts +6 -0
  60. package/dist/directives/xxhash32.js +193 -0
  61. package/dist/fns/client.d.ts +3 -0
  62. package/dist/fns/client.js +106 -0
  63. package/dist/fns/handler.d.ts +5 -0
  64. package/dist/fns/handler.js +269 -0
  65. package/dist/fns/registration.d.ts +2 -0
  66. package/dist/fns/registration.js +12 -0
  67. package/dist/fns/serialization.d.ts +6 -0
  68. package/dist/fns/serialization.js +208 -0
  69. package/dist/fns/server.d.ts +7 -0
  70. package/dist/fns/server.js +38 -0
  71. package/dist/fns/shared.d.ts +17 -0
  72. package/dist/fns/shared.js +105 -0
  73. package/dist/http/index.d.ts +81 -0
  74. package/dist/http/index.js +129 -0
  75. package/{src/index.tsx → dist/index.d.ts} +0 -2
  76. package/dist/index.jsx +6 -0
  77. package/dist/middleware/index.d.ts +38 -0
  78. package/dist/middleware/index.js +59 -0
  79. package/dist/router.d.ts +6 -0
  80. package/dist/router.jsx +29 -0
  81. package/dist/server/StartServer.d.ts +9 -0
  82. package/dist/server/StartServer.jsx +34 -0
  83. package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
  84. package/{src/server/assets/PatchVirtualDevStyles.tsx → dist/server/assets/PatchVirtualDevStyles.jsx} +7 -10
  85. package/dist/server/assets/index.d.ts +2 -0
  86. package/dist/server/assets/index.js +52 -0
  87. package/dist/server/assets/render.d.ts +19 -0
  88. package/dist/server/assets/render.jsx +14 -0
  89. package/dist/server/collect-styles.d.ts +3 -0
  90. package/dist/server/collect-styles.js +57 -0
  91. package/dist/server/fetchEvent.d.ts +7 -0
  92. package/dist/server/fetchEvent.js +26 -0
  93. package/dist/server/handler.d.ts +64 -0
  94. package/dist/server/handler.js +222 -0
  95. package/dist/server/index.d.ts +9 -0
  96. package/{src/server/index.tsx → dist/server/index.jsx} +4 -19
  97. package/dist/server/manifest/client-manifest.d.ts +9 -0
  98. package/dist/server/manifest/client-manifest.js +6 -0
  99. package/dist/server/manifest/dev-client-manifest.d.ts +4 -0
  100. package/dist/server/manifest/dev-client-manifest.js +24 -0
  101. package/dist/server/manifest/dev-ssr-manifest.d.ts +5 -0
  102. package/dist/server/manifest/dev-ssr-manifest.js +23 -0
  103. package/dist/server/manifest/prod-client-manifest.d.ts +5 -0
  104. package/dist/server/manifest/prod-client-manifest.js +26 -0
  105. package/dist/server/manifest/prod-ssr-manifest.d.ts +6 -0
  106. package/dist/server/manifest/prod-ssr-manifest.js +85 -0
  107. package/dist/server/manifest/ssr-manifest.d.ts +4 -0
  108. package/dist/server/manifest/ssr-manifest.js +6 -0
  109. package/dist/server/routes.d.ts +23 -0
  110. package/dist/server/routes.js +74 -0
  111. package/dist/server/spa/StartServer.d.ts +9 -0
  112. package/dist/server/spa/StartServer.jsx +25 -0
  113. package/dist/server/spa/handler.d.ts +36 -0
  114. package/dist/server/spa/handler.js +20 -0
  115. package/{src/server/spa/index.tsx → dist/server/spa/index.d.ts} +0 -1
  116. package/dist/server/spa/index.jsx +5 -0
  117. package/dist/server/types.d.ts +75 -0
  118. package/dist/server/types.js +1 -0
  119. package/dist/server/util.d.ts +2 -0
  120. package/dist/server/util.js +8 -0
  121. package/dist/shared/ErrorBoundary.d.ts +3 -0
  122. package/dist/shared/ErrorBoundary.jsx +36 -0
  123. package/dist/shared/GET.d.ts +5 -0
  124. package/dist/shared/GET.js +8 -0
  125. package/dist/shared/HttpHeader.d.ts +10 -0
  126. package/dist/shared/HttpHeader.jsx +38 -0
  127. package/dist/shared/HttpStatusCode.d.ts +9 -0
  128. package/dist/shared/HttpStatusCode.js +18 -0
  129. package/dist/shared/clientOnly.d.ts +12 -0
  130. package/dist/shared/clientOnly.js +27 -0
  131. package/dist/shared/dev-overlay/CodeView.d.ts +7 -0
  132. package/dist/shared/dev-overlay/CodeView.jsx +62 -0
  133. package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +9 -0
  134. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +226 -0
  135. package/dist/shared/dev-overlay/createStackFrame.d.ts +9 -0
  136. package/dist/shared/dev-overlay/createStackFrame.js +56 -0
  137. package/dist/shared/dev-overlay/download.d.ts +1 -0
  138. package/dist/shared/dev-overlay/download.js +6 -0
  139. package/dist/shared/dev-overlay/get-source-map.d.ts +2 -0
  140. package/dist/shared/dev-overlay/get-source-map.js +25 -0
  141. package/dist/shared/dev-overlay/icons.d.ts +28 -0
  142. package/dist/shared/dev-overlay/icons.jsx +150 -0
  143. package/dist/shared/dev-overlay/index.d.ts +5 -0
  144. package/dist/shared/dev-overlay/index.jsx +39 -0
  145. package/dist/shared/lazy.d.ts +3 -0
  146. package/dist/shared/lazy.js +42 -0
  147. package/dist/shared/serverFunction.d.ts +6 -0
  148. package/dist/shared/serverFunction.js +8 -0
  149. package/dist/utils/debounce.d.ts +4 -0
  150. package/dist/utils/debounce.js +10 -0
  151. package/package.json +7 -2
  152. package/scripts/build.js +0 -15
  153. package/scripts/validate-imports.js +0 -316
  154. package/src/client/mount.ts +0 -1
  155. package/src/client/spa/index.tsx +0 -9
  156. package/src/config/constants.ts +0 -19
  157. package/src/config/dev-server.ts +0 -161
  158. package/src/config/env.ts +0 -105
  159. package/src/config/fs-router.ts +0 -162
  160. package/src/config/fs-routes/fs-watcher.ts +0 -66
  161. package/src/config/fs-routes/index.ts +0 -136
  162. package/src/config/fs-routes/router.ts +0 -184
  163. package/src/config/fs-routes/tree-shake.ts +0 -324
  164. package/src/config/index.ts +0 -239
  165. package/src/config/lazy.ts +0 -132
  166. package/src/config/manifest.ts +0 -120
  167. package/src/config/utils.ts +0 -5
  168. package/src/config/vite-utils.ts +0 -113
  169. package/src/directives/bubble-function-declaration.ts +0 -33
  170. package/src/directives/compile.ts +0 -54
  171. package/src/directives/generate-unique-name.ts +0 -22
  172. package/src/directives/get-descriptive-name.ts +0 -39
  173. package/src/directives/get-import-identifier.ts +0 -34
  174. package/src/directives/get-root-statement-path.ts +0 -14
  175. package/src/directives/index.ts +0 -233
  176. package/src/directives/is-statement-top-level.ts +0 -13
  177. package/src/directives/paths.ts +0 -63
  178. package/src/directives/plugin.ts +0 -389
  179. package/src/directives/remove-unused-variables.ts +0 -70
  180. package/src/directives/xxhash32.ts +0 -214
  181. package/src/env.d.ts +0 -17
  182. package/src/fns/client.ts +0 -141
  183. package/src/fns/handler.spec.ts +0 -85
  184. package/src/fns/handler.ts +0 -287
  185. package/src/fns/registration.ts +0 -19
  186. package/src/fns/serialization.ts +0 -250
  187. package/src/fns/server.ts +0 -46
  188. package/src/fns/shared.ts +0 -116
  189. package/src/http/index.ts +0 -216
  190. package/src/internal.d.ts +0 -14
  191. package/src/middleware/index.ts +0 -92
  192. package/src/router.tsx +0 -37
  193. package/src/server/StartServer.tsx +0 -58
  194. package/src/server/assets/index.ts +0 -70
  195. package/src/server/assets/render.tsx +0 -46
  196. package/src/server/collect-styles.ts +0 -70
  197. package/src/server/fetchEvent.spec.ts +0 -85
  198. package/src/server/fetchEvent.ts +0 -36
  199. package/src/server/handler.ts +0 -261
  200. package/src/server/manifest/client-manifest.ts +0 -8
  201. package/src/server/manifest/dev-client-manifest.ts +0 -21
  202. package/src/server/manifest/dev-ssr-manifest.ts +0 -23
  203. package/src/server/manifest/prod-client-manifest.ts +0 -21
  204. package/src/server/manifest/prod-ssr-manifest.ts +0 -109
  205. package/src/server/manifest/ssr-manifest.ts +0 -10
  206. package/src/server/routes.ts +0 -126
  207. package/src/server/spa/StartServer.tsx +0 -42
  208. package/src/server/spa/handler.ts +0 -29
  209. package/src/server/types.ts +0 -82
  210. package/src/server/util.ts +0 -12
  211. package/src/shared/ErrorBoundary.tsx +0 -52
  212. package/src/shared/GET.ts +0 -8
  213. package/src/shared/HttpHeader.tsx +0 -42
  214. package/src/shared/HttpStatusCode.ts +0 -27
  215. package/src/shared/clientOnly.ts +0 -44
  216. package/src/shared/dev-overlay/CodeView.tsx +0 -90
  217. package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
  218. package/src/shared/dev-overlay/createStackFrame.ts +0 -74
  219. package/src/shared/dev-overlay/download.ts +0 -6
  220. package/src/shared/dev-overlay/env.d.ts +0 -4
  221. package/src/shared/dev-overlay/get-source-map.ts +0 -33
  222. package/src/shared/dev-overlay/icons.tsx +0 -456
  223. package/src/shared/dev-overlay/index.tsx +0 -63
  224. package/src/shared/lazy.ts +0 -52
  225. package/src/shared/serverFunction.ts +0 -10
  226. package/src/utils/debounce.ts +0 -10
  227. package/src/virtual.d.ts +0 -27
  228. package/tsconfig.json +0 -24
  229. package/vitest.config.ts +0 -9
  230. /package/{src/client/index.tsx → dist/client/index.d.ts} +0 -0
  231. /package/{src → dist}/shared/dev-overlay/styles.css +0 -0
@@ -1,389 +0,0 @@
1
- import type * as babel from "@babel/core";
2
- import type { Binding } from "@babel/traverse";
3
- import * as t from "@babel/types";
4
- import { bubbleFunctionDeclaration } from "./bubble-function-declaration.ts";
5
- import { generateUniqueName } from "./generate-unique-name.ts";
6
- import { getDescriptiveName } from "./get-descriptive-name.ts";
7
- import { getImportIdentifier } from "./get-import-identifier.ts";
8
- import { getRootStatementPath } from "./get-root-statement-path.ts";
9
- import { isStatementTopLevel } from "./is-statement-top-level.ts";
10
- import { isPathValid, unwrapPath } from "./paths.ts";
11
- import { removeUnusedVariables } from "./remove-unused-variables.ts";
12
- import type { ImportDefinition } from "./types.ts";
13
-
14
- export interface StateContext {
15
- env: "production" | "development";
16
- mode: "server" | "client";
17
- directive: string;
18
- hash: string;
19
- count: number;
20
- imports: Map<string, t.Identifier>;
21
- valid: boolean;
22
-
23
- definitions: {
24
- register: ImportDefinition;
25
- clone: ImportDefinition;
26
- };
27
- }
28
-
29
- type ValidFunction = t.ArrowFunctionExpression | t.FunctionExpression;
30
-
31
- function isValidFunction(node: t.Node): node is ValidFunction {
32
- return t.isArrowFunctionExpression(node) || t.isFunctionExpression(node);
33
- }
34
-
35
- function isDirectiveValid(ctx: StateContext, directives: t.Directive[]) {
36
- for (let i = 0, len = directives.length; i < len; i++) {
37
- if (directives[i]!.value.value === ctx.directive) {
38
- return true;
39
- }
40
- }
41
- return false;
42
- }
43
-
44
- function cleanDirectives(path: babel.NodePath<t.BlockStatement | t.Program>, target: string): void {
45
- const newDirectives: t.Directive[] = [];
46
- for (let i = 0, len = path.node.directives.length; i < len; i++) {
47
- const current = path.node.directives[i]!;
48
- if (current.value.value !== target) {
49
- newDirectives.push(current);
50
- }
51
- }
52
- path.node.directives = newDirectives;
53
- }
54
-
55
- function cleanFunctionDirectives(
56
- ctx: StateContext,
57
- path: babel.NodePath<t.FunctionDeclaration | ValidFunction>,
58
- ) {
59
- const body = path.get("body");
60
-
61
- if (isPathValid(body, t.isBlockStatement)) {
62
- cleanDirectives(body, ctx.directive);
63
- }
64
- }
65
-
66
- function isFunctionDirectiveValid(
67
- ctx: StateContext,
68
- path: babel.NodePath<t.FunctionDeclaration | ValidFunction>,
69
- ) {
70
- const body = path.get("body");
71
-
72
- if (isPathValid(body, t.isBlockStatement)) {
73
- return isDirectiveValid(ctx, body.node.directives);
74
- }
75
-
76
- return false;
77
- }
78
-
79
- function createID(ctx: StateContext, name: string) {
80
- const base = `${ctx.hash}-${ctx.count++}`;
81
- if (ctx.env === "development") {
82
- return `${base}-${name}`;
83
- }
84
- return base;
85
- }
86
-
87
- function transformFunction(
88
- ctx: StateContext,
89
- path: babel.NodePath<ValidFunction>,
90
- direct: boolean,
91
- ) {
92
- if (!direct) {
93
- if (!isFunctionDirectiveValid(ctx, path)) {
94
- return;
95
- }
96
- cleanFunctionDirectives(ctx, path);
97
- }
98
- // First, get root statement
99
- const rootStatement = getRootStatementPath(path);
100
-
101
- // Create a unique ID for the function
102
- const fnID = createID(ctx, getDescriptiveName(path, "anonymous"));
103
-
104
- if (ctx.mode === "server") {
105
- // Create a "source" function on the root-level
106
- const sourceReference = t.callExpression(
107
- getImportIdentifier(ctx.imports, path, ctx.definitions.register),
108
- [t.stringLiteral(fnID), path.node],
109
- );
110
-
111
- const sourceID = generateUniqueName(path, "serverFn");
112
-
113
- rootStatement.insertBefore(
114
- t.variableDeclaration("const", [t.variableDeclarator(sourceID, sourceReference)]),
115
- );
116
-
117
- // Clone the source function to replace the server function
118
- path.replaceWith(
119
- t.callExpression(getImportIdentifier(ctx.imports, path, ctx.definitions.clone), [sourceID]),
120
- );
121
- } else {
122
- // Otherwise, clone the function based on its ID
123
- path.replaceWith(
124
- t.callExpression(getImportIdentifier(ctx.imports, path, ctx.definitions.clone), [
125
- t.stringLiteral(fnID),
126
- ]),
127
- );
128
- }
129
-
130
- path.scope.crawl();
131
- }
132
-
133
- function traceBinding(path: babel.NodePath, name: string): Binding | undefined {
134
- const current = path.scope.getBinding(name);
135
- if (!current) {
136
- return undefined;
137
- }
138
- switch (current.kind) {
139
- case "const":
140
- case "let":
141
- case "var": {
142
- if (isPathValid(current.path, t.isVariableDeclarator)) {
143
- // Check if left is identifier
144
- const left = unwrapPath(current.path.get("id"), t.isIdentifier);
145
- if (left) {
146
- const right = unwrapPath(current.path.get("init"), t.isIdentifier);
147
- if (right) {
148
- return traceBinding(path, right.node.name);
149
- }
150
-
151
- // Only valid for functions
152
- const func = unwrapPath(current.path.get("init"), isValidFunction);
153
- if (func) {
154
- return current;
155
- }
156
- }
157
- }
158
- return undefined;
159
- }
160
- case "hoisted":
161
- case "local":
162
- case "module":
163
- case "param":
164
- case "unknown":
165
- return undefined;
166
- }
167
- }
168
-
169
- function transformBindingForServer(ctx: StateContext, binding: Binding) {
170
- if (isPathValid(binding.path, t.isVariableDeclarator)) {
171
- const right = unwrapPath(binding.path.get("init"), isValidFunction);
172
- if (right) {
173
- transformFunction(ctx, right, true);
174
- }
175
- }
176
- }
177
-
178
- interface State extends babel.PluginPass {
179
- opts: StateContext;
180
- }
181
-
182
- function transformModuleLevelDirective(ctx: StateContext, program: babel.NodePath<t.Program>) {
183
- cleanDirectives(program, ctx.directive);
184
- program.traverse({
185
- FunctionDeclaration(child) {
186
- // We only need to move top-level functions
187
- if (isStatementTopLevel(child)) {
188
- bubbleFunctionDeclaration(child);
189
- }
190
- },
191
- });
192
- program.scope.crawl();
193
- if (ctx.mode === "server") {
194
- // Trace bindings
195
- const bindings = new Set<Binding>();
196
-
197
- program.traverse({
198
- ExportDefaultDeclaration(path) {
199
- const id = unwrapPath(path.get("declaration"), t.isIdentifier);
200
- if (id) {
201
- const binding = traceBinding(path, id.node.name);
202
- if (binding) {
203
- bindings.add(binding);
204
- }
205
- }
206
- },
207
- ExportNamedDeclaration(path) {
208
- if (path.node.source || path.node.exportKind === "type") {
209
- return;
210
- }
211
- for (const specifier of path.get("specifiers")) {
212
- if (isPathValid(specifier, t.isExportSpecifier)) {
213
- const binding = traceBinding(specifier, specifier.node.local.name);
214
-
215
- if (binding) {
216
- bindings.add(binding);
217
- }
218
- }
219
- }
220
- const declarations = path.get("declaration");
221
-
222
- if (isPathValid(declarations, t.isVariableDeclaration)) {
223
- for (const declaration of declarations.get("declarations")) {
224
- // Check if left is identifier
225
- const left = unwrapPath(declaration.get("id"), t.isIdentifier);
226
- if (left) {
227
- const binding = traceBinding(left, left.node.name);
228
- if (binding) {
229
- bindings.add(binding);
230
- }
231
- }
232
- }
233
- }
234
- },
235
- });
236
-
237
- for (const binding of bindings) {
238
- transformBindingForServer(ctx, binding);
239
- }
240
- } else {
241
- // Trace bindings
242
- const uniqueBindings = new Set<Binding>();
243
- const exportedBindings = new Map<string, Binding>();
244
-
245
- program.traverse({
246
- ExportDefaultDeclaration(path) {
247
- const id = unwrapPath(path.get("declaration"), t.isIdentifier);
248
- if (id) {
249
- const binding = traceBinding(path, id.node.name);
250
- if (binding) {
251
- uniqueBindings.add(binding);
252
- exportedBindings.set("default", binding);
253
- }
254
- }
255
- },
256
- ExportNamedDeclaration(path) {
257
- if (path.node.source || path.node.exportKind === "type") {
258
- return;
259
- }
260
- for (const specifier of path.get("specifiers")) {
261
- if (isPathValid(specifier, t.isExportSpecifier)) {
262
- const binding = traceBinding(specifier, specifier.node.local.name);
263
-
264
- if (binding) {
265
- const key = t.isIdentifier(specifier.node.exported)
266
- ? specifier.node.exported.name
267
- : specifier.node.exported.value;
268
- uniqueBindings.add(binding);
269
- exportedBindings.set(key, binding);
270
- }
271
- }
272
- }
273
-
274
- const declarations = path.get("declaration");
275
-
276
- if (isPathValid(declarations, t.isVariableDeclaration)) {
277
- for (const declaration of declarations.get("declarations")) {
278
- // Check if left is identifier
279
- const left = unwrapPath(declaration.get("id"), t.isIdentifier);
280
- if (left) {
281
- const binding = traceBinding(left, left.node.name);
282
- if (binding) {
283
- uniqueBindings.add(binding);
284
- exportedBindings.set(left.node.name, binding);
285
- }
286
- }
287
- }
288
- }
289
- },
290
- });
291
-
292
- // generate ids for each unique binding
293
- const sourceIDs = new Map<Binding, string>();
294
- for (const binding of uniqueBindings) {
295
- if (isPathValid(binding.path, t.isVariableDeclarator)) {
296
- const init = unwrapPath(binding.path.get("init"), isValidFunction);
297
- if (init) {
298
- sourceIDs.set(binding, createID(ctx, getDescriptiveName(init, "anonymous")));
299
- }
300
- }
301
- }
302
-
303
- // clear body
304
- program.node.body = [];
305
-
306
- const declarations: t.VariableDeclarator[] = [];
307
- const specifiers: t.ExportSpecifier[] = [];
308
-
309
- const declarationMap = new Map<Binding, t.Identifier>();
310
-
311
- // Declare all client functions
312
- for (const [exported, binding] of exportedBindings) {
313
- let currentIdentifier = declarationMap.get(binding);
314
- if (!currentIdentifier) {
315
- currentIdentifier = generateUniqueName(program, "fn");
316
-
317
- const fnID = sourceIDs.get(binding);
318
-
319
- if (fnID) {
320
- declarations.push(
321
- t.variableDeclarator(
322
- currentIdentifier,
323
- t.callExpression(getImportIdentifier(ctx.imports, program, ctx.definitions.clone), [
324
- t.stringLiteral(fnID),
325
- ]),
326
- ),
327
- );
328
-
329
- declarationMap.set(binding, currentIdentifier);
330
- }
331
- }
332
-
333
- if (currentIdentifier) {
334
- specifiers.push(t.exportSpecifier(currentIdentifier, t.stringLiteral(exported)));
335
- }
336
- }
337
-
338
- const body: t.Statement[] = [];
339
-
340
- if (declarations.length > 0) {
341
- body.push(t.variableDeclaration("const", declarations));
342
- }
343
- if (specifiers.length > 0) {
344
- body.push(t.exportNamedDeclaration(null, specifiers, null));
345
- }
346
-
347
- program.pushContainer("body", body);
348
- }
349
- }
350
-
351
- export function directivesPlugin(): babel.PluginObj<State> {
352
- return {
353
- name: "solid-start:directives",
354
- visitor: {
355
- Program(program, ctx) {
356
- const isModuleLevel = isDirectiveValid(ctx.opts, program.node.directives);
357
- if (isModuleLevel) {
358
- transformModuleLevelDirective(ctx.opts, program);
359
- ctx.opts.valid = true;
360
- } else {
361
- // First, bubble up function declarations
362
- program.traverse({
363
- FunctionDeclaration(child) {
364
- // if (isFunctionDirectiveValid(ctx.opts, child)) {
365
- bubbleFunctionDeclaration(child);
366
- // }
367
- },
368
- });
369
- program.scope.crawl();
370
- // Now we transform each function
371
- program.traverse({
372
- ArrowFunctionExpression(path) {
373
- transformFunction(ctx.opts, path, false);
374
- },
375
- FunctionExpression(path) {
376
- transformFunction(ctx.opts, path, false);
377
- },
378
- });
379
- program.scope.crawl();
380
-
381
- if (ctx.opts.count > 0) {
382
- ctx.opts.valid = true;
383
- removeUnusedVariables(program);
384
- }
385
- }
386
- },
387
- },
388
- };
389
- }
@@ -1,70 +0,0 @@
1
- import type * as babel from "@babel/core";
2
- import * as t from "@babel/types";
3
- import { isPathValid } from "./paths.ts";
4
-
5
- function isInvalidForRemoval(path: babel.NodePath) {
6
- if (isPathValid(path, t.isCatchClause)) {
7
- // This case is for `catch (error)` blocks
8
- return true;
9
- }
10
-
11
- // This one is for destructured variables
12
- let target = path;
13
- if (isPathValid(path, t.isVariableDeclarator)) {
14
- target = path.get('id');
15
- }
16
- return isPathValid(target, t.isObjectPattern) || isPathValid(target, t.isArrayPattern);
17
- }
18
-
19
- export function removeUnusedVariables(program: babel.NodePath<t.Program>) {
20
- // TODO(Alexis):
21
- // This implementation is simple but slow
22
- // We repeat removing unused variables from each pass
23
- // until no potential unused variables are left.
24
- // There might be a simpler implementation.
25
- let dirty = true;
26
-
27
- while (dirty) {
28
- dirty = false;
29
- program.traverse({
30
- BindingIdentifier(path) {
31
- const binding = path.scope.getBinding(path.node.name);
32
-
33
- if (binding) {
34
- switch (binding.kind) {
35
- case "const":
36
- case "let":
37
- case "var":
38
- case "hoisted":
39
- case "module":
40
- if (binding.references === 0 && !binding.path.removed) {
41
- const parent = binding.path.parentPath;
42
- if (isPathValid(parent, t.isImportDeclaration)) {
43
- if (parent.node.specifiers.length === 1) {
44
- parent.remove();
45
- } else {
46
- binding.path.remove();
47
- }
48
- dirty = true;
49
- } else if (!(isInvalidForRemoval(binding.path))) {
50
- binding.path.remove();
51
- dirty = true;
52
- }
53
- }
54
- break;
55
- case "local":
56
- case "param":
57
- case "unknown":
58
- break;
59
- }
60
- }
61
- },
62
- VariableDeclaration(path) {
63
- if (path.node.declarations.length === 0) {
64
- path.remove();
65
- }
66
- },
67
- });
68
- program.scope.crawl();
69
- }
70
- }
@@ -1,214 +0,0 @@
1
- // @ts-nocheck
2
- /**
3
- * Copyright (c) 2019 Jason Dent
4
- * https://github.com/Jason3S/xxhash
5
- */
6
- const PRIME32_1 = 2654435761;
7
- const PRIME32_2 = 2246822519;
8
- const PRIME32_3 = 3266489917;
9
- const PRIME32_4 = 668265263;
10
- const PRIME32_5 = 374761393;
11
-
12
- function toUtf8(text: string): Uint8Array {
13
- const bytes: number[] = [];
14
- for (let i = 0, n = text.length; i < n; ++i) {
15
- const c = text.charCodeAt(i);
16
- if (c < 0x80) {
17
- bytes.push(c);
18
- } else if (c < 0x800) {
19
- bytes.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
20
- } else if (c < 0xd800 || c >= 0xe000) {
21
- bytes.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
22
- } else {
23
- const cp =
24
- 0x10000 + (((c & 0x3ff) << 10) | (text.charCodeAt(++i) & 0x3ff));
25
- bytes.push(
26
- 0xf0 | ((cp >> 18) & 0x7),
27
- 0x80 | ((cp >> 12) & 0x3f),
28
- 0x80 | ((cp >> 6) & 0x3f),
29
- 0x80 | (cp & 0x3f),
30
- );
31
- }
32
- }
33
- return new Uint8Array(bytes);
34
- }
35
- /**
36
- *
37
- * @param buffer - byte array or string
38
- * @param seed - optional seed (32-bit unsigned);
39
- */
40
- export default function xxHash32(
41
- buffer: Uint8Array | string,
42
- seed = 0,
43
- ): number {
44
- buffer = typeof buffer === 'string' ? toUtf8(buffer) : buffer;
45
- const b = buffer;
46
-
47
- /*
48
- Step 1. Initialize internal accumulators
49
- Each accumulator gets an initial value based on optional seed input.
50
- Since the seed is optional, it can be 0.
51
- ```
52
- u32 acc1 = seed + PRIME32_1 + PRIME32_2;
53
- u32 acc2 = seed + PRIME32_2;
54
- u32 acc3 = seed + 0;
55
- u32 acc4 = seed - PRIME32_1;
56
- ```
57
- Special case : input is less than 16 bytes
58
- When input is too small (< 16 bytes), the algorithm will not process any stripe.
59
- Consequently, it will not make use of parallel accumulators.
60
- In which case, a simplified initialization is performed, using a single accumulator :
61
- u32 acc = seed + PRIME32_5;
62
- The algorithm then proceeds directly to step 4.
63
- */
64
-
65
- let acc = (seed + PRIME32_5) & 0xffffffff;
66
- let offset = 0;
67
-
68
- if (b.length >= 16) {
69
- const accN = [
70
- (seed + PRIME32_1 + PRIME32_2) & 0xffffffff,
71
- (seed + PRIME32_2) & 0xffffffff,
72
- (seed + 0) & 0xffffffff,
73
- (seed - PRIME32_1) & 0xffffffff,
74
- ];
75
-
76
- /*
77
- Step 2. Process stripes
78
- A stripe is a contiguous segment of 16 bytes. It is evenly divided into 4 lanes,
79
- of 4 bytes each. The first lane is used to update accumulator 1, the second lane
80
- is used to update accumulator 2, and so on. Each lane read its associated 32-bit
81
- value using little-endian convention. For each {lane, accumulator}, the update
82
- process is called a round, and applies the following formula :
83
- ```
84
- accN = accN + (laneN * PRIME32_2);
85
- accN = accN <<< 13;
86
- accN = accN * PRIME32_1;
87
- ```
88
- This shuffles the bits so that any bit from input lane impacts several bits in
89
- output accumulator. All operations are performed modulo 2^32.
90
- Input is consumed one full stripe at a time. Step 2 is looped as many times as
91
- necessary to consume the whole input, except the last remaining bytes which cannot
92
- form a stripe (< 16 bytes). When that happens, move to step 3.
93
- */
94
-
95
- const b = buffer;
96
- const limit = b.length - 16;
97
- let lane = 0;
98
- for (offset = 0; (offset & 0xfffffff0) <= limit; offset += 4) {
99
- const i = offset;
100
- const laneN0 = b[i + 0] + (b[i + 1] << 8);
101
- const laneN1 = b[i + 2] + (b[i + 3] << 8);
102
- const laneNP = laneN0 * PRIME32_2 + ((laneN1 * PRIME32_2) << 16);
103
- let acc = (accN[lane] + laneNP) & 0xffffffff;
104
- acc = (acc << 13) | (acc >>> 19);
105
- const acc0 = acc & 0xffff;
106
- const acc1 = acc >>> 16;
107
- accN[lane] = (acc0 * PRIME32_1 + ((acc1 * PRIME32_1) << 16)) & 0xffffffff;
108
- lane = (lane + 1) & 0x3;
109
- }
110
-
111
- /*
112
- Step 3. Accumulator convergence
113
- All 4 lane accumulators from previous steps are merged to produce a
114
- single remaining accumulator
115
- of same width (32-bit). The associated formula is as follows :
116
- ```
117
- acc = (acc1 <<< 1) + (acc2 <<< 7) + (acc3 <<< 12) + (acc4 <<< 18);
118
- ```
119
- */
120
- acc =
121
- (((accN[0] << 1) | (accN[0] >>> 31)) +
122
- ((accN[1] << 7) | (accN[1] >>> 25)) +
123
- ((accN[2] << 12) | (accN[2] >>> 20)) +
124
- ((accN[3] << 18) | (accN[3] >>> 14))) &
125
- 0xffffffff;
126
- }
127
-
128
- /*
129
- Step 4. Add input length
130
- The input total length is presumed known at this stage.
131
- This step is just about adding the length to
132
- accumulator, so that it participates to final mixing.
133
- ```
134
- acc = acc + (u32)inputLength;
135
- ```
136
- */
137
- acc = (acc + buffer.length) & 0xffffffff;
138
-
139
- /*
140
- Step 5. Consume remaining input
141
- There may be up to 15 bytes remaining to consume from the input.
142
- The final stage will digest them according
143
- to following pseudo-code :
144
- ```
145
- while (remainingLength >= 4) {
146
- lane = read_32bit_little_endian(input_ptr);
147
- acc = acc + lane * PRIME32_3;
148
- acc = (acc <<< 17) * PRIME32_4;
149
- input_ptr += 4; remainingLength -= 4;
150
- }
151
- ```
152
- This process ensures that all input bytes are present in the final mix.
153
- */
154
-
155
- const limit = buffer.length - 4;
156
- for (; offset <= limit; offset += 4) {
157
- const i = offset;
158
- const laneN0 = b[i + 0] + (b[i + 1] << 8);
159
- const laneN1 = b[i + 2] + (b[i + 3] << 8);
160
- const laneP = laneN0 * PRIME32_3 + ((laneN1 * PRIME32_3) << 16);
161
- acc = (acc + laneP) & 0xffffffff;
162
- acc = (acc << 17) | (acc >>> 15);
163
- acc =
164
- ((acc & 0xffff) * PRIME32_4 + (((acc >>> 16) * PRIME32_4) << 16)) &
165
- 0xffffffff;
166
- }
167
-
168
- /*
169
- ```
170
- while (remainingLength >= 1) {
171
- lane = read_byte(input_ptr);
172
- acc = acc + lane * PRIME32_5;
173
- acc = (acc <<< 11) * PRIME32_1;
174
- input_ptr += 1; remainingLength -= 1;
175
- }
176
- ```
177
- */
178
-
179
- for (; offset < b.length; ++offset) {
180
- const lane = b[offset];
181
- acc += lane * PRIME32_5;
182
- acc = (acc << 11) | (acc >>> 21);
183
- acc =
184
- ((acc & 0xffff) * PRIME32_1 + (((acc >>> 16) * PRIME32_1) << 16)) &
185
- 0xffffffff;
186
- }
187
-
188
- /*
189
- Step 6. Final mix (avalanche)
190
- The final mix ensures that all input bits have a chance to impact any bit in
191
- the output digest, resulting in an unbiased distribution. This is also called
192
- avalanche effect.
193
- ```
194
- acc = acc xor (acc >> 15);
195
- acc = acc * PRIME32_2;
196
- acc = acc xor (acc >> 13);
197
- acc = acc * PRIME32_3;
198
- acc = acc xor (acc >> 16);
199
- ```
200
- */
201
-
202
- acc ^= acc >>> 15;
203
- acc =
204
- (((acc & 0xffff) * PRIME32_2) & 0xffffffff) +
205
- (((acc >>> 16) * PRIME32_2) << 16);
206
- acc ^= acc >>> 13;
207
- acc =
208
- (((acc & 0xffff) * PRIME32_3) & 0xffffffff) +
209
- (((acc >>> 16) * PRIME32_3) << 16);
210
- acc ^= acc >>> 16;
211
-
212
- // turn any negatives back into a positive number;
213
- return acc < 0 ? acc + 4294967296 : acc;
214
- }
package/src/env.d.ts DELETED
@@ -1,17 +0,0 @@
1
- // This file contains global type definitions that are internal to SolidStart and are not exported
2
-
3
- declare module "solid-start:server-fn-manifest" {
4
- type ServerFn = (...args: Array<any>) => Promise<any>;
5
- export function getServerFnById(id: string): Promise<ServerFn>;
6
- }
7
-
8
- interface ImportMetaEnv extends SolidStartMetaEnv {}
9
-
10
- interface SolidStartMetaEnv {
11
- START_SSR: boolean;
12
- START_APP_ENTRY: string;
13
- START_CLIENT_ENTRY: string;
14
- START_ISLANDS: boolean;
15
- // START_DEV_OVERLAY: boolean;
16
- // SERVER_BASE_URL: string;
17
- }