@solidjs/start 2.0.0-beta.0 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/config/dev-server.js +3 -1
- package/dist/config/fs-router.d.ts +1 -1
- package/dist/http/index.d.ts +4 -4
- package/package.json +11 -5
- package/scripts/build.js +0 -15
- package/scripts/validate-imports.js +0 -316
- package/src/client/StartClient.tsx +0 -34
- package/src/client/index.tsx +0 -2
- package/src/client/mount.ts +0 -1
- package/src/client/spa/index.tsx +0 -9
- package/src/config/constants.ts +0 -19
- package/src/config/dev-server.ts +0 -157
- package/src/config/env.ts +0 -105
- package/src/config/fs-router.ts +0 -162
- package/src/config/fs-routes/fs-watcher.ts +0 -66
- package/src/config/fs-routes/index.ts +0 -136
- package/src/config/fs-routes/router.ts +0 -184
- package/src/config/fs-routes/tree-shake.ts +0 -324
- package/src/config/index.ts +0 -239
- package/src/config/lazy.ts +0 -132
- package/src/config/manifest.ts +0 -120
- package/src/config/utils.ts +0 -5
- package/src/config/vite-utils.ts +0 -113
- package/src/directives/bubble-function-declaration.ts +0 -33
- package/src/directives/compile.ts +0 -54
- package/src/directives/generate-unique-name.ts +0 -22
- package/src/directives/get-descriptive-name.ts +0 -39
- package/src/directives/get-import-identifier.ts +0 -34
- package/src/directives/get-root-statement-path.ts +0 -14
- package/src/directives/index.ts +0 -233
- package/src/directives/is-statement-top-level.ts +0 -13
- package/src/directives/paths.ts +0 -63
- package/src/directives/plugin.ts +0 -389
- package/src/directives/remove-unused-variables.ts +0 -70
- package/src/directives/types.ts +0 -12
- package/src/directives/xxhash32.ts +0 -214
- package/src/env.d.ts +0 -17
- package/src/fns/client.ts +0 -141
- package/src/fns/handler.spec.ts +0 -85
- package/src/fns/handler.ts +0 -287
- package/src/fns/registration.ts +0 -19
- package/src/fns/serialization.ts +0 -250
- package/src/fns/server.ts +0 -46
- package/src/fns/shared.ts +0 -116
- package/src/http/index.ts +0 -216
- package/src/index.tsx +0 -7
- package/src/internal.d.ts +0 -14
- package/src/middleware/index.ts +0 -92
- package/src/router.tsx +0 -37
- package/src/server/StartServer.tsx +0 -58
- package/src/server/assets/PatchVirtualDevStyles.tsx +0 -31
- package/src/server/assets/index.ts +0 -70
- package/src/server/assets/render.tsx +0 -46
- package/src/server/collect-styles.ts +0 -70
- package/src/server/fetchEvent.spec.ts +0 -85
- package/src/server/fetchEvent.ts +0 -36
- package/src/server/handler.ts +0 -261
- package/src/server/index.tsx +0 -29
- package/src/server/manifest/client-manifest.ts +0 -8
- package/src/server/manifest/dev-client-manifest.ts +0 -21
- package/src/server/manifest/dev-ssr-manifest.ts +0 -23
- package/src/server/manifest/prod-client-manifest.ts +0 -21
- package/src/server/manifest/prod-ssr-manifest.ts +0 -109
- package/src/server/manifest/ssr-manifest.ts +0 -10
- package/src/server/routes.ts +0 -126
- package/src/server/spa/StartServer.tsx +0 -42
- package/src/server/spa/handler.ts +0 -29
- package/src/server/spa/index.tsx +0 -5
- package/src/server/types.ts +0 -82
- package/src/server/util.ts +0 -12
- package/src/shared/ErrorBoundary.tsx +0 -52
- package/src/shared/GET.ts +0 -8
- package/src/shared/HttpHeader.tsx +0 -42
- package/src/shared/HttpStatusCode.ts +0 -27
- package/src/shared/clientOnly.ts +0 -44
- package/src/shared/dev-overlay/CodeView.tsx +0 -90
- package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
- package/src/shared/dev-overlay/createStackFrame.ts +0 -74
- package/src/shared/dev-overlay/download.ts +0 -6
- package/src/shared/dev-overlay/env.d.ts +0 -4
- package/src/shared/dev-overlay/get-source-map.ts +0 -33
- package/src/shared/dev-overlay/icons.tsx +0 -456
- package/src/shared/dev-overlay/index.tsx +0 -63
- package/src/shared/dev-overlay/styles.css +0 -292
- package/src/shared/lazy.ts +0 -52
- package/src/shared/serverFunction.ts +0 -10
- package/src/utils/debounce.ts +0 -10
- package/src/virtual.d.ts +0 -27
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -9
package/src/directives/paths.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type * as t from "@babel/types";
|
|
2
|
-
|
|
3
|
-
type TypeFilter<V extends t.Node> = (node: t.Node) => node is V;
|
|
4
|
-
|
|
5
|
-
export function isPathValid<V extends t.Node>(
|
|
6
|
-
path: unknown,
|
|
7
|
-
key: TypeFilter<V>,
|
|
8
|
-
): path is babel.NodePath<V> {
|
|
9
|
-
const node = (path as babel.NodePath).node;
|
|
10
|
-
return node ? key(node) : false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type NestedExpression =
|
|
14
|
-
| t.ParenthesizedExpression
|
|
15
|
-
| t.TypeCastExpression
|
|
16
|
-
| t.TSAsExpression
|
|
17
|
-
| t.TSSatisfiesExpression
|
|
18
|
-
| t.TSNonNullExpression
|
|
19
|
-
| t.TSInstantiationExpression
|
|
20
|
-
| t.TSTypeAssertion;
|
|
21
|
-
|
|
22
|
-
export function isNestedExpression(node: t.Node): node is NestedExpression {
|
|
23
|
-
switch (node.type) {
|
|
24
|
-
case "ParenthesizedExpression":
|
|
25
|
-
case "TypeCastExpression":
|
|
26
|
-
case "TSAsExpression":
|
|
27
|
-
case "TSSatisfiesExpression":
|
|
28
|
-
case "TSNonNullExpression":
|
|
29
|
-
case "TSTypeAssertion":
|
|
30
|
-
case "TSInstantiationExpression":
|
|
31
|
-
return true;
|
|
32
|
-
default:
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type TypeCheck<K> = K extends TypeFilter<infer U> ? U : never;
|
|
38
|
-
|
|
39
|
-
export function unwrapNode<K extends (value: t.Node) => boolean>(
|
|
40
|
-
node: t.Node,
|
|
41
|
-
key: K,
|
|
42
|
-
): TypeCheck<K> | undefined {
|
|
43
|
-
if (key(node)) {
|
|
44
|
-
return node as TypeCheck<K>;
|
|
45
|
-
}
|
|
46
|
-
if (isNestedExpression(node)) {
|
|
47
|
-
return unwrapNode(node.expression, key);
|
|
48
|
-
}
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function unwrapPath<V extends t.Node>(
|
|
53
|
-
path: unknown,
|
|
54
|
-
key: TypeFilter<V>,
|
|
55
|
-
): babel.NodePath<V> | undefined {
|
|
56
|
-
if (isPathValid(path, key)) {
|
|
57
|
-
return path;
|
|
58
|
-
}
|
|
59
|
-
if (isPathValid(path, isNestedExpression)) {
|
|
60
|
-
return unwrapPath(path.get("expression"), key);
|
|
61
|
-
}
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
package/src/directives/plugin.ts
DELETED
|
@@ -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
|
-
}
|
package/src/directives/types.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface NamedImportDefinition {
|
|
2
|
-
kind: "named";
|
|
3
|
-
name: string;
|
|
4
|
-
source: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface DefaultImportDefinition {
|
|
8
|
-
kind: "default";
|
|
9
|
-
source: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type ImportDefinition = DefaultImportDefinition | NamedImportDefinition;
|