@mun-ui/react 0.0.0-stage → 0.2.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/dist/advanced.d.ts +7 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +6 -0
- package/dist/advanced.js.map +1 -0
- package/dist/continuous-corners.d.ts +4 -0
- package/dist/continuous-corners.d.ts.map +1 -0
- package/dist/continuous-corners.js +54 -0
- package/dist/continuous-corners.js.map +1 -0
- package/dist/controls.d.ts +7 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +6 -0
- package/dist/controls.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/interop.d.ts +23 -0
- package/dist/interop.d.ts.map +1 -0
- package/dist/interop.js +75 -0
- package/dist/interop.js.map +1 -0
- package/dist/legacy/builder.d.ts +6 -0
- package/dist/legacy/builder.d.ts.map +1 -0
- package/dist/legacy/builder.js +13 -0
- package/dist/legacy/builder.js.map +1 -0
- package/dist/legacy/closures.d.ts +3 -0
- package/dist/legacy/closures.d.ts.map +1 -0
- package/dist/legacy/closures.js +3 -0
- package/dist/legacy/closures.js.map +1 -0
- package/dist/legacy/collections.d.ts +53 -0
- package/dist/legacy/collections.d.ts.map +1 -0
- package/dist/legacy/collections.js +154 -0
- package/dist/legacy/collections.js.map +1 -0
- package/dist/legacy/compiler/ast.d.ts +84 -0
- package/dist/legacy/compiler/ast.d.ts.map +1 -0
- package/dist/legacy/compiler/ast.js +697 -0
- package/dist/legacy/compiler/ast.js.map +1 -0
- package/dist/legacy/compiler/builder-transform.d.ts +2 -0
- package/dist/legacy/compiler/builder-transform.d.ts.map +1 -0
- package/dist/legacy/compiler/builder-transform.js +422 -0
- package/dist/legacy/compiler/builder-transform.js.map +1 -0
- package/dist/legacy/compiler/errors.d.ts +5 -0
- package/dist/legacy/compiler/errors.d.ts.map +1 -0
- package/dist/legacy/compiler/errors.js +7 -0
- package/dist/legacy/compiler/errors.js.map +1 -0
- package/dist/legacy/compiler/index.d.ts +15 -0
- package/dist/legacy/compiler/index.d.ts.map +1 -0
- package/dist/legacy/compiler/index.js +10 -0
- package/dist/legacy/compiler/index.js.map +1 -0
- package/dist/legacy/compiler/language-service.d.ts +26 -0
- package/dist/legacy/compiler/language-service.d.ts.map +1 -0
- package/dist/legacy/compiler/language-service.js +35 -0
- package/dist/legacy/compiler/language-service.js.map +1 -0
- package/dist/legacy/compiler/language-tools.d.ts +12 -0
- package/dist/legacy/compiler/language-tools.d.ts.map +1 -0
- package/dist/legacy/compiler/language-tools.js +44 -0
- package/dist/legacy/compiler/language-tools.js.map +1 -0
- package/dist/legacy/compiler/source-map.d.ts +36 -0
- package/dist/legacy/compiler/source-map.d.ts.map +1 -0
- package/dist/legacy/compiler/source-map.js +188 -0
- package/dist/legacy/compiler/source-map.js.map +1 -0
- package/dist/legacy/compiler/struct-transform.d.ts +18 -0
- package/dist/legacy/compiler/struct-transform.d.ts.map +1 -0
- package/dist/legacy/compiler/struct-transform.js +268 -0
- package/dist/legacy/compiler/struct-transform.js.map +1 -0
- package/dist/legacy/compiler/swc-transform.d.ts +7 -0
- package/dist/legacy/compiler/swc-transform.d.ts.map +1 -0
- package/dist/legacy/compiler/swc-transform.js +33 -0
- package/dist/legacy/compiler/swc-transform.js.map +1 -0
- package/dist/legacy/compiler/typescript-language-service.d.ts +12 -0
- package/dist/legacy/compiler/typescript-language-service.d.ts.map +1 -0
- package/dist/legacy/compiler/typescript-language-service.js +185 -0
- package/dist/legacy/compiler/typescript-language-service.js.map +1 -0
- package/dist/legacy/compiler/vite-builder.d.ts +11 -0
- package/dist/legacy/compiler/vite-builder.d.ts.map +1 -0
- package/dist/legacy/compiler/vite-builder.js +40 -0
- package/dist/legacy/compiler/vite-builder.js.map +1 -0
- package/dist/legacy/controls.d.ts +59 -0
- package/dist/legacy/controls.d.ts.map +1 -0
- package/dist/legacy/controls.js +119 -0
- package/dist/legacy/controls.js.map +1 -0
- package/dist/legacy/coordinate.d.ts +17 -0
- package/dist/legacy/coordinate.d.ts.map +1 -0
- package/dist/legacy/coordinate.js +17 -0
- package/dist/legacy/coordinate.js.map +1 -0
- package/dist/legacy/elements.d.ts +98 -0
- package/dist/legacy/elements.d.ts.map +1 -0
- package/dist/legacy/elements.js +367 -0
- package/dist/legacy/elements.js.map +1 -0
- package/dist/legacy/experimental.d.ts +19 -0
- package/dist/legacy/experimental.d.ts.map +1 -0
- package/dist/legacy/experimental.js +16 -0
- package/dist/legacy/experimental.js.map +1 -0
- package/dist/legacy/index.d.ts +27 -0
- package/dist/legacy/index.d.ts.map +1 -0
- package/dist/legacy/index.js +13 -0
- package/dist/legacy/index.js.map +1 -0
- package/dist/legacy/jsx-dev-runtime.d.ts +3 -0
- package/dist/legacy/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/legacy/jsx-dev-runtime.js +2 -0
- package/dist/legacy/jsx-dev-runtime.js.map +1 -0
- package/dist/legacy/jsx-runtime.d.ts +61 -0
- package/dist/legacy/jsx-runtime.d.ts.map +1 -0
- package/dist/legacy/jsx-runtime.js +56 -0
- package/dist/legacy/jsx-runtime.js.map +1 -0
- package/dist/legacy/layout-engine.d.ts +15 -0
- package/dist/legacy/layout-engine.d.ts.map +1 -0
- package/dist/legacy/layout-engine.js +11 -0
- package/dist/legacy/layout-engine.js.map +1 -0
- package/dist/legacy/layout.d.ts +19 -0
- package/dist/legacy/layout.d.ts.map +1 -0
- package/dist/legacy/layout.js +102 -0
- package/dist/legacy/layout.js.map +1 -0
- package/dist/legacy/modifiers.d.ts +12 -0
- package/dist/legacy/modifiers.d.ts.map +1 -0
- package/dist/legacy/modifiers.js +242 -0
- package/dist/legacy/modifiers.js.map +1 -0
- package/dist/legacy/presentation.d.ts +40 -0
- package/dist/legacy/presentation.d.ts.map +1 -0
- package/dist/legacy/presentation.js +449 -0
- package/dist/legacy/presentation.js.map +1 -0
- package/dist/legacy/react-types.d.ts +9 -0
- package/dist/legacy/react-types.d.ts.map +1 -0
- package/dist/legacy/react-types.js +2 -0
- package/dist/legacy/react-types.js.map +1 -0
- package/dist/legacy/runtime/arrays.d.ts +5 -0
- package/dist/legacy/runtime/arrays.d.ts.map +1 -0
- package/dist/legacy/runtime/arrays.js +27 -0
- package/dist/legacy/runtime/arrays.js.map +1 -0
- package/dist/legacy/runtime/coordinate-runtime.d.ts +10 -0
- package/dist/legacy/runtime/coordinate-runtime.d.ts.map +1 -0
- package/dist/legacy/runtime/coordinate-runtime.js +7 -0
- package/dist/legacy/runtime/coordinate-runtime.js.map +1 -0
- package/dist/legacy/runtime/jsx-node.d.ts +9 -0
- package/dist/legacy/runtime/jsx-node.d.ts.map +1 -0
- package/dist/legacy/runtime/jsx-node.js +10 -0
- package/dist/legacy/runtime/jsx-node.js.map +1 -0
- package/dist/legacy/runtime/layout-observer.d.ts +4 -0
- package/dist/legacy/runtime/layout-observer.d.ts.map +1 -0
- package/dist/legacy/runtime/layout-observer.js +22 -0
- package/dist/legacy/runtime/layout-observer.js.map +1 -0
- package/dist/legacy/runtime/modifier-pipeline.d.ts +10 -0
- package/dist/legacy/runtime/modifier-pipeline.d.ts.map +1 -0
- package/dist/legacy/runtime/modifier-pipeline.js +17 -0
- package/dist/legacy/runtime/modifier-pipeline.js.map +1 -0
- package/dist/legacy/runtime/renderer.d.ts +24 -0
- package/dist/legacy/runtime/renderer.d.ts.map +1 -0
- package/dist/legacy/runtime/renderer.js +94 -0
- package/dist/legacy/runtime/renderer.js.map +1 -0
- package/dist/legacy/runtime/view-graph.d.ts +22 -0
- package/dist/legacy/runtime/view-graph.d.ts.map +1 -0
- package/dist/legacy/runtime/view-graph.js +70 -0
- package/dist/legacy/runtime/view-graph.js.map +1 -0
- package/dist/legacy/runtime/view-storage.d.ts +14 -0
- package/dist/legacy/runtime/view-storage.d.ts.map +1 -0
- package/dist/legacy/runtime/view-storage.js +15 -0
- package/dist/legacy/runtime/view-storage.js.map +1 -0
- package/dist/legacy/state.d.ts +8 -0
- package/dist/legacy/state.d.ts.map +1 -0
- package/dist/legacy/state.js +23 -0
- package/dist/legacy/state.js.map +1 -0
- package/dist/legacy/types.d.ts +111 -0
- package/dist/legacy/types.d.ts.map +1 -0
- package/dist/legacy/types.js +2 -0
- package/dist/legacy/types.js.map +1 -0
- package/dist/legacy/view-system.d.ts +111 -0
- package/dist/legacy/view-system.d.ts.map +1 -0
- package/dist/legacy/view-system.js +421 -0
- package/dist/legacy/view-system.js.map +1 -0
- package/dist/legacy/view.d.ts +15 -0
- package/dist/legacy/view.d.ts.map +1 -0
- package/dist/legacy/view.js +30 -0
- package/dist/legacy/view.js.map +1 -0
- package/dist/legacy/vite.d.ts +32 -0
- package/dist/legacy/vite.d.ts.map +1 -0
- package/dist/legacy/vite.js +540 -0
- package/dist/legacy/vite.js.map +1 -0
- package/dist/presentation.d.ts +7 -0
- package/dist/presentation.d.ts.map +1 -0
- package/dist/presentation.js +6 -0
- package/dist/presentation.js.map +1 -0
- package/dist/renderer.d.ts +34 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +1461 -0
- package/dist/renderer.js.map +1 -0
- package/dist/views.d.ts +7 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/views.js +6 -0
- package/dist/views.js.map +1 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createMunSourceMap } from './source-map.js';
|
|
2
|
+
import { diagnoseMunSource, formatMunSource } from './language-tools.js';
|
|
3
|
+
function clampOffset(source, offset) {
|
|
4
|
+
return Math.max(0, Math.min(source.length, Math.trunc(offset)));
|
|
5
|
+
}
|
|
6
|
+
function positionAt(source, offset) {
|
|
7
|
+
const bounded = clampOffset(source, offset);
|
|
8
|
+
const before = source.slice(0, bounded);
|
|
9
|
+
const lineStart = before.lastIndexOf('\n') + 1;
|
|
10
|
+
return {
|
|
11
|
+
line: before.split('\n').length,
|
|
12
|
+
column: bounded - lineStart + 1,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function offsetAt(source, position) {
|
|
16
|
+
const line = Math.max(1, Math.trunc(position.line));
|
|
17
|
+
const column = Math.max(1, Math.trunc(position.column));
|
|
18
|
+
const lines = source.split('\n');
|
|
19
|
+
const lineStart = lines.slice(0, Math.min(line - 1, lines.length - 1))
|
|
20
|
+
.reduce((offset, value) => offset + value.length + 1, 0);
|
|
21
|
+
return clampOffset(source, lineStart + column - 1);
|
|
22
|
+
}
|
|
23
|
+
export function createMunLanguageService() {
|
|
24
|
+
return {
|
|
25
|
+
format: formatMunSource,
|
|
26
|
+
diagnose: diagnoseMunSource,
|
|
27
|
+
transform(source, id = 'mun-source.ts') {
|
|
28
|
+
const code = formatMunSource(source);
|
|
29
|
+
return { code, map: createMunSourceMap(source, code, id) };
|
|
30
|
+
},
|
|
31
|
+
positionAt,
|
|
32
|
+
offsetAt,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=language-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-service.js","sourceRoot":"","sources":["../../../src/legacy/compiler/language-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAsB,MAAM,qBAAqB,CAAA;AA0B5F,SAAS,WAAW,CAAC,MAAc,EAAE,MAAc;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AACjE,CAAC;AAED,SAAS,UAAU,CAAC,MAAc,EAAE,MAAc;IAChD,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3C,MAAM,MAAM,GAAG,MAAM,C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BAAkB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAA;QAC5D,CAAC;QACD,UAAU;QACV,QAAQ;KACT,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface MunDiagnostic {
|
|
2
|
+
severity: 'error';
|
|
3
|
+
code: 'MUN_SYNTAX';
|
|
4
|
+
message: string;
|
|
5
|
+
line: number;
|
|
6
|
+
column: number;
|
|
7
|
+
}
|
|
8
|
+
/** The canonical formatter/compiler entry used by editor integrations. */
|
|
9
|
+
export declare function formatMunSource(source: string): string;
|
|
10
|
+
/** Return structured diagnostics without making an editor parse exceptions. */
|
|
11
|
+
export declare function diagnoseMunSource(source: string): readonly MunDiagnostic[];
|
|
12
|
+
//# sourceMappingURL=language-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-tools.d.ts","sourceRoot":"","sources":["../../../src/legacy/compiler/language-tools.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,CAAA;IACjB,IAAI,EAAE,YAAY,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAYD,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMtD;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,aAAa,EAAE,CAmB1E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { transformMunBuilderSyntax } from './builder-transform.js';
|
|
2
|
+
import { transformMunStructSyntax } from './struct-transform.js';
|
|
3
|
+
function ensureRuntimeImport(source, name) {
|
|
4
|
+
const existing = /import\s*\{([\s\S]*?)\}\s*from\s*(['"])@mun-ui\/ui\/legacy\2[\t ]*;?/.exec(source);
|
|
5
|
+
if (!existing)
|
|
6
|
+
return `import { ${name} } from '@mun-ui/ui/legacy'\n${source}`;
|
|
7
|
+
const imported = existing[1].split(',').map(value => value.trim()).filter(Boolean);
|
|
8
|
+
if (imported.includes(name))
|
|
9
|
+
return source;
|
|
10
|
+
imported.push(name);
|
|
11
|
+
const replacement = `import { ${imported.join(', ')} } from '@mun-ui/ui/legacy'`;
|
|
12
|
+
return source.slice(0, existing.index) + replacement + source.slice(existing.index + existing[0].length);
|
|
13
|
+
}
|
|
14
|
+
/** The canonical formatter/compiler entry used by editor integrations. */
|
|
15
|
+
export function formatMunSource(source) {
|
|
16
|
+
const transformed = transformMunBuilderSyntax(transformMunStructSyntax(source));
|
|
17
|
+
return [
|
|
18
|
+
...(transformed.includes('namedArguments(') ? ['namedArguments'] : []),
|
|
19
|
+
...(transformed.includes('overloadClosure(') ? ['overloadClosure'] : []),
|
|
20
|
+
].reduce((value, name) => ensureRuntimeImport(value, name), transformed);
|
|
21
|
+
}
|
|
22
|
+
/** Return structured diagnostics without making an editor parse exceptions. */
|
|
23
|
+
export function diagnoseMunSource(source) {
|
|
24
|
+
try {
|
|
25
|
+
formatMunSource(source);
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
30
|
+
const offset = typeof error === 'object' && error !== null && 'offset' in error && typeof error.offset === 'number'
|
|
31
|
+
? error.offset
|
|
32
|
+
: undefined;
|
|
33
|
+
if (offset === undefined) {
|
|
34
|
+
const lineMatch = /line\s+(\d+)/i.exec(message);
|
|
35
|
+
const line = lineMatch ? Number(lineMatch[1]) : 1;
|
|
36
|
+
return [{ severity: 'error', code: 'MUN_SYNTAX', message, line, column: 1 }];
|
|
37
|
+
}
|
|
38
|
+
const before = source.slice(0, offset);
|
|
39
|
+
const line = before.split('\n').length;
|
|
40
|
+
const lineStart = before.lastIndexOf('\n') + 1;
|
|
41
|
+
return [{ severity: 'error', code: 'MUN_SYNTAX', message, line, column: offset - lineStart + 1 }];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=language-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-tools.js","sourceRoot":"","sources":["../../../src/legacy/compiler/language-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAUhE,SAAS,mBAAmB,CAAC,MAAc,EAAE,IAAY;IACvD,MAAM,QAAQ,GAAG,sEAAsE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACpG,IAAI,CAAC,QAAQ;QAAE,OAAO,YAAY,IAAI,gCAAgC,MAAM,EAAE,CAAA;IAC9E,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAClF,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,MAAM,CAAA;IAC1C,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnB,MAAM,WAAW,GAAG,YAAY,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAA;IAChF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;AAC1G,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,MAAM,WAAW,GAAG,yBAAyB,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAA;IAC/E,OAAO;Q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E,CAAC,EAAE,CAAC,CAAA;QAC9E,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAA;QACtC,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC9C,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,CAAC,EAAE,CAAC,CAAA;IACnG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface MunSourceMapAnchor {
|
|
2
|
+
readonly line: number;
|
|
3
|
+
readonly column: number;
|
|
4
|
+
readonly generatedColumn: number;
|
|
5
|
+
}
|
|
6
|
+
export interface MunSourcePosition {
|
|
7
|
+
readonly line: number;
|
|
8
|
+
readonly column: number;
|
|
9
|
+
}
|
|
10
|
+
export interface MunSourceMap {
|
|
11
|
+
readonly version: 3;
|
|
12
|
+
readonly file: string;
|
|
13
|
+
readonly sources: readonly string[];
|
|
14
|
+
readonly sourcesContent: readonly string[];
|
|
15
|
+
readonly names: readonly string[];
|
|
16
|
+
readonly mappings: string;
|
|
17
|
+
/** Line anchors are intentionally retained for editor/TypeScript adapters. */
|
|
18
|
+
readonly x_mun: {
|
|
19
|
+
readonly lineMappings: readonly MunSourceMapAnchor[];
|
|
20
|
+
readonly segments: readonly (readonly MunSourceMapAnchor[])[];
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Produce a line-preserving source map for lexical transforms. The transform
|
|
25
|
+
* keeps original expression text wherever possible, so line anchors are more
|
|
26
|
+
* useful than returning `null`; generated columns that are synthesized by a
|
|
27
|
+
* builder are intentionally anchored at the beginning of their source line.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createMunSourceMap(source: string, generated: string, id: string): MunSourceMap;
|
|
30
|
+
/** Standard-only compatibility map for Vite callers that do not consume Mun anchors. */
|
|
31
|
+
export declare function createLegacyMunSourceMap(source: string, generated: string, id: string): Omit<MunSourceMap, 'x_mun'>;
|
|
32
|
+
/** Map a generated TypeScript position back to its original Mun position. */
|
|
33
|
+
export declare function mapGeneratedPosition(map: MunSourceMap, position: MunSourcePosition): MunSourcePosition;
|
|
34
|
+
/** Map an original Mun position to the nearest generated position. */
|
|
35
|
+
export declare function mapOriginalPosition(map: MunSourceMap, position: MunSourcePosition): MunSourcePosition;
|
|
36
|
+
//# sourceMappingURL=source-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-map.d.ts","sourceRoot":"","sources":["../../../src/legacy/compiler/source-map.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;CACjC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1C,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,YAAY,EAAE,SAAS,kBAAkB,EAAE,CAAA;QACpD,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,SAAS,kBAAkB,EAAE,CAAC,EAAE,CAAA;KAC9D,CAAA;CACF;AAmFD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,YAAY,CA4D9F;AAED,wFAAwF;AACxF,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,GACT,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAY7B;AAED,6EAA6E;AAC7E,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,GAAG,iBAAiB,CAatG;AAED,sEAAsE;AACtE,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,GAAG,iBAAiB,CAuBrG"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
2
|
+
function vlq(value) {
|
|
3
|
+
let current = value < 0 ? ((-value) << 1) | 1 : value << 1;
|
|
4
|
+
let output = '';
|
|
5
|
+
do {
|
|
6
|
+
let digit = current & 31;
|
|
7
|
+
current >>>= 5;
|
|
8
|
+
if (current > 0)
|
|
9
|
+
digit |= 32;
|
|
10
|
+
output += alphabet[digit];
|
|
11
|
+
} while (current > 0);
|
|
12
|
+
return output;
|
|
13
|
+
}
|
|
14
|
+
function tokens(line) {
|
|
15
|
+
return [...line.matchAll(/[A-Za-z_$][A-Za-z0-9_$]*/g)].map(match => ({
|
|
16
|
+
value: match[0],
|
|
17
|
+
column: match.index ?? 0,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
function allTokens(source) {
|
|
21
|
+
return source.split('\n').flatMap((line, lineIndex) => tokens(line).map(token => ({
|
|
22
|
+
value: token.value,
|
|
23
|
+
line: lineIndex,
|
|
24
|
+
column: token.column,
|
|
25
|
+
})));
|
|
26
|
+
}
|
|
27
|
+
function tokenKey(line, column) {
|
|
28
|
+
return `${line}:${column}`;
|
|
29
|
+
}
|
|
30
|
+
/** Match generated occurrences to source occurrences in order, not by name alone. */
|
|
31
|
+
function alignTokenAnchors(source, generated) {
|
|
32
|
+
const original = allTokens(source);
|
|
33
|
+
const output = allTokens(generated);
|
|
34
|
+
const anchors = new Map();
|
|
35
|
+
let cursor = 0;
|
|
36
|
+
let previous = { line: 0, column: 0 };
|
|
37
|
+
for (const token of output) {
|
|
38
|
+
while (cursor < original.length && original[cursor].value !== token.value)
|
|
39
|
+
cursor += 1;
|
|
40
|
+
const anchor = original[cursor];
|
|
41
|
+
if (anchor) {
|
|
42
|
+
previous = { line: anchor.line, column: anchor.column };
|
|
43
|
+
cursor += 1;
|
|
44
|
+
}
|
|
45
|
+
anchors.set(tokenKey(token.line, token.column), previous);
|
|
46
|
+
}
|
|
47
|
+
return anchors;
|
|
48
|
+
}
|
|
49
|
+
function sourceAnchorForToken(token, sourceTokens, fallbackLine) {
|
|
50
|
+
const candidates = sourceTokens.get(token) ?? [];
|
|
51
|
+
let best;
|
|
52
|
+
for (const candidate of candidates) {
|
|
53
|
+
const distance = Math.abs(candidate.line - fallbackLine);
|
|
54
|
+
const score = token.length - distance;
|
|
55
|
+
if (!best || score > best.score || (score === best.score && distance < best.distance)) {
|
|
56
|
+
best = { score, distance, line: candidate.line, column: candidate.column };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return best ? { line: best.line, column: best.column } : undefined;
|
|
60
|
+
}
|
|
61
|
+
function anchorsForGeneratedLine(generatedLine, generatedLineIndex, sourceLines, sourceTokens, alignedAnchors, fallbackLine) {
|
|
62
|
+
const generatedTokens = tokens(generatedLine);
|
|
63
|
+
if (generatedTokens.length === 0) {
|
|
64
|
+
return [{ line: Math.min(fallbackLine, sourceLines.length - 1), column: 0, generatedColumn: 0 }];
|
|
65
|
+
}
|
|
66
|
+
return generatedTokens.map(token => {
|
|
67
|
+
const source = alignedAnchors.get(tokenKey(generatedLineIndex, token.column))
|
|
68
|
+
?? sourceAnchorForToken(token.value, sourceTokens, fallbackLine)
|
|
69
|
+
?? { line: Math.min(fallbackLine, sourceLines.length - 1), column: 0 };
|
|
70
|
+
return { ...source, generatedColumn: token.column };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Produce a line-preserving source map for lexical transforms. The transform
|
|
75
|
+
* keeps original expression text wherever possible, so line anchors are more
|
|
76
|
+
* useful than returning `null`; generated columns that are synthesized by a
|
|
77
|
+
* builder are intentionally anchored at the beginning of their source line.
|
|
78
|
+
*/
|
|
79
|
+
export function createMunSourceMap(source, generated, id) {
|
|
80
|
+
const sourceLineValues = source.split('\n');
|
|
81
|
+
const sourceLines = Math.max(1, sourceLineValues.length);
|
|
82
|
+
const sourceTokens = new Map();
|
|
83
|
+
sourceLineValues.forEach((line, lineIndex) => {
|
|
84
|
+
for (const token of tokens(line)) {
|
|
85
|
+
const values = sourceTokens.get(token.value) ?? [];
|
|
86
|
+
values.push({ line: lineIndex, column: token.column });
|
|
87
|
+
sourceTokens.set(token.value, values);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
if (source === generated) {
|
|
91
|
+
const identitySegments = sourceLineValues.map((_, line) => [{ line, column: 0, generatedColumn: 0 }]);
|
|
92
|
+
let previousLine = 0;
|
|
93
|
+
const mappings = identitySegments.map(([anchor]) => {
|
|
94
|
+
const value = `${vlq(0)}${vlq(0)}${vlq(anchor.line - previousLine)}${vlq(0)}`;
|
|
95
|
+
previousLine = anchor.line;
|
|
96
|
+
return value;
|
|
97
|
+
}).join(';');
|
|
98
|
+
return {
|
|
99
|
+
version: 3,
|
|
100
|
+
file: id,
|
|
101
|
+
sources: [id],
|
|
102
|
+
sourcesContent: [source],
|
|
103
|
+
names: [],
|
|
104
|
+
mappings,
|
|
105
|
+
x_mun: { lineMappings: identitySegments.map(value => value[0]), segments: identitySegments },
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const alignedAnchors = alignTokenAnchors(source, generated);
|
|
109
|
+
let previousOriginalLine = 0;
|
|
110
|
+
let previousOriginalColumn = 0;
|
|
111
|
+
const segments = generated.split('\n').map((generatedLine, line) => anchorsForGeneratedLine(generatedLine, line, sourceLineValues, sourceTokens, alignedAnchors, Math.min(line, sourceLines - 1)));
|
|
112
|
+
const lineMappings = segments.map(value => value[0]);
|
|
113
|
+
const mappings = segments.map(lineSegments => {
|
|
114
|
+
let previousGeneratedColumn = 0;
|
|
115
|
+
return lineSegments.map(anchor => {
|
|
116
|
+
const mapping = `${vlq(anchor.generatedColumn - previousGeneratedColumn)}${vlq(0)}${vlq(anchor.line - previousOriginalLine)}${vlq(anchor.column - previousOriginalColumn)}`;
|
|
117
|
+
previousGeneratedColumn = anchor.generatedColumn;
|
|
118
|
+
previousOriginalLine = anchor.line;
|
|
119
|
+
previousOriginalColumn = anchor.column;
|
|
120
|
+
return mapping;
|
|
121
|
+
}).join(',');
|
|
122
|
+
}).join(';');
|
|
123
|
+
return {
|
|
124
|
+
version: 3,
|
|
125
|
+
file: id,
|
|
126
|
+
sources: [id],
|
|
127
|
+
sourcesContent: [source],
|
|
128
|
+
names: [],
|
|
129
|
+
mappings,
|
|
130
|
+
x_mun: { lineMappings, segments },
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** Standard-only compatibility map for Vite callers that do not consume Mun anchors. */
|
|
134
|
+
export function createLegacyMunSourceMap(source, generated, id) {
|
|
135
|
+
const rich = createMunSourceMap(source, generated, id);
|
|
136
|
+
let previousOriginalLine = 0;
|
|
137
|
+
let previousOriginalColumn = 0;
|
|
138
|
+
const mappings = rich.x_mun.lineMappings.map(anchor => {
|
|
139
|
+
const value = `${vlq(0)}${vlq(0)}${vlq(anchor.line - previousOriginalLine)}${vlq(anchor.column - previousOriginalColumn)}`;
|
|
140
|
+
previousOriginalLine = anchor.line;
|
|
141
|
+
previousOriginalColumn = anchor.column;
|
|
142
|
+
return value;
|
|
143
|
+
}).join(';');
|
|
144
|
+
const { x_mun: _xMun, ...standard } = rich;
|
|
145
|
+
return { ...standard, mappings };
|
|
146
|
+
}
|
|
147
|
+
/** Map a generated TypeScript position back to its original Mun position. */
|
|
148
|
+
export function mapGeneratedPosition(map, position) {
|
|
149
|
+
const line = Math.max(1, Math.trunc(position.line));
|
|
150
|
+
const column = Math.max(1, Math.trunc(position.column));
|
|
151
|
+
const anchors = map.x_mun.segments[Math.min(line - 1, Math.max(0, map.x_mun.segments.length - 1))]
|
|
152
|
+
?? map.x_mun.lineMappings;
|
|
153
|
+
const generatedColumn = column - 1;
|
|
154
|
+
const anchor = [...anchors].reverse().find(value => value.generatedColumn <= generatedColumn)
|
|
155
|
+
?? anchors[0]
|
|
156
|
+
?? { line: 0, column: 0, generatedColumn: 0 };
|
|
157
|
+
return {
|
|
158
|
+
line: anchor.line + 1,
|
|
159
|
+
column: anchor.column + Math.max(0, generatedColumn - anchor.generatedColumn) + 1,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** Map an original Mun position to the nearest generated position. */
|
|
163
|
+
export function mapOriginalPosition(map, position) {
|
|
164
|
+
const line = Math.max(1, Math.trunc(position.line)) - 1;
|
|
165
|
+
const column = Math.max(1, Math.trunc(position.column)) - 1;
|
|
166
|
+
const segments = map.x_mun.segments;
|
|
167
|
+
if (segments.length === 0)
|
|
168
|
+
return { line: 1, column: 1 };
|
|
169
|
+
let bestLine = 0;
|
|
170
|
+
let bestAnchor = map.x_mun.lineMappings[0];
|
|
171
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
172
|
+
for (let lineIndex = 0; lineIndex < segments.length; lineIndex += 1) {
|
|
173
|
+
for (const candidate of segments[lineIndex]) {
|
|
174
|
+
const distance = Math.abs(candidate.line - line) * 10000 + Math.abs(candidate.column - column);
|
|
175
|
+
if (distance >= bestDistance)
|
|
176
|
+
continue;
|
|
177
|
+
bestDistance = distance;
|
|
178
|
+
bestLine = lineIndex;
|
|
179
|
+
bestAnchor = candidate;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const anchor = bestAnchor ?? { line: 0, column: 0, generatedColumn: 0 };
|
|
183
|
+
return {
|
|
184
|
+
line: bestLine + 1,
|
|
185
|
+
column: Math.max(1, anchor.generatedColumn + column - anchor.column + 1),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=source-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-map.js","sourceRoot":"","sources":["../../../src/legacy/compiler/source-map.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG,kEAAkE,CAAA;AAEnF,SAAS,GAAG,CAAC,KAAa;IACxB,IAAI,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAA;IAC1D,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,GAAG,CAAC;QACF,IAAI,KAAK,GAAG,OAAO,GAAG,EAAE,CAAA;QACxB,OAAO,MAAM,CAAC,CAAA;QACd,IAAI,OAAO,GAAG,CAAC;YAAE,KAAK,IAAI,EAAE,CAAA;QAC5B,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC,QAAQ,OAAO,GAAG,CAAC,EAAC;IACrB,OAAO,MAAM,CAAA;AACf,CAAC;AA2BD,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACnE,KAAK,EAAE,KAAK,CAAC,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's small struct/View surface.
|
|
3
|
+
*
|
|
4
|
+
* It intentionally handles the declarative subset rather than pretending that
|
|
5
|
+
* a JavaScript parser can understand Swift syntax. For example:
|
|
6
|
+
*
|
|
7
|
+
* struct Card<Content: View>: View {
|
|
8
|
+
* let content: Content
|
|
9
|
+
* init(@ViewBuilder content: () => Content) { self.content = content() }
|
|
10
|
+
* var body: some View { VStack() { content } }
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* becomes a normal `defineView` declaration. TypeScript/JS remains the host
|
|
14
|
+
* language for expressions inside the initializer and body.
|
|
15
|
+
*/
|
|
16
|
+
/** Transform `struct Name: View { ... }` declarations into defineView calls. */
|
|
17
|
+
export declare function transformMunStructSyntax(source: string): string;
|
|
18
|
+
//# sourceMappingURL=struct-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"struct-transform.d.ts","sourceRoot":"","sources":["../../../src/legacy/compiler/struct-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgNH,gFAAgF;AAChF,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA4B/D"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level transform for Mun's small struct/View surface.
|
|
3
|
+
*
|
|
4
|
+
* It intentionally handles the declarative subset rather than pretending that
|
|
5
|
+
* a JavaScript parser can understand Swift syntax. For example:
|
|
6
|
+
*
|
|
7
|
+
* struct Card<Content: View>: View {
|
|
8
|
+
* let content: Content
|
|
9
|
+
* init(@ViewBuilder content: () => Content) { self.content = content() }
|
|
10
|
+
* var body: some View { VStack() { content } }
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* becomes a normal `defineView` declaration. TypeScript/JS remains the host
|
|
14
|
+
* language for expressions inside the initializer and body.
|
|
15
|
+
*/
|
|
16
|
+
import { transformMunBuilderSyntax } from './builder-transform.js';
|
|
17
|
+
import { parseMunStructs } from './ast.js';
|
|
18
|
+
import { munSyntaxError } from './errors.js';
|
|
19
|
+
function skipQuoted(source, index, quote) {
|
|
20
|
+
for (let i = index + 1; i < source.length; i += 1) {
|
|
21
|
+
if (source[i] === '\\') {
|
|
22
|
+
i += 1;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (source[i] === quote)
|
|
26
|
+
return i + 1;
|
|
27
|
+
}
|
|
28
|
+
throw munSyntaxError(`Unclosed ${quote} string in Mun struct source`, index);
|
|
29
|
+
}
|
|
30
|
+
function skipTemplate(source, index) {
|
|
31
|
+
for (let i = index + 1; i < source.length; i += 1) {
|
|
32
|
+
if (source[i] === '\\') {
|
|
33
|
+
i += 1;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (source[i] === '`')
|
|
37
|
+
return i + 1;
|
|
38
|
+
}
|
|
39
|
+
throw munSyntaxError('Unclosed template literal in Mun struct source', index);
|
|
40
|
+
}
|
|
41
|
+
function splitArguments(source) {
|
|
42
|
+
const values = [];
|
|
43
|
+
let start = 0;
|
|
44
|
+
let parens = 0;
|
|
45
|
+
let braces = 0;
|
|
46
|
+
for (let i = 0; i < source.length; i += 1) {
|
|
47
|
+
const char = source[i];
|
|
48
|
+
if (char === "'" || char === '"') {
|
|
49
|
+
i = skipQuoted(source, i, char) - 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (char === '`') {
|
|
53
|
+
i = skipTemplate(source, i) - 1;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (char === '(')
|
|
57
|
+
parens += 1;
|
|
58
|
+
else if (char === ')')
|
|
59
|
+
parens -= 1;
|
|
60
|
+
else if (char === '{')
|
|
61
|
+
braces += 1;
|
|
62
|
+
else if (char === '}')
|
|
63
|
+
braces -= 1;
|
|
64
|
+
else if (char === ',' && parens === 0 && braces === 0) {
|
|
65
|
+
values.push(source.slice(start, i).trim());
|
|
66
|
+
start = i + 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const last = source.slice(start).trim();
|
|
70
|
+
if (last)
|
|
71
|
+
values.push(last);
|
|
72
|
+
return values;
|
|
73
|
+
}
|
|
74
|
+
function parseParameter(source, offset = 0) {
|
|
75
|
+
const kind = source.includes('@ViewBuilder') ? 'viewBuilder' : source.includes('@Action') ? 'action' : 'value';
|
|
76
|
+
const withoutAnnotation = source.replace(/@(?:ViewBuilder|Action)\s*/g, '').trim();
|
|
77
|
+
let defaultIndex = -1;
|
|
78
|
+
for (let index = 0; index < withoutAnnotation.length; index += 1) {
|
|
79
|
+
if (withoutAnnotation[index] !== '=' || withoutAnnotation[index + 1] === '>' || withoutAnnotation[index - 1] === '=' || withoutAnnotation[index - 1] === '<' || withoutAnnotation[index - 1] === '!')
|
|
80
|
+
continue;
|
|
81
|
+
defaultIndex = index;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
const declaration = defaultIndex < 0 ? withoutAnnotation : withoutAnnotation.slice(0, defaultIndex).trim();
|
|
85
|
+
const colon = declaration.indexOf(':');
|
|
86
|
+
const head = (colon < 0 ? declaration : declaration.slice(0, colon)).trim();
|
|
87
|
+
const names = head.split(/\s+/).filter(Boolean);
|
|
88
|
+
const name = names[names.length - 1]?.replace(/^_+/, '');
|
|
89
|
+
if (!name)
|
|
90
|
+
throw munSyntaxError(`Invalid initializer parameter: ${source}`, offset);
|
|
91
|
+
const type = colon < 0 ? undefined : declaration.slice(colon + 1).trim();
|
|
92
|
+
const defaultValue = defaultIndex < 0 ? undefined : withoutAnnotation.slice(defaultIndex + 1).trim();
|
|
93
|
+
return { name, kind, label: names[0] === '_' ? undefined : names[0], type, required: defaultIndex < 0, defaultValue };
|
|
94
|
+
}
|
|
95
|
+
function parameterMetadata(parameters) {
|
|
96
|
+
return `[${parameters.map(parameter => `{ kind: '${parameter.kind}', label: ${parameter.label ? `'${parameter.label}'` : 'undefined'}, type: ${parameter.type ? JSON.stringify(parameter.type) : 'undefined'}, required: ${parameter.required}${parameter.defaultValue ? `, defaultValue: ${JSON.stringify(parameter.defaultValue)}` : ''} }`).join(', ')}]`;
|
|
97
|
+
}
|
|
98
|
+
function initializerAccepts(parameters) {
|
|
99
|
+
const checks = parameters.map((parameter, index) => {
|
|
100
|
+
if (parameter.kind === 'viewBuilder' || parameter.kind === 'action') {
|
|
101
|
+
return parameter.required
|
|
102
|
+
? `typeof args[${index}] === 'function'`
|
|
103
|
+
: `(args[${index}] === undefined || typeof args[${index}] === 'function')`;
|
|
104
|
+
}
|
|
105
|
+
return 'true';
|
|
106
|
+
});
|
|
107
|
+
const required = parameters.filter(parameter => parameter.required).length;
|
|
108
|
+
return `args.length >= ${required} && args.length <= ${parameters.length}${checks.length ? ` && ${checks.join(' && ')}` : ''}`;
|
|
109
|
+
}
|
|
110
|
+
function buildBody(parameters, fields, assignments, stateFields, defaults = new Map()) {
|
|
111
|
+
const locals = parameters.map((parameter, index) => {
|
|
112
|
+
const expression = parameter.defaultValue
|
|
113
|
+
? `(args[${index}] === undefined ? (${parameter.defaultValue}) : args[${index}])`
|
|
114
|
+
: `args[${index}]`;
|
|
115
|
+
return `const ${parameter.name} = ${expression} as any`;
|
|
116
|
+
}).join('; ');
|
|
117
|
+
const values = fields.filter(field => !stateFields.has(field)).map(field => {
|
|
118
|
+
const assignment = assignments.get(field);
|
|
119
|
+
if (assignment) {
|
|
120
|
+
const parameter = parameters.find(item => item.name === assignment.replace(/\(\)$/, '').trim());
|
|
121
|
+
if (parameter?.kind === 'viewBuilder' && assignment === `${parameter.name}()`) {
|
|
122
|
+
return `${field}: resolveBuilderClosure(${parameter.name})`;
|
|
123
|
+
}
|
|
124
|
+
return `${field}: ${assignment}`;
|
|
125
|
+
}
|
|
126
|
+
const parameter = parameters.find(item => item.name === field);
|
|
127
|
+
if (parameter?.kind === 'viewBuilder')
|
|
128
|
+
return `${field}: resolveBuilderClosure(${field})`;
|
|
129
|
+
if (parameter)
|
|
130
|
+
return `${field}: ${field}`;
|
|
131
|
+
const defaultValue = defaults.get(field);
|
|
132
|
+
return `${field}: ${defaultValue ?? 'undefined'}`;
|
|
133
|
+
});
|
|
134
|
+
return `args => { ${locals}; return { ${values.join(', ')} } }`;
|
|
135
|
+
}
|
|
136
|
+
function findAssignments(initBody) {
|
|
137
|
+
const assignments = new Map();
|
|
138
|
+
const expression = /self\.([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*([\s\S]*?)(?=;|\n|$)/g;
|
|
139
|
+
for (const match of initBody.matchAll(expression))
|
|
140
|
+
assignments.set(match[1], match[2].trim());
|
|
141
|
+
return assignments;
|
|
142
|
+
}
|
|
143
|
+
function previousSignificant(source, index) {
|
|
144
|
+
for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
|
|
145
|
+
if (!/\s/.test(source[cursor]))
|
|
146
|
+
return source[cursor];
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
function bindingShorthandContext(source, index) {
|
|
151
|
+
const previous = previousSignificant(source, index);
|
|
152
|
+
if (previous !== undefined && '([{=,:;?'.includes(previous))
|
|
153
|
+
return true;
|
|
154
|
+
const prefix = source.slice(0, index).match(/([A-Za-z_$][A-Za-z0-9_$]*)\s*$/)?.[1];
|
|
155
|
+
return prefix === 'return' || prefix === 'yield' || prefix === 'case';
|
|
156
|
+
}
|
|
157
|
+
function lowerBindingShorthand(source) {
|
|
158
|
+
const nonBindingDollarNames = new Set([
|
|
159
|
+
'attrs', 'data', 'emit', 'el', 'forceUpdate', 'nextTick', 'options', 'parent', 'props', 'refs', 'root', 'slots', 'watch',
|
|
160
|
+
]);
|
|
161
|
+
let output = '';
|
|
162
|
+
for (let index = 0; index < source.length;) {
|
|
163
|
+
const char = source[index];
|
|
164
|
+
if (char === "'" || char === '"') {
|
|
165
|
+
const end = skipQuoted(source, index, char);
|
|
166
|
+
output += source.slice(index, end);
|
|
167
|
+
index = end;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (char === '`') {
|
|
171
|
+
const end = skipTemplate(source, index);
|
|
172
|
+
output += source.slice(index, end);
|
|
173
|
+
index = end;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (char === '$' && bindingShorthandContext(source, index)) {
|
|
177
|
+
const match = /^\$([A-Za-z_$][A-Za-z0-9_$]*)/.exec(source.slice(index));
|
|
178
|
+
if (match && !nonBindingDollarNames.has(match[1])) {
|
|
179
|
+
output += `Binding(${match[1]})`;
|
|
180
|
+
index += match[0].length;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
output += char;
|
|
185
|
+
index += 1;
|
|
186
|
+
}
|
|
187
|
+
return output;
|
|
188
|
+
}
|
|
189
|
+
function transformOne(declaration) {
|
|
190
|
+
const { name, bodyExpressionSource: bodyExpression } = declaration;
|
|
191
|
+
const fields = declaration.fields.map(field => field.name);
|
|
192
|
+
const stateValues = new Map(declaration.fields
|
|
193
|
+
.filter(field => field.kind === 'state')
|
|
194
|
+
.map(field => [field.name, field.initializer?.trim() ?? 'undefined']));
|
|
195
|
+
const stateFields = new Set(stateValues.keys());
|
|
196
|
+
const defaults = new Map(declaration.fields.map(field => [field.name, field.initializer]));
|
|
197
|
+
const initializers = [];
|
|
198
|
+
for (const syntax of declaration.initializers) {
|
|
199
|
+
const parameters = splitArguments(syntax.parametersSource).map(parameter => parseParameter(parameter, syntax.parametersRange.start));
|
|
200
|
+
const initializerBody = syntax.bodySource;
|
|
201
|
+
const assignments = findAssignments(initializerBody);
|
|
202
|
+
const signature = `${name}(${parameters.map(parameter => `${parameter.kind === 'viewBuilder' ? '@ViewBuilder ' : parameter.kind === 'action' ? '@Action ' : ''}${parameter.label ?? parameter.name}`).join(', ')})`;
|
|
203
|
+
initializers.push(`initializer(${JSON.stringify(signature)}, args => ${initializerAccepts(parameters)}, ${buildBody(parameters, fields, assignments, stateFields, defaults)}, ${parameterMetadata(parameters)})`);
|
|
204
|
+
}
|
|
205
|
+
if (initializers.length === 0) {
|
|
206
|
+
const parameters = fields.filter(field => !stateFields.has(field)).map(field => ({ name: field, kind: 'value', label: field, required: true }));
|
|
207
|
+
initializers.push(`initializer(${JSON.stringify(`${name}(${parameters.map(parameter => parameter.name).join(', ')})`)}, args => args.length === ${parameters.length}, ${buildBody(parameters, fields, new Map(), stateFields, defaults)}, ${parameterMetadata(parameters)})`);
|
|
208
|
+
}
|
|
209
|
+
const destructure = fields.length > 0 ? `const { ${fields.join(', ')} } = props; ` : '';
|
|
210
|
+
const sourceBody = bodyExpression.trim();
|
|
211
|
+
const result = /^return\b([\s\S]*)/.exec(sourceBody);
|
|
212
|
+
const bodyCode = lowerBindingShorthand(result ? result[1].replace(/;\s*$/, '') : sourceBody);
|
|
213
|
+
const state = stateValues.size > 0
|
|
214
|
+
? `, state: (_props: any) => ({ ${[...stateValues.entries()].map(([field, value]) => `${field}: State(${value})`).join(', ')} })`
|
|
215
|
+
: '';
|
|
216
|
+
return `defineView(${JSON.stringify(name)}, { name: ${JSON.stringify(name)}, initializers: [${initializers.join(', ')}]${state}, body: (props: any) => { ${destructure} return ${bodyCode}; } })`;
|
|
217
|
+
}
|
|
218
|
+
/** Transform `struct Name: View { ... }` declarations into defineView calls. */
|
|
219
|
+
export function transformMunStructSyntax(source) {
|
|
220
|
+
const declarations = parseMunStructs(source);
|
|
221
|
+
if (declarations.length === 0)
|
|
222
|
+
return source;
|
|
223
|
+
let output = '';
|
|
224
|
+
let cursor = 0;
|
|
225
|
+
for (const declaration of declarations) {
|
|
226
|
+
const transformedBody = transformOne({
|
|
227
|
+
...declaration,
|
|
228
|
+
bodyExpressionSource: transformMunBuilderSyntax(declaration.bodyExpressionSource),
|
|
229
|
+
});
|
|
230
|
+
let prefix = source.slice(cursor, declaration.range.start);
|
|
231
|
+
const exported = /export\s*$/.test(prefix);
|
|
232
|
+
if (exported)
|
|
233
|
+
prefix = prefix.replace(/export\s*$/, '') + 'export ';
|
|
234
|
+
output += prefix + `const ${declaration.name} = ${transformedBody}`;
|
|
235
|
+
cursor = declaration.range.end;
|
|
236
|
+
}
|
|
237
|
+
output += source.slice(cursor);
|
|
238
|
+
const runtimeImports = stateValuesInSource(output)
|
|
239
|
+
? (output.includes('Binding(')
|
|
240
|
+
? 'Binding, State, defineView, initializer, resolveBuilderClosure'
|
|
241
|
+
: 'State, defineView, initializer, resolveBuilderClosure')
|
|
242
|
+
: (output.includes('Binding(')
|
|
243
|
+
? 'Binding, defineView, initializer, resolveBuilderClosure'
|
|
244
|
+
: 'defineView, initializer, resolveBuilderClosure');
|
|
245
|
+
const names = runtimeImports.split(',').map(name => name.trim()).filter(Boolean);
|
|
246
|
+
if (output.includes('namedArguments(') && !names.includes('namedArguments'))
|
|
247
|
+
names.push('namedArguments');
|
|
248
|
+
if (output.includes('overloadClosure(') && !names.includes('overloadClosure'))
|
|
249
|
+
names.push('overloadClosure');
|
|
250
|
+
return injectRuntimeImports(output, names.join(', '));
|
|
251
|
+
}
|
|
252
|
+
function stateValuesInSource(source) {
|
|
253
|
+
return /\bstate:\s*\(/.test(source);
|
|
254
|
+
}
|
|
255
|
+
function injectRuntimeImports(source, names) {
|
|
256
|
+
const required = names.split(',').map(name => name.trim()).filter(Boolean);
|
|
257
|
+
const existing = /import\s*\{([\s\S]*?)\}\s*from\s*(['"])@mun-ui\/ui\/legacy\2[\t ]*;?/.exec(source);
|
|
258
|
+
if (!existing)
|
|
259
|
+
return `import { ${required.join(', ')} } from '@mun-ui/ui/legacy'\n${source}`;
|
|
260
|
+
const imported = existing[1].split(',').map(name => name.trim()).filter(Boolean);
|
|
261
|
+
const merged = [...imported];
|
|
262
|
+
for (const name of required)
|
|
263
|
+
if (!merged.includes(name))
|
|
264
|
+
merged.push(name);
|
|
265
|
+
const replacement = `import { ${merged.join(', ')} } from '@mun-ui/ui/legacy'`;
|
|
266
|
+
return source.slice(0, existing.index) + replacement + source.slice(existing.index + existing[0].length);
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=struct-transform.js.map
|