@esportsplus/reactivity 0.24.4 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -1,17 +1,12 @@
1
1
  import { COMPUTED, SIGNAL, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_RECOMPUTING } from './constants';
2
2
  import { ReactiveArray, ReactiveObject } from './reactive';
3
+ import { ts } from '@esportsplus/typescript';
3
4
 
4
5
 
5
6
  type BindingType = 'array' | 'computed' | 'object' | 'signal';
6
7
 
7
8
  type Bindings = Map<string, BindingType>;
8
9
 
9
- interface Namespaces {
10
- array: string;
11
- constants: string;
12
- reactivity: string;
13
- }
14
-
15
10
  interface Computed<T> {
16
11
  cleanup: VoidFunction | VoidFunction[] | null;
17
12
  deps: Link | null;
@@ -48,14 +43,20 @@ type Signal<T> = {
48
43
  value: T;
49
44
  };
50
45
 
46
+ interface TransformResult {
47
+ code: string;
48
+ sourceFile: ts.SourceFile;
49
+ transformed: boolean;
50
+ }
51
+
51
52
 
52
53
  export type {
53
54
  BindingType,
54
55
  Bindings,
55
56
  Computed,
56
57
  Link,
57
- Namespaces,
58
58
  ReactiveArray,
59
59
  ReactiveObject,
60
- Signal
60
+ Signal,
61
+ TransformResult
61
62
  };
@@ -1,6 +1,6 @@
1
1
  import { resolve } from 'path';
2
2
  import { defineConfig } from 'vite';
3
- import reactivity from '../build/transformer/plugins/vite.js';
3
+ import { plugin as reactivity } from '../build/plugins/vite.js';
4
4
 
5
5
 
6
6
  export default defineConfig({
@@ -1,13 +0,0 @@
1
- import { ts } from '@esportsplus/typescript';
2
- declare function createReadCall(factory: ts.NodeFactory, ns: string, expr: ts.Expression): ts.CallExpression;
3
- declare function createSetCall(factory: ts.NodeFactory, ns: string, target: ts.Expression, value: ts.Expression): ts.CallExpression;
4
- declare function createSignalCall(factory: ts.NodeFactory, ns: string, initialValue: ts.Expression): ts.CallExpression;
5
- declare function createComputedCall(factory: ts.NodeFactory, ns: string, fn: ts.Expression): ts.CallExpression;
6
- declare function createArrayLengthCall(factory: ts.NodeFactory, arrayExpr: ts.Expression): ts.CallExpression;
7
- declare function createArraySetCall(factory: ts.NodeFactory, arrayExpr: ts.Expression, index: ts.Expression, value: ts.Expression): ts.CallExpression;
8
- declare function createReactiveArrayNew(factory: ts.NodeFactory, ns: string, elements: ts.Expression[]): ts.NewExpression;
9
- declare function createDisposeCall(factory: ts.NodeFactory, ns: string, expr: ts.Expression): ts.CallExpression;
10
- declare function createBinaryExpr(factory: ts.NodeFactory, left: ts.Expression, op: ts.BinaryOperator, right: ts.Expression): ts.BinaryExpression;
11
- declare function createCommaExpr(factory: ts.NodeFactory, first: ts.Expression, second: ts.Expression): ts.ParenthesizedExpression;
12
- declare function createPostfixIncrementExpr(factory: ts.NodeFactory, ns: string, tmpName: string, signalName: string, op: ts.SyntaxKind.PlusToken | ts.SyntaxKind.MinusToken): ts.CallExpression;
13
- export { createArrayLengthCall, createArraySetCall, createBinaryExpr, createCommaExpr, createComputedCall, createDisposeCall, createPostfixIncrementExpr, createReactiveArrayNew, createReadCall, createSetCall, createSignalCall };
@@ -1,36 +0,0 @@
1
- import { ts } from '@esportsplus/typescript';
2
- function createReadCall(factory, ns, expr) {
3
- return factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'read'), undefined, [expr]);
4
- }
5
- function createSetCall(factory, ns, target, value) {
6
- return factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'set'), undefined, [target, value]);
7
- }
8
- function createSignalCall(factory, ns, initialValue) {
9
- return factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'signal'), undefined, [initialValue]);
10
- }
11
- function createComputedCall(factory, ns, fn) {
12
- return factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'computed'), undefined, [fn]);
13
- }
14
- function createArrayLengthCall(factory, arrayExpr) {
15
- return factory.createCallExpression(factory.createPropertyAccessExpression(arrayExpr, '$length'), undefined, []);
16
- }
17
- function createArraySetCall(factory, arrayExpr, index, value) {
18
- return factory.createCallExpression(factory.createPropertyAccessExpression(arrayExpr, '$set'), undefined, [index, value]);
19
- }
20
- function createReactiveArrayNew(factory, ns, elements) {
21
- return factory.createNewExpression(factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'ReactiveArray'), undefined, elements);
22
- }
23
- function createDisposeCall(factory, ns, expr) {
24
- return factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'dispose'), undefined, [expr]);
25
- }
26
- function createBinaryExpr(factory, left, op, right) {
27
- return factory.createBinaryExpression(left, op, right);
28
- }
29
- function createCommaExpr(factory, first, second) {
30
- return factory.createParenthesizedExpression(factory.createBinaryExpression(first, ts.SyntaxKind.CommaToken, second));
31
- }
32
- function createPostfixIncrementExpr(factory, ns, tmpName, signalName, op) {
33
- let tmpIdent = factory.createIdentifier(tmpName), signalIdent = factory.createIdentifier(signalName);
34
- return factory.createCallExpression(factory.createParenthesizedExpression(factory.createArrowFunction(undefined, undefined, [factory.createParameterDeclaration(undefined, undefined, tmpIdent)], undefined, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), createCommaExpr(factory, createSetCall(factory, ns, signalIdent, factory.createBinaryExpression(tmpIdent, op, factory.createNumericLiteral(1))), tmpIdent))), undefined, [factory.createPropertyAccessExpression(signalIdent, 'value')]);
35
- }
36
- export { createArrayLengthCall, createArraySetCall, createBinaryExpr, createCommaExpr, createComputedCall, createDisposeCall, createPostfixIncrementExpr, createReactiveArrayNew, createReadCall, createSetCall, createSignalCall };
@@ -1,141 +0,0 @@
1
- import { ts } from '@esportsplus/typescript';
2
-
3
-
4
- // Create: ns.read(expr)
5
- function createReadCall(factory: ts.NodeFactory, ns: string, expr: ts.Expression): ts.CallExpression {
6
- return factory.createCallExpression(
7
- factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'read'),
8
- undefined,
9
- [expr]
10
- );
11
- }
12
-
13
- // Create: ns.set(target, value)
14
- function createSetCall(factory: ts.NodeFactory, ns: string, target: ts.Expression, value: ts.Expression): ts.CallExpression {
15
- return factory.createCallExpression(
16
- factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'set'),
17
- undefined,
18
- [target, value]
19
- );
20
- }
21
-
22
- // Create: ns.signal(initialValue)
23
- function createSignalCall(factory: ts.NodeFactory, ns: string, initialValue: ts.Expression): ts.CallExpression {
24
- return factory.createCallExpression(
25
- factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'signal'),
26
- undefined,
27
- [initialValue]
28
- );
29
- }
30
-
31
- // Create: ns.computed(fn)
32
- function createComputedCall(factory: ts.NodeFactory, ns: string, fn: ts.Expression): ts.CallExpression {
33
- return factory.createCallExpression(
34
- factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'computed'),
35
- undefined,
36
- [fn]
37
- );
38
- }
39
-
40
- // Create: arr.$length()
41
- function createArrayLengthCall(factory: ts.NodeFactory, arrayExpr: ts.Expression): ts.CallExpression {
42
- return factory.createCallExpression(
43
- factory.createPropertyAccessExpression(arrayExpr, '$length'),
44
- undefined,
45
- []
46
- );
47
- }
48
-
49
- // Create: arr.$set(index, value)
50
- function createArraySetCall(factory: ts.NodeFactory, arrayExpr: ts.Expression, index: ts.Expression, value: ts.Expression): ts.CallExpression {
51
- return factory.createCallExpression(
52
- factory.createPropertyAccessExpression(arrayExpr, '$set'),
53
- undefined,
54
- [index, value]
55
- );
56
- }
57
-
58
- // Create: new ns.ReactiveArray(elements...)
59
- function createReactiveArrayNew(factory: ts.NodeFactory, ns: string, elements: ts.Expression[]): ts.NewExpression {
60
- return factory.createNewExpression(
61
- factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'ReactiveArray'),
62
- undefined,
63
- elements
64
- );
65
- }
66
-
67
- // Create: ns.dispose(expr)
68
- function createDisposeCall(factory: ts.NodeFactory, ns: string, expr: ts.Expression): ts.CallExpression {
69
- return factory.createCallExpression(
70
- factory.createPropertyAccessExpression(factory.createIdentifier(ns), 'dispose'),
71
- undefined,
72
- [expr]
73
- );
74
- }
75
-
76
- // Create binary expression: left op right
77
- function createBinaryExpr(factory: ts.NodeFactory, left: ts.Expression, op: ts.BinaryOperator, right: ts.Expression): ts.BinaryExpression {
78
- return factory.createBinaryExpression(left, op, right);
79
- }
80
-
81
- // Create: (expr1, expr2) - comma expression
82
- function createCommaExpr(factory: ts.NodeFactory, first: ts.Expression, second: ts.Expression): ts.ParenthesizedExpression {
83
- return factory.createParenthesizedExpression(
84
- factory.createBinaryExpression(first, ts.SyntaxKind.CommaToken, second)
85
- );
86
- }
87
-
88
- // Create: ((tmp) => (ns.set(name, tmp op delta), tmp))(name.value)
89
- function createPostfixIncrementExpr(
90
- factory: ts.NodeFactory,
91
- ns: string,
92
- tmpName: string,
93
- signalName: string,
94
- op: ts.SyntaxKind.PlusToken | ts.SyntaxKind.MinusToken
95
- ): ts.CallExpression {
96
- let tmpIdent = factory.createIdentifier(tmpName),
97
- signalIdent = factory.createIdentifier(signalName);
98
-
99
- return factory.createCallExpression(
100
- factory.createParenthesizedExpression(
101
- factory.createArrowFunction(
102
- undefined,
103
- undefined,
104
- [factory.createParameterDeclaration(undefined, undefined, tmpIdent)],
105
- undefined,
106
- factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
107
- createCommaExpr(
108
- factory,
109
- createSetCall(
110
- factory,
111
- ns,
112
- signalIdent,
113
- factory.createBinaryExpression(
114
- tmpIdent,
115
- op,
116
- factory.createNumericLiteral(1)
117
- )
118
- ),
119
- tmpIdent
120
- )
121
- )
122
- ),
123
- undefined,
124
- [factory.createPropertyAccessExpression(signalIdent, 'value')]
125
- );
126
- }
127
-
128
-
129
- export {
130
- createArrayLengthCall,
131
- createArraySetCall,
132
- createBinaryExpr,
133
- createCommaExpr,
134
- createComputedCall,
135
- createDisposeCall,
136
- createPostfixIncrementExpr,
137
- createReactiveArrayNew,
138
- createReadCall,
139
- createSetCall,
140
- createSignalCall
141
- };