@dreamkit/dev 0.0.4 → 0.0.5
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/lib/DreamkitDevServer.d.ts.map +1 -1
- package/lib/DreamkitDevServer.js +5 -6
- package/lib/plugins/dreamkit.d.ts.map +1 -1
- package/lib/plugins/dreamkit.js +1 -9
- package/lib/transforms/to-solid-import.d.ts +2 -0
- package/lib/transforms/to-solid-import.d.ts.map +1 -0
- package/lib/transforms/to-solid-import.js +18 -0
- package/lib/transforms/to-solid-route.d.ts.map +1 -1
- package/lib/transforms/to-solid-route.js +11 -36
- package/lib/utils/ast.d.ts +2 -0
- package/lib/utils/ast.d.ts.map +1 -1
- package/lib/utils/ast.js +3 -0
- package/lib/utils/transform.d.ts +16 -8
- package/lib/utils/transform.d.ts.map +1 -1
- package/lib/utils/transform.js +21 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DreamkitDevServer.d.ts","sourceRoot":"","sources":["../src/DreamkitDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,cAAc,CAAC;AAKtB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"DreamkitDevServer.d.ts","sourceRoot":"","sources":["../src/DreamkitDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,cAAc,CAAC;AAKtB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AASpD,OAAO,EAAE,GAAG,EAAW,KAAK,EAAU,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAmC,aAAa,EAAE,MAAM,MAAM,CAAC;AAGtE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,GACtD,0BAA0B,CAAC;AAC7B,MAAM,MAAM,kBAAkB,GAAG,wBAAwB,GACvD,0BAA0B,CAAC;AAE7B,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,SAAS,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IACnD,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBACzB,SAAS,EAAE,oBAAoB;IA6BrC,KAAK,CAAC,IAAI,EAAE,MAAM;IAMlB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAKxC,gBAAgB;IAyBhB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAIjD,OAAO,CAAC,uBAAuB,UAAO;IAqCtC,IAAI;CAIX"}
|
package/lib/DreamkitDevServer.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { dreamkitPluginOptions, } from "./options.js";
|
|
2
|
-
import { generateIfChanges } from "./utils/ast.js";
|
|
3
2
|
import { log } from "./utils/log.js";
|
|
4
|
-
import { resolvePath } from "./utils/path.js";
|
|
3
|
+
import { getExt, resolvePath } from "./utils/path.js";
|
|
5
4
|
import { findFileRoutes } from "./utils/router.js";
|
|
6
5
|
import { VirtualShaking } from "./utils/shaking.js";
|
|
7
|
-
import { createTransformUrl,
|
|
6
|
+
import { createTransformUrl, getUrlTransforms, transformAndGenerate, } from "./utils/transform.js";
|
|
8
7
|
import { App, isRoute, $route } from "@dreamkit/app";
|
|
9
8
|
import { existsSync } from "fs";
|
|
10
9
|
import { createServer, createViteRuntime } from "vite";
|
|
@@ -48,7 +47,8 @@ export class DreamkitDevServer {
|
|
|
48
47
|
async fetch(path) {
|
|
49
48
|
//const mod = $server.moduleGraph.getModuleById(shaking.entry);
|
|
50
49
|
//if (mod) $server.moduleGraph.invalidateModule(mod);
|
|
51
|
-
|
|
50
|
+
const ext = getExt(path);
|
|
51
|
+
return await this.runtime.executeUrl(`${path}?${Date.now()}&ext=${ext}`);
|
|
52
52
|
}
|
|
53
53
|
async fetchDefault(path) {
|
|
54
54
|
const result = await this.fetch(path);
|
|
@@ -100,8 +100,7 @@ export class DreamkitDevServer {
|
|
|
100
100
|
enforce: "pre",
|
|
101
101
|
load: (id) => this.entry.tryLoad(id),
|
|
102
102
|
transform(code, id) {
|
|
103
|
-
|
|
104
|
-
return generateIfChanges(ast);
|
|
103
|
+
return transformAndGenerate(code, { toSolidImport: true }, ...getUrlTransforms(id));
|
|
105
104
|
},
|
|
106
105
|
handleHotUpdate: async ({ file, read, modules }) => {
|
|
107
106
|
return this.entry.tryUpdate(file, read, modules);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dreamkit.d.ts","sourceRoot":"","sources":["../../src/plugins/dreamkit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"dreamkit.d.ts","sourceRoot":"","sources":["../../src/plugins/dreamkit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAItD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,wBAAgB,cAAc,CAAC,SAAS,GAAE,qBAA0B,GAAG,MAAM,CA+C5E"}
|
package/lib/plugins/dreamkit.js
CHANGED
|
@@ -23,15 +23,7 @@ export function dreamkitPlugin(inOptions = {}) {
|
|
|
23
23
|
const searchParams = new URLSearchParams(searchString);
|
|
24
24
|
const dreamkitPickEntry = searchParams.get("dk-pick-entry");
|
|
25
25
|
const picks = searchParams.getAll("pick");
|
|
26
|
-
const transforms = [];
|
|
27
|
-
if (code.includes("'dreamkit'") || code.includes('"dreamkit"'))
|
|
28
|
-
transforms.push({
|
|
29
|
-
replaceImportSpec: {
|
|
30
|
-
source: "dreamkit",
|
|
31
|
-
spec: ["Link"],
|
|
32
|
-
newSource: "dreamkit/adapters/solid.js",
|
|
33
|
-
},
|
|
34
|
-
});
|
|
26
|
+
const transforms = [{ toSolidImport: true }];
|
|
35
27
|
if (dreamkitPickEntry) {
|
|
36
28
|
transforms.push({
|
|
37
29
|
pickExport: [dreamkitPickEntry],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-solid-import.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-import.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,oDAgBxB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineTransform } from "../utils/ast.js";
|
|
2
|
+
import { replaceImportSpec } from "./replace-import-spec.js";
|
|
3
|
+
export const toSolidImport = defineTransform({
|
|
4
|
+
onlyIf: (code) => code.includes("'dreamkit'") || code.includes('"dreamkit"'),
|
|
5
|
+
run: (ast) => replaceImportSpec(ast, {
|
|
6
|
+
source: "dreamkit",
|
|
7
|
+
newSource: "dreamkit/solid",
|
|
8
|
+
spec: [
|
|
9
|
+
"Link",
|
|
10
|
+
"Input",
|
|
11
|
+
"createAction",
|
|
12
|
+
"useRoute",
|
|
13
|
+
"defineLink",
|
|
14
|
+
"LinkComponent",
|
|
15
|
+
"$route",
|
|
16
|
+
],
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-solid-route.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"to-solid-route.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,YAAY,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,UA2IpD"}
|
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
import { addFileChanges, getFirstChain } from "../utils/ast.js";
|
|
2
2
|
import { traverse } from "../utils/babel.js";
|
|
3
|
-
import { replaceImportSpec } from "./replace-import-spec.js";
|
|
4
3
|
import * as t from "@babel/types";
|
|
5
4
|
export function toSolidRoute(ast) {
|
|
6
5
|
let changes = 0;
|
|
7
|
-
let imports;
|
|
8
6
|
let routeImportName;
|
|
9
7
|
const routeSpec = "$route";
|
|
10
|
-
const routeSource = "dreamkit";
|
|
11
|
-
const routeNewSource = "dreamkit/adapters/solid.js";
|
|
12
|
-
replaceImportSpec(ast, {
|
|
13
|
-
newSource: routeNewSource,
|
|
14
|
-
source: routeSource,
|
|
15
|
-
spec: [routeSpec],
|
|
16
|
-
});
|
|
8
|
+
const routeSource = "dreamkit/solid";
|
|
17
9
|
traverse(ast, {
|
|
18
10
|
Program(programPath) {
|
|
19
11
|
traverse(programPath.node, {
|
|
20
12
|
ImportDeclaration(importPath) {
|
|
21
13
|
importPath.traverse({
|
|
22
14
|
ImportSpecifier(path) {
|
|
23
|
-
// import { route as ? } from "dreamkit/
|
|
15
|
+
// import { route as ? } from "dreamkit/solid";
|
|
24
16
|
const isRouteImport = path.node.imported.type === "Identifier" &&
|
|
25
17
|
path.node.imported.name === routeSpec &&
|
|
26
|
-
importPath.node.source.value ===
|
|
18
|
+
importPath.node.source.value === routeSource;
|
|
27
19
|
if (isRouteImport)
|
|
28
20
|
routeImportName = path.node.local.name;
|
|
29
21
|
},
|
|
@@ -35,11 +27,10 @@ export function toSolidRoute(ast) {
|
|
|
35
27
|
// import { $route } from "dreamkit";
|
|
36
28
|
// export default route.params({}).create(() => {});
|
|
37
29
|
// [output]
|
|
38
|
-
// import { $route as _$route } from "dreamkit/
|
|
39
|
-
// import * as $deps from "dreamkit/adapters/solid-deps.js"
|
|
30
|
+
// import { $route as _$route } from "dreamkit/solid"
|
|
40
31
|
// const selfRoute = _$route.params({});
|
|
41
32
|
// export const route = selfRoute.createRouteDefinition();
|
|
42
|
-
// export default delfRoute.
|
|
33
|
+
// export default delfRoute.create(() => {})
|
|
43
34
|
if (
|
|
44
35
|
// route.?.?.?.create()
|
|
45
36
|
dec.type === "CallExpression" &&
|
|
@@ -48,16 +39,14 @@ export function toSolidRoute(ast) {
|
|
|
48
39
|
dec.callee.property.type == "Identifier" &&
|
|
49
40
|
dec.callee.property.name === "create") {
|
|
50
41
|
changes++;
|
|
51
|
-
if (!imports)
|
|
52
|
-
imports = addImports(ast, programPath);
|
|
53
42
|
const selfRoute = programPath.scope.generateUid("selfRoute");
|
|
54
43
|
ast.program.body.splice(ast.program.body.indexOf(path.node), 1,
|
|
55
44
|
// const selfRoute = route.?.?.?
|
|
56
45
|
createSelfRoute(selfRoute, dec.callee.object),
|
|
57
46
|
// export const route = selfRoute.createRouteDefinition();
|
|
58
47
|
createExportRouteDefinition(selfRoute),
|
|
59
|
-
// export default selfRoute.
|
|
60
|
-
createDefaultExportRoute(selfRoute,
|
|
48
|
+
// export default selfRoute.create(() => {})
|
|
49
|
+
createDefaultExportRoute(selfRoute, dec.arguments[0]));
|
|
61
50
|
}
|
|
62
51
|
},
|
|
63
52
|
// [input]
|
|
@@ -65,8 +54,7 @@ export function toSolidRoute(ast) {
|
|
|
65
54
|
// export const route = $route.params({}).path('/path');
|
|
66
55
|
// export default function Users() { useRoute(route); }
|
|
67
56
|
// [output]
|
|
68
|
-
// import { $route as _$route } from "dreamkit/
|
|
69
|
-
// import * as $deps from "dreamkit/adapters/solid-deps.js"
|
|
57
|
+
// import { $route as _$route } from "dreamkit/solid"
|
|
70
58
|
// const selfRoute = _$route.params({}).path('/path');
|
|
71
59
|
// export const route = selfRoute.createRouteDefinition();
|
|
72
60
|
// export default selfRoute.create(function Users() { useRoute(selfRoute); });
|
|
@@ -83,8 +71,6 @@ export function toSolidRoute(ast) {
|
|
|
83
71
|
// [output]
|
|
84
72
|
// const _selfRoute = $route.?;
|
|
85
73
|
// export const route = _selfRoute.createRouteDefinition();
|
|
86
|
-
if (!imports)
|
|
87
|
-
imports = addImports(ast, programPath);
|
|
88
74
|
let exportFunction;
|
|
89
75
|
const selfRoute = programPath.scope.generateUid("selfRoute");
|
|
90
76
|
const index = ast.program.body.indexOf(path.node);
|
|
@@ -105,7 +91,7 @@ export function toSolidRoute(ast) {
|
|
|
105
91
|
});
|
|
106
92
|
ast.program.body.splice(index, 1, createSelfRoute(selfRoute, dec.init), createExportRouteDefinition(selfRoute), ...(exportFunction
|
|
107
93
|
? [
|
|
108
|
-
createDefaultExportRoute(selfRoute,
|
|
94
|
+
createDefaultExportRoute(selfRoute, exportFunction.type === "FunctionDeclaration"
|
|
109
95
|
? t.functionExpression(exportFunction.id, exportFunction.params, exportFunction.body)
|
|
110
96
|
: exportFunction),
|
|
111
97
|
]
|
|
@@ -128,17 +114,6 @@ function createExportRouteDefinition(name) {
|
|
|
128
114
|
t.variableDeclarator(t.identifier("route"), t.callExpression(t.memberExpression(t.identifier(name), t.identifier("createRouteDefinition")), [])),
|
|
129
115
|
]));
|
|
130
116
|
}
|
|
131
|
-
function createDefaultExportRoute(name,
|
|
132
|
-
return t.exportDefaultDeclaration(t.callExpression(t.memberExpression(t.
|
|
133
|
-
t.objectExpression([
|
|
134
|
-
t.objectProperty(t.identifier("deps"), t.identifier(depsImportName)),
|
|
135
|
-
]),
|
|
136
|
-
]), t.identifier("create")), [component]));
|
|
137
|
-
}
|
|
138
|
-
function addImports(ast, program) {
|
|
139
|
-
const deps = program.scope.generateUid("deps");
|
|
140
|
-
ast.program.body.unshift(t.importDeclaration([t.importNamespaceSpecifier(t.identifier(deps))], t.stringLiteral("dreamkit/adapters/solid-deps.js")));
|
|
141
|
-
return {
|
|
142
|
-
deps,
|
|
143
|
-
};
|
|
117
|
+
function createDefaultExportRoute(name, component) {
|
|
118
|
+
return t.exportDefaultDeclaration(t.callExpression(t.memberExpression(t.identifier(name), t.identifier("create")), [component]));
|
|
144
119
|
}
|
package/lib/utils/ast.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Transform } from "./transform.js";
|
|
1
2
|
import { ParseResult } from "@babel/parser";
|
|
2
3
|
import * as t from "@babel/types";
|
|
3
4
|
import * as lexer from "es-module-lexer";
|
|
@@ -14,4 +15,5 @@ export declare function getFirstChain(ref: t.Node): {
|
|
|
14
15
|
export declare function analyzeModule(path: string): Promise<readonly [imports: readonly lexer.ImportSpecifier[], exports: readonly lexer.ExportSpecifier[], facade: boolean, hasModuleSyntax: boolean]>;
|
|
15
16
|
export declare function findExportedNames(ast: ParseFileResult): string[];
|
|
16
17
|
export declare function findExportedNamesFromFile(path: string): Promise<string[]>;
|
|
18
|
+
export declare function defineTransform<T>(transform: Transform<T>): Transform<T>;
|
|
17
19
|
//# sourceMappingURL=ast.d.ts.map
|
package/lib/utils/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/utils/ast.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AAIzC,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,iBAIjD;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAElD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,uBAKrC;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EA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,aAAa,CAAC,IAAI,EAAE,MAAM,uJAQ/C;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,eAAe,YAkBrD;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,qBAG3D;AACD,wBAAgB,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAExE"}
|
package/lib/utils/ast.js
CHANGED
package/lib/utils/transform.d.ts
CHANGED
|
@@ -8,18 +8,26 @@ declare const $transforms: {
|
|
|
8
8
|
pickExport: typeof pickExport;
|
|
9
9
|
exportDefault: typeof exportDefault;
|
|
10
10
|
noExport: typeof noExport;
|
|
11
|
-
toSolidRoute: typeof toSolidRoute;
|
|
12
11
|
replaceImportSpec: typeof replaceImportSpec;
|
|
12
|
+
toSolidRoute: typeof toSolidRoute;
|
|
13
|
+
toSolidImport: Transform<unknown>;
|
|
14
|
+
};
|
|
15
|
+
export type TransformObject = {
|
|
16
|
+
[K in keyof typeof $transforms]?: TrueIfUndefined<Parameters<(typeof $transforms)[K] extends Transform<any> ? (typeof $transforms)[K]["run"] : (typeof $transforms)[K] extends TransformRun<any> ? (typeof $transforms)[K] : never>[1]>;
|
|
17
|
+
};
|
|
18
|
+
export type TransformRun<T = any> = (ast: ParseFileResult, options: T) => number;
|
|
19
|
+
export type Transform<T = any> = {
|
|
20
|
+
onlyIf?: (code: string, options: T) => boolean;
|
|
21
|
+
run: TransformRun<T>;
|
|
13
22
|
};
|
|
14
|
-
export
|
|
15
|
-
|
|
23
|
+
export declare function transformCode(code: string, ...input: TransformObject[]): ParseFileResult | undefined;
|
|
24
|
+
export declare function transformAndGenerate(code: string, ...input: TransformObject[]): import("@babel/generator").GeneratorResult | {
|
|
25
|
+
code: undefined;
|
|
26
|
+
map: undefined;
|
|
16
27
|
};
|
|
17
|
-
export declare function transformCode(code: string, ...input: Transform[]): ParseFileResult | undefined;
|
|
18
28
|
export declare function transformCodeByUrl(id: string, code: string): ParseFileResult | undefined;
|
|
19
29
|
type TrueIfUndefined<T> = [undefined] extends [T] ? true : T;
|
|
20
|
-
export declare function createTransformUrl(id: string, ...transforms:
|
|
21
|
-
|
|
22
|
-
}[]): string;
|
|
23
|
-
export declare function getUrlTransforms(id: string): Transform[];
|
|
30
|
+
export declare function createTransformUrl(id: string, ...transforms: TransformObject[]): string;
|
|
31
|
+
export declare function getUrlTransforms(id: string): TransformObject[];
|
|
24
32
|
export {};
|
|
25
33
|
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAgC,eAAe,EAAE,MAAM,UAAU,CAAC;AAEzE,QAAA,MAAM,WAAW;;;;;;;CAOhB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;KAC3B,CAAC,IAAI,MAAM,OAAO,WAAW,CAAC,CAAC,EAAE,eAAe,CAC/C,UAAU,CACR,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,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"../transforms/no-export.js";
|
|
3
3
|
import { pickExport } from "../transforms/pick-export.js";
|
|
4
4
|
import { replaceImportSpec } from "../transforms/replace-import-spec.js";
|
|
5
|
+
import { toSolidImport } from "../transforms/to-solid-import.js";
|
|
5
6
|
import { toSolidRoute } from "../transforms/to-solid-route.js";
|
|
6
|
-
import { parseFile } from "./ast.js";
|
|
7
|
+
import { generateIfChanges, parseFile } from "./ast.js";
|
|
7
8
|
const $transforms = {
|
|
8
9
|
pickExport,
|
|
9
10
|
exportDefault,
|
|
10
11
|
noExport,
|
|
11
|
-
toSolidRoute,
|
|
12
12
|
replaceImportSpec,
|
|
13
|
+
toSolidRoute,
|
|
14
|
+
toSolidImport,
|
|
13
15
|
};
|
|
14
16
|
export function transformCode(code, ...input) {
|
|
15
17
|
let ast;
|
|
16
18
|
for (const item of input) {
|
|
17
|
-
for (let [name,
|
|
19
|
+
for (let [name, options] of Object.entries(item)) {
|
|
18
20
|
if (name in $transforms) {
|
|
21
|
+
const $transform = $transforms[name];
|
|
22
|
+
let run;
|
|
23
|
+
if ("run" in $transform) {
|
|
24
|
+
if (ast === undefined && $transform.onlyIf)
|
|
25
|
+
if (!$transform.onlyIf(code, options))
|
|
26
|
+
continue;
|
|
27
|
+
run = $transform.run;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
run = $transform;
|
|
31
|
+
}
|
|
19
32
|
ast = ast || parseFile(code);
|
|
20
|
-
|
|
33
|
+
run(ast, options);
|
|
21
34
|
}
|
|
22
35
|
}
|
|
23
36
|
}
|
|
24
37
|
return ast;
|
|
25
38
|
}
|
|
39
|
+
export function transformAndGenerate(code, ...input) {
|
|
40
|
+
const ast = transformCode(code, ...input);
|
|
41
|
+
return generateIfChanges(ast) || { code: undefined, map: undefined };
|
|
42
|
+
}
|
|
26
43
|
export function transformCodeByUrl(id, code) {
|
|
27
44
|
const transforms = getUrlTransforms(id);
|
|
28
45
|
return transformCode(code, ...transforms);
|