svelte-origin 0.0.0 → 1.0.0-next.15
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.
Potentially problematic release.
This version of svelte-origin might be problematic. Click here for more details.
- package/LLM.md +754 -0
- package/README.md +412 -1
- package/dist/aliases.d.ts +44 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.js +3440 -0
- package/dist/generate-dts.d.ts +31 -0
- package/dist/globals.d.ts +576 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +6685 -0
- package/dist/plugin.d.ts +143 -0
- package/dist/plugin.js +3467 -0
- package/dist/post-process.d.ts +27 -0
- package/dist/post-process.js +3071 -0
- package/dist/preprocess.d.ts +73 -0
- package/dist/preprocess.js +3360 -0
- package/dist/runtime/attrs.d.ts +52 -0
- package/dist/runtime/index.d.ts +8 -0
- package/dist/runtime/index.js +3665 -0
- package/dist/runtime/origin.d.ts +144 -0
- package/dist/runtime/types.d.ts +173 -0
- package/dist/transform/attrs-for-transform.d.ts +24 -0
- package/dist/transform/attrs-origin-transform.d.ts +62 -0
- package/dist/transform/attrs-schema.d.ts +52 -0
- package/dist/transform/codegen.d.ts +15 -0
- package/dist/transform/core.d.ts +62 -0
- package/dist/transform/declaration-parser.d.ts +77 -0
- package/dist/transform/element-types.d.ts +10 -0
- package/dist/transform/origin-transform.d.ts +51 -0
- package/dist/transform/patterns.d.ts +82 -0
- package/dist/transform/schema.d.ts +116 -0
- package/dist/transform/standalone-attrs-transform.d.ts +36 -0
- package/dist/vite-dts.d.ts +17 -0
- package/dist/vite-dts.js +606 -0
- package/package.json +73 -3
|
@@ -0,0 +1,82 @@
|
|
|
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 $attrs({...}) inside origin definition */
|
|
15
|
+
attrsInOrigin: RegExp;
|
|
16
|
+
/** Match standalone $attrs({...}) or $attrs([...], {...}) */
|
|
17
|
+
standaloneAttrs: RegExp;
|
|
18
|
+
/** Match $bindable(...) inside attrs */
|
|
19
|
+
bindableInAttrs: RegExp;
|
|
20
|
+
/** Match $attrs.origin(X) */
|
|
21
|
+
attrsOrigin: RegExp;
|
|
22
|
+
/** Match $attrs.for(X) where X is an identifier (origin factory) */
|
|
23
|
+
attrsForOrigin: RegExp;
|
|
24
|
+
/** Match $attrs.for('x') where x is a string (element name) */
|
|
25
|
+
attrsForElement: RegExp;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Check if source code contains any svelte-origin macros
|
|
29
|
+
*/
|
|
30
|
+
export declare function containsMacros(source: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Find all $origin(...) calls in source
|
|
33
|
+
*/
|
|
34
|
+
export declare function findOriginCalls(source: string): RegExpExecArray[];
|
|
35
|
+
/**
|
|
36
|
+
* Find all $attrs.origin(X) calls in source
|
|
37
|
+
*/
|
|
38
|
+
export declare function findAttrsOriginCalls(source: string): {
|
|
39
|
+
name: string;
|
|
40
|
+
index: number;
|
|
41
|
+
length: number;
|
|
42
|
+
}[];
|
|
43
|
+
/**
|
|
44
|
+
* Find all $attrs.for(X) calls in source where X is an origin factory
|
|
45
|
+
*/
|
|
46
|
+
export declare function findAttrsForOriginCalls(source: string): {
|
|
47
|
+
name: string;
|
|
48
|
+
index: number;
|
|
49
|
+
length: number;
|
|
50
|
+
}[];
|
|
51
|
+
/**
|
|
52
|
+
* Find all $attrs.for('x') calls in source where x is an element name
|
|
53
|
+
*/
|
|
54
|
+
export declare function findAttrsForElementCalls(source: string): {
|
|
55
|
+
element: string;
|
|
56
|
+
index: number;
|
|
57
|
+
length: number;
|
|
58
|
+
}[];
|
|
59
|
+
/**
|
|
60
|
+
* Check if a position in the source is inside a string literal or comment.
|
|
61
|
+
* This is used to avoid transforming macro-like syntax that appears inside strings/comments.
|
|
62
|
+
*/
|
|
63
|
+
export declare function isInsideStringOrComment(source: string, position: number): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Extract $bindable from a value string, handling nested generics.
|
|
66
|
+
* Returns { isBindable: true, innerValue: '...' } or { isBindable: false }
|
|
67
|
+
*/
|
|
68
|
+
export declare function extractBindable(value: string): {
|
|
69
|
+
isBindable: true;
|
|
70
|
+
innerValue: string;
|
|
71
|
+
} | {
|
|
72
|
+
isBindable: false;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Find the position of ' as ' that's not inside nested structures.
|
|
76
|
+
* Properly handles angle brackets for generics.
|
|
77
|
+
*/
|
|
78
|
+
export declare function findTopLevelAs(value: string): number;
|
|
79
|
+
/**
|
|
80
|
+
* Find the matching closing bracket for an opening bracket
|
|
81
|
+
*/
|
|
82
|
+
export declare function findMatchingBracket(source: string, openIndex: number, openChar?: string, closeChar?: string): number;
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* Parsed attr info from source
|
|
9
|
+
*/
|
|
10
|
+
export interface ParsedAttrInfo {
|
|
11
|
+
key: string;
|
|
12
|
+
defaultValue: string;
|
|
13
|
+
bindable: boolean;
|
|
14
|
+
hasDefault: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parsed origin schema from source
|
|
18
|
+
*/
|
|
19
|
+
export interface ParsedOriginSchema {
|
|
20
|
+
attrs: ParsedAttrInfo[];
|
|
21
|
+
parentNames: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parse an origin's schema from its source code.
|
|
25
|
+
*
|
|
26
|
+
* Looks for patterns like:
|
|
27
|
+
* ```ts
|
|
28
|
+
* export const Counter = $origin({
|
|
29
|
+
* attrs: $attrs({
|
|
30
|
+
* label: 'Counter',
|
|
31
|
+
* count: $bindable(0),
|
|
32
|
+
* step: 1 as number
|
|
33
|
+
* }),
|
|
34
|
+
* ...
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param source The source code of the origin file
|
|
39
|
+
* @param exportName The name of the exported origin (e.g., 'Counter')
|
|
40
|
+
* @returns Parsed schema or null if not found
|
|
41
|
+
*/
|
|
42
|
+
export declare function parseOriginSchemaFromSource(source: string, exportName: string): ParsedOriginSchema | null;
|
|
43
|
+
/**
|
|
44
|
+
* Generate $props() destructuring code from parsed attrs
|
|
45
|
+
*
|
|
46
|
+
* Uses $attrs.Of<typeof Factory> type annotation which is properly connected
|
|
47
|
+
* to the factory type. This approach is required for svelte-check to properly
|
|
48
|
+
* infer component props from the origin factory definition.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* generatePropsDestructuring([
|
|
52
|
+
* { key: 'label', defaultValue: "'Counter'", bindable: false, hasDefault: true },
|
|
53
|
+
* { key: 'count', defaultValue: '0', bindable: true, hasDefault: true }
|
|
54
|
+
* ], 'Counter')
|
|
55
|
+
* // Returns: "let { label = 'Counter', count = $bindable(0) }: $attrs.Of<typeof Counter> = $props()"
|
|
56
|
+
*/
|
|
57
|
+
export declare function generatePropsDestructuring(attrs: ParsedAttrInfo[], factoryName: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Generate factory call code from parsed attrs.
|
|
60
|
+
* For bindable attrs, we create getters AND setters to maintain two-way binding.
|
|
61
|
+
* For non-bindable attrs, we only create getters.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* generateFactoryCallFromAttrs('Counter', [
|
|
65
|
+
* { key: 'label', defaultValue: "'Counter'", bindable: false, hasDefault: true },
|
|
66
|
+
* { key: 'count', defaultValue: '0', bindable: true, hasDefault: true }
|
|
67
|
+
* ])
|
|
68
|
+
* // Returns: "Counter({ get label() { return label }, get count() { return count }, set count(v) { count = v } })"
|
|
69
|
+
*/
|
|
70
|
+
export declare function generateFactoryCallFromAttrs(factoryName: string, attrs: ParsedAttrInfo[]): string;
|
|
71
|
+
/**
|
|
72
|
+
* Extract import path for a given identifier from source
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* findImportPath("import { Counter } from './origins/counter.svelte'", 'Counter')
|
|
76
|
+
* // Returns: './origins/counter.svelte'
|
|
77
|
+
*/
|
|
78
|
+
export declare function findImportPath(source: string, identifier: string): string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Schema resolution context for async resolution
|
|
81
|
+
*/
|
|
82
|
+
export interface SchemaResolver {
|
|
83
|
+
/**
|
|
84
|
+
* Resolve the schema for an origin factory by its import path
|
|
85
|
+
* @param importPath The import path (e.g., './origins/counter.svelte')
|
|
86
|
+
* @param exportName The name of the exported origin (e.g., 'Counter')
|
|
87
|
+
* @returns Parsed schema or null if not resolvable
|
|
88
|
+
*/
|
|
89
|
+
resolve(importPath: string, exportName: string): Promise<ParsedOriginSchema | null>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Generate a TypeScript interface content from a parsed schema.
|
|
93
|
+
* Used for generating .svelte.d.ts declaration files.
|
|
94
|
+
*
|
|
95
|
+
* @param schema The parsed origin schema
|
|
96
|
+
* @returns Object with interfaceContent (the interface body) and bindings (array of bindable prop names)
|
|
97
|
+
*/
|
|
98
|
+
export declare function generatePropsInterface(schema: ParsedOriginSchema): {
|
|
99
|
+
interfaceContent: string;
|
|
100
|
+
bindings: string[];
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Infer TypeScript type from a default value expression.
|
|
104
|
+
* Used for generating .d.ts files.
|
|
105
|
+
*/
|
|
106
|
+
export declare function inferTypeFromDefault(defaultValue: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Generate the content for a .svelte.d.ts file.
|
|
109
|
+
* Shared between vite-dts.ts and generate-dts.ts.
|
|
110
|
+
*
|
|
111
|
+
* @param factoryName - The name of the origin factory
|
|
112
|
+
* @param importPath - The import path for the factory
|
|
113
|
+
* @param schema - The parsed origin schema
|
|
114
|
+
* @param comment - Optional custom comment for the file header
|
|
115
|
+
*/
|
|
116
|
+
export declare function generateDtsContent(factoryName: string, importPath: string, schema: ParsedOriginSchema, comment?: string): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone $attrs() transformation logic.
|
|
3
|
+
*
|
|
4
|
+
* This module handles transforming standalone $attrs({...}) macro calls
|
|
5
|
+
* (outside of $origin definitions) into __createAttrs({...}) runtime calls.
|
|
6
|
+
*/
|
|
7
|
+
import type MagicString from 'magic-string';
|
|
8
|
+
/**
|
|
9
|
+
* Transform standalone $attrs({...}) calls.
|
|
10
|
+
*
|
|
11
|
+
* Input:
|
|
12
|
+
* ```ts
|
|
13
|
+
* export const BaseAttrs = $attrs({
|
|
14
|
+
* label: 'Default',
|
|
15
|
+
* disabled: false
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // With inheritance:
|
|
19
|
+
* export const WidgetAttrs = $attrs([BaseAttrs], {
|
|
20
|
+
* value: $bindable(0)
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Output:
|
|
25
|
+
* ```ts
|
|
26
|
+
* export const BaseAttrs = __createAttrs({
|
|
27
|
+
* __attrSchema: { label: {...}, disabled: {...} }
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* export const WidgetAttrs = __createAttrs({
|
|
31
|
+
* __parents: [BaseAttrs],
|
|
32
|
+
* __attrSchema: { value: {...} }
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function transformStandaloneAttrsCalls(s: MagicString, source: string, neededImports: Set<string>): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate .svelte.d.ts declaration files for svelte-origin components
|
|
3
|
+
*
|
|
4
|
+
* This module generates sidecar .d.ts files when a component uses $attrs.origin().
|
|
5
|
+
* These declaration files help svelte-check and TypeScript understand the
|
|
6
|
+
* transformed props, since svelte2tsx runs on original file content.
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from 'vite';
|
|
9
|
+
export interface DtsGeneratorOptions {
|
|
10
|
+
/** Enable debug logging */
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a Vite plugin that generates .svelte.d.ts files for origin-based components.
|
|
15
|
+
*/
|
|
16
|
+
export declare function svelteOriginDts(options?: DtsGeneratorOptions): Plugin;
|
|
17
|
+
export default svelteOriginDts;
|