@ogygia/compiler 0.0.0-stage → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +63 -2
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/app-spec.d.ts +18 -0
- package/dist/app-spec.js +22 -0
- package/dist/blank-styles.d.ts +1 -0
- package/dist/blank-styles.js +24 -0
- package/dist/bom.d.ts +2 -0
- package/dist/bom.js +7 -0
- package/dist/build-cache.d.ts +13 -0
- package/dist/build-cache.js +65 -0
- package/dist/ctx.d.ts +238 -0
- package/dist/ctx.js +221 -0
- package/dist/dev/css-scope.d.ts +16 -0
- package/dist/dev/css-scope.js +32 -0
- package/dist/dev/dev-hmr.d.ts +24 -0
- package/dist/dev/dev-hmr.js +51 -0
- package/dist/dev/hmr.d.ts +34 -0
- package/dist/dev/hmr.js +52 -0
- package/dist/driver.d.ts +349 -0
- package/dist/driver.js +1401 -0
- package/dist/exports/index.d.ts +77 -0
- package/dist/exports/index.js +349 -0
- package/dist/exports/parse.d.ts +65 -0
- package/dist/exports/parse.js +251 -0
- package/dist/fouc-css.d.ts +102 -0
- package/dist/fouc-css.js +304 -0
- package/dist/free-vars.d.ts +32 -0
- package/dist/free-vars.js +454 -0
- package/dist/fs.d.ts +31 -0
- package/dist/fs.js +82 -0
- package/dist/ids.d.ts +49 -0
- package/dist/ids.js +52 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +23 -0
- package/dist/kit.d.ts +204 -0
- package/dist/kit.js +554 -0
- package/dist/leg.d.ts +34 -0
- package/dist/leg.js +26 -0
- package/dist/link/analyses.d.ts +26 -0
- package/dist/link/analyses.js +237 -0
- package/dist/link/build-output.d.ts +47 -0
- package/dist/link/build-output.js +168 -0
- package/dist/link/caps.d.ts +32 -0
- package/dist/link/caps.js +39 -0
- package/dist/link/context-detect.d.ts +28 -0
- package/dist/link/context-detect.js +143 -0
- package/dist/link/emit-gate.d.ts +43 -0
- package/dist/link/emit-gate.js +55 -0
- package/dist/link/file-token.d.ts +11 -0
- package/dist/link/file-token.js +15 -0
- package/dist/link/island-deps.d.ts +183 -0
- package/dist/link/island-deps.js +802 -0
- package/dist/link/location-map.d.ts +24 -0
- package/dist/link/location-map.js +51 -0
- package/dist/link/own-reach.d.ts +15 -0
- package/dist/link/own-reach.js +188 -0
- package/dist/link/registry-stub.d.ts +50 -0
- package/dist/link/registry-stub.js +163 -0
- package/dist/link/relocations.d.ts +79 -0
- package/dist/link/relocations.js +198 -0
- package/dist/link/router-css.d.ts +38 -0
- package/dist/link/router-css.js +124 -0
- package/dist/link/runtime-entry.d.ts +103 -0
- package/dist/link/runtime-entry.js +183 -0
- package/dist/link/server-manifest.d.ts +25 -0
- package/dist/link/server-manifest.js +102 -0
- package/dist/link/transport.d.ts +42 -0
- package/dist/link/transport.js +91 -0
- package/dist/macros/dollar.d.ts +24 -0
- package/dist/macros/dollar.js +397 -0
- package/dist/macros/pipeline.d.ts +50 -0
- package/dist/macros/pipeline.js +133 -0
- package/dist/macros/source.d.ts +9 -0
- package/dist/macros/source.js +115 -0
- package/dist/macros/store.d.ts +22 -0
- package/dist/macros/store.js +217 -0
- package/dist/macros/wire.d.ts +17 -0
- package/dist/macros/wire.js +116 -0
- package/dist/map-chain.d.ts +18 -0
- package/dist/map-chain.js +42 -0
- package/dist/messages.d.ts +672 -0
- package/dist/messages.js +938 -0
- package/dist/ownership-stamps.d.ts +9 -0
- package/dist/ownership-stamps.js +101 -0
- package/dist/parse/oxc.d.ts +36 -0
- package/dist/parse/oxc.js +35 -0
- package/dist/parse/roots.d.ts +4 -0
- package/dist/parse/roots.js +27 -0
- package/dist/parse/scan.d.ts +65 -0
- package/dist/parse/scan.js +297 -0
- package/dist/parse/svelte-ast.d.ts +7 -0
- package/dist/parse/svelte-ast.js +99 -0
- package/dist/program.d.ts +140 -0
- package/dist/program.js +304 -0
- package/dist/queries.d.ts +105 -0
- package/dist/queries.js +326 -0
- package/dist/region/emit.d.ts +168 -0
- package/dist/region/emit.js +292 -0
- package/dist/region/identity.d.ts +32 -0
- package/dist/region/identity.js +46 -0
- package/dist/region/ir.d.ts +56 -0
- package/dist/region/ir.js +0 -0
- package/dist/region/marked-imports.d.ts +27 -0
- package/dist/region/marked-imports.js +265 -0
- package/dist/region/transform.d.ts +189 -0
- package/dist/region/transform.js +1565 -0
- package/dist/scan-facts.d.ts +36 -0
- package/dist/scan-facts.js +54 -0
- package/dist/script-request.d.ts +1 -0
- package/dist/script-request.js +33 -0
- package/dist/splice.d.ts +11 -0
- package/dist/splice.js +33 -0
- package/dist/transportables.d.ts +23 -0
- package/dist/transportables.js +144 -0
- package/dist/virtual/core.d.ts +158 -0
- package/dist/virtual/core.js +588 -0
- package/dist/virtual/resolver.d.ts +56 -0
- package/dist/virtual/resolver.js +249 -0
- package/dist/virtual/specifier.d.ts +10 -0
- package/dist/virtual/specifier.js +6 -0
- package/dist/virtual/table.d.ts +118 -0
- package/dist/virtual/table.js +54 -0
- package/dist/virtual/types.d.ts +17 -0
- package/dist/virtual/types.js +100 -0
- package/dist/virtual/value-names.d.ts +2 -0
- package/dist/virtual/value-names.js +18 -0
- package/dist/vite/definers.d.ts +16 -0
- package/dist/vite/definers.js +69 -0
- package/dist/vite/dev-maps.d.ts +34 -0
- package/dist/vite/dev-maps.js +91 -0
- package/dist/vite/index.d.ts +21 -0
- package/dist/vite/index.js +874 -0
- package/dist/vite/kit-dirs.d.ts +6 -0
- package/dist/vite/kit-dirs.js +53 -0
- package/dist/vite/late-island.d.ts +11 -0
- package/dist/vite/late-island.js +19 -0
- package/dist/vite/lazy-files.d.ts +2 -0
- package/dist/vite/lazy-files.js +72 -0
- package/dist/vite/options.d.ts +195 -0
- package/dist/vite/options.js +72 -0
- package/dist/vite/package-files.d.ts +3 -0
- package/dist/vite/package-files.js +88 -0
- package/dist/vite/paths.d.ts +14 -0
- package/dist/vite/paths.js +37 -0
- package/dist/vite/plugin-api.d.ts +316 -0
- package/dist/vite/plugin-api.js +328 -0
- package/dist/vite/session.d.ts +28 -0
- package/dist/vite/session.js +43 -0
- package/dist/vite/sourcemaps.d.ts +19 -0
- package/dist/vite/sourcemaps.js +75 -0
- package/dist/vite/style-preprocess.d.ts +2 -0
- package/dist/vite/style-preprocess.js +84 -0
- package/dist/vite/svelte-entries.d.ts +4 -0
- package/dist/vite/svelte-entries.js +10 -0
- package/package.json +85 -3
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { find_og_calls, og_js_regions } from "../parse/scan.js";
|
|
2
|
+
import { parse_module } from "../parse/oxc.js";
|
|
3
|
+
import { OgygiaError } from "../messages.js";
|
|
4
|
+
import { splice_text } from "../splice.js";
|
|
5
|
+
// src/macros/wire.ts
|
|
6
|
+
const STATIC_WIRE_TAIL_RE = /\bstatic\s+wire\s*=\s*$/;
|
|
7
|
+
/** The key expression a wire member rewrites to — the same symbol the runtime registry uses. */
|
|
8
|
+
const WIRE_EXPR = "Symbol.for('ogygia.wire')";
|
|
9
|
+
const MARKER = "import.meta.og.wire";
|
|
10
|
+
/** If `node` is the member expression `import.meta.og.<name>`, return `<name>`; else null. */
|
|
11
|
+
function og_member(node) {
|
|
12
|
+
if (!node || node.type !== "MemberExpression" || node.computed) return null;
|
|
13
|
+
const name = node.property?.name;
|
|
14
|
+
if (typeof name !== "string") return null;
|
|
15
|
+
const og = node.object;
|
|
16
|
+
if (og?.type !== "MemberExpression" || og.computed || og.property?.name !== "og") return null;
|
|
17
|
+
const meta = og.object;
|
|
18
|
+
if (meta?.type !== "MetaProperty" || meta.meta?.name !== "import" || meta.property?.name !== "meta") return null;
|
|
19
|
+
return name;
|
|
20
|
+
}
|
|
21
|
+
function walk(node, visit) {
|
|
22
|
+
visit(node);
|
|
23
|
+
for (const key in node) {
|
|
24
|
+
if (key === "type" || key === "start" || key === "end") continue;
|
|
25
|
+
const child = node[key];
|
|
26
|
+
if (Array.isArray(child)) {
|
|
27
|
+
for (const c of child) if (c && typeof c === "object" && typeof c.type === "string") walk(c, visit);
|
|
28
|
+
} else if (child && typeof child === "object" && typeof child.type === "string") walk(child, visit);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function line_of(src, offset) {
|
|
32
|
+
let line = 1;
|
|
33
|
+
for (let i = 0; i < offset && i < src.length; i++) if (src[i] === "\n") line++;
|
|
34
|
+
return line;
|
|
35
|
+
}
|
|
36
|
+
function misuse(id, src, offset, what) {
|
|
37
|
+
throw new OgygiaError("macro_wire_misuse", {
|
|
38
|
+
file: id,
|
|
39
|
+
line: line_of(src, offset),
|
|
40
|
+
problem: what
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function ast_edits_or_null_unparsed(src, region, id) {
|
|
44
|
+
const { program, ok } = parse_module(region.code, id);
|
|
45
|
+
if (!ok || !program) return null;
|
|
46
|
+
const edits = [];
|
|
47
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
48
|
+
walk(program, (n) => {
|
|
49
|
+
if ((n.type === "PropertyDefinition" || n.type === "ClassProperty") && n.static === true) {
|
|
50
|
+
const v = n.value;
|
|
51
|
+
if (v?.type === "CallExpression" && og_member(v.callee) === "wire") {
|
|
52
|
+
const abs = region.offset + n.start;
|
|
53
|
+
const key = n.key;
|
|
54
|
+
const name = !n.computed && key?.type === "Identifier" ? key.name : null;
|
|
55
|
+
if (name !== "wire") misuse(id, src, abs, `the wire member must be named exactly \`wire\` (got \`${name ?? "<computed>"}\`)`);
|
|
56
|
+
const args = v.arguments;
|
|
57
|
+
if (!args || args.length !== 1) misuse(id, src, abs, `wire() takes exactly one argument — the codec ({ encode, decode })`);
|
|
58
|
+
claimed.add(v);
|
|
59
|
+
claimed.add(v.callee);
|
|
60
|
+
const a = args[0];
|
|
61
|
+
edits.push({
|
|
62
|
+
start: abs,
|
|
63
|
+
end: region.offset + a.start,
|
|
64
|
+
text: `static [${WIRE_EXPR}] = `
|
|
65
|
+
});
|
|
66
|
+
edits.push({
|
|
67
|
+
start: region.offset + a.end,
|
|
68
|
+
end: region.offset + v.end,
|
|
69
|
+
text: ""
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (n.type === "CallExpression" && og_member(n.callee) === "wire" && !claimed.has(n)) misuse(id, src, region.offset + n.start, `wire() called outside a static class member`);
|
|
75
|
+
if (og_member(n) === "wire" && !claimed.has(n)) misuse(id, src, region.offset + n.start, `bare import.meta.og.wire used as a value`);
|
|
76
|
+
});
|
|
77
|
+
edits.sort((a, b) => a.start - b.start);
|
|
78
|
+
return edits;
|
|
79
|
+
}
|
|
80
|
+
function unparsed_scan_edits(src, region) {
|
|
81
|
+
const edits = [];
|
|
82
|
+
const code = region.code;
|
|
83
|
+
for (const call of find_og_calls(code, "import.meta.og.")) {
|
|
84
|
+
if (call.method !== "wire") continue;
|
|
85
|
+
const before = code.slice(0, call.start);
|
|
86
|
+
const m = STATIC_WIRE_TAIL_RE.exec(before);
|
|
87
|
+
if (!m) continue;
|
|
88
|
+
const inner = call.args.trim();
|
|
89
|
+
if (!inner) continue;
|
|
90
|
+
edits.push({
|
|
91
|
+
start: region.offset + m.index,
|
|
92
|
+
end: region.offset + call.end,
|
|
93
|
+
text: `static [${WIRE_EXPR}] = ${inner}`
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return edits;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Rewrite every wire mark in `src`, enforcing the strict position rules. Extension-aware:
|
|
100
|
+
* whole-file for JS/TS, `<script>` blocks for `.svelte`. Returns the input unchanged (same
|
|
101
|
+
* reference) when there is nothing to do. Throws (build-error voice, file:line) on any misuse.
|
|
102
|
+
* `markup_exts` is the resolved construct-host set (the plugin passes `['.svelte']`).
|
|
103
|
+
*/
|
|
104
|
+
function rewrite_wire(src, id, markup_exts) {
|
|
105
|
+
return splice_text(src, wire_edits(src, id, markup_exts));
|
|
106
|
+
}
|
|
107
|
+
/** The edits `rewrite_wire` makes to `src`: none when there is nothing to do. */
|
|
108
|
+
function wire_edits(src, id, markup_exts) {
|
|
109
|
+
if (!src.includes(MARKER)) return [];
|
|
110
|
+
const regions = og_js_regions(src, id, markup_exts);
|
|
111
|
+
if (!regions) return [];
|
|
112
|
+
const edits = [];
|
|
113
|
+
for (const region of regions) edits.push(...ast_edits_or_null_unparsed(src, region, id) ?? unparsed_scan_edits(src, region));
|
|
114
|
+
return edits;
|
|
115
|
+
}
|
|
116
|
+
export { WIRE_EXPR, og_member, rewrite_wire, wire_edits };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SourceMapInput } from "@jridgewell/remapping";
|
|
2
|
+
/** One pass's map from its output back to its input; `null` when the pass cannot say (a text-only plugin macro). */
|
|
3
|
+
export type StepMap = (() => SourceMapInput) | null;
|
|
4
|
+
/** The map of a module rewritten by several passes, each mapping its output back to its input. */
|
|
5
|
+
export declare class MapChain {
|
|
6
|
+
#private;
|
|
7
|
+
/** A pass ran over the current text. */
|
|
8
|
+
step(map: StepMap): void;
|
|
9
|
+
/** Several passes ran, in order. */
|
|
10
|
+
steps(maps: readonly StepMap[]): void;
|
|
11
|
+
/** The output's map back to the file as read; empty mappings when a pass could not say. */
|
|
12
|
+
result(source: string): {
|
|
13
|
+
version: 3;
|
|
14
|
+
sources: string[];
|
|
15
|
+
names: string[];
|
|
16
|
+
mappings: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import remapping from "@jridgewell/remapping";
|
|
2
|
+
// src/map-chain.ts
|
|
3
|
+
/** The map of a module rewritten by several passes, each mapping its output back to its input. */
|
|
4
|
+
var MapChain = class {
|
|
5
|
+
#steps = [];
|
|
6
|
+
/** A pass ran over the current text. */
|
|
7
|
+
step(map) {
|
|
8
|
+
this.#steps.push(map);
|
|
9
|
+
}
|
|
10
|
+
/** Several passes ran, in order. */
|
|
11
|
+
steps(maps) {
|
|
12
|
+
for (const map of maps) this.#steps.push(map);
|
|
13
|
+
}
|
|
14
|
+
/** The output's map back to the file as read; empty mappings when a pass could not say. */
|
|
15
|
+
result(source) {
|
|
16
|
+
const maps = [];
|
|
17
|
+
for (let i = this.#steps.length - 1; i >= 0; i--) {
|
|
18
|
+
const make = this.#steps[i];
|
|
19
|
+
if (make === null) return {
|
|
20
|
+
version: 3,
|
|
21
|
+
sources: [source],
|
|
22
|
+
names: [],
|
|
23
|
+
mappings: ""
|
|
24
|
+
};
|
|
25
|
+
maps.push(make());
|
|
26
|
+
}
|
|
27
|
+
if (!maps.length) return {
|
|
28
|
+
version: 3,
|
|
29
|
+
sources: [source],
|
|
30
|
+
names: [],
|
|
31
|
+
mappings: ""
|
|
32
|
+
};
|
|
33
|
+
const map = remapping(maps.length === 1 ? maps[0] : maps, () => null);
|
|
34
|
+
return {
|
|
35
|
+
version: 3,
|
|
36
|
+
sources: map.sources.map(() => source),
|
|
37
|
+
names: map.names,
|
|
38
|
+
mappings: typeof map.mappings === "string" ? map.mappings : ""
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export { MapChain };
|