@volynets/reflex-vite-plugin 0.0.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.
- package/dist/ast-utils.d.ts +48 -0
- package/dist/ast-utils.d.ts.map +1 -0
- package/dist/ast-utils.js +118 -0
- package/dist/ast-utils.js.map +1 -0
- package/dist/expressions.d.ts +37 -0
- package/dist/expressions.d.ts.map +1 -0
- package/dist/expressions.js +67 -0
- package/dist/expressions.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-utils.d.ts +17 -0
- package/dist/jsx-utils.d.ts.map +1 -0
- package/dist/jsx-utils.js +23 -0
- package/dist/jsx-utils.js.map +1 -0
- package/dist/normalize-options.d.ts +40 -0
- package/dist/normalize-options.d.ts.map +1 -0
- package/dist/normalize-options.js +64 -0
- package/dist/normalize-options.js.map +1 -0
- package/dist/parser.d.ts +20 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +38 -0
- package/dist/parser.js.map +1 -0
- package/dist/string-utils.d.ts +31 -0
- package/dist/string-utils.d.ts.map +1 -0
- package/dist/string-utils.js +45 -0
- package/dist/string-utils.js.map +1 -0
- package/dist/transform.d.ts +13 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +33 -0
- package/dist/transform.js.map +1 -0
- package/dist/types.d.ts +134 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +58 -0
- package/dist/types.js.map +1 -0
- package/dist/visitor.d.ts +27 -0
- package/dist/visitor.d.ts.map +1 -0
- package/dist/visitor.js +113 -0
- package/dist/visitor.js.map +1 -0
- package/dist/vite-plugins.d.ts +24 -0
- package/dist/vite-plugins.d.ts.map +1 -0
- package/dist/vite-plugins.js +49 -0
- package/dist/vite-plugins.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AST node creation and utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import type { ArrowFunctionExpression, CallExpression, Expression, ImportDeclaration, Program } from "@swc/core";
|
|
5
|
+
import { type NormalizedReflexModelTransformOptions } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Creates an identifier expression
|
|
8
|
+
* @param value - The identifier value
|
|
9
|
+
* @returns The identifier expression
|
|
10
|
+
*/
|
|
11
|
+
export declare function createIdentifier(value: string): Expression;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a call expression
|
|
14
|
+
* @param callee - The function to call
|
|
15
|
+
* @param expression - The argument expression
|
|
16
|
+
* @returns The call expression
|
|
17
|
+
*/
|
|
18
|
+
export declare function createCallExpression(callee: Expression, expression: Expression): CallExpression;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the span of an expression
|
|
21
|
+
* @param expression - The expression
|
|
22
|
+
* @returns The span of the expression
|
|
23
|
+
*/
|
|
24
|
+
export declare function getExpressionSpan(expression: Expression): {
|
|
25
|
+
readonly start: 0;
|
|
26
|
+
readonly end: 0;
|
|
27
|
+
readonly ctxt: 0;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Creates an accessor (arrow function) expression that wraps the given expression
|
|
31
|
+
* @param expression - The expression to wrap
|
|
32
|
+
* @returns The arrow function expression
|
|
33
|
+
*/
|
|
34
|
+
export declare function createAccessorExpression(expression: Expression): ArrowFunctionExpression;
|
|
35
|
+
/**
|
|
36
|
+
* Creates an import declaration for the model value read helper
|
|
37
|
+
* @param options - The model transform options
|
|
38
|
+
* @returns The import declaration
|
|
39
|
+
*/
|
|
40
|
+
export declare function createModelValueReadImport(options: NormalizedReflexModelTransformOptions): ImportDeclaration;
|
|
41
|
+
/**
|
|
42
|
+
* Injects the model value read import at the beginning of the program
|
|
43
|
+
* @param program - The program to inject into
|
|
44
|
+
* @param options - The model transform options
|
|
45
|
+
* @returns The modified program
|
|
46
|
+
*/
|
|
47
|
+
export declare function injectModelValueReadImport(program: Program, options: NormalizedReflexModelTransformOptions): Program;
|
|
48
|
+
//# sourceMappingURL=ast-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-utils.d.ts","sourceRoot":"","sources":["../src/ast-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,uBAAuB,EACvB,cAAc,EACd,UAAU,EAEV,iBAAiB,EAGjB,OAAO,EAER,MAAM,WAAW,CAAC;AACnB,OAAO,EAGL,KAAK,qCAAqC,EAC3C,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAQ1D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,UAAU,GACrB,cAAc,CAShB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU;;;;EAEvD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,UAAU,GACrB,uBAAuB,CAYzB;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,qCAAqC,GAC7C,iBAAiB,CAuCnB;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,qCAAqC,GAC7C,OAAO,CAWT"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AST node creation and utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import { DUMMY_SPAN, MODEL_READ_EXPORT, } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Creates an identifier expression
|
|
7
|
+
* @param value - The identifier value
|
|
8
|
+
* @returns The identifier expression
|
|
9
|
+
*/
|
|
10
|
+
export function createIdentifier(value) {
|
|
11
|
+
return {
|
|
12
|
+
type: "Identifier",
|
|
13
|
+
span: DUMMY_SPAN,
|
|
14
|
+
ctxt: 0,
|
|
15
|
+
value,
|
|
16
|
+
optional: false,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a call expression
|
|
21
|
+
* @param callee - The function to call
|
|
22
|
+
* @param expression - The argument expression
|
|
23
|
+
* @returns The call expression
|
|
24
|
+
*/
|
|
25
|
+
export function createCallExpression(callee, expression) {
|
|
26
|
+
return {
|
|
27
|
+
type: "CallExpression",
|
|
28
|
+
span: getExpressionSpan(expression),
|
|
29
|
+
ctxt: 0,
|
|
30
|
+
callee,
|
|
31
|
+
arguments: [{ expression }],
|
|
32
|
+
typeArguments: undefined,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the span of an expression
|
|
37
|
+
* @param expression - The expression
|
|
38
|
+
* @returns The span of the expression
|
|
39
|
+
*/
|
|
40
|
+
export function getExpressionSpan(expression) {
|
|
41
|
+
return expression.span ?? DUMMY_SPAN;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates an accessor (arrow function) expression that wraps the given expression
|
|
45
|
+
* @param expression - The expression to wrap
|
|
46
|
+
* @returns The arrow function expression
|
|
47
|
+
*/
|
|
48
|
+
export function createAccessorExpression(expression) {
|
|
49
|
+
return {
|
|
50
|
+
type: "ArrowFunctionExpression",
|
|
51
|
+
span: expression.span,
|
|
52
|
+
ctxt: 0,
|
|
53
|
+
params: [],
|
|
54
|
+
body: expression,
|
|
55
|
+
async: false,
|
|
56
|
+
generator: false,
|
|
57
|
+
typeParameters: undefined,
|
|
58
|
+
returnType: undefined,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates an import declaration for the model value read helper
|
|
63
|
+
* @param options - The model transform options
|
|
64
|
+
* @returns The import declaration
|
|
65
|
+
*/
|
|
66
|
+
export function createModelValueReadImport(options) {
|
|
67
|
+
const local = {
|
|
68
|
+
type: "Identifier",
|
|
69
|
+
span: DUMMY_SPAN,
|
|
70
|
+
ctxt: 0,
|
|
71
|
+
value: options.helper,
|
|
72
|
+
optional: false,
|
|
73
|
+
};
|
|
74
|
+
const imported = {
|
|
75
|
+
type: "Identifier",
|
|
76
|
+
span: DUMMY_SPAN,
|
|
77
|
+
ctxt: 0,
|
|
78
|
+
value: MODEL_READ_EXPORT,
|
|
79
|
+
optional: false,
|
|
80
|
+
};
|
|
81
|
+
const specifier = {
|
|
82
|
+
type: "ImportSpecifier",
|
|
83
|
+
span: DUMMY_SPAN,
|
|
84
|
+
local,
|
|
85
|
+
imported,
|
|
86
|
+
isTypeOnly: false,
|
|
87
|
+
};
|
|
88
|
+
const source = {
|
|
89
|
+
type: "StringLiteral",
|
|
90
|
+
span: DUMMY_SPAN,
|
|
91
|
+
value: options.importSource,
|
|
92
|
+
raw: JSON.stringify(options.importSource),
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
type: "ImportDeclaration",
|
|
96
|
+
span: DUMMY_SPAN,
|
|
97
|
+
specifiers: [specifier],
|
|
98
|
+
source,
|
|
99
|
+
typeOnly: false,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Injects the model value read import at the beginning of the program
|
|
104
|
+
* @param program - The program to inject into
|
|
105
|
+
* @param options - The model transform options
|
|
106
|
+
* @returns The modified program
|
|
107
|
+
*/
|
|
108
|
+
export function injectModelValueReadImport(program, options) {
|
|
109
|
+
if (program.type !== "Module") {
|
|
110
|
+
return program;
|
|
111
|
+
}
|
|
112
|
+
const helperImport = createModelValueReadImport(options);
|
|
113
|
+
return {
|
|
114
|
+
...program,
|
|
115
|
+
body: [helperImport, ...program.body],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=ast-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../src/ast-utils.ts"],"names":[],"mappings":"AAAA;;GAEG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AAI,EAAE,YAAY;QAClB,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,iBAAiB;QACxB,QAAQ,EAAE,KAAK;KACS,CAAC;IAE3B,MAAM,SAAS,GAAoB;QACjC,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,UAAU;QAChB,KAAK;QACL,QAAQ;QACR,UAAU,EAAE,KAAK;KACY,CAAC;IAEhC,MAAM,MAAM,GAAkB;QAC5B,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,OAAO,CAAC,YAAY;QAC3B,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC;KACd,CAAC;IAE9B,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,IAAI,EAAE,UAAU;QAChB,UAAU,EAAE,CAAC,SAAS,CAAC;QACvB,MAAM;QACN,QAAQ,EAAE,KAAK;KACgB,CAAC;AACpC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAAgB,EAChB,OAA8C;IAE9C,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,YAAY,GAAG,0BAA0B,CAAC,OAAO,CAAe,CAAC;IAEvE,OAAO;QACL,GAAG,OAAO;QACV,IAAI,EAAE,CAAC,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;KACtC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expression checking and utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import type { Expression, MemberExpression } from "@swc/core";
|
|
5
|
+
/**
|
|
6
|
+
* Checks if an expression should be wrapped in an accessor
|
|
7
|
+
* @param expression - The expression to check
|
|
8
|
+
* @returns Whether the expression should be wrapped
|
|
9
|
+
*/
|
|
10
|
+
export declare function shouldWrapExpression(expression: Expression): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a model attribute should be wrapped
|
|
13
|
+
* @param propName - The property name
|
|
14
|
+
* @returns Whether the attribute should be wrapped
|
|
15
|
+
*/
|
|
16
|
+
export declare function shouldWrapModelAttribute(propName: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Unwraps wrapped expressions (like parenthesis or type assertions)
|
|
19
|
+
* @param expression - The expression to unwrap
|
|
20
|
+
* @returns The unwrapped expression
|
|
21
|
+
*/
|
|
22
|
+
export declare function unwrapExpression(expression: Expression): Expression;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if an expression is a model member expression
|
|
25
|
+
* @param expression - The expression to check
|
|
26
|
+
* @param roots - The set of model root names
|
|
27
|
+
* @returns Whether the expression is a model member expression
|
|
28
|
+
*/
|
|
29
|
+
export declare function isModelMemberExpression(expression: Expression, roots: ReadonlySet<string>): expression is MemberExpression;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if an expression is a model member root
|
|
32
|
+
* @param expression - The expression to check
|
|
33
|
+
* @param roots - The set of model root names
|
|
34
|
+
* @returns Whether the expression is a model member root
|
|
35
|
+
*/
|
|
36
|
+
export declare function isModelMemberRoot(expression: Expression, roots: ReadonlySet<string>): boolean;
|
|
37
|
+
//# sourceMappingURL=expressions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../src/expressions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG9D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAEpE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAElE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAanE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GACzB,UAAU,IAAI,gBAAgB,CAOhC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GACzB,OAAO,CAYT"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expression checking and utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import { WRAPPABLE_EXPRESSION_TYPES } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Checks if an expression should be wrapped in an accessor
|
|
7
|
+
* @param expression - The expression to check
|
|
8
|
+
* @returns Whether the expression should be wrapped
|
|
9
|
+
*/
|
|
10
|
+
export function shouldWrapExpression(expression) {
|
|
11
|
+
return WRAPPABLE_EXPRESSION_TYPES.has(expression.type);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Checks if a model attribute should be wrapped
|
|
15
|
+
* @param propName - The property name
|
|
16
|
+
* @returns Whether the attribute should be wrapped
|
|
17
|
+
*/
|
|
18
|
+
export function shouldWrapModelAttribute(propName) {
|
|
19
|
+
return propName !== "key" && propName !== "ref" && !/^on[A-Z]/.test(propName);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Unwraps wrapped expressions (like parenthesis or type assertions)
|
|
23
|
+
* @param expression - The expression to unwrap
|
|
24
|
+
* @returns The unwrapped expression
|
|
25
|
+
*/
|
|
26
|
+
export function unwrapExpression(expression) {
|
|
27
|
+
switch (expression.type) {
|
|
28
|
+
case "ParenthesisExpression":
|
|
29
|
+
case "TsAsExpression":
|
|
30
|
+
case "TsConstAssertion":
|
|
31
|
+
case "TsInstantiation":
|
|
32
|
+
case "TsNonNullExpression":
|
|
33
|
+
case "TsSatisfiesExpression":
|
|
34
|
+
case "TsTypeAssertion":
|
|
35
|
+
return unwrapExpression(expression.expression);
|
|
36
|
+
default:
|
|
37
|
+
return expression;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks if an expression is a model member expression
|
|
42
|
+
* @param expression - The expression to check
|
|
43
|
+
* @param roots - The set of model root names
|
|
44
|
+
* @returns Whether the expression is a model member expression
|
|
45
|
+
*/
|
|
46
|
+
export function isModelMemberExpression(expression, roots) {
|
|
47
|
+
const unwrapped = unwrapExpression(expression);
|
|
48
|
+
return (unwrapped.type === "MemberExpression" &&
|
|
49
|
+
isModelMemberRoot(unwrapped.object, roots));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks if an expression is a model member root
|
|
53
|
+
* @param expression - The expression to check
|
|
54
|
+
* @param roots - The set of model root names
|
|
55
|
+
* @returns Whether the expression is a model member root
|
|
56
|
+
*/
|
|
57
|
+
export function isModelMemberRoot(expression, roots) {
|
|
58
|
+
const unwrapped = unwrapExpression(expression);
|
|
59
|
+
if (unwrapped.type === "Identifier") {
|
|
60
|
+
return roots.has(unwrapped.value);
|
|
61
|
+
}
|
|
62
|
+
if (unwrapped.type === "MemberExpression") {
|
|
63
|
+
return isModelMemberRoot(unwrapped.object, roots);
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=expressions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressions.js","sourceRoot":"","sources":["../src/expressions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAErD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAAsB;IACzD,OAAO,0BAA0B,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAgB;IACvD,OAAO,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@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reflex/vite-plugin
|
|
3
|
+
* Main entry point for the Reflex Vite plugin
|
|
4
|
+
*
|
|
5
|
+
* This plugin provides:
|
|
6
|
+
* - JSX transformation for automatic runtime
|
|
7
|
+
* - Reactive props handling for computed dependencies
|
|
8
|
+
* - Model value tracking and optimization
|
|
9
|
+
*/
|
|
10
|
+
export type { ReflexDOMTransformOptions, ReflexDOMTransformResult, ReflexModelTransformOptions, NormalizedReflexModelTransformOptions, NormalizedDOMTransformOptions, ReflexPluginOptions, SelectorType, } from "./types";
|
|
11
|
+
export { transformReflexDOMJSX } from "./transform";
|
|
12
|
+
export { reflexDOMVitePlugin, reflexJSXVitePlugin, reflex, } from "./vite-plugins";
|
|
13
|
+
export { reflex as default } from "./vite-plugins";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,2BAA2B,EAC3B,qCAAqC,EACrC,6BAA6B,EAC7B,mBAAmB,EACnB,YAAY,GACb,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,MAAM,GACP,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reflex/vite-plugin
|
|
3
|
+
* Main entry point for the Reflex Vite plugin
|
|
4
|
+
*
|
|
5
|
+
* This plugin provides:
|
|
6
|
+
* - JSX transformation for automatic runtime
|
|
7
|
+
* - Reactive props handling for computed dependencies
|
|
8
|
+
* - Model value tracking and optimization
|
|
9
|
+
*/
|
|
10
|
+
// Re-export the main transformation function
|
|
11
|
+
export { transformReflexDOMJSX } from "./transform";
|
|
12
|
+
// Re-export plugin creators
|
|
13
|
+
export { reflexDOMVitePlugin, reflexJSXVitePlugin, reflex, } from "./vite-plugins";
|
|
14
|
+
// Default export
|
|
15
|
+
export { reflex as default } from "./vite-plugins";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,6CAA6C;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD,4BAA4B;AAC5B,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,MAAM,GACP,MAAM,gBAAgB,CAAC;AAExB,iBAAiB;AACjB,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import type { JSXAttributeName, JSXAttrValue, JSXExpressionContainer } from "@swc/core";
|
|
5
|
+
/**
|
|
6
|
+
* Gets the name of a JSX attribute
|
|
7
|
+
* @param name - The attribute name node
|
|
8
|
+
* @returns The attribute name string or null
|
|
9
|
+
*/
|
|
10
|
+
export declare function getJSXAttributeName(name: JSXAttributeName): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Type guard for JSXExpressionContainer
|
|
13
|
+
* @param value - The value to check
|
|
14
|
+
* @returns Whether the value is a JSXExpressionContainer
|
|
15
|
+
*/
|
|
16
|
+
export declare function isJSXExpressionContainer(value: JSXAttrValue | undefined): value is JSXExpressionContainer;
|
|
17
|
+
//# sourceMappingURL=jsx-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-utils.d.ts","sourceRoot":"","sources":["../src/jsx-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACvB,MAAM,WAAW,CAAC;AAEnB;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,GAAG,IAAI,CAMzE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,YAAY,GAAG,SAAS,GAC9B,KAAK,IAAI,sBAAsB,CAEjC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Gets the name of a JSX attribute
|
|
6
|
+
* @param name - The attribute name node
|
|
7
|
+
* @returns The attribute name string or null
|
|
8
|
+
*/
|
|
9
|
+
export function getJSXAttributeName(name) {
|
|
10
|
+
if (name.type === "Identifier") {
|
|
11
|
+
return name.value;
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Type guard for JSXExpressionContainer
|
|
17
|
+
* @param value - The value to check
|
|
18
|
+
* @returns Whether the value is a JSXExpressionContainer
|
|
19
|
+
*/
|
|
20
|
+
export function isJSXExpressionContainer(value) {
|
|
21
|
+
return value?.type === "JSXExpressionContainer";
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=jsx-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-utils.js","sourceRoot":"","sources":["../src/jsx-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAsB;IACxD,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAA+B;IAE/B,OAAO,KAAK,EAAE,IAAI,KAAK,wBAAwB,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options normalization utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import type { ReflexDOMTransformOptions, ReflexModelTransformOptions, NormalizedDOMTransformOptions, NormalizedReflexModelTransformOptions } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes DOM transform options
|
|
7
|
+
* @param options - The raw DOM transform options
|
|
8
|
+
* @returns The normalized options
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeDOMOptions(options?: ReflexDOMTransformOptions): NormalizedDOMTransformOptions;
|
|
11
|
+
/**
|
|
12
|
+
* Normalizes model transform options
|
|
13
|
+
* @param options - The raw model options
|
|
14
|
+
* @returns The normalized model options or null if disabled
|
|
15
|
+
*/
|
|
16
|
+
export declare function normalizeModelOptions(options: boolean | ReflexModelTransformOptions | undefined): NormalizedReflexModelTransformOptions | null;
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes DOM plugin options
|
|
19
|
+
* @param options - The raw DOM plugin options
|
|
20
|
+
* @returns The normalized options or null if disabled
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeDOMPluginOptions(options: boolean | ReflexDOMTransformOptions | undefined): ReflexDOMTransformOptions | null;
|
|
23
|
+
/**
|
|
24
|
+
* Creates esbuild options for JSX handling
|
|
25
|
+
* @param jsxRuntime - The JSX runtime type
|
|
26
|
+
* @param jsxImportSource - The JSX import source
|
|
27
|
+
* @returns The esbuild options object
|
|
28
|
+
*/
|
|
29
|
+
export declare function createJSXEsbuildOptions(jsxRuntime?: "classic" | "automatic" | "reflex" | "tsrx", jsxImportSource?: string): {
|
|
30
|
+
jsx: "transform";
|
|
31
|
+
jsxFactory: string;
|
|
32
|
+
jsxFragment: string;
|
|
33
|
+
jsxImportSource?: undefined;
|
|
34
|
+
} | {
|
|
35
|
+
jsx: "automatic";
|
|
36
|
+
jsxImportSource: string;
|
|
37
|
+
jsxFactory?: undefined;
|
|
38
|
+
jsxFragment?: undefined;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=normalize-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-options.d.ts","sourceRoot":"","sources":["../src/normalize-options.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,qCAAqC,EACtC,MAAM,SAAS,CAAC;AASjB;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,yBAA8B,GACtC,6BAA6B,CAO/B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,GAAG,2BAA2B,GAAG,SAAS,GACzD,qCAAqC,GAAG,IAAI,CAY9C;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,GAAG,yBAAyB,GAAG,SAAS,GACvD,yBAAyB,GAAG,IAAI,CAMlC;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,GAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAoB,EACrE,eAAe,GAAE,MAAkC;;;;;;;;;;EAcpD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options normalization utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import { DEFAULT_MODEL_IMPORT_SOURCE, DEFAULT_MODEL_READ_HELPER, DEFAULT_MODEL_ROOTS, DEFAULT_REACTIVE_PROPS, DEFAULT_JSX_IMPORT_SOURCE, } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes DOM transform options
|
|
7
|
+
* @param options - The raw DOM transform options
|
|
8
|
+
* @returns The normalized options
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeDOMOptions(options = {}) {
|
|
11
|
+
return {
|
|
12
|
+
include: options.include ?? /\.[cm]?[jt]sx(?:$|\?)/,
|
|
13
|
+
exclude: options.exclude ?? /node_modules/,
|
|
14
|
+
reactiveProps: options.reactiveProps ?? DEFAULT_REACTIVE_PROPS,
|
|
15
|
+
model: normalizeModelOptions(options.model),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Normalizes model transform options
|
|
20
|
+
* @param options - The raw model options
|
|
21
|
+
* @returns The normalized model options or null if disabled
|
|
22
|
+
*/
|
|
23
|
+
export function normalizeModelOptions(options) {
|
|
24
|
+
if (options === false) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const normalized = options === true || options === undefined ? {} : options;
|
|
28
|
+
return {
|
|
29
|
+
roots: new Set(normalized.roots ?? DEFAULT_MODEL_ROOTS),
|
|
30
|
+
importSource: normalized.importSource ?? DEFAULT_MODEL_IMPORT_SOURCE,
|
|
31
|
+
helper: normalized.helper ?? DEFAULT_MODEL_READ_HELPER,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Normalizes DOM plugin options
|
|
36
|
+
* @param options - The raw DOM plugin options
|
|
37
|
+
* @returns The normalized options or null if disabled
|
|
38
|
+
*/
|
|
39
|
+
export function normalizeDOMPluginOptions(options) {
|
|
40
|
+
if (options === undefined || options === false) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return options === true ? {} : options;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates esbuild options for JSX handling
|
|
47
|
+
* @param jsxRuntime - The JSX runtime type
|
|
48
|
+
* @param jsxImportSource - The JSX import source
|
|
49
|
+
* @returns The esbuild options object
|
|
50
|
+
*/
|
|
51
|
+
export function createJSXEsbuildOptions(jsxRuntime = "automatic", jsxImportSource = DEFAULT_JSX_IMPORT_SOURCE) {
|
|
52
|
+
if (jsxRuntime === "classic") {
|
|
53
|
+
return {
|
|
54
|
+
jsx: "transform",
|
|
55
|
+
jsxFactory: "jsx",
|
|
56
|
+
jsxFragment: "Fragment",
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
jsx: "automatic",
|
|
61
|
+
jsxImportSource,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=normalize-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-options.js","sourceRoot":"","sources":["../src/normalize-options.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAqC,EAAE;IAEvC,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,uBAAuB;QACnD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc;QAC1C,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,sBAAsB;QAC9D,KAAK,EAAE,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAC;KAC5C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAA0D;IAE1D,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAE5E,OAAO;QACL,KAAK,EAAE,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,IAAI,mBAAmB,CAAC;QACvD,YAAY,EAAE,UAAU,CAAC,YAAY,IAAI,2BAA2B;QACpE,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,yBAAyB;KACvD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAwD;IAExD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,aAA0D,WAAW,EACrE,kBAA0B,yBAAyB;IAEnD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO;YACL,GAAG,EAAE,WAAoB;YACzB,UAAU,EAAE,KAAK;YACjB,WAAW,EAAE,UAAU;SACxB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,GAAG,EAAE,WAAoB;QACzB,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX module parsing and printing utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import type { Module, Program } from "@swc/core";
|
|
5
|
+
import type { ReflexDOMTransformResult } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Parses a JSX/TSX module
|
|
8
|
+
* @param code - The source code
|
|
9
|
+
* @param id - The module ID
|
|
10
|
+
* @returns The parsed module
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseJSXModule(code: string, id: string): Module;
|
|
13
|
+
/**
|
|
14
|
+
* Prints a program back to code
|
|
15
|
+
* @param program - The program to print
|
|
16
|
+
* @param id - The module ID
|
|
17
|
+
* @returns The transform result with code and source map
|
|
18
|
+
*/
|
|
19
|
+
export declare function printProgram(program: Program, id: string): ReflexDOMTransformResult;
|
|
20
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAU/D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,MAAM,GACT,wBAAwB,CAU1B"}
|
package/dist/parser.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX module parsing and printing utilities for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import { parseSync, printSync } from "@swc/core";
|
|
5
|
+
import { stripQueryAndHash } from "./string-utils";
|
|
6
|
+
/**
|
|
7
|
+
* Parses a JSX/TSX module
|
|
8
|
+
* @param code - The source code
|
|
9
|
+
* @param id - The module ID
|
|
10
|
+
* @returns The parsed module
|
|
11
|
+
*/
|
|
12
|
+
export function parseJSXModule(code, id) {
|
|
13
|
+
const cleanId = stripQueryAndHash(id);
|
|
14
|
+
const isTypeScript = /\.([cm]?ts)x$/i.test(cleanId);
|
|
15
|
+
return parseSync(code, {
|
|
16
|
+
syntax: isTypeScript ? "typescript" : "ecmascript",
|
|
17
|
+
tsx: isTypeScript,
|
|
18
|
+
jsx: !isTypeScript,
|
|
19
|
+
target: "es2022",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Prints a program back to code
|
|
24
|
+
* @param program - The program to print
|
|
25
|
+
* @param id - The module ID
|
|
26
|
+
* @returns The transform result with code and source map
|
|
27
|
+
*/
|
|
28
|
+
export function printProgram(program, id) {
|
|
29
|
+
const output = printSync(program, {
|
|
30
|
+
filename: stripQueryAndHash(id),
|
|
31
|
+
sourceMaps: true,
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
code: output.code,
|
|
35
|
+
map: output.map ?? null,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,EAAU;IACrD,MAAM,OAAO,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACtC,MAAM,YAAY,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEpD,OAAO,SAAS,CAAC,IAAI,EAAE;QACrB,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY;QAClD,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,CAAC,YAAY;QAClB,MAAM,EAAE,QAAQ;KACjB,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAgB,EAChB,EAAU;IAEV,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE;QAChC,QAAQ,EAAE,iBAAiB,CAAC,EAAE,CAAC;QAC/B,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,IAAI;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String utility functions for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Removes query string and hash from module ID
|
|
6
|
+
* @param id - The module ID
|
|
7
|
+
* @returns The cleaned module ID
|
|
8
|
+
*/
|
|
9
|
+
export declare function stripQueryAndHash(id: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a file should be processed based on include/exclude patterns
|
|
12
|
+
* @param id - The module ID
|
|
13
|
+
* @param include - The include regex pattern
|
|
14
|
+
* @param exclude - The exclude regex pattern
|
|
15
|
+
* @returns Whether the file should be processed
|
|
16
|
+
*/
|
|
17
|
+
export declare function shouldProcessFile(id: string, include: RegExp, exclude: RegExp): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if code contains potential reactive JSX expressions
|
|
20
|
+
* @param code - The source code
|
|
21
|
+
* @param reactiveProps - The list of reactive props
|
|
22
|
+
* @returns Whether the code likely contains reactive JSX expressions
|
|
23
|
+
*/
|
|
24
|
+
export declare function hasPotentialReactiveJSXExpression(code: string, reactiveProps: readonly string[]): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Determines if a file is TypeScript based on its extension
|
|
27
|
+
* @param id - The module ID
|
|
28
|
+
* @returns Whether the file is TypeScript
|
|
29
|
+
*/
|
|
30
|
+
export declare function isTypeScriptFile(id: string): boolean;
|
|
31
|
+
//# sourceMappingURL=string-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../src/string-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,OAAO,CAGT;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,SAAS,MAAM,EAAE,GAC/B,OAAO,CAUT;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAGpD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String utility functions for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Removes query string and hash from module ID
|
|
6
|
+
* @param id - The module ID
|
|
7
|
+
* @returns The cleaned module ID
|
|
8
|
+
*/
|
|
9
|
+
export function stripQueryAndHash(id) {
|
|
10
|
+
return id.replace(/[?#].*$/, "");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a file should be processed based on include/exclude patterns
|
|
14
|
+
* @param id - The module ID
|
|
15
|
+
* @param include - The include regex pattern
|
|
16
|
+
* @param exclude - The exclude regex pattern
|
|
17
|
+
* @returns Whether the file should be processed
|
|
18
|
+
*/
|
|
19
|
+
export function shouldProcessFile(id, include, exclude) {
|
|
20
|
+
const cleanId = stripQueryAndHash(id);
|
|
21
|
+
return include.test(cleanId) && !exclude.test(cleanId);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Checks if code contains potential reactive JSX expressions
|
|
25
|
+
* @param code - The source code
|
|
26
|
+
* @param reactiveProps - The list of reactive props
|
|
27
|
+
* @returns Whether the code likely contains reactive JSX expressions
|
|
28
|
+
*/
|
|
29
|
+
export function hasPotentialReactiveJSXExpression(code, reactiveProps) {
|
|
30
|
+
const hasReactivePropExpression = reactiveProps.some((propName) => new RegExp(`\\b${propName}\\s*=\\s*\\{`).test(code));
|
|
31
|
+
if (hasReactivePropExpression) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return code.includes("{") && /<[A-Za-z][\w.:$-]*(?:\s|>|\/)|<>/.test(code);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Determines if a file is TypeScript based on its extension
|
|
38
|
+
* @param id - The module ID
|
|
39
|
+
* @returns Whether the file is TypeScript
|
|
40
|
+
*/
|
|
41
|
+
export function isTypeScriptFile(id) {
|
|
42
|
+
const cleanId = stripQueryAndHash(id);
|
|
43
|
+
return /\.([cm]?ts)x$/i.test(cleanId);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=string-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-utils.js","sourceRoot":"","sources":["../src/string-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAU;IAC1C,OAAO,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAU,EACV,OAAe,EACf,OAAe;IAEf,MAAM,OAAO,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAC/C,IAAY,EACZ,aAAgC;IAEhC,MAAM,yBAAyB,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAChE,IAAI,MAAM,CAAC,MAAM,QAAQ,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CACpD,CAAC;IAEF,IAAI,yBAAyB,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,kCAAkC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAAU;IACzC,MAAM,OAAO,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACtC,OAAO,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main transformation logic for Reflex DOM JSX
|
|
3
|
+
*/
|
|
4
|
+
import type { ReflexDOMTransformOptions, ReflexDOMTransformResult } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Transforms Reflex DOM JSX code
|
|
7
|
+
* @param code - The source code
|
|
8
|
+
* @param id - The module ID
|
|
9
|
+
* @param rawOptions - The transform options
|
|
10
|
+
* @returns The transform result or null if no transformation needed
|
|
11
|
+
*/
|
|
12
|
+
export declare function transformReflexDOMJSX(code: string, id: string, rawOptions?: ReflexDOMTransformOptions): ReflexDOMTransformResult | null;
|
|
13
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAOjB;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,UAAU,GAAE,yBAA8B,GACzC,wBAAwB,GAAG,IAAI,CA0BjC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main transformation logic for Reflex DOM JSX
|
|
3
|
+
*/
|
|
4
|
+
import { normalizeDOMOptions } from "./normalize-options";
|
|
5
|
+
import { shouldProcessFile, hasPotentialReactiveJSXExpression } from "./string-utils";
|
|
6
|
+
import { parseJSXModule, printProgram } from "./parser";
|
|
7
|
+
import { ReflexDOMJSXReactivePropsVisitor } from "./visitor";
|
|
8
|
+
import { injectModelValueReadImport } from "./ast-utils";
|
|
9
|
+
/**
|
|
10
|
+
* Transforms Reflex DOM JSX code
|
|
11
|
+
* @param code - The source code
|
|
12
|
+
* @param id - The module ID
|
|
13
|
+
* @param rawOptions - The transform options
|
|
14
|
+
* @returns The transform result or null if no transformation needed
|
|
15
|
+
*/
|
|
16
|
+
export function transformReflexDOMJSX(code, id, rawOptions = {}) {
|
|
17
|
+
const options = normalizeDOMOptions(rawOptions);
|
|
18
|
+
if (!shouldProcessFile(id, options.include, options.exclude)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (!hasPotentialReactiveJSXExpression(code, options.reactiveProps)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const ast = parseJSXModule(code, id);
|
|
25
|
+
const visitor = new ReflexDOMJSXReactivePropsVisitor(new Set(options.reactiveProps), options.model);
|
|
26
|
+
let transformed = visitor.visitProgram(ast);
|
|
27
|
+
if (options.model !== null &&
|
|
28
|
+
visitor.shouldInjectModelValueReadHelper()) {
|
|
29
|
+
transformed = injectModelValueReadImport(transformed, options.model);
|
|
30
|
+
}
|
|
31
|
+
return printProgram(transformed, id);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,IAAY,EACZ,EAAU,EACV,aAAwC,EAAE;IAE1C,MAAM,OAAO,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAEhD,IAAI,CAAC,iBAAiB,CAAC,EAAE,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,iCAAiC,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,gCAAgC,CAClD,IAAI,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,EAC9B,OAAO,CAAC,KAAK,CACd,CAAC;IACF,IAAI,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,CAAY,CAAC;IAEvD,IACE,OAAO,CAAC,KAAK,KAAK,IAAI;QACtB,OAAO,CAAC,gCAAgC,EAAE,EAC1C,CAAC;QACD,WAAW,GAAG,0BAA0B,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions and constants for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Options for the Reflex DOM JSX transform
|
|
6
|
+
*/
|
|
7
|
+
export interface ReflexDOMTransformOptions {
|
|
8
|
+
include?: RegExp;
|
|
9
|
+
exclude?: RegExp;
|
|
10
|
+
reactiveProps?: readonly string[];
|
|
11
|
+
model?: boolean | ReflexModelTransformOptions;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Result of the Reflex DOM JSX transform
|
|
15
|
+
*/
|
|
16
|
+
export interface ReflexDOMTransformResult {
|
|
17
|
+
code: string;
|
|
18
|
+
map: string | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for Reflex model transform
|
|
22
|
+
*/
|
|
23
|
+
export interface ReflexModelTransformOptions {
|
|
24
|
+
roots?: readonly string[];
|
|
25
|
+
importSource?: string;
|
|
26
|
+
helper?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Normalized model transform options for internal use
|
|
30
|
+
*/
|
|
31
|
+
export interface NormalizedReflexModelTransformOptions {
|
|
32
|
+
roots: ReadonlySet<string>;
|
|
33
|
+
importSource: string;
|
|
34
|
+
helper: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalized DOM transform options for internal use
|
|
38
|
+
*/
|
|
39
|
+
export interface NormalizedDOMTransformOptions {
|
|
40
|
+
include: RegExp;
|
|
41
|
+
exclude: RegExp;
|
|
42
|
+
reactiveProps: readonly string[];
|
|
43
|
+
model: NormalizedReflexModelTransformOptions | null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Main options for the Reflex Vite plugin
|
|
47
|
+
*/
|
|
48
|
+
export interface ReflexPluginOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Can be used to process extra files like `.mdx`
|
|
51
|
+
* @example include: /\.(mdx|js|jsx|ts|tsx)$/
|
|
52
|
+
* @default /\.[tj]sx?$/
|
|
53
|
+
*/
|
|
54
|
+
include?: SelectorType;
|
|
55
|
+
/**
|
|
56
|
+
* Can be used to exclude JSX/TSX files that run in a worker or are not Reflex files.
|
|
57
|
+
* Except if explicitly desired, keep node_modules in the exclude list.
|
|
58
|
+
* @example exclude: [/\/pdf\//, /\.solid\.tsx$/, /\/node_modules\//]
|
|
59
|
+
* @default /\/node_modules\//
|
|
60
|
+
*/
|
|
61
|
+
exclude?: SelectorType;
|
|
62
|
+
/**
|
|
63
|
+
* Control where the JSX factory is imported from.
|
|
64
|
+
* https://oxc.rs/docs/guide/usage/transformer/jsx.html#import-source
|
|
65
|
+
* @default "@volynets/reflex-dom"
|
|
66
|
+
*/
|
|
67
|
+
jsxImportSource?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Note: Skipping Reflex import with classic runtime is not supported from v4.
|
|
70
|
+
* @default "automatic"
|
|
71
|
+
*/
|
|
72
|
+
jsxRuntime?: "classic" | "automatic" | "tsrx";
|
|
73
|
+
/**
|
|
74
|
+
* Reflex Fast Refresh runtime options.
|
|
75
|
+
*/
|
|
76
|
+
reflex?: {
|
|
77
|
+
/**
|
|
78
|
+
* Reflex Fast Refresh runtime URL prefix.
|
|
79
|
+
* Useful in a module federation context to enable HMR by specifying
|
|
80
|
+
* the host application URL in the Vite config of a remote application.
|
|
81
|
+
*/
|
|
82
|
+
refreshHost?: string;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Enables the DOM JSX transform that wraps computed reactive props
|
|
86
|
+
* like class/className/style into accessors.
|
|
87
|
+
*/
|
|
88
|
+
dom?: boolean | ReflexDOMTransformOptions;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Selector type for include/exclude patterns
|
|
92
|
+
*/
|
|
93
|
+
export type SelectorType = string | RegExp | Array<string | RegExp>;
|
|
94
|
+
/**
|
|
95
|
+
* JSX attribute name type union
|
|
96
|
+
*/
|
|
97
|
+
export type JSXAttributeNameType = "Identifier" | "NamespacedName" | "JSXMemberExpression";
|
|
98
|
+
/**
|
|
99
|
+
* Default constants for JSX import source
|
|
100
|
+
*/
|
|
101
|
+
export declare const DEFAULT_JSX_IMPORT_SOURCE = "@volynets/reflex-dom";
|
|
102
|
+
/**
|
|
103
|
+
* Default constants for model import source
|
|
104
|
+
*/
|
|
105
|
+
export declare const DEFAULT_MODEL_IMPORT_SOURCE = "@volynets/reflex";
|
|
106
|
+
/**
|
|
107
|
+
* Default helper function name for reading model values
|
|
108
|
+
*/
|
|
109
|
+
export declare const DEFAULT_MODEL_READ_HELPER = "__readReflexModelValue";
|
|
110
|
+
/**
|
|
111
|
+
* Default model roots to check for reactive expressions
|
|
112
|
+
*/
|
|
113
|
+
export declare const DEFAULT_MODEL_ROOTS: readonly ["model"];
|
|
114
|
+
/**
|
|
115
|
+
* Default reactive props that should be wrapped in accessors
|
|
116
|
+
*/
|
|
117
|
+
export declare const DEFAULT_REACTIVE_PROPS: readonly ["class", "className", "style"];
|
|
118
|
+
/**
|
|
119
|
+
* Export name for the model read helper
|
|
120
|
+
*/
|
|
121
|
+
export declare const MODEL_READ_EXPORT = "readModelValue";
|
|
122
|
+
/**
|
|
123
|
+
* Dummy span object for created AST nodes
|
|
124
|
+
*/
|
|
125
|
+
export declare const DUMMY_SPAN: {
|
|
126
|
+
readonly start: 0;
|
|
127
|
+
readonly end: 0;
|
|
128
|
+
readonly ctxt: 0;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Set of expression types that can be wrapped in accessors
|
|
132
|
+
*/
|
|
133
|
+
export declare const WRAPPABLE_EXPRESSION_TYPES: Set<"Identifier" | "JSXMemberExpression" | "ThisExpression" | "ArrayExpression" | "ObjectExpression" | "FunctionExpression" | "UnaryExpression" | "UpdateExpression" | "BinaryExpression" | "AssignmentExpression" | "MemberExpression" | "SuperPropExpression" | "ConditionalExpression" | "CallExpression" | "NewExpression" | "SequenceExpression" | "StringLiteral" | "BooleanLiteral" | "NullLiteral" | "NumericLiteral" | "BigIntLiteral" | "RegExpLiteral" | "JSXText" | "TemplateLiteral" | "TaggedTemplateExpression" | "ArrowFunctionExpression" | "ClassExpression" | "YieldExpression" | "MetaProperty" | "AwaitExpression" | "ParenthesisExpression" | "JSXNamespacedName" | "JSXEmptyExpression" | "JSXElement" | "JSXFragment" | "TsTypeAssertion" | "TsConstAssertion" | "TsNonNullExpression" | "TsAsExpression" | "TsSatisfiesExpression" | "TsInstantiation" | "PrivateName" | "OptionalChainingExpression" | "Invalid">;
|
|
134
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAA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ACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,gBAAgB,GAAG,qBAAqB,CAAC;AAE3F;;GAEG;AACH,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,2BAA2B,qBAAqB,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,yBAAyB,2BAA2B,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,mBAAmB,oBAAqB,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,sBAAsB,0CAA2C,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,iBAAiB,mBAAmB,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,UAAU;;;;CAAyC,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,0BAA0B,64BAsBrC,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions and constants for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default constants for JSX import source
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_JSX_IMPORT_SOURCE = "@volynets/reflex-dom";
|
|
8
|
+
/**
|
|
9
|
+
* Default constants for model import source
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_MODEL_IMPORT_SOURCE = "@volynets/reflex";
|
|
12
|
+
/**
|
|
13
|
+
* Default helper function name for reading model values
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_MODEL_READ_HELPER = "__readReflexModelValue";
|
|
16
|
+
/**
|
|
17
|
+
* Default model roots to check for reactive expressions
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_MODEL_ROOTS = ["model"];
|
|
20
|
+
/**
|
|
21
|
+
* Default reactive props that should be wrapped in accessors
|
|
22
|
+
*/
|
|
23
|
+
export const DEFAULT_REACTIVE_PROPS = ["class", "className", "style"];
|
|
24
|
+
/**
|
|
25
|
+
* Export name for the model read helper
|
|
26
|
+
*/
|
|
27
|
+
export const MODEL_READ_EXPORT = "readModelValue";
|
|
28
|
+
/**
|
|
29
|
+
* Dummy span object for created AST nodes
|
|
30
|
+
*/
|
|
31
|
+
export const DUMMY_SPAN = { start: 0, end: 0, ctxt: 0 };
|
|
32
|
+
/**
|
|
33
|
+
* Set of expression types that can be wrapped in accessors
|
|
34
|
+
*/
|
|
35
|
+
export const WRAPPABLE_EXPRESSION_TYPES = new Set([
|
|
36
|
+
"ArrayExpression",
|
|
37
|
+
"AssignmentExpression",
|
|
38
|
+
"AwaitExpression",
|
|
39
|
+
"BinaryExpression",
|
|
40
|
+
"CallExpression",
|
|
41
|
+
"ConditionalExpression",
|
|
42
|
+
"NewExpression",
|
|
43
|
+
"ObjectExpression",
|
|
44
|
+
"OptionalChainingExpression",
|
|
45
|
+
"ParenthesisExpression",
|
|
46
|
+
"SequenceExpression",
|
|
47
|
+
"TaggedTemplateExpression",
|
|
48
|
+
"TemplateLiteral",
|
|
49
|
+
"TsAsExpression",
|
|
50
|
+
"TsConstAssertion",
|
|
51
|
+
"TsInstantiation",
|
|
52
|
+
"TsNonNullExpression",
|
|
53
|
+
"TsSatisfiesExpression",
|
|
54
|
+
"TsTypeAssertion",
|
|
55
|
+
"UnaryExpression",
|
|
56
|
+
"UpdateExpression",
|
|
57
|
+
]);
|
|
58
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AA0GH;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAC;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB,CAAC;AAE9D;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,wBAAwB,CAAC;AAElE;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAO,CAAU,CAAC;AAEtD;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAU,CAAC;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAW,CAAC;AAEjE;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAqB;IACpE,iBAAiB;IACjB,sBAAsB;IACtB,iBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,uBAAuB;IACvB,eAAe;IACf,kBAAkB;IAClB,4BAA4B;IAC5B,uBAAuB;IACvB,oBAAoB;IACpB,0BAA0B;IAC1B,iBAAiB;IACjB,gBAAgB;IAChB,kBAAkB;IAClB,iBAAiB;IACjB,qBAAqB;IACrB,uBAAuB;IACvB,iBAAiB;IACjB,iBAAiB;IACjB,kBAAkB;CACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX reactive props visitor for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import { Visitor } from "@swc/core/Visitor.js";
|
|
5
|
+
import type { JSXAttribute, JSXAttributeOrSpread, JSXExpressionContainer, TsType } from "@swc/core";
|
|
6
|
+
import type { NormalizedReflexModelTransformOptions } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Visitor that transforms reactive JSX props into accessors
|
|
9
|
+
*/
|
|
10
|
+
export declare class ReflexDOMJSXReactivePropsVisitor extends Visitor {
|
|
11
|
+
private readonly reactiveProps;
|
|
12
|
+
private readonly modelOptions;
|
|
13
|
+
private jsxAttributeDepth;
|
|
14
|
+
private modelValueReadHelperUsed;
|
|
15
|
+
constructor(reactiveProps: ReadonlySet<string>, modelOptions: NormalizedReflexModelTransformOptions | null);
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the model value read helper is being used
|
|
18
|
+
* @returns Whether the helper is used
|
|
19
|
+
*/
|
|
20
|
+
shouldInjectModelValueReadHelper(): boolean;
|
|
21
|
+
visitTsType(node: TsType): TsType;
|
|
22
|
+
visitJSXAttribute(node: JSXAttribute): JSXAttributeOrSpread;
|
|
23
|
+
visitJSXExpressionContainer(node: JSXExpressionContainer): JSXExpressionContainer;
|
|
24
|
+
private shouldWrapModelExpression;
|
|
25
|
+
private createModelValueReadExpression;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=visitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitor.d.ts","sourceRoot":"","sources":["../src/visitor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,sBAAsB,EACtB,MAAM,EAEP,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,SAAS,CAAC;AAarE;;GAEG;AACH,qBAAa,gCAAiC,SAAQ,OAAO;IAKzD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAL/B,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,wBAAwB,CAAS;gBAGtB,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,EAClC,YAAY,EAAE,qCAAqC,GAAG,IAAI;IAK7E;;;OAGG;IACH,gCAAgC,IAAI,OAAO;IAIlC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIjC,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,oBAAoB;IAyD3D,2BAA2B,CAClC,IAAI,EAAE,sBAAsB,GAC3B,sBAAsB;IAgCzB,OAAO,CAAC,yBAAyB;IAejC,OAAO,CAAC,8BAA8B;CAYvC"}
|
package/dist/visitor.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX reactive props visitor for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import { Visitor } from "@swc/core/Visitor.js";
|
|
5
|
+
import { createAccessorExpression, createCallExpression, createIdentifier, } from "./ast-utils";
|
|
6
|
+
import { shouldWrapExpression, shouldWrapModelAttribute, isModelMemberExpression, } from "./expressions";
|
|
7
|
+
import { getJSXAttributeName, isJSXExpressionContainer } from "./jsx-utils";
|
|
8
|
+
/**
|
|
9
|
+
* Visitor that transforms reactive JSX props into accessors
|
|
10
|
+
*/
|
|
11
|
+
export class ReflexDOMJSXReactivePropsVisitor extends Visitor {
|
|
12
|
+
reactiveProps;
|
|
13
|
+
modelOptions;
|
|
14
|
+
jsxAttributeDepth = 0;
|
|
15
|
+
modelValueReadHelperUsed = false;
|
|
16
|
+
constructor(reactiveProps, modelOptions) {
|
|
17
|
+
super();
|
|
18
|
+
this.reactiveProps = reactiveProps;
|
|
19
|
+
this.modelOptions = modelOptions;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks if the model value read helper is being used
|
|
23
|
+
* @returns Whether the helper is used
|
|
24
|
+
*/
|
|
25
|
+
shouldInjectModelValueReadHelper() {
|
|
26
|
+
return this.modelValueReadHelperUsed;
|
|
27
|
+
}
|
|
28
|
+
visitTsType(node) {
|
|
29
|
+
return node;
|
|
30
|
+
}
|
|
31
|
+
visitJSXAttribute(node) {
|
|
32
|
+
this.jsxAttributeDepth++;
|
|
33
|
+
let next;
|
|
34
|
+
try {
|
|
35
|
+
next = super.visitJSXAttribute(node);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
this.jsxAttributeDepth--;
|
|
39
|
+
}
|
|
40
|
+
const propName = getJSXAttributeName(next.name);
|
|
41
|
+
if (!propName) {
|
|
42
|
+
return next;
|
|
43
|
+
}
|
|
44
|
+
const value = next.value;
|
|
45
|
+
if (!isJSXExpressionContainer(value)) {
|
|
46
|
+
return next;
|
|
47
|
+
}
|
|
48
|
+
// Safe to access expression because we've type-guarded
|
|
49
|
+
const containerValue = value;
|
|
50
|
+
const expression = containerValue.expression;
|
|
51
|
+
if (expression.type === "JSXEmptyExpression") {
|
|
52
|
+
return next;
|
|
53
|
+
}
|
|
54
|
+
if (this.shouldWrapModelExpression(expression, propName)) {
|
|
55
|
+
next.value = {
|
|
56
|
+
...value,
|
|
57
|
+
expression: createAccessorExpression(this.createModelValueReadExpression(expression)),
|
|
58
|
+
};
|
|
59
|
+
return next;
|
|
60
|
+
}
|
|
61
|
+
if (!this.reactiveProps.has(propName)) {
|
|
62
|
+
return next;
|
|
63
|
+
}
|
|
64
|
+
if (!shouldWrapExpression(expression)) {
|
|
65
|
+
return next;
|
|
66
|
+
}
|
|
67
|
+
next.value = {
|
|
68
|
+
...value,
|
|
69
|
+
expression: createAccessorExpression(expression),
|
|
70
|
+
};
|
|
71
|
+
return next;
|
|
72
|
+
}
|
|
73
|
+
visitJSXExpressionContainer(node) {
|
|
74
|
+
const next = super.visitJSXExpressionContainer(node);
|
|
75
|
+
if (this.jsxAttributeDepth > 0) {
|
|
76
|
+
return next;
|
|
77
|
+
}
|
|
78
|
+
const expression = next.expression;
|
|
79
|
+
if (expression.type === "JSXEmptyExpression") {
|
|
80
|
+
return next;
|
|
81
|
+
}
|
|
82
|
+
if (this.shouldWrapModelExpression(expression)) {
|
|
83
|
+
return {
|
|
84
|
+
...next,
|
|
85
|
+
expression: createAccessorExpression(this.createModelValueReadExpression(expression)),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (!shouldWrapExpression(expression)) {
|
|
89
|
+
return next;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
...next,
|
|
93
|
+
expression: createAccessorExpression(expression),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
shouldWrapModelExpression(expression, propName) {
|
|
97
|
+
if (this.modelOptions === null) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (propName !== undefined && !shouldWrapModelAttribute(propName)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return isModelMemberExpression(expression, this.modelOptions.roots);
|
|
104
|
+
}
|
|
105
|
+
createModelValueReadExpression(expression) {
|
|
106
|
+
if (this.modelOptions === null) {
|
|
107
|
+
return expression;
|
|
108
|
+
}
|
|
109
|
+
this.modelValueReadHelperUsed = true;
|
|
110
|
+
return createCallExpression(createIdentifier(this.modelOptions.helper), expression);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitor.js","sourceRoot":"","sources":["../src/visitor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAS/C,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE5E;;GAEG;AACH,MAAM,OAAO,gCAAiC,SAAQ,OAAO;IAKxC;IACA;IALX,iBAAiB,GAAG,CAAC,CAAC;IACtB,wBAAwB,GAAG,KAAK,CAAC;IAEzC,YACmB,aAAkC,EAClC,YAA0D;QAE3E,KAAK,EAAE,CAAC;QAHS,kBAAa,GAAb,aAAa,CAAqB;QAClC,iBAAY,GAAZ,YAAY,CAA8C;IAG7E,CAAC;IAED;;;OAGG;IACH,gCAAgC;QAC9B,OAAO,IAAI,CAAC,wBAAwB,CA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AC,UAAsB;QAC3D,IAAI,IAAI,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;YAC/B,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC;QAErC,OAAO,oBAAoB,CACzB,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAC1C,UAAU,CACX,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin implementations for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import type { Plugin } from "vite";
|
|
5
|
+
import type { ReflexDOMTransformOptions, ReflexPluginOptions } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Creates the Reflex DOM JSX reactive props Vite plugin
|
|
8
|
+
* @param options - The DOM transform options
|
|
9
|
+
* @returns The Vite plugin
|
|
10
|
+
*/
|
|
11
|
+
export declare function reflexDOMVitePlugin(options?: ReflexDOMTransformOptions): Plugin;
|
|
12
|
+
/**
|
|
13
|
+
* Creates the Reflex JSX Vite plugin for esbuild configuration
|
|
14
|
+
* @param options - The plugin options
|
|
15
|
+
* @returns The Vite plugin
|
|
16
|
+
*/
|
|
17
|
+
export declare function reflexJSXVitePlugin(options?: ReflexPluginOptions): Plugin;
|
|
18
|
+
/**
|
|
19
|
+
* Creates the main Reflex Vite plugin
|
|
20
|
+
* @param options - The plugin options
|
|
21
|
+
* @returns An array of Vite plugins
|
|
22
|
+
*/
|
|
23
|
+
export declare function reflex(options?: ReflexPluginOptions): Plugin[];
|
|
24
|
+
//# sourceMappingURL=vite-plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugins.d.ts","sourceRoot":"","sources":["../src/vite-plugins.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EACV,yBAAyB,EACzB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAOjB;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAQR;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAY7E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,EAAE,CAWlE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin implementations for the Reflex Vite plugin
|
|
3
|
+
*/
|
|
4
|
+
import { normalizeDOMPluginOptions, createJSXEsbuildOptions, } from "./normalize-options";
|
|
5
|
+
import { transformReflexDOMJSX } from "./transform";
|
|
6
|
+
/**
|
|
7
|
+
* Creates the Reflex DOM JSX reactive props Vite plugin
|
|
8
|
+
* @param options - The DOM transform options
|
|
9
|
+
* @returns The Vite plugin
|
|
10
|
+
*/
|
|
11
|
+
export function reflexDOMVitePlugin(options = {}) {
|
|
12
|
+
return {
|
|
13
|
+
name: "reflex-dom-jsx-reactive-props",
|
|
14
|
+
enforce: "pre",
|
|
15
|
+
transform(code, id) {
|
|
16
|
+
return transformReflexDOMJSX(code, id, options);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates the Reflex JSX Vite plugin for esbuild configuration
|
|
22
|
+
* @param options - The plugin options
|
|
23
|
+
* @returns The Vite plugin
|
|
24
|
+
*/
|
|
25
|
+
export function reflexJSXVitePlugin(options = {}) {
|
|
26
|
+
return {
|
|
27
|
+
name: "reflex-jsx",
|
|
28
|
+
config() {
|
|
29
|
+
return {
|
|
30
|
+
esbuild: createJSXEsbuildOptions(options.jsxRuntime, options.jsxImportSource),
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates the main Reflex Vite plugin
|
|
37
|
+
* @param options - The plugin options
|
|
38
|
+
* @returns An array of Vite plugins
|
|
39
|
+
*/
|
|
40
|
+
export function reflex(options = {}) {
|
|
41
|
+
const plugins = [];
|
|
42
|
+
const domOptions = normalizeDOMPluginOptions(options.dom);
|
|
43
|
+
if (domOptions !== null) {
|
|
44
|
+
plugins.push(reflexDOMVitePlugin(domOptions));
|
|
45
|
+
}
|
|
46
|
+
plugins.push(reflexJSXVitePlugin(options));
|
|
47
|
+
return plugins;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=vite-plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugins.js","sourceRoot":"","sources":["../src/vite-plugins.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAqC,EAAE;IAEvC,OAAO;QACL,IAAI,EAAE,+BAA+B;QACrC,OAAO,EAAE,KAAK;QACd,SAAS,CAAC,IAAI,EAAE,EAAE;YAChB,OAAO,qBAAqB,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA+B,EAAE;IACnE,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,MAAM;YACJ,OAAO;gBACL,OAAO,EAAE,uBAAuB,CAC9B,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,eAAe,CACxB;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,UAA+B,EAAE;IACtD,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,UAAU,GAAG,yBAAyB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAE1D,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;IAE3C,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@volynets/reflex-vite-plugin",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "The default Vite plugin for Reflex projects",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"reflex",
|
|
7
|
+
"vite",
|
|
8
|
+
"vite-plugin",
|
|
9
|
+
"jsx"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/volynetstyle/Reflex/tree/main/plugins/@vite/reflex-vite-plugin#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/volynetstyle/Reflex/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Andrii Volynets",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/volynetstyle/Reflex.git",
|
|
20
|
+
"directory": "plugins/@vite/reflex-vite-plugin"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"source": {
|
|
32
|
+
"types": "./src/index.ts",
|
|
33
|
+
"default": "./src/index.ts"
|
|
34
|
+
},
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
41
|
+
"build": "pnpm clean && tsc -p tsconfig.json",
|
|
42
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
43
|
+
"prepublishOnly": "pnpm typecheck && pnpm build"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@swc/core": "^1.15.18"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"vite": "^6.0.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"vite": "^6.0.0"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=20.19.0"
|
|
56
|
+
}
|
|
57
|
+
}
|