@ogygia/compiler 0.0.0 → 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 +62 -1
- 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 +87 -12
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { OgygiaError } from "../messages.js";
|
|
2
|
+
// src/region/marked-imports.ts
|
|
3
|
+
function line_of(src, offset) {
|
|
4
|
+
let line = 1;
|
|
5
|
+
for (let i = 0; i < offset; i++) if (src.charCodeAt(i) === 10) line++;
|
|
6
|
+
return line;
|
|
7
|
+
}
|
|
8
|
+
function line_col(src, offset) {
|
|
9
|
+
let line = 1;
|
|
10
|
+
let last = -1;
|
|
11
|
+
for (let i = 0; i < offset; i++) if (src.charCodeAt(i) === 10) {
|
|
12
|
+
line++;
|
|
13
|
+
last = i;
|
|
14
|
+
}
|
|
15
|
+
return `${line}:${offset - last}`;
|
|
16
|
+
}
|
|
17
|
+
function export_name_of(spec) {
|
|
18
|
+
if (spec.type === "ImportDefaultSpecifier") return "default";
|
|
19
|
+
const imported = spec.imported;
|
|
20
|
+
return imported?.type === "Literal" ? String(imported.value) : String(imported?.name);
|
|
21
|
+
}
|
|
22
|
+
function binding_text(exportName, local) {
|
|
23
|
+
if (exportName === "default") return local;
|
|
24
|
+
return exportName === local ? `{ ${local} }` : `{ ${exportName} as ${local} }`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The names a marked import declaration binds, each with the export it reads. Throws the coded error
|
|
28
|
+
* for a shape that binds no component: a type-only import (or a `type` specifier), a namespace, or
|
|
29
|
+
* nothing at all.
|
|
30
|
+
*/
|
|
31
|
+
function marked_import_bindings(node, source, host) {
|
|
32
|
+
const spec = String(node.source?.value ?? "");
|
|
33
|
+
const line = line_of(source, node.start);
|
|
34
|
+
const specifiers = node.specifiers ?? [];
|
|
35
|
+
const types = node.importKind === "type" ? specifiers : specifiers.filter((s) => s.importKind === "type" || s.importKind === "typeof");
|
|
36
|
+
if (node.importKind === "type" || types.length) throw new OgygiaError("region_import_type_only", {
|
|
37
|
+
host,
|
|
38
|
+
line,
|
|
39
|
+
names: types.map((s) => binding_text(export_name_of(s), s.local.name).replace(/^\{ | \}$/g, "")).join(", "),
|
|
40
|
+
spec
|
|
41
|
+
});
|
|
42
|
+
const ns = specifiers.find((s) => s.type === "ImportNamespaceSpecifier");
|
|
43
|
+
if (ns) throw new OgygiaError("region_import_namespace", {
|
|
44
|
+
host,
|
|
45
|
+
line,
|
|
46
|
+
name: ns.local.name,
|
|
47
|
+
spec
|
|
48
|
+
});
|
|
49
|
+
if (specifiers.length === 0) throw new OgygiaError("region_import_bare", {
|
|
50
|
+
host,
|
|
51
|
+
line,
|
|
52
|
+
spec
|
|
53
|
+
});
|
|
54
|
+
return specifiers.map((s) => ({
|
|
55
|
+
local: s.local.name,
|
|
56
|
+
exportName: export_name_of(s)
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
function is_import_meta_og(node, prop) {
|
|
60
|
+
return node?.type === "MemberExpression" && node.property?.type === "Identifier" && node.property.name === prop && node.object?.type === "MemberExpression" && node.object.property?.type === "Identifier" && node.object.property.name === "og" && node.object.object?.type === "MetaProperty" && node.object.object.meta?.name === "import" && node.object.object.property?.name === "meta";
|
|
61
|
+
}
|
|
62
|
+
const SKIP_KEYS = /* @__PURE__ */ new Set([
|
|
63
|
+
"start",
|
|
64
|
+
"end",
|
|
65
|
+
"loc",
|
|
66
|
+
"range",
|
|
67
|
+
"parent",
|
|
68
|
+
"metadata"
|
|
69
|
+
]);
|
|
70
|
+
function walk(node, visit, ancestors = []) {
|
|
71
|
+
if (!node || typeof node !== "object") return;
|
|
72
|
+
if (Array.isArray(node)) {
|
|
73
|
+
for (const n of node) walk(n, visit, ancestors);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const n = node;
|
|
77
|
+
if (typeof n.type !== "string") return;
|
|
78
|
+
if (visit(n, ancestors) === false) return;
|
|
79
|
+
ancestors.push(n);
|
|
80
|
+
for (const k of Object.keys(n)) {
|
|
81
|
+
if (SKIP_KEYS.has(k)) continue;
|
|
82
|
+
const v = n[k];
|
|
83
|
+
if (v && typeof v === "object") walk(v, visit, ancestors);
|
|
84
|
+
}
|
|
85
|
+
ancestors.pop();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* `import.meta.og.asRegion(…)` is gone. Any call anywhere in `roots` throws `as_region_removed`,
|
|
89
|
+
* listing for each call the marked import that replaces it (same options, aliased to the `const`).
|
|
90
|
+
*/
|
|
91
|
+
function refuse_as_region(roots, source, host) {
|
|
92
|
+
if (!source.includes("asRegion")) return;
|
|
93
|
+
const imports = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const root of roots) walk(root, (n) => {
|
|
95
|
+
if (n.type !== "ImportDeclaration") return;
|
|
96
|
+
for (const s of n.specifiers ?? []) imports.set(s.local?.name, n);
|
|
97
|
+
return false;
|
|
98
|
+
});
|
|
99
|
+
const fixes = [];
|
|
100
|
+
for (const root of roots) walk(root, (n, ancestors) => {
|
|
101
|
+
if (n.type !== "CallExpression" || !is_import_meta_og(n.callee, "asRegion")) return;
|
|
102
|
+
const comp = n.arguments?.[0];
|
|
103
|
+
const opts = n.arguments?.[1];
|
|
104
|
+
const comp_name = comp?.type === "Identifier" ? String(comp.name) : "Component";
|
|
105
|
+
const parent = ancestors[ancestors.length - 1];
|
|
106
|
+
const local = parent?.type === "VariableDeclarator" && parent.id?.type === "Identifier" ? String(parent.id.name) : comp_name;
|
|
107
|
+
const decl = imports.get(comp_name);
|
|
108
|
+
const spec_node = decl?.specifiers?.find((s) => s.local?.name === comp_name);
|
|
109
|
+
const export_name = spec_node && spec_node.type !== "ImportNamespaceSpecifier" ? export_name_of(spec_node) : comp_name;
|
|
110
|
+
const spec = decl ? source.slice(decl.source.start, decl.source.end) : `'…'`;
|
|
111
|
+
const with_text = opts ? source.slice(opts.start, opts.end) : `{ wake: 'load' }`;
|
|
112
|
+
fixes.push(` line ${line_of(source, n.start)}: import ${binding_text(export_name, local)} from ${spec} with ${with_text};`);
|
|
113
|
+
return false;
|
|
114
|
+
});
|
|
115
|
+
if (fixes.length) throw new OgygiaError("as_region_removed", {
|
|
116
|
+
host,
|
|
117
|
+
fixes: fixes.join("\n")
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function pattern_names(p, out) {
|
|
121
|
+
if (!p || typeof p !== "object") return;
|
|
122
|
+
switch (p.type) {
|
|
123
|
+
case "Identifier":
|
|
124
|
+
out.add(p.name);
|
|
125
|
+
return;
|
|
126
|
+
case "ObjectPattern":
|
|
127
|
+
for (const prop of p.properties ?? []) pattern_names(prop.type === "RestElement" ? prop.argument : prop.value, out);
|
|
128
|
+
return;
|
|
129
|
+
case "ArrayPattern":
|
|
130
|
+
for (const el of p.elements ?? []) pattern_names(el, out);
|
|
131
|
+
return;
|
|
132
|
+
case "RestElement":
|
|
133
|
+
pattern_names(p.argument, out);
|
|
134
|
+
return;
|
|
135
|
+
case "AssignmentPattern":
|
|
136
|
+
pattern_names(p.left, out);
|
|
137
|
+
return;
|
|
138
|
+
case "TSParameterProperty": pattern_names(p.parameter, out);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function declared_names(roots) {
|
|
142
|
+
const out = /* @__PURE__ */ new Set();
|
|
143
|
+
for (const root of roots) walk(root, (n) => {
|
|
144
|
+
switch (n.type) {
|
|
145
|
+
case "ImportDeclaration": return false;
|
|
146
|
+
case "VariableDeclarator":
|
|
147
|
+
pattern_names(n.id, out);
|
|
148
|
+
break;
|
|
149
|
+
case "FunctionDeclaration":
|
|
150
|
+
case "FunctionExpression":
|
|
151
|
+
case "ArrowFunctionExpression":
|
|
152
|
+
if (n.id) pattern_names(n.id, out);
|
|
153
|
+
for (const p of n.params ?? []) pattern_names(p, out);
|
|
154
|
+
break;
|
|
155
|
+
case "ClassDeclaration":
|
|
156
|
+
case "ClassExpression":
|
|
157
|
+
if (n.id) pattern_names(n.id, out);
|
|
158
|
+
break;
|
|
159
|
+
case "CatchClause":
|
|
160
|
+
pattern_names(n.param, out);
|
|
161
|
+
break;
|
|
162
|
+
case "EachBlock":
|
|
163
|
+
pattern_names(n.context, out);
|
|
164
|
+
if (typeof n.index === "string") out.add(n.index);
|
|
165
|
+
break;
|
|
166
|
+
case "AwaitBlock":
|
|
167
|
+
pattern_names(n.value, out);
|
|
168
|
+
pattern_names(n.error, out);
|
|
169
|
+
break;
|
|
170
|
+
case "SnippetBlock":
|
|
171
|
+
pattern_names(n.expression, out);
|
|
172
|
+
for (const p of n.parameters ?? []) pattern_names(p, out);
|
|
173
|
+
break;
|
|
174
|
+
case "LetDirective": if (typeof n.name === "string") out.add(n.name);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
const DOM_ELEMENTS = /* @__PURE__ */ new Set([
|
|
180
|
+
"RegularElement",
|
|
181
|
+
"SvelteElement",
|
|
182
|
+
"SvelteWindow",
|
|
183
|
+
"SvelteDocument",
|
|
184
|
+
"SvelteBody"
|
|
185
|
+
]);
|
|
186
|
+
const DIRECTIVE_USE = {
|
|
187
|
+
UseDirective: "used as an action",
|
|
188
|
+
TransitionDirective: "used as a transition",
|
|
189
|
+
AnimateDirective: "used as an animation"
|
|
190
|
+
};
|
|
191
|
+
function misuse_of(node, ancestors) {
|
|
192
|
+
const parent = ancestors[ancestors.length - 1];
|
|
193
|
+
if (!parent) return null;
|
|
194
|
+
switch (parent.type) {
|
|
195
|
+
case "CallExpression":
|
|
196
|
+
if (parent.callee !== node) return null;
|
|
197
|
+
return ancestors.some((a) => a.type === "RenderTag") ? "rendered with {@render}" : "called";
|
|
198
|
+
case "NewExpression": return parent.callee === node ? "constructed with new" : null;
|
|
199
|
+
case "TaggedTemplateExpression": return parent.tag === node ? "used as a template tag" : null;
|
|
200
|
+
case "MemberExpression": return parent.object === node ? "read as an object (a member access)" : null;
|
|
201
|
+
case "SpreadElement":
|
|
202
|
+
case "SpreadAttribute": return "spread";
|
|
203
|
+
case "UnaryExpression":
|
|
204
|
+
if (parent.operator === "void" || parent.operator === "!") return null;
|
|
205
|
+
return parent.operator === "typeof" ? "read with typeof" : `an operand of ${parent.operator}`;
|
|
206
|
+
case "UpdateExpression": return "assigned";
|
|
207
|
+
case "AssignmentExpression": return parent.left === node ? "assigned" : null;
|
|
208
|
+
case "TemplateLiteral": return "put in a template string";
|
|
209
|
+
case "HtmlTag": return "rendered with {@html}";
|
|
210
|
+
case "AttachTag": return "used as an attachment";
|
|
211
|
+
case "OnDirective": return "used as an event handler";
|
|
212
|
+
case "EachBlock": return parent.expression === node ? "iterated with {#each}" : null;
|
|
213
|
+
case "AwaitBlock": return parent.expression === node ? "awaited with {#await}" : null;
|
|
214
|
+
case "ExpressionTag": {
|
|
215
|
+
const holder = ancestors[ancestors.length - 2];
|
|
216
|
+
if (holder?.type === "Attribute") {
|
|
217
|
+
if (Array.isArray(holder.value) && holder.value.length > 1) return "put in an attribute string";
|
|
218
|
+
const element = ancestors[ancestors.length - 3];
|
|
219
|
+
if (/^on/i.test(String(holder.name)) && DOM_ELEMENTS.has(String(element?.type))) return "used as an event handler";
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return "rendered as text";
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* A marked binding is a component: placed as `<Name />`, or handed on as a value (`region(Name)`, a
|
|
229
|
+
* prop, a registry entry, an export). Any other use (a call, a member read, a spread, `typeof`, text,
|
|
230
|
+
* a store subscription, an action…) throws `region_binding_not_component` at the first one, naming
|
|
231
|
+
* its line and the plain import line to split it onto. `marked` maps each local to its import.
|
|
232
|
+
*/
|
|
233
|
+
function check_marked_uses(roots, marked, source, host) {
|
|
234
|
+
if (marked.size === 0) return;
|
|
235
|
+
const shadowed = declared_names(roots);
|
|
236
|
+
const watched = new Set([...marked.keys()].filter((n) => !shadowed.has(n)));
|
|
237
|
+
if (watched.size === 0) return;
|
|
238
|
+
const fail = (local, use, at) => {
|
|
239
|
+
const m = marked.get(local);
|
|
240
|
+
const spec = source.slice(m.node.source.start, m.node.source.end);
|
|
241
|
+
throw new OgygiaError("region_binding_not_component", {
|
|
242
|
+
host,
|
|
243
|
+
at: line_col(source, at),
|
|
244
|
+
name: local,
|
|
245
|
+
use,
|
|
246
|
+
fix: `import ${binding_text(m.exportName, local)} from ${spec};`
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
for (const root of roots) walk(root, (n, ancestors) => {
|
|
250
|
+
if (n.type === "ImportDeclaration" || String(n.type).startsWith("TS")) return false;
|
|
251
|
+
const how = DIRECTIVE_USE[n.type];
|
|
252
|
+
if (how && watched.has(n.name)) fail(n.name, how, n.start);
|
|
253
|
+
if (n.type !== "Identifier") return;
|
|
254
|
+
const name = String(n.name);
|
|
255
|
+
if (name.startsWith("$") && watched.has(name.slice(1))) fail(name.slice(1), `read as a store (${name})`, n.start);
|
|
256
|
+
if (!watched.has(name)) return;
|
|
257
|
+
const parent = ancestors[ancestors.length - 1];
|
|
258
|
+
if (parent?.type === "MemberExpression" && parent.property === n && !parent.computed) return;
|
|
259
|
+
if ((parent?.type === "Property" || parent?.type === "MethodDefinition") && parent.key === n && !parent.computed && !parent.shorthand) return;
|
|
260
|
+
if (parent?.type === "ExportSpecifier" && parent.exported === n && parent.local !== n) return;
|
|
261
|
+
const use = misuse_of(n, ancestors);
|
|
262
|
+
if (use) fail(name, use, n.start);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
export { check_marked_uses, marked_import_bindings, refuse_as_region };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { IslandDescriptor } from "../program.js";
|
|
2
|
+
import { regionId, regionIdentity, strategyKey } from "./identity.js";
|
|
3
|
+
import { AppAlias, AppSpecCtx } from "../app-spec.js";
|
|
4
|
+
import { regionBindingVirtualId, wrapperVirtualId } from "../ids.js";
|
|
5
|
+
import { foucCssVirtualId } from "../fouc-css.js";
|
|
6
|
+
import { SourceMap } from "magic-string";
|
|
7
|
+
interface HostCtx {
|
|
8
|
+
root: string;
|
|
9
|
+
libDir: string;
|
|
10
|
+
readFile: (abs: string) => string | null;
|
|
11
|
+
dev: boolean;
|
|
12
|
+
virtualPathFor: (hostId: string, iid: string) => string;
|
|
13
|
+
wrapperPathFor?: (hostId: string, iid: string) => string;
|
|
14
|
+
devUrlFor: (virtualPath: string) => string;
|
|
15
|
+
originOf?: (id: string) => string;
|
|
16
|
+
pkg_identity?: (abs: string) => string | null;
|
|
17
|
+
alias?: readonly AppAlias[];
|
|
18
|
+
stat?: AppSpecCtx["stat"];
|
|
19
|
+
appDir?: string;
|
|
20
|
+
visibleMargin: string | undefined;
|
|
21
|
+
presets: Record<string, unknown>;
|
|
22
|
+
importKeys: Partial<ImportKeys> | undefined;
|
|
23
|
+
idSalt?: string;
|
|
24
|
+
linkVirtualIsland?: boolean;
|
|
25
|
+
clientBindingStub?: string;
|
|
26
|
+
routeCsr: boolean | undefined;
|
|
27
|
+
ssr: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface TsRegionCtx {
|
|
30
|
+
root: string;
|
|
31
|
+
libDir: string;
|
|
32
|
+
dev: boolean;
|
|
33
|
+
virtualPathFor: (hostId: string, iid: string) => string;
|
|
34
|
+
devUrlFor: (virtualPath: string) => string;
|
|
35
|
+
appDir?: string;
|
|
36
|
+
importKeys: Partial<ImportKeys> | undefined;
|
|
37
|
+
idSalt?: string;
|
|
38
|
+
wrapperPathFor?: (hostId: string, iid: string) => string;
|
|
39
|
+
visibleMargin?: string;
|
|
40
|
+
pkg_identity?: (abs: string) => string | null;
|
|
41
|
+
alias?: readonly AppAlias[];
|
|
42
|
+
stat?: AppSpecCtx["stat"];
|
|
43
|
+
}
|
|
44
|
+
export declare const ISLAND_DIR = ".ogygia";
|
|
45
|
+
/** True for a GENERATED island glue id (virtual island entry / wrapper / region binding, or the legacy
|
|
46
|
+
* on-disk `.ogygia/` shape) — the ids that are ogygia's own emit, not authored app/component source. */
|
|
47
|
+
export declare function is_island_path(id: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Default import-attribute keys — the two-dial grammar. Internal role names stay `hydrate`/`defer`
|
|
50
|
+
* (the wire format + runtime keep those anchors); the user-facing ATTRIBUTE names are the values.
|
|
51
|
+
* Override via `ogygia({ importKeys })`.
|
|
52
|
+
* - `render` attribute → the MODE: `static` (inline HTML) | `deferred` (a hole, fetched) | `live`
|
|
53
|
+
* (a hole that revalidates). Defaults to `static`.
|
|
54
|
+
* - `fetch` attribute → a `deferred` hole's TIMING, when its HTML arrives (default `load`):
|
|
55
|
+
* `with { render: 'deferred', fetch: 'visible' }`.
|
|
56
|
+
* - `wake` attribute → when an island's JS runs (`none`: a lake). Never a hole's timing.
|
|
57
|
+
*/
|
|
58
|
+
export declare const DEFAULT_IMPORT_KEYS: {
|
|
59
|
+
readonly wake: "wake";
|
|
60
|
+
readonly fetch: "fetch";
|
|
61
|
+
readonly render: "render";
|
|
62
|
+
readonly preset: "preset";
|
|
63
|
+
readonly region: "region";
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Import-attribute key names claimed by the transform
|
|
67
|
+
* (`with { wake | fetch | render | preset | region }`). Override via `ogygia({ importKeys })` when
|
|
68
|
+
* another tool already uses the default names.
|
|
69
|
+
*/
|
|
70
|
+
export type ImportKeys = {
|
|
71
|
+
/** When an island's JS runs (default attribute `'wake'`); `'none'` makes a lake. For `live` it is
|
|
72
|
+
* the revalidate schedule. */
|
|
73
|
+
wake: string;
|
|
74
|
+
/** A `render: 'deferred'` hole's timing — when its HTML arrives (default attribute `'fetch'`):
|
|
75
|
+
* `'load'` | `'idle'` | `'visible'` | `'interaction'` | a media query. */
|
|
76
|
+
fetch: string;
|
|
77
|
+
/** The delivery MODE (default attribute `'render'`): `static` | `deferred` | `live`. */
|
|
78
|
+
render: string;
|
|
79
|
+
/** Named preset attribute (default `'preset'`). */
|
|
80
|
+
preset: string;
|
|
81
|
+
/** Held-across-a-boundary marker (default attribute `'region'`, only value `'raw'`) — a component
|
|
82
|
+
* a registry hands to `region()` where the transform can't see the call. */
|
|
83
|
+
region: string;
|
|
84
|
+
};
|
|
85
|
+
/** The keys a region preset takes, by their standard names: a preset is config, so `importKeys`
|
|
86
|
+
* never renames them. */
|
|
87
|
+
export declare const PRESET_KEYS: ReadonlySet<string>;
|
|
88
|
+
/**
|
|
89
|
+
* Merge partial `importKeys` with {@link DEFAULT_IMPORT_KEYS}.
|
|
90
|
+
* Rejects empty strings, non-identifiers, and colliding role names.
|
|
91
|
+
*
|
|
92
|
+
* @param overrides - Optional overrides for one or more roles.
|
|
93
|
+
* @returns Fully resolved key map used by the transform.
|
|
94
|
+
* @throws If a value is not a JS identifier or two roles share the same name.
|
|
95
|
+
*/
|
|
96
|
+
export declare function normalize_import_keys(overrides?: Partial<ImportKeys> | null): ImportKeys;
|
|
97
|
+
/**
|
|
98
|
+
* Cheap source-scan regex matching any of the configured import-attribute key names.
|
|
99
|
+
* Used to skip AST work on hosts that cannot contain region imports.
|
|
100
|
+
*
|
|
101
|
+
* @param import_keys - Resolved key map from {@link normalize_import_keys}.
|
|
102
|
+
*/
|
|
103
|
+
export declare function import_keys_hint(import_keys: ImportKeys): RegExp;
|
|
104
|
+
/** Deterministic short id for a region (stable across dev + build).
|
|
105
|
+
* When `salt` is set (production `OGYGIA_SECRET`), ids are not offline-computable (P1-ID).
|
|
106
|
+
* Paths are always posix so SSR/client builds agree across OS path separators. */
|
|
107
|
+
export declare function islandId(relHostPath: string, index: string | number, salt?: string): string;
|
|
108
|
+
/**
|
|
109
|
+
* The directory, under the app dir, of the STABLE names (an island's identity, the runtime's): not
|
|
110
|
+
* `immutable/`. A host serves `immutable/` for a year by name (every adapter, every CDN rule written
|
|
111
|
+
* for it), and a stable name keeps its name while its content follows each build: a year-old copy
|
|
112
|
+
* would load another build's code. Here a host's ordinary rule revalidates them. The content-hashed
|
|
113
|
+
* files they point at stay in `immutable/`.
|
|
114
|
+
*/
|
|
115
|
+
export declare const STABLE_NAME_DIR = "ogygia";
|
|
116
|
+
/**
|
|
117
|
+
* Deterministic client path of a hydrate island's stable name (mirrors the runtime's). SSR bakes it
|
|
118
|
+
* into `<ogygia-region entry>` as the island's identity — a name, not a file: the content-hashed
|
|
119
|
+
* entry is found through the handoff (the server) and the location maps (the browser,
|
|
120
|
+
* link/location-map.ts), since Kit builds server before client.
|
|
121
|
+
*/
|
|
122
|
+
export declare function islandChunkFileName(iid: string, appDir?: string): string;
|
|
123
|
+
/** App-internal URL for {@link islandChunkFileName}: `/<appDir>/ogygia/…` (leading slash, appDir,
|
|
124
|
+
* NO base). It is what SSR bakes onto `<ogygia-region entry>`; `Region.svelte` runs it through Kit's
|
|
125
|
+
* `asset()` at render time, which is the sole authority on `base` / the assets CDN / relative paths —
|
|
126
|
+
* so a base is never baked here (that would double-apply it). NOT the on-disk output filename. */
|
|
127
|
+
export declare function islandPublicUrl(iid: string, appDir?: string): string;
|
|
128
|
+
/**
|
|
129
|
+
* csr=false CLIENT host binding target. Kit still emits those page nodes; pointing marked
|
|
130
|
+
* imports here (instead of wrappers) keeps N island wrappers/entries out of the page graph so
|
|
131
|
+
* `emitFile` owns hydrate modules and Rolldown does not thin-facade them. Hydration uses
|
|
132
|
+
* `import(entry)` only — this stub is never loaded for island JS.
|
|
133
|
+
*
|
|
134
|
+
* Beside the stub the transform emits `import 'ogygia:region/fouc-css/<entry>'` so Kit still
|
|
135
|
+
* links stylesheets (FOUC) via CSS-only side effects. Importing the full `.svelte` JS module
|
|
136
|
+
* dual-owns it with the emitFile island entry and Rolldown thin-facades `og-region.*`.
|
|
137
|
+
* Omitting CSS entirely orphans rules (scoped class hashes, no stylesheet).
|
|
138
|
+
*/
|
|
139
|
+
export declare const CLIENT_BINDING_STUB: string;
|
|
140
|
+
/**
|
|
141
|
+
* The `with { region: … }` marker has ONE value — `'raw'` (an adjective: "a raw/held region"). It
|
|
142
|
+
* carries NO schedule: the wake timing is set at the `region()` call (`region(C, props, { wake })`)
|
|
143
|
+
* or, in a block tree, per node. This is the only surviving import-attribute marker for a component
|
|
144
|
+
* a registry hands to `region()` where the transform can't see the call site.
|
|
145
|
+
*
|
|
146
|
+
* @param raw the marker value
|
|
147
|
+
* @param where host label for error messages
|
|
148
|
+
* @param regionKey configured `region` attribute name (for the message)
|
|
149
|
+
*/
|
|
150
|
+
export declare function normalize_region_value(raw: string, where: string, regionKey?: string): void;
|
|
151
|
+
/**
|
|
152
|
+
* Validate a `wake:` schedule value on a held import (a `.ts` registry / remote). Accepts the wake
|
|
153
|
+
* strategies (`load` / `idle` / `visible` / `interaction`) or a media query — the same vocabulary as
|
|
154
|
+
* a placed island's `wake:`. Returns the value unchanged (it becomes the baked `__hydrate`).
|
|
155
|
+
*/
|
|
156
|
+
export declare function normalize_hydrate_value(raw: string, where: string, wakeKey?: string): string;
|
|
157
|
+
export declare function transformHost(source: string, id: string, ctx: HostCtx): {
|
|
158
|
+
code: string;
|
|
159
|
+
map: SourceMap;
|
|
160
|
+
islands: never[];
|
|
161
|
+
} | {
|
|
162
|
+
code: string;
|
|
163
|
+
map: SourceMap;
|
|
164
|
+
islands: IslandDescriptor[];
|
|
165
|
+
hasWireCrossing: boolean;
|
|
166
|
+
} | null;
|
|
167
|
+
/**
|
|
168
|
+
* Rewrite held-region imports in a `.ts` / `.js` module (a load or remote function, where held
|
|
169
|
+
* regions are minted and handed to `region()`). Svelte's `parse()` can't read these files, so this
|
|
170
|
+
* reads the module's oxc AST; only the default-import form is a region import. A `.ts` module has no template,
|
|
171
|
+
* so every marked import here is HELD → a descriptor. Two markers:
|
|
172
|
+
* - `region: 'raw'` → bakes no schedule (set at the `region()` call).
|
|
173
|
+
* - `wake: 'x'` → bakes that schedule (the `region()` call can still override).
|
|
174
|
+
* Each registers a server-manifest entry + client chunk and is rewritten to import the leg-split
|
|
175
|
+
* descriptor module. Returns the same `{code, map, islands}` shape, or `null` when nothing matched.
|
|
176
|
+
*
|
|
177
|
+
* @param source
|
|
178
|
+
* @param id absolute module path
|
|
179
|
+
* @param ctx same context fields as {@link transformHost} (root, libDir, dev, devUrlFor,
|
|
180
|
+
* virtualPathFor, importKeys, idSalt)
|
|
181
|
+
* @returns
|
|
182
|
+
*/
|
|
183
|
+
export declare function transformTsRegions(source: string, id: string, ctx: TsRegionCtx): {
|
|
184
|
+
code: string;
|
|
185
|
+
map: SourceMap;
|
|
186
|
+
islands: IslandDescriptor[];
|
|
187
|
+
hasWireCrossing: boolean;
|
|
188
|
+
} | null;
|
|
189
|
+
export { foucCssVirtualId, regionBindingVirtualId, regionId, regionIdentity, strategyKey, wrapperVirtualId };
|