@meekojs/meeko 0.0.3 → 0.0.4
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 +18 -1
- package/dist/autoimports-ts.d.ts +26 -0
- package/dist/autoimports-ts.js +127 -0
- package/dist/autoimports-ts.js.map +1 -0
- package/dist/autoimports.d.ts +21 -0
- package/dist/autoimports.js +285 -0
- package/dist/autoimports.js.map +1 -0
- package/dist/check.js +35 -23
- package/dist/check.js.map +1 -0
- package/dist/cli.js +33 -4
- package/dist/cli.js.map +1 -0
- package/dist/compiler/import-graph.d.ts +8 -0
- package/dist/compiler/import-graph.js +33 -0
- package/dist/compiler/import-graph.js.map +1 -0
- package/dist/compiler/mapping.js +1 -0
- package/dist/compiler/mapping.js.map +1 -0
- package/dist/compiler/project-root.d.ts +2 -0
- package/dist/compiler/project-root.js +18 -0
- package/dist/compiler/project-root.js.map +1 -0
- package/dist/compiler/sfc.js +1 -0
- package/dist/compiler/sfc.js.map +1 -0
- package/dist/compiler/sourcemap.d.ts +3 -0
- package/dist/compiler/sourcemap.js +75 -0
- package/dist/compiler/sourcemap.js.map +1 -0
- package/dist/compiler/template.js +1 -0
- package/dist/compiler/template.js.map +1 -0
- package/dist/compiler.js +11 -5
- package/dist/compiler.js.map +1 -0
- package/dist/devtools-ui/index.js +1 -0
- package/dist/devtools-ui/index.js.map +1 -0
- package/dist/devtools.js +1 -0
- package/dist/devtools.js.map +1 -0
- package/dist/dom.d.ts +8 -1
- package/dist/dom.js +10 -5
- package/dist/dom.js.map +1 -0
- package/dist/framework/check-app.d.ts +5 -0
- package/dist/framework/check-app.js +59 -0
- package/dist/framework/check-app.js.map +1 -0
- package/dist/framework/client.d.ts +45 -0
- package/dist/framework/client.js +146 -0
- package/dist/framework/client.js.map +1 -0
- package/dist/framework/clients.d.ts +82 -0
- package/dist/framework/clients.js +182 -0
- package/dist/framework/clients.js.map +1 -0
- package/dist/framework/config-type.d.ts +10 -0
- package/dist/framework/config-type.js +4 -0
- package/dist/framework/config-type.js.map +1 -0
- package/dist/framework/config.d.ts +15 -0
- package/dist/framework/config.js +138 -0
- package/dist/framework/config.js.map +1 -0
- package/dist/framework/contracts-generate.d.ts +8 -0
- package/dist/framework/contracts-generate.js +227 -0
- package/dist/framework/contracts-generate.js.map +1 -0
- package/dist/framework/generate.d.ts +7 -0
- package/dist/framework/generate.js +67 -0
- package/dist/framework/generate.js.map +1 -0
- package/dist/framework/init.d.ts +2 -0
- package/dist/framework/init.js +362 -0
- package/dist/framework/init.js.map +1 -0
- package/dist/framework/modules.d.ts +22 -0
- package/dist/framework/modules.js +29 -0
- package/dist/framework/modules.js.map +1 -0
- package/dist/framework/page.d.ts +60 -0
- package/dist/framework/page.js +42 -0
- package/dist/framework/page.js.map +1 -0
- package/dist/framework/prerender.d.ts +14 -0
- package/dist/framework/prerender.js +104 -0
- package/dist/framework/prerender.js.map +1 -0
- package/dist/framework/router.d.ts +39 -0
- package/dist/framework/router.js +173 -0
- package/dist/framework/router.js.map +1 -0
- package/dist/framework/server.d.ts +51 -0
- package/dist/framework/server.js +192 -0
- package/dist/framework/server.js.map +1 -0
- package/dist/framework/socket-contracts-generate.d.ts +5 -0
- package/dist/framework/socket-contracts-generate.js +159 -0
- package/dist/framework/socket-contracts-generate.js.map +1 -0
- package/dist/framework/socket.d.ts +70 -0
- package/dist/framework/socket.js +150 -0
- package/dist/framework/socket.js.map +1 -0
- package/dist/framework/state.d.ts +15 -0
- package/dist/framework/state.js +72 -0
- package/dist/framework/state.js.map +1 -0
- package/dist/framework-server/auto-clients.d.ts +3 -0
- package/dist/framework-server/auto-clients.js +27 -0
- package/dist/framework-server/auto-clients.js.map +1 -0
- package/dist/framework-server/context.d.ts +21 -0
- package/dist/framework-server/context.js +22 -0
- package/dist/framework-server/context.js.map +1 -0
- package/dist/framework-server/contracts.d.ts +64 -0
- package/dist/framework-server/contracts.js +129 -0
- package/dist/framework-server/contracts.js.map +1 -0
- package/dist/framework-server/discovery.d.ts +40 -0
- package/dist/framework-server/discovery.js +252 -0
- package/dist/framework-server/discovery.js.map +1 -0
- package/dist/framework-server/local.d.ts +19 -0
- package/dist/framework-server/local.js +98 -0
- package/dist/framework-server/local.js.map +1 -0
- package/dist/framework-server/node-upgrade.d.ts +23 -0
- package/dist/framework-server/node-upgrade.js +78 -0
- package/dist/framework-server/node-upgrade.js.map +1 -0
- package/dist/framework-server/node-websocket.d.ts +16 -0
- package/dist/framework-server/node-websocket.js +125 -0
- package/dist/framework-server/node-websocket.js.map +1 -0
- package/dist/framework-server/openapi.d.ts +17 -0
- package/dist/framework-server/openapi.js +118 -0
- package/dist/framework-server/openapi.js.map +1 -0
- package/dist/framework-server/session-stores.d.ts +66 -0
- package/dist/framework-server/session-stores.js +96 -0
- package/dist/framework-server/session-stores.js.map +1 -0
- package/dist/framework-server/sessions.d.ts +64 -0
- package/dist/framework-server/sessions.js +136 -0
- package/dist/framework-server/sessions.js.map +1 -0
- package/dist/framework-server/socket.d.ts +83 -0
- package/dist/framework-server/socket.js +161 -0
- package/dist/framework-server/socket.js.map +1 -0
- package/dist/framework-server.d.ts +21 -0
- package/dist/framework-server.js +12 -0
- package/dist/framework-server.js.map +1 -0
- package/dist/framework.d.ts +29 -0
- package/dist/framework.js +13 -0
- package/dist/framework.js.map +1 -0
- package/dist/hmr.js +1 -0
- package/dist/hmr.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/dist/init.js +4 -2
- package/dist/init.js.map +1 -0
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -0
- package/dist/node.d.ts +12 -0
- package/dist/node.js +52 -0
- package/dist/node.js.map +1 -0
- package/dist/reactivity.d.ts +12 -0
- package/dist/reactivity.js +40 -3
- package/dist/reactivity.js.map +1 -0
- package/dist/server.js +1 -0
- package/dist/server.js.map +1 -0
- package/dist/types.js +23 -8
- package/dist/types.js.map +1 -0
- package/dist/vite.js +91 -6
- package/dist/vite.js.map +1 -0
- package/package.json +14 -3
package/dist/check.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { readFile,
|
|
4
|
-
import {
|
|
3
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import {
|
|
7
|
+
import { compileWithAutoImports } from "./autoimports.js";
|
|
8
8
|
import { originalOffset } from "./compiler/mapping.js";
|
|
9
|
+
import { moduleSpecifiers } from "./compiler/import-graph.js";
|
|
10
|
+
import { projectRoot } from "./compiler/project-root.js";
|
|
9
11
|
import { compileError, MeekoCompileError, locate } from "./compiler/sfc.js";
|
|
10
12
|
const execFileAsync = promisify(execFile);
|
|
11
13
|
const tscPath = join(dirname(fileURLToPath(import.meta.resolve("typescript/package.json"))), "bin", "tsc");
|
|
@@ -13,39 +15,49 @@ async function compileGraph(source, filename) {
|
|
|
13
15
|
const byOriginal = new Map();
|
|
14
16
|
const byGenerated = new Map();
|
|
15
17
|
const nonce = randomUUID();
|
|
18
|
+
const rootDirectory = projectRoot(filename);
|
|
19
|
+
const generatedDirectory = join(rootDirectory, ".meeko", "check", nonce);
|
|
16
20
|
async function add(original, content) {
|
|
17
21
|
const previous = byOriginal.get(original);
|
|
18
22
|
if (previous)
|
|
19
23
|
return previous;
|
|
20
|
-
const
|
|
24
|
+
const target = relative(rootDirectory, original).split(/[\\/]/)[0] === "server" ? "server" : "client";
|
|
25
|
+
const compiled = await compileWithAutoImports(content, original, {}, target);
|
|
21
26
|
const entry = {
|
|
22
27
|
original, source: content, code: compiled.code,
|
|
23
|
-
generated: join(
|
|
28
|
+
generated: join(generatedDirectory, relative(rootDirectory, original) + ".ts"),
|
|
24
29
|
mappings: compiled.mappings.map((mapping) => ({ ...mapping })),
|
|
25
30
|
};
|
|
26
31
|
byOriginal.set(original, entry);
|
|
27
32
|
byGenerated.set(entry.generated, entry);
|
|
28
|
-
const importPattern = /\b(?:from\s*|import\s*)["']([^"']+\.meeko)["']/g;
|
|
29
33
|
const edits = [];
|
|
30
|
-
for (const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
for (const specifier of moduleSpecifiers(entry.code, entry.generated)) {
|
|
35
|
+
const { value, start, end } = specifier;
|
|
36
|
+
if (!value.endsWith(".meeko") && !value.startsWith("."))
|
|
37
|
+
continue;
|
|
38
|
+
if (value.endsWith(".meeko") && !value.startsWith(".")) {
|
|
34
39
|
throw compileError(content, original, "MEEK033", "Component imports must use relative .meeko paths", originalOffset(entry.mappings, start) ?? 0);
|
|
35
40
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
childSource
|
|
41
|
+
let destination;
|
|
42
|
+
if (value.endsWith(".meeko")) {
|
|
43
|
+
const childFilename = resolve(dirname(original), value);
|
|
44
|
+
let childSource;
|
|
45
|
+
try {
|
|
46
|
+
childSource = await readFile(childFilename, "utf8");
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
throw compileError(content, original, "MEEK034", `Component import not found: ${value}`, originalOffset(entry.mappings, start) ?? 0);
|
|
50
|
+
}
|
|
51
|
+
const child = await add(childFilename, childSource);
|
|
52
|
+
destination = child.generated.replace(/\.ts$/, ".js");
|
|
40
53
|
}
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
else {
|
|
55
|
+
destination = resolve(dirname(original), value);
|
|
43
56
|
}
|
|
44
|
-
|
|
45
|
-
let target = relative(dirname(entry.generated), child.generated).replaceAll("\\", "/").replace(/\.ts$/, ".js");
|
|
57
|
+
let target = relative(dirname(entry.generated), destination).replaceAll("\\", "/");
|
|
46
58
|
if (!target.startsWith("./") && !target.startsWith("../"))
|
|
47
59
|
target = `./${target}`;
|
|
48
|
-
edits.push({ start, end
|
|
60
|
+
edits.push({ start, end, text: target });
|
|
49
61
|
}
|
|
50
62
|
for (const edit of edits.reverse()) {
|
|
51
63
|
const delta = edit.text.length - (edit.end - edit.start);
|
|
@@ -60,7 +72,7 @@ async function compileGraph(source, filename) {
|
|
|
60
72
|
return entry;
|
|
61
73
|
}
|
|
62
74
|
const root = await add(filename, source);
|
|
63
|
-
return { root, entries: byGenerated };
|
|
75
|
+
return { root, entries: byGenerated, tempDirectory: generatedDirectory };
|
|
64
76
|
}
|
|
65
77
|
function generatedOffset(code, line, column) {
|
|
66
78
|
const lines = code.split("\n");
|
|
@@ -92,12 +104,11 @@ export async function checkSource(source, filename) {
|
|
|
92
104
|
return [error.diagnostic];
|
|
93
105
|
throw error;
|
|
94
106
|
}
|
|
95
|
-
const written = [];
|
|
96
107
|
let output = "";
|
|
97
108
|
try {
|
|
98
109
|
for (const entry of graph.entries.values()) {
|
|
110
|
+
await mkdir(dirname(entry.generated), { recursive: true });
|
|
99
111
|
await writeFile(entry.generated, entry.code, { encoding: "utf8", flag: "wx" });
|
|
100
|
-
written.push(entry.generated);
|
|
101
112
|
}
|
|
102
113
|
try {
|
|
103
114
|
const result = await execFileAsync(process.execPath, [
|
|
@@ -116,7 +127,7 @@ export async function checkSource(source, filename) {
|
|
|
116
127
|
}
|
|
117
128
|
}
|
|
118
129
|
finally {
|
|
119
|
-
await
|
|
130
|
+
await rm(graph.tempDirectory, { recursive: true, force: true });
|
|
120
131
|
}
|
|
121
132
|
const typed = parseTypeScriptOutput(output);
|
|
122
133
|
if (typed.length === 0 && output.trim())
|
|
@@ -128,3 +139,4 @@ export async function checkSource(source, filename) {
|
|
|
128
139
|
return { code: diagnostic.code, message, filename: entry?.original ?? absolute, location: locate(entry?.source ?? source, offset ?? 0) };
|
|
129
140
|
});
|
|
130
141
|
}
|
|
142
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"m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AC,KAAK,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC;IAC3I,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { fileURLToPath } from \"node:url\";\nimport { compileWithAutoImports } from \"./autoimports.js\";\nimport { originalOffset } from \"./compiler/mapping.js\";\nimport type { SourceMapping } from \"./compiler/mapping.js\";\nimport { moduleSpecifiers } from \"./compiler/import-graph.js\";\nimport { projectRoot } from \"./compiler/project-root.js\";\nimport { compileError, MeekoCompileError, locate } from \"./compiler/sfc.js\";\nimport type { CompileDiagnostic } from \"./compiler/sfc.js\";\n\nconst execFileAsync = promisify(execFile);\nconst tscPath = join(dirname(fileURLToPath(import.meta.resolve(\"typescript/package.json\"))), \"bin\", \"tsc\");\n\ninterface GeneratedEntry {\n original: string;\n generated: string;\n source: string;\n code: string;\n mappings: SourceMapping[];\n}\n\nasync function compileGraph(source: string, filename: string): Promise<{ root: GeneratedEntry; entries: Map<string, GeneratedEntry>; tempDirectory: string }> {\n const byOriginal = new Map<string, GeneratedEntry>();\n const byGenerated = new Map<string, GeneratedEntry>();\n const nonce = randomUUID();\n const rootDirectory = projectRoot(filename);\n const generatedDirectory = join(rootDirectory, \".meeko\", \"check\", nonce);\n async function add(original: string, content: string): Promise<GeneratedEntry> {\n const previous = byOriginal.get(original);\n if (previous) return previous;\n const target = relative(rootDirectory, original).split(/[\\\\/]/)[0] === \"server\" ? \"server\" : \"client\";\n const compiled = await compileWithAutoImports(content, original, {}, target);\n const entry: GeneratedEntry = {\n original, source: content, code: compiled.code,\n generated: join(generatedDirectory, relative(rootDirectory, original) + \".ts\"),\n mappings: compiled.mappings.map((mapping) => ({ ...mapping })),\n };\n byOriginal.set(original, entry);\n byGenerated.set(entry.generated, entry);\n const edits: Array<{ start: number; end: number; text: string }> = [];\n for (const specifier of moduleSpecifiers(entry.code, entry.generated)) {\n const { value, start, end } = specifier;\n if (!value.endsWith(\".meeko\") && !value.startsWith(\".\")) continue;\n if (value.endsWith(\".meeko\") && !value.startsWith(\".\")) {\n throw compileError(content, original, \"MEEK033\", \"Component imports must use relative .meeko paths\", originalOffset(entry.mappings, start) ?? 0);\n }\n let destination: string;\n if (value.endsWith(\".meeko\")) {\n const childFilename = resolve(dirname(original), value);\n let childSource: string;\n try {\n childSource = await readFile(childFilename, \"utf8\");\n } catch {\n throw compileError(content, original, \"MEEK034\", `Component import not found: ${value}`, originalOffset(entry.mappings, start) ?? 0);\n }\n const child = await add(childFilename, childSource);\n destination = child.generated.replace(/\\.ts$/, \".js\");\n } else {\n destination = resolve(dirname(original), value);\n }\n let target = relative(dirname(entry.generated), destination).replaceAll(\"\\\\\", \"/\");\n if (!target.startsWith(\"./\") && !target.startsWith(\"../\")) target = `./${target}`;\n edits.push({ start, end, text: target });\n }\n for (const edit of edits.reverse()) {\n const delta = edit.text.length - (edit.end - edit.start);\n entry.code = entry.code.slice(0, edit.start) + edit.text + entry.code.slice(edit.end);\n for (const mapping of entry.mappings) {\n if (mapping.generatedStart >= edit.end) mapping.generatedStart += delta;\n if (mapping.generatedEnd >= edit.end) mapping.generatedEnd += delta;\n }\n }\n return entry;\n }\n const root = await add(filename, source);\n return { root, entries: byGenerated, tempDirectory: generatedDirectory };\n}\n\nfunction generatedOffset(code: string, line: number, column: number): number {\n const lines = code.split(\"\\n\");\n let offset = 0;\n for (let index = 0; index < line - 1; index++) offset += (lines[index]?.length ?? 0) + 1;\n return offset + column - 1;\n}\n\nfunction parseTypeScriptOutput(output: string): Array<{ file: string; line: number; column: number; code: string; message: string }> {\n const diagnostics: Array<{ file: string; line: number; column: number; code: string; message: string }> = [];\n for (const line of output.split(/\\r?\\n/)) {\n const match = /^(.*)\\((\\d+),(\\d+)\\): error TS(\\d+): (.*)$/.exec(line);\n if (match) diagnostics.push({ file: match[1] ?? \"\", line: Number(match[2]), column: Number(match[3]), code: `TS${match[4]}`, message: match[5] ?? \"\" });\n else if (line.trim() && diagnostics.length > 0) diagnostics[diagnostics.length - 1]!.message += `\\n${line}`;\n }\n return diagnostics;\n}\n\n/** Comprueba un componente con TypeScript 7 y devuelve errores ubicados en el .meeko original. */\nexport async function checkSource(source: string, filename: string): Promise<CompileDiagnostic[]> {\n const absolute = resolve(filename);\n let graph: Awaited<ReturnType<typeof compileGraph>>;\n try {\n graph = await compileGraph(source, absolute);\n } catch (error) {\n if (error instanceof MeekoCompileError) return [error.diagnostic];\n throw error;\n }\n\n let output = \"\";\n try {\n for (const entry of graph.entries.values()) {\n await mkdir(dirname(entry.generated), { recursive: true });\n await writeFile(entry.generated, entry.code, { encoding: \"utf8\", flag: \"wx\" });\n }\n try {\n const result = await execFileAsync(process.execPath, [\n tscPath, \"--ignoreConfig\", \"--noEmit\", \"--pretty\", \"false\", \"--strict\", \"--skipLibCheck\",\n \"--noUncheckedIndexedAccess\", \"--exactOptionalPropertyTypes\", \"--verbatimModuleSyntax\",\n \"--module\", \"nodenext\", \"--moduleResolution\", \"nodenext\", \"--target\", \"es2022\",\n \"--lib\", \"es2022,dom\", graph.root.generated,\n ], { cwd: dirname(absolute), maxBuffer: 8 * 1024 * 1024 });\n output = result.stdout + result.stderr;\n } catch (error) {\n const failure = error as Error & { stdout?: string; stderr?: string };\n output = `${failure.stdout ?? \"\"}${failure.stderr ?? \"\"}`;\n if (!output.trim()) throw error;\n }\n } finally {\n await rm(graph.tempDirectory, { recursive: true, force: true });\n }\n\n const typed = parseTypeScriptOutput(output);\n if (typed.length === 0 && output.trim()) throw new Error(`TypeScript 7 check failed: ${output.trim()}`);\n return typed.map((diagnostic) => {\n const entry = graph.entries.get(resolve(dirname(absolute), diagnostic.file));\n const offset = entry ? originalOffset(entry.mappings, generatedOffset(entry.code, diagnostic.line, diagnostic.column)) : undefined;\n const message = entry && offset !== undefined ? diagnostic.message : `Generated TypeScript: ${diagnostic.message}`;\n return { code: diagnostic.code, message, filename: entry?.original ?? absolute, location: locate(entry?.source ?? source, offset ?? 0) };\n });\n}\n"]}
|
package/dist/cli.js
CHANGED
|
@@ -6,19 +6,47 @@ import { checkSource } from "./check.js";
|
|
|
6
6
|
import { compile } from "./compiler.js";
|
|
7
7
|
import { generateTypes } from "./types.js";
|
|
8
8
|
import { initProject } from "./init.js";
|
|
9
|
+
import { initFrameworkProject } from "./framework/init.js";
|
|
10
|
+
import { generateRoutes } from "./framework/generate.js";
|
|
11
|
+
import { generateServerContracts } from "./framework/contracts-generate.js";
|
|
12
|
+
import { checkApp, generateAppTypes } from "./framework/check-app.js";
|
|
13
|
+
import { prerenderProject } from "./framework/prerender.js";
|
|
14
|
+
import { generateTypeScriptAutoImports } from "./autoimports-ts.js";
|
|
9
15
|
const [command, input, output] = process.argv.slice(2);
|
|
10
|
-
if ((command !== "compile" && command !== "check" && command !== "types" && command !== "init") || !input || (command === "compile" && !output) || (command === "check" && output !== undefined && output !== "--json") || ((command === "types" || command === "init") && output !== undefined)) {
|
|
11
|
-
process.stderr.write("Usage: meeko check <component.meeko> [--json]\n meeko compile <component.meeko> <output.ts>\n meeko types <component.meeko>\n meeko init <directory>\n");
|
|
16
|
+
if ((command !== "compile" && command !== "check" && command !== "check-app" && command !== "types" && command !== "init" && command !== "init-framework" && command !== "routes" && command !== "prerender") || !input || (command === "compile" && !output) || (command === "check" && output !== undefined && output !== "--json") || ((command === "types" || command === "init" || command === "init-framework" || command === "routes" || command === "check-app" || command === "prerender") && output !== undefined)) {
|
|
17
|
+
process.stderr.write("Usage: meeko check <component.meeko> [--json]\n meeko check-app <project-directory>\n meeko compile <component.meeko> <output.ts>\n meeko types <component.meeko>\n meeko routes <project-directory>\n meeko prerender <project-directory>\n meeko init <directory>\n meeko init-framework <directory>\n");
|
|
12
18
|
process.exitCode = 1;
|
|
13
19
|
}
|
|
14
20
|
else {
|
|
15
21
|
try {
|
|
16
|
-
if (command === "init") {
|
|
17
|
-
const target = await initProject(input);
|
|
22
|
+
if (command === "init" || command === "init-framework") {
|
|
23
|
+
const target = command === "init" ? await initProject(input) : await initFrameworkProject(input);
|
|
18
24
|
const manager = existsSync(join(target, "pnpm-lock.yaml")) ? "pnpm" : "npm";
|
|
19
25
|
const prefix = target === resolve(".") ? "" : `cd ${target} && `;
|
|
20
26
|
process.stdout.write(`Created ${target}\nNext: ${prefix}${manager} install && ${manager} run dev\n`);
|
|
21
27
|
}
|
|
28
|
+
else if (command === "routes") {
|
|
29
|
+
const generated = await generateRoutes(input);
|
|
30
|
+
const server = await generateServerContracts(input);
|
|
31
|
+
const components = await generateAppTypes(input);
|
|
32
|
+
const imports = await generateTypeScriptAutoImports(input);
|
|
33
|
+
process.stdout.write(`${generated.types}\n${generated.manifest}\n${server.types}\n${server.manifest}\n${components.map((file) => `${file}\n`).join("")}${imports.client}\n${imports.server}\n${imports.shared}\n`);
|
|
34
|
+
}
|
|
35
|
+
else if (command === "prerender") {
|
|
36
|
+
for (const file of await prerenderProject(input))
|
|
37
|
+
process.stdout.write(`${file}\n`);
|
|
38
|
+
}
|
|
39
|
+
else if (command === "check-app") {
|
|
40
|
+
const diagnostics = await checkApp(input);
|
|
41
|
+
for (const diagnostic of diagnostics) {
|
|
42
|
+
const { line, column } = diagnostic.location;
|
|
43
|
+
process.stderr.write(`${diagnostic.filename}:${line}:${column} ${diagnostic.code}: ${diagnostic.message}\n`);
|
|
44
|
+
}
|
|
45
|
+
if (diagnostics.length > 0)
|
|
46
|
+
process.exitCode = 1;
|
|
47
|
+
else
|
|
48
|
+
process.stdout.write(`${input}: OK\n`);
|
|
49
|
+
}
|
|
22
50
|
else {
|
|
23
51
|
const source = await readFile(input, "utf8");
|
|
24
52
|
const diagnostics = await checkSource(source, input);
|
|
@@ -52,3 +80,4 @@ else {
|
|
|
52
80
|
process.exitCode = 1;
|
|
53
81
|
}
|
|
54
82
|
}
|
|
83
|
+
//# sourceMappingURL=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,KAAK,QAAQ,CAAC,CAAC;YACzC,CAAC;YACD,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpF,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { checkSource } from \"./check.js\";\nimport { compile } from \"./compiler.js\";\nimport { generateTypes } from \"./types.js\";\nimport { initProject } from \"./init.js\";\nimport { initFrameworkProject } from \"./framework/init.js\";\nimport { generateRoutes } from \"./framework/generate.js\";\nimport { generateServerContracts } from \"./framework/contracts-generate.js\";\nimport { checkApp, generateAppTypes } from \"./framework/check-app.js\";\nimport { prerenderProject } from \"./framework/prerender.js\";\nimport { generateTypeScriptAutoImports } from \"./autoimports-ts.js\";\n\nconst [command, input, output] = process.argv.slice(2);\nif ((command !== \"compile\" && command !== \"check\" && command !== \"check-app\" && command !== \"types\" && command !== \"init\" && command !== \"init-framework\" && command !== \"routes\" && command !== \"prerender\") || !input || (command === \"compile\" && !output) || (command === \"check\" && output !== undefined && output !== \"--json\") || ((command === \"types\" || command === \"init\" || command === \"init-framework\" || command === \"routes\" || command === \"check-app\" || command === \"prerender\") && output !== undefined)) {\n process.stderr.write(\"Usage: meeko check <component.meeko> [--json]\\n meeko check-app <project-directory>\\n meeko compile <component.meeko> <output.ts>\\n meeko types <component.meeko>\\n meeko routes <project-directory>\\n meeko prerender <project-directory>\\n meeko init <directory>\\n meeko init-framework <directory>\\n\");\n process.exitCode = 1;\n} else {\n try {\n if (command === \"init\" || command === \"init-framework\") {\n const target = command === \"init\" ? await initProject(input) : await initFrameworkProject(input);\n const manager = existsSync(join(target, \"pnpm-lock.yaml\")) ? \"pnpm\" : \"npm\";\n const prefix = target === resolve(\".\") ? \"\" : `cd ${target} && `;\n process.stdout.write(`Created ${target}\\nNext: ${prefix}${manager} install && ${manager} run dev\\n`);\n } else if (command === \"routes\") {\n const generated = await generateRoutes(input);\n const server = await generateServerContracts(input);\n const components = await generateAppTypes(input);\n const imports = await generateTypeScriptAutoImports(input);\n process.stdout.write(`${generated.types}\\n${generated.manifest}\\n${server.types}\\n${server.manifest}\\n${components.map((file) => `${file}\\n`).join(\"\")}${imports.client}\\n${imports.server}\\n${imports.shared}\\n`);\n } else if (command === \"prerender\") {\n for (const file of await prerenderProject(input)) process.stdout.write(`${file}\\n`);\n } else if (command === \"check-app\") {\n const diagnostics = await checkApp(input);\n for (const diagnostic of diagnostics) {\n const { line, column } = diagnostic.location;\n process.stderr.write(`${diagnostic.filename}:${line}:${column} ${diagnostic.code}: ${diagnostic.message}\\n`);\n }\n if (diagnostics.length > 0) process.exitCode = 1;\n else process.stdout.write(`${input}: OK\\n`);\n } else {\n const source = await readFile(input, \"utf8\");\n const diagnostics = await checkSource(source, input);\n if (command === \"check\" && output === \"--json\") {\n process.stdout.write(`${JSON.stringify(diagnostics)}\\n`);\n } else if (diagnostics.length > 0) {\n for (const diagnostic of diagnostics) {\n const { line, column } = diagnostic.location;\n process.stderr.write(`${diagnostic.filename}:${line}:${column} ${diagnostic.code}: ${diagnostic.message}\\n`);\n }\n } else if (command === \"compile\") {\n const result = compile(source, input);\n await writeFile(output!, result.code, \"utf8\");\n process.stdout.write(`${output}\\n`);\n } else if (command === \"types\") {\n for (const generated of await generateTypes(source, input)) process.stdout.write(`${generated}\\n`);\n } else {\n process.stdout.write(`${input}: OK\\n`);\n }\n if (diagnostics.length > 0) process.exitCode = 1;\n }\n } catch (error) {\n process.stderr.write(`${error instanceof Error ? error.message : String(error)}\\n`);\n process.exitCode = 1;\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ModuleSpecifier {
|
|
2
|
+
value: string;
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
}
|
|
6
|
+
/** Read static ESM edges from TypeScript instead of matching source text. */
|
|
7
|
+
export declare function moduleSpecifiers(code: string, filename: string): ModuleSpecifier[];
|
|
8
|
+
export declare function replaceModuleSpecifiers(code: string, filename: string, convert: (specifier: ModuleSpecifier) => string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import ts from "@typescript/typescript6";
|
|
2
|
+
/** Read static ESM edges from TypeScript instead of matching source text. */
|
|
3
|
+
export function moduleSpecifiers(code, filename) {
|
|
4
|
+
const file = ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
5
|
+
const result = [];
|
|
6
|
+
for (const statement of file.statements) {
|
|
7
|
+
if (!ts.isImportDeclaration(statement) && !ts.isExportDeclaration(statement))
|
|
8
|
+
continue;
|
|
9
|
+
const literal = statement.moduleSpecifier;
|
|
10
|
+
if (!literal || !ts.isStringLiteral(literal))
|
|
11
|
+
continue;
|
|
12
|
+
result.push({ value: literal.text, start: literal.getStart(file) + 1, end: literal.getEnd() - 1 });
|
|
13
|
+
}
|
|
14
|
+
const visit = (node) => {
|
|
15
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword && node.arguments.length === 1 && ts.isStringLiteral(node.arguments[0])) {
|
|
16
|
+
const literal = node.arguments[0];
|
|
17
|
+
result.push({ value: literal.text, start: literal.getStart(file) + 1, end: literal.getEnd() - 1 });
|
|
18
|
+
}
|
|
19
|
+
ts.forEachChild(node, visit);
|
|
20
|
+
};
|
|
21
|
+
visit(file);
|
|
22
|
+
result.sort((a, b) => a.start - b.start);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
export function replaceModuleSpecifiers(code, filename, convert) {
|
|
26
|
+
let output = code;
|
|
27
|
+
for (const specifier of moduleSpecifiers(code, filename).reverse()) {
|
|
28
|
+
const replacement = convert(specifier);
|
|
29
|
+
output = output.slice(0, specifier.start) + replacement + output.slice(specifier.end);
|
|
30
|
+
}
|
|
31
|
+
return output;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=import-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-graph.js","sourceRoot":"","sources":["../../src/compiler/import-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAQzC,6EAA6E;AAC7E,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,QAAgB;IAC7D,MAAM,IAAI,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IACjG,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC;YAAE,SAAS;QACvF,MAAM,OAAO,GAAG,SAAS,CAAC,eAAe,CAAC;QAC1C,IAAI,CAAC,OAAO,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;YAAE,SAAS;QACvD,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACrG,CAAC;IACD,MAAM,KAAK,GAAG,CAAC,IAA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AC;IACxF,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import ts from \"@typescript/typescript6\";\n\nexport interface ModuleSpecifier {\n value: string;\n start: number;\n end: number;\n}\n\n/** Read static ESM edges from TypeScript instead of matching source text. */\nexport function moduleSpecifiers(code: string, filename: string): ModuleSpecifier[] {\n const file = ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const result: ModuleSpecifier[] = [];\n for (const statement of file.statements) {\n if (!ts.isImportDeclaration(statement) && !ts.isExportDeclaration(statement)) continue;\n const literal = statement.moduleSpecifier;\n if (!literal || !ts.isStringLiteral(literal)) continue;\n result.push({ value: literal.text, start: literal.getStart(file) + 1, end: literal.getEnd() - 1 });\n }\n const visit = (node: ts.Node): void => {\n if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword && node.arguments.length === 1 && ts.isStringLiteral(node.arguments[0]!)) {\n const literal = node.arguments[0];\n result.push({ value: literal.text, start: literal.getStart(file) + 1, end: literal.getEnd() - 1 });\n }\n ts.forEachChild(node, visit);\n };\n visit(file);\n result.sort((a, b) => a.start - b.start);\n return result;\n}\n\nexport function replaceModuleSpecifiers(code: string, filename: string, convert: (specifier: ModuleSpecifier) => string): string {\n let output = code;\n for (const specifier of moduleSpecifiers(code, filename).reverse()) {\n const replacement = convert(specifier);\n output = output.slice(0, specifier.start) + replacement + output.slice(specifier.end);\n }\n return output;\n}\n"]}
|
package/dist/compiler/mapping.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.js","sourceRoot":"","sources":["../../src/compiler/mapping.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,GAAG,UAAU,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AACrD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,qBAAqB,WAAW,kCAAkC,EAAE,GAAG,CAAC,CAAC;AAEnG,oFAAoF;AACpF,MAA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,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC;AACpH,CAAC;AACD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC","sourcesContent":["/** Segmento que relaciona una porción del módulo generado con el archivo .meeko. */\nexport interface SourceMapping {\n generatedStart: number;\n generatedEnd: number;\n originalStart: number;\n originalLength: number;\n}\n\nconst markerToken = randomUUID().replaceAll(\"-\", \"\");\nconst marker = new RegExp(`/\\\\*__MEEK_SOURCE_${markerToken}_(START|END):(\\\\d+):(\\\\d+)__\\\\*/`, \"g\");\n\n/** Marca código conservando la ubicación de su expresión o declaración original. */\nexport function markSource(code: string, originalStart: number, originalLength = code.length): string {\n return `/*__MEEK_SOURCE_${markerToken}_START:${originalStart}:${originalLength}__*/${code}/*__MEEK_SOURCE_${markerToken}_END:${originalStart}:${originalLength}__*/`;\n}\n\n/** Retira marcas internas y produce el mapa de segmentos del módulo emitido. */\nexport function extractSourceMappings(markedCode: string): { code: string; mappings: SourceMapping[] } {\n const mappings: SourceMapping[] = [];\n const open: Array<{ generatedStart: number; originalStart: number; originalLength: number }> = [];\n const parts: string[] = [];\n let generatedOffset = 0;\n let cursor = 0;\n for (const match of markedCode.matchAll(marker)) {\n const index = match.index;\n const chunk = markedCode.slice(cursor, index);\n parts.push(chunk);\n generatedOffset += chunk.length;\n const originalStart = Number(match[2]);\n const originalLength = Number(match[3]);\n if (match[1] === \"START\") {\n open.push({ generatedStart: generatedOffset, originalStart, originalLength });\n } else {\n const span = open.pop();\n if (!span || span.originalStart !== originalStart || span.originalLength !== originalLength) {\n throw new Error(\"Invalid Meeko source mapping markers\");\n }\n mappings.push({ ...span, generatedEnd: generatedOffset });\n }\n cursor = index + match[0].length;\n }\n const tail = markedCode.slice(cursor);\n parts.push(tail);\n if (open.length !== 0) throw new Error(\"Unclosed Meeko source mapping marker\");\n return { code: parts.join(\"\"), mappings: mappings.sort((a, b) => a.generatedStart - b.generatedStart) };\n}\n\n/** Convierte un desplazamiento generado en uno del archivo .meeko si existe origen preciso. */\nexport function originalOffset(mappings: readonly SourceMapping[], generatedOffset: number): number | undefined {\n const span = mappings\n .filter((entry) => generatedOffset >= entry.generatedStart && generatedOffset < entry.generatedEnd)\n .sort((a, b) => (a.generatedEnd - a.generatedStart) - (b.generatedEnd - b.generatedStart))[0];\n if (!span) return undefined;\n return span.originalStart + Math.min(generatedOffset - span.generatedStart, Math.max(0, span.originalLength - 1));\n}\nimport { randomUUID } from \"node:crypto\";\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, parse, resolve } from "node:path";
|
|
3
|
+
/** The package owns generated Meeko artifacts; a standalone TS project is a fallback. */
|
|
4
|
+
export function projectRoot(filename) {
|
|
5
|
+
let directory = dirname(resolve(filename));
|
|
6
|
+
let tsProject;
|
|
7
|
+
for (;;) {
|
|
8
|
+
if (existsSync(resolve(directory, "package.json")))
|
|
9
|
+
return directory;
|
|
10
|
+
if (!tsProject && existsSync(resolve(directory, "tsconfig.json")))
|
|
11
|
+
tsProject = directory;
|
|
12
|
+
const parent = dirname(directory);
|
|
13
|
+
if (parent === directory || directory === parse(directory).root)
|
|
14
|
+
return tsProject ?? dirname(resolve(filename));
|
|
15
|
+
directory = parent;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=project-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-root.js","sourceRoot":"","sources":["../../src/compiler/project-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpD,yFAAyF;AACzF,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,IAAI,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3C,IAAI,SAA6B,CAAC;IAClC,SAAS,CAAC;QACR,IAAI,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;YAAE,OAAO,SAAS,CAAC;QACrE,IAAI,CAAC,SAAS,IAAI,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YAAE,SAAS,GAAG,SAAS,CAAC;QACzF,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QAClC,IAAI,MAAM,KAAK,SAAS,IAAI,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI;YAAE,OAAO,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAChH,SAAS,GAAG,MAAM,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { dirname, parse, resolve } from \"node:path\";\n\n/** The package owns generated Meeko artifacts; a standalone TS project is a fallback. */\nexport function projectRoot(filename: string): string {\n let directory = dirname(resolve(filename));\n let tsProject: string | undefined;\n for (;;) {\n if (existsSync(resolve(directory, \"package.json\"))) return directory;\n if (!tsProject && existsSync(resolve(directory, \"tsconfig.json\"))) tsProject = directory;\n const parent = dirname(directory);\n if (parent === directory || directory === parse(directory).root) return tsProject ?? dirname(resolve(filename));\n directory = parent;\n }\n}\n"]}
|
package/dist/compiler/sfc.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sfc.js","sourceRoot":"","sources":["../../src/compiler/sfc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAiBvC,wEAAwE;AACxE,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,UAAU,CAAoB;IAEvC,YAAY,UAA6B;QACvC,KAAK,CAAC,GAAG,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI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C;IACpC,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACpE,CAAC","sourcesContent":["import { parseFragment } from \"parse5\";\n\n/** Ubicación de un diagnóstico en el archivo .meeko original. */\nexport interface SourceLocation {\n offset: number;\n line: number;\n column: number;\n}\n\n/** Error de compilación con ubicación y código estable para herramientas. */\nexport interface CompileDiagnostic {\n code: string;\n message: string;\n filename: string;\n location: SourceLocation;\n}\n\n/** Error que conserva el diagnóstico estructurado para CLI y editor. */\nexport class MeekoCompileError extends Error {\n readonly diagnostic: CompileDiagnostic;\n\n constructor(diagnostic: CompileDiagnostic) {\n super(`${diagnostic.filename}:${diagnostic.location.line}:${diagnostic.location.column} ${diagnostic.code}: ${diagnostic.message}`);\n this.name = \"MeekoCompileError\";\n this.diagnostic = diagnostic;\n }\n}\n\ninterface ParseLocation {\n startOffset: number;\n endOffset: number;\n startTag?: { endOffset: number };\n endTag?: { startOffset: number };\n}\n\ninterface ParsedNode {\n nodeName: string;\n tagName?: string;\n value?: string;\n attrs?: Array<{ name: string; value: string }>;\n sourceCodeLocation?: ParseLocation;\n childNodes?: ParsedNode[];\n}\n\n/** Una sección SFC con posiciones conservadas en el archivo fuente. */\nexport interface SfcSection {\n name: \"script\" | \"template\" | \"style\";\n start: number;\n end: number;\n content: string;\n contentStart: number;\n contentEnd: number;\n attributes: ReadonlyArray<{ name: string; value: string }>;\n}\n\n/** Estructura validada de las secciones de un componente. */\nexport interface SfcDocument {\n script: SfcSection;\n template: SfcSection;\n style?: SfcSection;\n}\n\n/** Convierte un desplazamiento UTF-16 en línea y columna, empezando en uno. */\nexport function locate(source: string, offset: number): SourceLocation {\n const before = source.slice(0, offset);\n const lines = before.split(/\\r\\n|\\r|\\n/);\n return { offset, line: lines.length, column: (lines.at(-1)?.length ?? 0) + 1 };\n}\n\n/** Crea un error de compilación asociado al archivo original. */\nexport function compileError(source: string, filename: string, code: string, message: string, offset: number): MeekoCompileError {\n return new MeekoCompileError({ code, message, filename, location: locate(source, offset) });\n}\n\n/** Analiza y valida las secciones superiores de un archivo .meeko. */\nexport function parseSfc(source: string, filename = \"anonymous.meeko\"): SfcDocument {\n const parseErrors: Array<{ code: string; startOffset: number }> = [];\n const root = parseFragment(source, {\n sourceCodeLocationInfo: true,\n onParseError(error) {\n parseErrors.push({ code: error.code, startOffset: error.startOffset });\n },\n }) as unknown as ParsedNode;\n if (parseErrors[0]) {\n const error = parseErrors[0];\n throw compileError(source, filename, \"MEEK001\", `Invalid component HTML: ${error.code}`, error.startOffset);\n }\n\n const sections = new Map<SfcSection[\"name\"], SfcSection>();\n for (const node of root.childNodes ?? []) {\n if (node.nodeName === \"#comment\" || (node.nodeName === \"#text\" && !(node.value ?? \"\").trim())) continue;\n const tag = node.tagName;\n const location = node.sourceCodeLocation;\n if (tag !== \"script\" && tag !== \"template\" && tag !== \"style\") {\n throw compileError(source, filename, \"MEEK002\", \"Only script, template and style sections are allowed at the top level\", location?.startOffset ?? 0);\n }\n if (!location?.startTag || !location.endTag) {\n throw compileError(source, filename, \"MEEK003\", `Section <${tag}> must have a closing tag`, location?.startOffset ?? 0);\n }\n if (sections.has(tag)) {\n throw compileError(source, filename, \"MEEK004\", `Duplicate <${tag}> section`, location.startOffset);\n }\n sections.set(tag, {\n name: tag,\n start: location.startOffset,\n end: location.endOffset,\n content: source.slice(location.startTag.endOffset, location.endTag.startOffset),\n contentStart: location.startTag.endOffset,\n contentEnd: location.endTag.startOffset,\n attributes: node.attrs ?? [],\n });\n }\n\n const script = sections.get(\"script\");\n const template = sections.get(\"template\");\n if (!script) throw compileError(source, filename, \"MEEK005\", \"A <script lang=\\\"ts\\\"> section is required\", 0);\n if (!script.attributes.some((attribute) => attribute.name === \"lang\" && attribute.value === \"ts\")) {\n throw compileError(source, filename, \"MEEK006\", \"The script section must use lang=\\\"ts\\\"\", script.contentStart);\n }\n if (!template) throw compileError(source, filename, \"MEEK007\", \"A <template> section is required\", source.length);\n const style = sections.get(\"style\");\n return style ? { script, template, style } : { script, template };\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SourceMapping } from "./mapping.js";
|
|
2
|
+
/** Input sourcemap for Oxc: generated TypeScript locations point to the original SFC. */
|
|
3
|
+
export declare function sourceMapForCompiled(code: string, source: string, filename: string, mappings: readonly SourceMapping[]): object;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
2
|
+
function vlq(value) {
|
|
3
|
+
let bits = value < 0 ? (-value << 1) | 1 : value << 1;
|
|
4
|
+
let output = "";
|
|
5
|
+
do {
|
|
6
|
+
let digit = bits & 31;
|
|
7
|
+
bits >>>= 5;
|
|
8
|
+
if (bits)
|
|
9
|
+
digit |= 32;
|
|
10
|
+
output += base64[digit];
|
|
11
|
+
} while (bits);
|
|
12
|
+
return output;
|
|
13
|
+
}
|
|
14
|
+
function lineStarts(source) {
|
|
15
|
+
const starts = [0];
|
|
16
|
+
for (let index = 0; index < source.length; index++)
|
|
17
|
+
if (source[index] === "\n")
|
|
18
|
+
starts.push(index + 1);
|
|
19
|
+
return starts;
|
|
20
|
+
}
|
|
21
|
+
function position(starts, offset) {
|
|
22
|
+
let low = 0;
|
|
23
|
+
let high = starts.length;
|
|
24
|
+
while (low + 1 < high) {
|
|
25
|
+
const middle = (low + high) >>> 1;
|
|
26
|
+
if (starts[middle] <= offset)
|
|
27
|
+
low = middle;
|
|
28
|
+
else
|
|
29
|
+
high = middle;
|
|
30
|
+
}
|
|
31
|
+
return { line: low, column: offset - starts[low] };
|
|
32
|
+
}
|
|
33
|
+
/** Input sourcemap for Oxc: generated TypeScript locations point to the original SFC. */
|
|
34
|
+
export function sourceMapForCompiled(code, source, filename, mappings) {
|
|
35
|
+
const offsets = new Array(code.length);
|
|
36
|
+
// Broad marks first; nested expression marks override them.
|
|
37
|
+
for (const span of [...mappings].sort((a, b) => (b.generatedEnd - b.generatedStart) - (a.generatedEnd - a.generatedStart))) {
|
|
38
|
+
for (let generated = span.generatedStart; generated < span.generatedEnd; generated++) {
|
|
39
|
+
offsets[generated] = span.originalStart + Math.min(generated - span.generatedStart, Math.max(0, span.originalLength - 1));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const sourceLines = lineStarts(source);
|
|
43
|
+
const generatedLines = lineStarts(code);
|
|
44
|
+
const rows = [];
|
|
45
|
+
let previousOriginalLine = 0;
|
|
46
|
+
let previousOriginalColumn = 0;
|
|
47
|
+
for (let line = 0; line < generatedLines.length; line++) {
|
|
48
|
+
const begin = generatedLines[line];
|
|
49
|
+
const end = generatedLines[line + 1] === undefined ? code.length : generatedLines[line + 1] - 1;
|
|
50
|
+
const segments = [];
|
|
51
|
+
let previousGeneratedColumn = 0;
|
|
52
|
+
let mapped = false;
|
|
53
|
+
for (let offset = begin; offset < end; offset++) {
|
|
54
|
+
const original = offsets[offset];
|
|
55
|
+
const generatedColumn = offset - begin;
|
|
56
|
+
if (original === undefined) {
|
|
57
|
+
if (mapped) {
|
|
58
|
+
segments.push(vlq(generatedColumn - previousGeneratedColumn));
|
|
59
|
+
previousGeneratedColumn = generatedColumn;
|
|
60
|
+
mapped = false;
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const { line: originalLine, column: originalColumn } = position(sourceLines, original);
|
|
65
|
+
segments.push(vlq(generatedColumn - previousGeneratedColumn) + vlq(0) + vlq(originalLine - previousOriginalLine) + vlq(originalColumn - previousOriginalColumn));
|
|
66
|
+
previousGeneratedColumn = generatedColumn;
|
|
67
|
+
previousOriginalLine = originalLine;
|
|
68
|
+
previousOriginalColumn = originalColumn;
|
|
69
|
+
mapped = true;
|
|
70
|
+
}
|
|
71
|
+
rows.push(segments.join(","));
|
|
72
|
+
}
|
|
73
|
+
return { version: 3, file: `${filename}.ts`, sources: [filename], sourcesContent: [source], names: [], mappings: rows.join(";") };
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=sourcemap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourcemap.js","sourceRoot":"","sources":["../../src/compiler/sourcemap.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAG,kEAAkE,CAAC;AAElF,SAAS,GAAG,CAAC,KAAa;IACxB,IAAI,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IACtD,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,GAAG,CAAC;QACF,IAAI,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QACtB,IAAI,MAAM,CAAC,CAAC;QACZ,IAAI,IAAI;YAAE,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,IAAI,MAAM,CAAC,KAAK,CAAE,CAAC;IAC3B,CAAC,QAAQ,IAAI,EAAE;IACf,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,UAAU,CAAC,MAAc;IAChC,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE;QAAE,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI;YAAE,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACvG,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,QAAQ,CAAC,MAAyB,EAAE,MAAc;IACzD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;IACzB,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC;QACtB,MAAM,MAA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AAC,cAAc,GAAG,sBAAsB,CAAC,CAAC,CAAC;YACjK,uBAAuB,GAAG,eAAe,CAAC;YAC1C,oBAAoB,GAAG,YAAY,CAAC;YACpC,sBAAsB,GAAG,cAAc,CAAC;YACxC,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,QAAQ,KAAK,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACpI,CAAC","sourcesContent":["import type { SourceMapping } from \"./mapping.js\";\n\nconst base64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\nfunction vlq(value: number): string {\n let bits = value < 0 ? (-value << 1) | 1 : value << 1;\n let output = \"\";\n do {\n let digit = bits & 31;\n bits >>>= 5;\n if (bits) digit |= 32;\n output += base64[digit]!;\n } while (bits);\n return output;\n}\n\nfunction lineStarts(source: string): number[] {\n const starts = [0];\n for (let index = 0; index < source.length; index++) if (source[index] === \"\\n\") starts.push(index + 1);\n return starts;\n}\n\nfunction position(starts: readonly number[], offset: number): { line: number; column: number } {\n let low = 0;\n let high = starts.length;\n while (low + 1 < high) {\n const middle = (low + high) >>> 1;\n if (starts[middle]! <= offset) low = middle;\n else high = middle;\n }\n return { line: low, column: offset - starts[low]! };\n}\n\n/** Input sourcemap for Oxc: generated TypeScript locations point to the original SFC. */\nexport function sourceMapForCompiled(code: string, source: string, filename: string, mappings: readonly SourceMapping[]): object {\n const offsets: Array<number | undefined> = new Array(code.length);\n // Broad marks first; nested expression marks override them.\n for (const span of [...mappings].sort((a, b) => (b.generatedEnd - b.generatedStart) - (a.generatedEnd - a.generatedStart))) {\n for (let generated = span.generatedStart; generated < span.generatedEnd; generated++) {\n offsets[generated] = span.originalStart + Math.min(generated - span.generatedStart, Math.max(0, span.originalLength - 1));\n }\n }\n const sourceLines = lineStarts(source);\n const generatedLines = lineStarts(code);\n const rows: string[] = [];\n let previousOriginalLine = 0;\n let previousOriginalColumn = 0;\n for (let line = 0; line < generatedLines.length; line++) {\n const begin = generatedLines[line]!;\n const end = generatedLines[line + 1] === undefined ? code.length : generatedLines[line + 1]! - 1;\n const segments: string[] = [];\n let previousGeneratedColumn = 0;\n let mapped = false;\n for (let offset = begin; offset < end; offset++) {\n const original = offsets[offset];\n const generatedColumn = offset - begin;\n if (original === undefined) {\n if (mapped) {\n segments.push(vlq(generatedColumn - previousGeneratedColumn));\n previousGeneratedColumn = generatedColumn;\n mapped = false;\n }\n continue;\n }\n const { line: originalLine, column: originalColumn } = position(sourceLines, original);\n segments.push(vlq(generatedColumn - previousGeneratedColumn) + vlq(0) + vlq(originalLine - previousOriginalLine) + vlq(originalColumn - previousOriginalColumn));\n previousGeneratedColumn = generatedColumn;\n previousOriginalLine = originalLine;\n previousOriginalColumn = originalColumn;\n mapped = true;\n }\n rows.push(segments.join(\",\"));\n }\n return { version: 3, file: `${filename}.ts`, sources: [filename], sourcesContent: [source], names: [], mappings: rows.join(\";\") };\n}\n"]}
|
|
@@ -42,3 +42,4 @@ export function parseTemplate(source, template, filename) {
|
|
|
42
42
|
throw compileError(source, filename, "MEEK008", `Invalid template HTML: ${error.code}`, template.contentStart + error.startOffset);
|
|
43
43
|
return normalize(parsed, template);
|
|
44
44
|
}
|
|
45
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/compiler/template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE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cSection } from \"./sfc.js\";\n\n/** Atributo normalizado de una etiqueta de plantilla. */\nexport interface TemplateAttribute {\n name: string;\n value: string;\n start: number;\n end: number;\n}\n\n/** Nodo propio de plantilla con límites absolutos en el archivo .meeko. */\nexport interface TemplateNode {\n nodeName: string;\n tagName?: string;\n value?: string;\n attrs?: TemplateAttribute[];\n childNodes?: TemplateNode[];\n content?: { childNodes: TemplateNode[] };\n start: number;\n end: number;\n sourceCodeLocation?: {\n startOffset: number;\n endOffset: number;\n attrs?: Record<string, { startOffset: number; endOffset: number }>;\n };\n}\n\ninterface ParsedNode {\n nodeName: string;\n tagName?: string;\n value?: string;\n attrs?: Array<{ name: string; value: string }>;\n childNodes?: ParsedNode[];\n content?: { childNodes?: ParsedNode[] };\n sourceCodeLocation?: {\n startOffset: number;\n endOffset: number;\n attrs?: Record<string, { startOffset: number; endOffset: number }>;\n };\n}\n\nfunction normalize(node: ParsedNode, template: SfcSection): TemplateNode {\n const location = node.sourceCodeLocation;\n const attrs = node.attrs?.map((attribute) => {\n const span = location?.attrs?.[attribute.name];\n return {\n name: attribute.name,\n value: attribute.value,\n start: template.contentStart + (span?.startOffset ?? location?.startOffset ?? 0),\n end: template.contentStart + (span?.endOffset ?? location?.endOffset ?? 0),\n };\n });\n const result: TemplateNode = {\n nodeName: node.nodeName,\n start: template.contentStart + (location?.startOffset ?? 0),\n end: template.contentStart + (location?.endOffset ?? template.content.length),\n };\n if (node.tagName !== undefined) result.tagName = node.tagName;\n if (node.value !== undefined) result.value = node.value;\n if (attrs !== undefined) result.attrs = attrs;\n if (node.childNodes !== undefined) result.childNodes = node.childNodes.map((child) => normalize(child, template));\n if (node.content !== undefined) result.content = { childNodes: (node.content.childNodes ?? []).map((child) => normalize(child, template)) };\n if (location !== undefined) result.sourceCodeLocation = location;\n return result;\n}\n\n/** Analiza HTML y entrega un AST independiente del parser con posiciones originales. */\nexport function parseTemplate(source: string, template: SfcSection, filename: string): TemplateNode {\n const errors: Array<{ code: string; startOffset: number }> = [];\n const parsed = parseFragment(template.content, {\n sourceCodeLocationInfo: true,\n onParseError(error) { errors.push({ code: error.code, startOffset: error.startOffset }); },\n }) as unknown as ParsedNode;\n const error = errors[0];\n if (error) throw compileError(source, filename, \"MEEK008\", `Invalid template HTML: ${error.code}`, template.contentStart + error.startOffset);\n return normalize(parsed, template);\n}\n"]}
|
package/dist/compiler.js
CHANGED
|
@@ -154,9 +154,10 @@ function renderNodeContent(node, bindings, context) {
|
|
|
154
154
|
const position = node.start;
|
|
155
155
|
const referenceAttribute = node.attrs?.find((attribute) => attribute.name === "is");
|
|
156
156
|
const reference = referenceAttribute?.value ?? "";
|
|
157
|
-
if (
|
|
158
|
-
throw compileError(context.source, context.filename, "MEEK030", "A component requires is=\"
|
|
159
|
-
|
|
157
|
+
if (!reference.trim())
|
|
158
|
+
throw compileError(context.source, context.filename, "MEEK030", "A component requires is=\"expression\"", position);
|
|
159
|
+
const referenceOffset = attributeValueOffset(node, "is", context);
|
|
160
|
+
validateExpression(reference, context.source, context.filename, referenceOffset);
|
|
160
161
|
if ((node.childNodes ?? []).some((child) => child.nodeName !== "#text" || Boolean(child.value?.trim()))) {
|
|
161
162
|
throw compileError(context.source, context.filename, "MEEK031", "Component children are not supported; close the tag without content", position);
|
|
162
163
|
}
|
|
@@ -174,7 +175,6 @@ function renderNodeContent(node, bindings, context) {
|
|
|
174
175
|
props.push({ name, nameOffset: attribute.start + 5, expression: attribute.value, offset });
|
|
175
176
|
}
|
|
176
177
|
const id = context.nextRegion++;
|
|
177
|
-
const referenceOffset = attributeValueOffset(node, "is", context);
|
|
178
178
|
bindings.components.push({ id, reference, referenceOffset, props, offset: position });
|
|
179
179
|
const mappedProps = props.map((prop) => `${markSource(quote(prop.name), prop.nameOffset, prop.name.length)}: ${markSource(prop.expression, prop.offset)}`);
|
|
180
180
|
const object = markSource(`{ ${mappedProps.join(", ")} }`, position, node.end - position);
|
|
@@ -278,6 +278,11 @@ function compileScript(section, source, filename) {
|
|
|
278
278
|
types.push(markSource(statement.getText(file), section.contentStart + statement.getStart(file)));
|
|
279
279
|
continue;
|
|
280
280
|
}
|
|
281
|
+
if (ts.isExportDeclaration(statement) && (statement.isTypeOnly ||
|
|
282
|
+
(statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.every((element) => element.isTypeOnly)))) {
|
|
283
|
+
types.push(markSource(statement.getText(file), section.contentStart + statement.getStart(file)));
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
281
286
|
if (ts.isVariableStatement(statement)) {
|
|
282
287
|
if (statement.declarationList.declarations.length !== 1)
|
|
283
288
|
throw compileError(source, filename, "MEEK014", "Declare one variable per statement in .meeko scripts", section.contentStart + statement.getStart(file));
|
|
@@ -342,7 +347,7 @@ function hydrationBody(bindings, context, hot, locals = new Map()) {
|
|
|
342
347
|
const location = `${basename(context.filename)}:${point.line}:${point.column} (component ${entry.reference})`;
|
|
343
348
|
const props = entry.props.map((prop) => `${markSource(quote(prop.name), prop.nameOffset, prop.name.length)}: ${mappedExpression(prop.expression, prop.offset)}`);
|
|
344
349
|
const object = markSource(`{ ${props.join(", ")} }`, entry.offset, 1);
|
|
345
|
-
componentStatements.push(`cleanups.push(__meeko.bindComponent(__scope, ${entry.id}, ${mappedExpression(entry.reference, entry.referenceOffset)}, () => (${object}), ${quote(location)}));`);
|
|
350
|
+
componentStatements.push(`cleanups.push(__meeko.bindComponent(__scope, ${entry.id}, () => ${mappedExpression(entry.reference, entry.referenceOffset)}, () => (${object}), ${quote(location)}));`);
|
|
346
351
|
}
|
|
347
352
|
statements.unshift(...componentStatements);
|
|
348
353
|
for (const entry of bindings.regions) {
|
|
@@ -407,3 +412,4 @@ export function compile(source, filename = "anonymous.meeko", options = {}) {
|
|
|
407
412
|
const { code, mappings } = extractSourceMappings(markedCode);
|
|
408
413
|
return { code, css, mappings };
|
|
409
414
|
}
|
|
415
|
+
//# sourceMappingURL=compiler.js.map
|