irisout 0.2.1

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.
@@ -0,0 +1,83 @@
1
+ //#region packages/compiler/src/diagnostics.ts
2
+ function e(e) {
3
+ return typeof e == "object" && e ? e : null;
4
+ }
5
+ function t(e, t) {
6
+ let n = Math.max(0, Math.min(t, e.length)), r = e.slice(0, n);
7
+ return {
8
+ line: r.split("\n").length,
9
+ column: n - r.lastIndexOf("\n")
10
+ };
11
+ }
12
+ function n(e, t, n) {
13
+ if (t <= 1) return Math.max(0, n - 1);
14
+ let r = 0, i = 1;
15
+ for (; i < t;) {
16
+ let t = e.indexOf("\n", r);
17
+ if (t < 0) return e.length;
18
+ r = t + 1, i += 1;
19
+ }
20
+ return Math.min(e.length, r + Math.max(0, n - 1));
21
+ }
22
+ function r(e, t, r, i) {
23
+ if (!i || i.length === 0) return null;
24
+ let a = n(e, t, r), o = i.find((e) => a >= e.generatedStart && a <= e.generatedEnd);
25
+ if (!o) return null;
26
+ let s = Math.max(0, a - o.generatedStart), c = e.slice(o.generatedStart, a), l = c.split("\n").length, u = o.source.split("\n"), d = Math.min(Math.max(1, l), Math.max(1, u.length)), f = u[d - 1] ?? "", p = Math.min(Math.max(1, l === 1 ? s : c.lastIndexOf("\n") + 1), Math.max(1, f.length + 1));
27
+ return {
28
+ filePath: o.filePath,
29
+ line: d,
30
+ column: p
31
+ };
32
+ }
33
+ function i(n, r) {
34
+ let i = e(n), a = e(i?.start) ?? i;
35
+ if (!a) return null;
36
+ let o = typeof a.line == "number" ? a.line : null, s = typeof a.column == "number" ? a.column : null;
37
+ return o != null && s != null ? {
38
+ line: Math.max(1, o),
39
+ column: Math.max(1, s + 1)
40
+ } : typeof a.index == "number" ? t(r, a.index) : null;
41
+ }
42
+ function a(t, n) {
43
+ let r = /* @__PURE__ */ new Set(), a = t;
44
+ for (; a != null;) {
45
+ let t = e(a);
46
+ if (!t || r.has(t)) return null;
47
+ r.add(t);
48
+ let o = i(t.loc, n);
49
+ if (o) return o;
50
+ a = t.cause;
51
+ }
52
+ return null;
53
+ }
54
+ function o(e, t) {
55
+ for (let n of e.matchAll(/["'`]([^"'`\n]+)["'`]/g)) {
56
+ let e = n[1];
57
+ if (!e || e.length < 2) continue;
58
+ let r = t.indexOf(e);
59
+ if (r >= 0) return r;
60
+ }
61
+ return null;
62
+ }
63
+ function s(e, n) {
64
+ let i = n.offset == null ? a(e, n.source) ?? t(n.source, o(e instanceof Error ? e.message : String(e), n.source) ?? 0) : t(n.source, n.offset);
65
+ return r(n.source, i.line, i.column, n.origins) ?? {
66
+ filePath: n.filePath,
67
+ ...i
68
+ };
69
+ }
70
+ var c = class extends Error {
71
+ filePath;
72
+ line;
73
+ column;
74
+ constructor(e, t, n) {
75
+ let r = e.startsWith("compile:") ? e : `compile: ${e}`, i = s(n ?? e, t);
76
+ super(`${r} [${i.filePath}:${i.line}:${i.column}]`, { cause: n }), this.name = "CompileDiagnostic", this.filePath = i.filePath, this.line = i.line, this.column = i.column;
77
+ }
78
+ };
79
+ function l(e, t) {
80
+ return e instanceof c ? e : new c(e instanceof Error ? e.message : String(e), t, e);
81
+ }
82
+ //#endregion
83
+ export { c as CompileDiagnostic, s as diagnosticPosition, l as withCompileDiagnostic };
@@ -0,0 +1,16 @@
1
+ import type { DeclId, MarkerId } from './compiler/state.ts';
2
+ import { createCompilerState } from './compiler/state.ts';
3
+ import type { IrisoutSourceMap } from './source-map.ts';
4
+ export { CompileDiagnostic } from './diagnostics.ts';
5
+ export interface CompileResult {
6
+ code: string;
7
+ map: IrisoutSourceMap;
8
+ initialHtml: string;
9
+ markers: ReturnType<typeof createCompilerState>['markers'];
10
+ signalToMarkers: Map<DeclId, Set<MarkerId>>;
11
+ declName: Map<DeclId, string>;
12
+ /** compileProject()が読み込んだ入口と相対moduleの絶対path。 */
13
+ dependencies: string[];
14
+ }
15
+ export declare function compile(source: string): CompileResult;
16
+ export declare function compileProject(entryPath: string): CompileResult;