svelte-origin 0.0.0 → 1.0.0-next.49

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.
Files changed (49) hide show
  1. package/LLM.md +545 -0
  2. package/README.md +678 -1
  3. package/dist/aliases.d.ts +45 -0
  4. package/dist/cli.d.ts +20 -0
  5. package/dist/cli.js +163 -0
  6. package/dist/generate-dts.d.ts +31 -0
  7. package/dist/globals.d.ts +649 -0
  8. package/dist/index.d.ts +9 -0
  9. package/dist/index.js +108 -0
  10. package/dist/plugin.d.ts +176 -0
  11. package/dist/plugin.js +81 -0
  12. package/dist/post-process.d.ts +31 -0
  13. package/dist/post-process.js +99 -0
  14. package/dist/preprocess.d.ts +119 -0
  15. package/dist/preprocess.js +81 -0
  16. package/dist/runtime/attrs.d.ts +65 -0
  17. package/dist/runtime/index.d.ts +8 -0
  18. package/dist/runtime/index.js +28 -0
  19. package/dist/runtime/origin.d.ts +170 -0
  20. package/dist/runtime/types.d.ts +193 -0
  21. package/dist/runtime-inline.d.ts +117 -0
  22. package/dist/runtime-inline.min.js +1 -0
  23. package/dist/schema-resolver.d.ts +61 -0
  24. package/dist/shared-state.d.ts +47 -0
  25. package/dist/transform/ast-parser.d.ts +282 -0
  26. package/dist/transform/attrs-for-transform.d.ts +17 -0
  27. package/dist/transform/attrs-origin-transform.d.ts +38 -0
  28. package/dist/transform/attrs-schema.d.ts +63 -0
  29. package/dist/transform/codegen.d.ts +15 -0
  30. package/dist/transform/comments.d.ts +31 -0
  31. package/dist/transform/core.d.ts +37 -0
  32. package/dist/transform/declaration-parser.d.ts +77 -0
  33. package/dist/transform/element-types.d.ts +10 -0
  34. package/dist/transform/expression-utils.d.ts +59 -0
  35. package/dist/transform/origin-body-helpers.d.ts +143 -0
  36. package/dist/transform/origin-create-transform.d.ts +32 -0
  37. package/dist/transform/origin-destructure-transform.d.ts +62 -0
  38. package/dist/transform/origin-transform.d.ts +51 -0
  39. package/dist/transform/patterns.d.ts +86 -0
  40. package/dist/transform/reserved-keywords.d.ts +87 -0
  41. package/dist/transform/schema-codegen.d.ts +105 -0
  42. package/dist/transform/schema-parse.d.ts +50 -0
  43. package/dist/transform/schema-types.d.ts +40 -0
  44. package/dist/transform/schema.d.ts +11 -0
  45. package/dist/transform/standalone-attrs-transform.d.ts +36 -0
  46. package/dist/utils.d.ts +21 -0
  47. package/dist/vite-dts.d.ts +17 -0
  48. package/dist/vite-dts.js +24 -0
  49. package/package.json +79 -3
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Helper functions for transforming $origin({...}) body content.
3
+ *
4
+ * These are extracted from the main transformOriginBody to improve
5
+ * testability and maintainability. Each function has a clear,
6
+ * focused responsibility.
7
+ */
8
+ import type { AttrDetail, ObjectMember } from './attrs-schema';
9
+ /**
10
+ * Parsed $origin.create() call information.
11
+ */
12
+ export interface ParsedOriginCreateCall {
13
+ callStart: number;
14
+ callEnd: number;
15
+ factoryExpr: string;
16
+ propsExpr: string | null;
17
+ }
18
+ /**
19
+ * Find and parse all $origin.create() calls in code.
20
+ * Returns positions and parsed arguments for each call.
21
+ *
22
+ * Used by both string-based transformation (inside origin definitions)
23
+ * and MagicString-based transformation (top-level source code).
24
+ */
25
+ export declare function findOriginCreateCalls(code: string): ParsedOriginCreateCall[];
26
+ /**
27
+ * Transform $origin.bind(expr) markers into __bindable() calls.
28
+ *
29
+ * - `$origin.bind(myVar)` → `__bindable(() => myVar, (v) => { myVar = v })`
30
+ * - `$origin.bind(obj.prop)` → `__bindable(() => obj.prop, (v) => { obj.prop = v })`
31
+ *
32
+ * Returns transformed code and whether any bind markers were found.
33
+ */
34
+ export declare function transformOriginBindMarkers(propsExpr: string): {
35
+ code: string;
36
+ hasBindable: boolean;
37
+ };
38
+ /**
39
+ * Generate replacement code for an $origin.create() call.
40
+ *
41
+ * - `$origin.create(Factory)` → `Factory({})`
42
+ * - `$origin.create(Factory, props)` → `__createOriginInstance(Factory, transformedProps)`
43
+ *
44
+ * Also transforms $origin.bind() markers inside props to __bindable() calls.
45
+ */
46
+ export declare function generateOriginCreateReplacement(factoryExpr: string, propsExpr: string | null): {
47
+ replacement: string;
48
+ needsHelper: boolean;
49
+ needsBindable: boolean;
50
+ };
51
+ /**
52
+ * Transform inline $origin.create() calls within a code string.
53
+ * Used for transforming content inside $origin({...}) definitions.
54
+ *
55
+ * Returns the transformed code, whether __createOriginInstance is needed,
56
+ * and whether __bindable is needed for $origin.bind() markers.
57
+ */
58
+ export declare function transformInlineOriginCreate(code: string): {
59
+ result: string;
60
+ needsHelper: boolean;
61
+ needsBindable: boolean;
62
+ };
63
+ /**
64
+ * Metadata collected from first-pass analysis of origin members
65
+ */
66
+ export interface MemberMetadata {
67
+ /** Getters containing $derived - will be hoisted to __name variables */
68
+ derivedNames: Set<string>;
69
+ /** $state(...) properties - will be hoisted to local variables */
70
+ stateNames: Set<string>;
71
+ /** Regular value properties (non-$state, non-getter, non-method) */
72
+ valueNames: Set<string>;
73
+ /** Methods - need to keep this.method() for these */
74
+ methodNames: Set<string>;
75
+ /** All getters (including non-$derived) */
76
+ getterNames: Set<string>;
77
+ /** Getters that only return this.super.X */
78
+ superDelegatingGetters: Set<string>;
79
+ /** Methods that only return this.super.X() */
80
+ superDelegatingMethods: Set<string>;
81
+ }
82
+ /**
83
+ * Context for code transformation
84
+ */
85
+ export interface TransformContext {
86
+ /** Whether the origin has parent(s) for inheritance */
87
+ hasParents: boolean;
88
+ /** The property name used for attrs (e.g., 'props', 'attrs') */
89
+ propName: string;
90
+ /** Member metadata collected from first pass */
91
+ metadata: MemberMetadata;
92
+ }
93
+ /**
94
+ * Analyze object members and collect metadata about their types.
95
+ * This first pass determines which members need hoisting, transformation, etc.
96
+ */
97
+ export declare function collectMemberMetadata(members: ObjectMember[], hasParents: boolean): MemberMetadata;
98
+ /**
99
+ * Transform code that runs BEFORE object creation (hoisted code).
100
+ * e.g., $derived expressions, $state initializers
101
+ *
102
+ * CRITICAL: In hoisted code, `this` does NOT exist. All member access must be:
103
+ * - Local variables (__props, __name, name) for locally defined members
104
+ * - __super.member for inherited members from parents
105
+ */
106
+ export declare function transformForHoistedCode(code: string, ctx: TransformContext): string;
107
+ /**
108
+ * Transform code that runs AFTER object creation (methods, getters).
109
+ *
110
+ * CRITICAL: We use `__self` instead of `this` because Svelte's reactivity
111
+ * may call getters/methods without proper `this` binding.
112
+ */
113
+ export declare function transformForMemberCode(code: string, ctx: TransformContext): string;
114
+ /**
115
+ * Generate the __props wrapper code that provides defaults for attrs.
116
+ *
117
+ * The setter checks if __inputAttrs has a setter before writing.
118
+ * This ensures getter-only props (from $origin.create without $origin.bind)
119
+ * cannot be modified by the origin - enforcing one-directional data flow.
120
+ */
121
+ export declare function generatePropsWrapper(attrDetails: AttrDetail[]): string;
122
+ /**
123
+ * Process a $state field and generate its declaration.
124
+ * Returns null if not a valid $state field.
125
+ */
126
+ export declare function processStateField(key: string, value: string): {
127
+ declaration: string;
128
+ getter: string;
129
+ setter: string;
130
+ } | null;
131
+ /**
132
+ * Process a getter with $derived and generate its declaration.
133
+ * Returns null if not a $derived getter.
134
+ */
135
+ export declare function processDerivedGetter(key: string, value: string, ctx: TransformContext): {
136
+ declaration: string;
137
+ getter: string;
138
+ } | null;
139
+ /**
140
+ * Normalize indentation of a code block to a target base level.
141
+ * Removes existing indentation and applies new consistent indentation.
142
+ */
143
+ export declare function normalizeIndentation(code: string, targetIndent: string): string;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * $origin.create() transformation logic.
3
+ *
4
+ * This module handles transforming $origin.create(Factory, props?) calls
5
+ * into proper reactive origin instantiation.
6
+ *
7
+ * Unlike $origin.component() which binds to $props(), $origin.create() is used
8
+ * outside of component context and wraps props in $state() for reactivity.
9
+ */
10
+ import type MagicString from 'magic-string';
11
+ /**
12
+ * Transform $origin.create() calls in source code.
13
+ *
14
+ * This creates reactive origin instances outside of component context.
15
+ * Props are wrapped in $state() to maintain reactivity.
16
+ */
17
+ export declare function transformOriginCreateCalls(s: MagicString, source: string, neededImports: Set<string>): boolean;
18
+ /**
19
+ * Transform inline $origin.create() calls that are NOT variable declarations.
20
+ *
21
+ * These are calls like:
22
+ * - `childCounter: $origin.create(SimpleCounter)`
23
+ * - `this.childCounter = $origin.create(SimpleCounter)`
24
+ *
25
+ * Since we can't expand to multiple lines in these contexts, we transform:
26
+ * - `$origin.create(Factory)` → `Factory({})`
27
+ * - `$origin.create(Factory, { ... })` → `__createOriginInstance(Factory, { ... })`
28
+ * - `$origin.bind(expr)` inside props → `__bindable(() => expr, (v) => { expr = v })`
29
+ *
30
+ * Uses shared parsing logic from origin-body-helpers.ts.
31
+ */
32
+ export declare function transformInlineOriginCreateCalls(s: MagicString, source: string, neededImports: Set<string>): boolean;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Origin destructuring transformation logic.
3
+ *
4
+ * Handles patterns like:
5
+ * - `let { increment } = counter` - destructure methods with this-binding
6
+ * - `let { value } = counter.props` - destructure props directly
7
+ * - `let { props: { value } } = counter` - nested props destructuring
8
+ * - `let { value = $bindable(0) } = counter.props` - override with bindable
9
+ *
10
+ * Methods are bound to preserve `this` context.
11
+ * Props are converted to reactive $derived values.
12
+ */
13
+ import type MagicString from 'magic-string';
14
+ import type { TrackedOriginInstance } from './attrs-origin-transform';
15
+ /**
16
+ * Parsed destructuring pattern from origin
17
+ */
18
+ export interface OriginDestructure {
19
+ /** Full match start position */
20
+ startPos: number;
21
+ /** Full match end position */
22
+ endPos: number;
23
+ /** The source variable being destructured from */
24
+ sourceVar: string;
25
+ /** Whether destructuring from .props (e.g., counter.props) */
26
+ isPropsAccess: boolean;
27
+ /** Destructured method names (need this binding) */
28
+ methods: DestructuredItem[];
29
+ /** Destructured props (need reactive access) */
30
+ props: DestructuredProp[];
31
+ /** Props pattern within nested `props: { ... }` */
32
+ nestedPropsPattern: NestedPropsPattern | null;
33
+ }
34
+ export interface DestructuredItem {
35
+ /** Original key in the origin */
36
+ key: string;
37
+ /** Alias if renamed (e.g., `increment: inc`) */
38
+ alias: string | null;
39
+ /** Default value if provided */
40
+ defaultValue: string | null;
41
+ }
42
+ export interface DestructuredProp extends DestructuredItem {
43
+ /** Whether $bindable() was used in the default */
44
+ isBindable: boolean;
45
+ /** The value inside $bindable() if bindable */
46
+ bindableDefault: string | null;
47
+ }
48
+ export interface NestedPropsPattern {
49
+ /** Start of the `props: { ... }` pattern */
50
+ startPos: number;
51
+ /** End of the `props: { ... }` pattern */
52
+ endPos: number;
53
+ /** Props within the nested pattern */
54
+ props: DestructuredProp[];
55
+ }
56
+ /**
57
+ * Transform origin destructuring patterns in the source.
58
+ *
59
+ * Tracks origin instances created via $origin.component() or direct factory calls,
60
+ * then transforms destructuring patterns that reference them.
61
+ */
62
+ export declare function transformOriginDestructuring(s: MagicString, source: string, originInstances: Map<string, TrackedOriginInstance>): boolean;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * $origin() transformation logic.
3
+ *
4
+ * This module handles transforming $origin({...}) macro calls into
5
+ * __createOrigin({...}) runtime calls with proper code generation.
6
+ */
7
+ import type MagicString from 'magic-string';
8
+ /**
9
+ * Result of transforming the origin body
10
+ */
11
+ export interface TransformOriginBodyResult {
12
+ body: string;
13
+ attachments: string[];
14
+ }
15
+ /**
16
+ * Transform $origin({...}) macro calls.
17
+ *
18
+ * Input:
19
+ * ```ts
20
+ * export const Counter = $origin({
21
+ * props: $origin.props({
22
+ * label: 'Counter',
23
+ * count: $bindable(0)
24
+ * }),
25
+ * _internal: $state(0),
26
+ * get double() { return $derived(this.attrs.count * 2) },
27
+ * increment() { this.attrs.count++ }
28
+ * })
29
+ * ```
30
+ *
31
+ * Output:
32
+ * ```ts
33
+ * export const Counter = __createOrigin({
34
+ * __attrSchema: {
35
+ * label: { default: "Counter", bindable: false, hasDefault: true },
36
+ * count: { default: 0, bindable: true, hasDefault: true }
37
+ * },
38
+ * __create: (attrs) => {
39
+ * let _internal = $state(0)
40
+ * return {
41
+ * get attrs() { return attrs },
42
+ * get _internal() { return _internal },
43
+ * set _internal(v) { _internal = v },
44
+ * get double() { return $derived(attrs.count * 2) },
45
+ * increment() { attrs.count++ }
46
+ * }
47
+ * }
48
+ * })
49
+ * ```
50
+ */
51
+ export declare function transformOriginCalls(s: MagicString, source: string, neededImports: Set<string>, svelteImports?: Set<string>): boolean;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Pattern matching utilities for svelte-origin macros
3
+ */
4
+ /**
5
+ * Patterns for detecting macro usage in source code
6
+ */
7
+ export declare const patterns: {
8
+ /** Quick check if file might contain our macros */
9
+ hasMacros: RegExp;
10
+ /** Match $origin(...) call */
11
+ origin: RegExp;
12
+ /** Match $origin([...], {...}) with parents */
13
+ originWithParents: RegExp;
14
+ /** Match $origin.props({...}) inside origin definition */
15
+ originPropsInOrigin: RegExp;
16
+ /** Match standalone $origin.props({...}) or $origin.props([...], {...}) */
17
+ standaloneOriginProps: RegExp;
18
+ /** Match $bindable(...) inside attrs */
19
+ bindableInAttrs: RegExp;
20
+ /** Match $origin.component(X) */
21
+ originComponent: RegExp;
22
+ /** Match $origin.create(X) or $origin.create(X, {...}) */
23
+ originCreate: RegExp;
24
+ /** Match $origin.bind(X) inside $origin.create props */
25
+ originBind: RegExp;
26
+ /** Match $origin.for(X) where X is an identifier (origin factory) */
27
+ originForOrigin: RegExp;
28
+ /** Match $origin.for('x') where x is a string (element name) */
29
+ originForElement: RegExp;
30
+ };
31
+ /**
32
+ * Check if source code contains any svelte-origin macros
33
+ */
34
+ export declare function containsMacros(source: string): boolean;
35
+ /**
36
+ * Find all $origin(...) calls in source
37
+ */
38
+ export declare function findOriginCalls(source: string): RegExpExecArray[];
39
+ /**
40
+ * Find all $origin.component(X) calls in source
41
+ */
42
+ export declare function findOriginComponentCalls(source: string): {
43
+ name: string;
44
+ index: number;
45
+ length: number;
46
+ }[];
47
+ /**
48
+ * Find all $origin.for(X) calls in source where X is an origin factory
49
+ */
50
+ export declare function findOriginForCalls(source: string): {
51
+ name: string;
52
+ index: number;
53
+ length: number;
54
+ }[];
55
+ /**
56
+ * Find all $origin.for('x') calls in source where x is an element name
57
+ */
58
+ export declare function findOriginForElementCalls(source: string): {
59
+ element: string;
60
+ index: number;
61
+ length: number;
62
+ }[];
63
+ /**
64
+ * Check if a position in the source is inside a string literal or comment.
65
+ * This is used to avoid transforming macro-like syntax that appears inside strings/comments.
66
+ */
67
+ export declare function isInsideStringOrComment(source: string, position: number): boolean;
68
+ /**
69
+ * Extract $bindable from a value string, handling nested generics.
70
+ * Returns { isBindable: true, innerValue: '...' } or { isBindable: false }
71
+ */
72
+ export declare function extractBindable(value: string): {
73
+ isBindable: true;
74
+ innerValue: string;
75
+ } | {
76
+ isBindable: false;
77
+ };
78
+ /**
79
+ * Find the position of ' as ' that's not inside nested structures.
80
+ * Properly handles angle brackets for generics.
81
+ */
82
+ export declare function findTopLevelAs(value: string): number;
83
+ /**
84
+ * Find the matching closing bracket for an opening bracket
85
+ */
86
+ export declare function findMatchingBracket(source: string, openIndex: number, openChar?: string, closeChar?: string): number;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Reserved keyword handling for generated code.
3
+ *
4
+ * JavaScript/TypeScript reserved keywords cannot be used as bare identifiers
5
+ * in destructuring patterns. When a prop name is a reserved keyword (like 'class'),
6
+ * we need to use a renamed internal variable.
7
+ *
8
+ * Example:
9
+ * ```ts
10
+ * // This is INVALID:
11
+ * let { class = '' } = $props()
12
+ *
13
+ * // This is VALID:
14
+ * let { class: ___class = '' } = $props()
15
+ * ```
16
+ */
17
+ /**
18
+ * Check if a string is a reserved keyword that needs renaming
19
+ */
20
+ export declare function isReservedKeyword(name: string): boolean;
21
+ /**
22
+ * Get the internal variable name for a prop.
23
+ *
24
+ * For reserved keywords and collision prevention, we prefix with `___`.
25
+ * This ensures the generated code is valid JavaScript.
26
+ *
27
+ * @param propName The original prop name
28
+ * @param forcePrefix If true, always add prefix (for collision prevention)
29
+ * @returns The internal variable name to use
30
+ *
31
+ * @example
32
+ * getInternalVarName('class') // '___class'
33
+ * getInternalVarName('value') // '___value'
34
+ * getInternalVarName('count') // '___count'
35
+ */
36
+ export declare function getInternalVarName(propName: string): string;
37
+ /**
38
+ * Generate the prop destructuring part for a single prop.
39
+ * Handles reserved keywords by using property renaming.
40
+ *
41
+ * @param propName The original prop name
42
+ * @param defaultValue The default value expression (already formatted)
43
+ * @returns The destructuring part for this prop
44
+ *
45
+ * @example
46
+ * // Reserved keyword
47
+ * generatePropDestructure('class', "''")
48
+ * // Returns: "class: ___class = ''"
49
+ *
50
+ * // Normal prop
51
+ * generatePropDestructure('value', '$bindable()')
52
+ * // Returns: "value: ___value = $bindable()"
53
+ */
54
+ export declare function generatePropDestructure(propName: string, defaultValue: string): string;
55
+ /**
56
+ * Generate the prop destructuring part for a prop without a default value.
57
+ *
58
+ * @param propName The original prop name
59
+ * @returns The destructuring part for this prop
60
+ *
61
+ * @example
62
+ * generatePropDestructureNoDefault('class')
63
+ * // Returns: "class: ___class"
64
+ */
65
+ export declare function generatePropDestructureNoDefault(propName: string): string;
66
+ /**
67
+ * Generate a getter for the reactive attrs wrapper.
68
+ *
69
+ * @param propName The original prop name
70
+ * @returns The getter definition
71
+ *
72
+ * @example
73
+ * generateGetter('class')
74
+ * // Returns: "get class() { return ___class }"
75
+ */
76
+ export declare function generateGetter(propName: string): string;
77
+ /**
78
+ * Generate a setter for the reactive attrs wrapper.
79
+ *
80
+ * @param propName The original prop name
81
+ * @returns The setter definition
82
+ *
83
+ * @example
84
+ * generateSetter('class')
85
+ * // Returns: "set class(v) { ___class = v }"
86
+ */
87
+ export declare function generateSetter(propName: string): string;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Schema code generation utilities for svelte-origin
3
+ *
4
+ * This module handles generating code from parsed schemas:
5
+ * - $props() destructuring
6
+ * - Factory call generation
7
+ * - TypeScript type inference
8
+ * - .d.ts file generation
9
+ */
10
+ import type { ParsedAttrInfo, ParsedOriginSchema } from './schema-types';
11
+ /**
12
+ * Options for generating props destructuring.
13
+ */
14
+ export interface GeneratePropsDestructuringOptions {
15
+ /**
16
+ * If true, use `$origin.Props` type helper (new API).
17
+ * If false, use `$origin.Props` type helper (legacy API).
18
+ * Defaults to true (new API).
19
+ */
20
+ useNewApi?: boolean;
21
+ /**
22
+ * If true, uses `$$Props` as the type annotation instead of generating one.
23
+ * This is used when the user has already declared their own `$$Props` type.
24
+ */
25
+ useUserPropsType?: boolean;
26
+ }
27
+ /**
28
+ * Generate $props() destructuring code from parsed attrs
29
+ *
30
+ * Uses `$origin.Props<typeof Factory>` type annotation (new API) or
31
+ * `$origin.Props<typeof Factory>` (legacy API) which is properly connected
32
+ * to the factory type. This approach is required for svelte-check to properly
33
+ * infer component props from the origin factory definition.
34
+ *
35
+ * For generic factory functions that are called (e.g., `TableState<T>()`),
36
+ * uses `$origin.Props<ReturnType<typeof TableState<T>>>` since `typeof` cannot
37
+ * be applied to a function call expression.
38
+ *
39
+ * All props use internal variable names (prefixed with ___) to:
40
+ * 1. Avoid reserved keyword conflicts (e.g., 'class' -> 'class: ___class')
41
+ * 2. Prevent accidental naming collisions with user code
42
+ *
43
+ * @example
44
+ * // Direct origin export (new API - default)
45
+ * generatePropsDestructuring([
46
+ * { key: 'class', defaultValue: "''", bindable: false, hasDefault: true },
47
+ * { key: 'count', defaultValue: '0', bindable: true, hasDefault: true }
48
+ * ], 'Counter')
49
+ * // Returns: "let { class: ___class = '', count: ___count = $bindable(0) }: $origin.Props<typeof Counter> = $props()"
50
+ *
51
+ * @example
52
+ * // Generic factory function
53
+ * generatePropsDestructuring([
54
+ * { key: 'data', defaultValue: '[] as T[]', bindable: true, hasDefault: true }
55
+ * ], 'TableState<User>()')
56
+ * // Returns: "let { data: ___data = $bindable([] as T[]) }: $origin.Props<ReturnType<typeof TableState<User>>> = $props()"
57
+ *
58
+ * @example
59
+ * // Legacy API
60
+ * generatePropsDestructuring([...], 'Counter', { useNewApi: false })
61
+ * // Returns: "let { ... }: $origin.Props<typeof Counter> = $props()"
62
+ */
63
+ export declare function generatePropsDestructuring(attrs: ParsedAttrInfo[], factoryName: string, options?: GeneratePropsDestructuringOptions): string;
64
+ /**
65
+ * Generate factory call code from parsed attrs.
66
+ * For bindable attrs, we create getters AND setters to maintain two-way binding.
67
+ * For non-bindable attrs, we only create getters.
68
+ *
69
+ * Getters/setters reference internal variable names (___key) that were
70
+ * destructured from $props().
71
+ *
72
+ * @example
73
+ * generateFactoryCallFromAttrs('Counter', [
74
+ * { key: 'class', defaultValue: "''", bindable: false, hasDefault: true },
75
+ * { key: 'count', defaultValue: '0', bindable: true, hasDefault: true }
76
+ * ])
77
+ * // Returns: "Counter({ get class() { return ___class }, get count() { return ___count }, set count(v) { ___count = v } })"
78
+ */
79
+ export declare function generateFactoryCallFromAttrs(factoryName: string, attrs: ParsedAttrInfo[]): string;
80
+ /**
81
+ * Generate a TypeScript interface content from a parsed schema.
82
+ * Used for generating .svelte.d.ts declaration files.
83
+ *
84
+ * @param schema The parsed origin schema
85
+ * @returns Object with interfaceContent (the interface body) and bindings (array of bindable prop names)
86
+ */
87
+ export declare function generatePropsInterface(schema: ParsedOriginSchema): {
88
+ interfaceContent: string;
89
+ bindings: string[];
90
+ };
91
+ /**
92
+ * Infer TypeScript type from a default value expression.
93
+ * Used for generating .d.ts files.
94
+ */
95
+ export declare function inferTypeFromDefault(defaultValue: string): string;
96
+ /**
97
+ * Generate the content for a .svelte.d.ts file.
98
+ * Shared between vite-dts.ts and generate-dts.ts.
99
+ *
100
+ * @param factoryName - The name of the origin factory
101
+ * @param importPath - The import path for the factory
102
+ * @param schema - The parsed origin schema
103
+ * @param comment - Optional custom comment for the file header
104
+ */
105
+ export declare function generateDtsContent(factoryName: string, importPath: string, schema: ParsedOriginSchema, comment?: string): string;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Schema parsing utilities for svelte-origin
3
+ *
4
+ * This module handles static extraction of attr schemas from origin source files.
5
+ * Used by the Vite plugin and preprocessor to enable proper $bindable() expansion.
6
+ */
7
+ import type { ParsedOriginSchema } from './schema-types';
8
+ /**
9
+ * Parse an origin's schema from its source code.
10
+ *
11
+ * Looks for patterns like:
12
+ * ```ts
13
+ * export const Counter = $origin({
14
+ * props: $origin.props({
15
+ * label: 'Counter',
16
+ * count: $bindable(0),
17
+ * step: 1 as number
18
+ * }),
19
+ * ...
20
+ * })
21
+ * ```
22
+ *
23
+ * @param source The source code of the origin file
24
+ * @param exportName The name of the exported origin (e.g., 'Counter')
25
+ * @returns Parsed schema or null if not found
26
+ */
27
+ export declare function parseOriginSchemaFromSource(source: string, exportName: string): ParsedOriginSchema | null;
28
+ /**
29
+ * Parse an $origin.props factory's schema from its source code.
30
+ *
31
+ * Looks for patterns like:
32
+ * ```ts
33
+ * export const TextAttrs = $origin.props({ ... })
34
+ * export const TextAttrs = $origin.props([BaseAttrs], { ... })
35
+ * ```
36
+ *
37
+ * Or compiled:
38
+ * ```js
39
+ * export var TextAttrs = __createAttrs({ __attrSchema: {...}, __parents: [...] })
40
+ * ```
41
+ */
42
+ export declare function parseAttrsSchemaFromSource(source: string, exportName: string): ParsedOriginSchema | null;
43
+ /**
44
+ * Extract import path for a given identifier from source
45
+ *
46
+ * @example
47
+ * findImportPath("import { Counter } from './origins/counter.svelte'", 'Counter')
48
+ * // Returns: './origins/counter.svelte'
49
+ */
50
+ export declare function findImportPath(source: string, identifier: string): string | null;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Schema types for svelte-origin
3
+ *
4
+ * Contains shared type definitions used across schema parsing and code generation.
5
+ */
6
+ /**
7
+ * Parsed attr info from source
8
+ */
9
+ export interface ParsedAttrInfo {
10
+ key: string;
11
+ defaultValue: string;
12
+ bindable: boolean;
13
+ hasDefault: boolean;
14
+ }
15
+ /**
16
+ * Parsed origin schema from source
17
+ */
18
+ export interface ParsedOriginSchema {
19
+ attrs: ParsedAttrInfo[];
20
+ parentNames: string[];
21
+ /** Reference to external $origin.props factory (e.g., 'TextAttrs' when props: TextAttrs is used) */
22
+ propsRef?: string;
23
+ }
24
+ /**
25
+ * Schema resolution context for async resolution
26
+ */
27
+ export interface SchemaResolver {
28
+ /**
29
+ * Resolve the schema for an origin factory by its import path.
30
+ *
31
+ * When importPath is null (e.g., import is in module script, not visible
32
+ * to component script), implementations may use alternative resolution
33
+ * strategies such as searching common sibling file patterns.
34
+ *
35
+ * @param importPath The import path (e.g., './origins/counter.svelte') or null if not found
36
+ * @param exportName The name of the exported origin (e.g., 'Counter')
37
+ * @returns Parsed schema or null if not resolvable
38
+ */
39
+ resolve(importPath: string | null, exportName: string): Promise<ParsedOriginSchema | null>;
40
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Schema resolution utilities for svelte-origin
3
+ *
4
+ * This module handles static extraction of attr schemas from origin source files.
5
+ * Used by the Vite plugin and preprocessor to enable proper $bindable() expansion.
6
+ *
7
+ * This is a barrel file that re-exports from the split modules for backwards compatibility.
8
+ */
9
+ export type { ParsedAttrInfo, ParsedOriginSchema, SchemaResolver } from './schema-types';
10
+ export { parseOriginSchemaFromSource, parseAttrsSchemaFromSource, findImportPath } from './schema-parse';
11
+ export { generatePropsDestructuring, generateFactoryCallFromAttrs, generatePropsInterface, generateDtsContent, inferTypeFromDefault } from './schema-codegen';