@esportsplus/reactivity 0.33.0 → 0.34.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.
@@ -1,5 +1,5 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
2
  import type { ReplacementIntent } from '@esportsplus/typescript/compiler';
3
3
  import type { Bindings } from './types.js';
4
- declare const _default: (sourceFile: ts.SourceFile, bindings: Bindings, checker?: ts.TypeChecker) => ReplacementIntent[];
5
4
  export default _default;
5
+ declare function _default(sourceFile: ts.SourceFile, bindings: Bindings, checker?: ts.Checker): ReplacementIntent[];
@@ -160,7 +160,7 @@ function visit(ctx, node) {
160
160
  node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
161
161
  ts.isIdentifier(node.left)) {
162
162
  let name = node.left.text, right = node.right;
163
- while (ts.isAsExpression(right) || ts.isTypeAssertionExpression(right)) {
163
+ while (ts.isAsExpression(right) || ts.isTypeAssertion(right)) {
164
164
  right = right.expression;
165
165
  }
166
166
  if (ctx.bindings.get(name) === TYPES.Array && ts.isArrayLiteralExpression(right)) {
@@ -172,7 +172,7 @@ function visit(ctx, node) {
172
172
  });
173
173
  }
174
174
  }
175
- ts.forEachChild(node, n => visit(ctx, n));
175
+ node.forEachChild(n => visit(ctx, n));
176
176
  }
177
177
  export default (sourceFile, bindings, checker) => {
178
178
  let ctx = {
@@ -27,7 +27,7 @@ function hasReactiveCalls(checker, node) {
27
27
  return true;
28
28
  }
29
29
  let found = false;
30
- ts.forEachChild(node, child => {
30
+ node.forEachChild(child => {
31
31
  if (!found && hasReactiveCalls(checker, child)) {
32
32
  found = true;
33
33
  }
@@ -41,7 +41,7 @@ function visit(ctx, node) {
41
41
  node
42
42
  });
43
43
  }
44
- ts.forEachChild(node, n => visit(ctx, n));
44
+ node.forEachChild(n => visit(ctx, n));
45
45
  }
46
46
  export default {
47
47
  patterns: ['reactive(', 'reactive<'],
@@ -5,5 +5,5 @@ type ObjectTransformResult = {
5
5
  prepend: string[];
6
6
  replacements: ReplacementIntent[];
7
7
  };
8
- declare const _default: (sourceFile: ts.SourceFile, bindings: Bindings, checker?: ts.TypeChecker) => ObjectTransformResult;
9
8
  export default _default;
9
+ declare function _default(sourceFile: ts.SourceFile, bindings: Bindings, checker?: ts.Checker): ObjectTransformResult;
@@ -13,10 +13,10 @@ function analyzeProperty(prop, sourceFile) {
13
13
  return null;
14
14
  }
15
15
  let unwrapped = prop.initializer, value = unwrapped, valueText = value.getText(sourceFile);
16
- while (ts.isAsExpression(unwrapped) || ts.isTypeAssertionExpression(unwrapped) || ts.isParenthesizedExpression(unwrapped)) {
16
+ while (ts.isAsExpression(unwrapped) || ts.isTypeAssertion(unwrapped) || ts.isParenthesizedExpression(unwrapped)) {
17
17
  unwrapped = unwrapped.expression;
18
18
  }
19
- if (ts.isAsExpression(value) || ts.isTypeAssertionExpression(value)) {
19
+ if (ts.isAsExpression(value) || ts.isTypeAssertion(value)) {
20
20
  let type = value.type;
21
21
  if (ts.isArrayTypeNode(type) ||
22
22
  (ts.isTypeReferenceNode(type) &&
@@ -161,12 +161,12 @@ function visit(ctx, node) {
161
161
  for (let i = 0, n = props.length; i < n; i++) {
162
162
  let prop = props[i];
163
163
  if (ts.isSpreadAssignment(prop)) {
164
- ts.forEachChild(node, n => visit(ctx, n));
164
+ node.forEachChild(n => visit(ctx, n));
165
165
  return;
166
166
  }
167
167
  let analyzed = analyzeProperty(prop, ctx.sourceFile);
168
168
  if (!analyzed) {
169
- ts.forEachChild(node, n => visit(ctx, n));
169
+ node.forEachChild(n => visit(ctx, n));
170
170
  return;
171
171
  }
172
172
  properties.push(analyzed);
@@ -183,7 +183,7 @@ function visit(ctx, node) {
183
183
  });
184
184
  }
185
185
  }
186
- ts.forEachChild(node, n => visit(ctx, n));
186
+ node.forEachChild(n => visit(ctx, n));
187
187
  }
188
188
  export default (sourceFile, bindings, checker) => {
189
189
  let ctx = {
@@ -1,12 +1,14 @@
1
1
  declare const _default: ({ root }?: {
2
2
  root?: string;
3
3
  }) => {
4
+ closeBundle: () => void;
5
+ closeWatcher: () => void;
4
6
  configResolved: (config: unknown) => void;
5
- enforce: "pre";
7
+ enforce: 'pre';
6
8
  name: string;
7
9
  transform: (code: string, id: string) => {
8
10
  code: string;
9
- map: null;
11
+ map: import("@esportsplus/typescript/compiler").SourceMapV3;
10
12
  } | null;
11
13
  watchChange: (id: string) => void;
12
14
  };
@@ -1,5 +1,5 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
2
  import type { ReplacementIntent } from '@esportsplus/typescript/compiler';
3
3
  import type { Bindings } from './types.js';
4
- declare const _default: (sourceFile: ts.SourceFile, bindings: Bindings, isReactiveCall: (node: ts.Node) => boolean) => ReplacementIntent[];
5
4
  export default _default;
5
+ declare function _default(sourceFile: ts.SourceFile, bindings: Bindings, isReactiveCall: (node: ts.Node) => boolean): ReplacementIntent[];
@@ -37,7 +37,7 @@ function visit(ctx, node) {
37
37
  }
38
38
  else {
39
39
  let unwrapped = arg;
40
- while (ts.isAsExpression(unwrapped) || ts.isParenthesizedExpression(unwrapped) || ts.isTypeAssertionExpression(unwrapped)) {
40
+ while (ts.isAsExpression(unwrapped) || ts.isParenthesizedExpression(unwrapped) || ts.isTypeAssertion(unwrapped)) {
41
41
  unwrapped = unwrapped.expression;
42
42
  }
43
43
  if (ts.isArrayLiteralExpression(unwrapped) || ts.isObjectLiteralExpression(unwrapped)) {
@@ -48,7 +48,7 @@ function visit(ctx, node) {
48
48
  generate: () => `${NAMESPACE}.reactive`,
49
49
  node: call.expression
50
50
  });
51
- ts.forEachChild(node, n => visit(ctx, n));
51
+ node.forEachChild(n => visit(ctx, n));
52
52
  return;
53
53
  }
54
54
  }
@@ -97,7 +97,7 @@ function visit(ctx, node) {
97
97
  node.parent &&
98
98
  !(ts.isVariableDeclaration(node.parent) && node.parent.name === node)) {
99
99
  if (ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) {
100
- ts.forEachChild(node, n => visit(ctx, n));
100
+ node.forEachChild(n => visit(ctx, n));
101
101
  return;
102
102
  }
103
103
  let bindings = ctx.scopedBindings, binding, name = node.text;
@@ -178,7 +178,7 @@ function visit(ctx, node) {
178
178
  }
179
179
  }
180
180
  }
181
- ts.forEachChild(node, n => visit(ctx, n));
181
+ node.forEachChild(n => visit(ctx, n));
182
182
  }
183
183
  export default (sourceFile, bindings, isReactiveCall) => {
184
184
  let ctx = {
package/build/system.d.ts CHANGED
@@ -1,25 +1,25 @@
1
1
  import { Computed, ComputedResult, Settled, Signal } from './types.js';
2
2
  declare const batch: <T>(fn: () => T) => T;
3
- declare const computed: {
4
- <T>(fn: Computed<T>["fn"], equals?: ((a: Settled<T>, b: Settled<T>) => boolean) | null): ComputedResult<T>;
5
- invalidate<T>(c: Computed<T>): void;
6
- };
3
+ declare function computed<T>(fn: Computed<T>['fn'], equals?: ((a: Settled<T>, b: Settled<T>) => boolean) | null): ComputedResult<T>;
4
+ declare namespace computed {
5
+ var invalidate: <T>(c: Computed<T>) => void;
6
+ }
7
7
  declare const dispose: <T>(computed: Computed<T>) => void;
8
- declare const effect: <T>(fn: Computed<T>["fn"], apply?: (value: T, prev: T | undefined) => void) => () => void;
8
+ declare const effect: <T>(fn: Computed<T>['fn'], apply?: (value: T, prev: T | undefined) => void) => () => void;
9
9
  declare const flush: () => void;
10
10
  declare const isComputed: (value: unknown) => value is Computed<unknown>;
11
11
  declare const isSignal: (value: unknown) => value is Signal<unknown>;
12
12
  declare const onCleanup: (fn: VoidFunction) => typeof fn;
13
13
  declare const peek: <T>(node: Signal<T> | Computed<T>) => T;
14
14
  declare const read: <T>(node: Signal<T> | Computed<T>) => T;
15
- declare const root: {
16
- <T>(fn: ((dispose: VoidFunction) => T) | (() => T)): T;
17
- disposables: number;
18
- };
19
- declare const signal: {
20
- <T>(value: T, equals?: ((a: T, b: T) => boolean) | null): Signal<T>;
21
- selector<T>(node: Signal<T>, key: T): boolean;
22
- };
15
+ declare function root<T>(fn: ((dispose: VoidFunction) => T) | (() => T)): T;
16
+ declare namespace root {
17
+ var disposables: number;
18
+ }
19
+ declare function signal<T>(value: T, equals?: ((a: T, b: T) => boolean) | null): Signal<T>;
20
+ declare namespace signal {
21
+ var selector: <T>(node: Signal<T>, key: T) => boolean;
22
+ }
23
23
  declare const untrack: <T>(fn: () => T) => T;
24
24
  declare const write: <T>(signal: Signal<T>, value: T) => void;
25
25
  export { batch, computed, dispose, effect, flush, isComputed, isSignal, onCleanup, peek, read, root, signal, untrack, write };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "@esportsplus/utilities": "^0.28.0"
5
5
  },
6
6
  "devDependencies": {
7
- "@esportsplus/typescript": "^0.29.5",
7
+ "@esportsplus/typescript": "^0.31.0",
8
8
  "@types/node": "^26.1.1",
9
9
  "vite": "^8.1.5",
10
10
  "vitest": "^4.1.10"
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "type": "module",
38
38
  "types": "build/index.d.ts",
39
- "version": "0.33.0",
39
+ "version": "0.34.0",
40
40
  "scripts": {
41
41
  "agent:bench": "vitest bench --run",
42
42
  "agent:test": "tsc --noEmit && vitest run",
@@ -1,2 +1,4 @@
1
1
  allowBuilds:
2
2
  esbuild: true
3
+ minimumReleaseAgeExclude:
4
+ - '@esportsplus/typescript@0.31.0'
@@ -7,13 +7,13 @@ import type { Bindings } from './types';
7
7
 
8
8
  type VisitContext = {
9
9
  bindings: Bindings;
10
- checker: ts.TypeChecker | undefined;
10
+ checker: ts.Checker | undefined;
11
11
  replacements: ReplacementIntent[];
12
12
  sourceFile: ts.SourceFile;
13
13
  };
14
14
 
15
15
 
16
- function isReactiveCall(checker: ts.TypeChecker | undefined, node: ts.Node): node is ts.CallExpression {
16
+ function isReactiveCall(checker: ts.Checker | undefined, node: ts.Node): node is ts.CallExpression {
17
17
  if (!ts.isCallExpression(node) || !ts.isIdentifier(node.expression)) {
18
18
  return false;
19
19
  }
@@ -220,7 +220,7 @@ function visit(ctx: VisitContext, node: ts.Node): void {
220
220
  right = node.right;
221
221
 
222
222
  // Unwrap "as" expressions: arr = [] as Type[]
223
- while (ts.isAsExpression(right) || ts.isTypeAssertionExpression(right)) {
223
+ while (ts.isAsExpression(right) || ts.isTypeAssertion(right)) {
224
224
  right = right.expression;
225
225
  }
226
226
 
@@ -234,11 +234,11 @@ function visit(ctx: VisitContext, node: ts.Node): void {
234
234
  }
235
235
  }
236
236
 
237
- ts.forEachChild(node, n => visit(ctx, n));
237
+ node.forEachChild(n => visit(ctx, n));
238
238
  }
239
239
 
240
240
 
241
- export default (sourceFile: ts.SourceFile, bindings: Bindings, checker?: ts.TypeChecker): ReplacementIntent[] => {
241
+ export default (sourceFile: ts.SourceFile, bindings: Bindings, checker?: ts.Checker): ReplacementIntent[] => {
242
242
  let ctx: VisitContext = {
243
243
  bindings,
244
244
  checker,
@@ -10,7 +10,7 @@ import primitives from './primitives';
10
10
 
11
11
 
12
12
  type FindRemainingContext = {
13
- checker: ts.TypeChecker;
13
+ checker: ts.Checker;
14
14
  replacements: ReplacementIntent[];
15
15
  sourceFile: ts.SourceFile;
16
16
  transformedNodes: Set<ts.Node>;
@@ -18,7 +18,7 @@ type FindRemainingContext = {
18
18
 
19
19
 
20
20
  function findRemainingCalls(
21
- checker: ts.TypeChecker,
21
+ checker: ts.Checker,
22
22
  sourceFile: ts.SourceFile,
23
23
  transformedNodes: Set<ts.Node>
24
24
  ): ReplacementIntent[] {
@@ -29,7 +29,7 @@ function findRemainingCalls(
29
29
  return ctx.replacements;
30
30
  }
31
31
 
32
- function isReactiveCallExpression(checker: ts.TypeChecker, node: ts.Node): node is ts.CallExpression {
32
+ function isReactiveCallExpression(checker: ts.Checker, node: ts.Node): node is ts.CallExpression {
33
33
  if (!ts.isCallExpression(node)) {
34
34
  return false;
35
35
  }
@@ -49,14 +49,14 @@ function isReactiveCallExpression(checker: ts.TypeChecker, node: ts.Node): node
49
49
  return false;
50
50
  }
51
51
 
52
- function hasReactiveCalls(checker: ts.TypeChecker, node: ts.Node): boolean {
52
+ function hasReactiveCalls(checker: ts.Checker, node: ts.Node): boolean {
53
53
  if (isReactiveCallExpression(checker, node)) {
54
54
  return true;
55
55
  }
56
56
 
57
57
  let found = false;
58
58
 
59
- ts.forEachChild(node, child => {
59
+ node.forEachChild(child => {
60
60
  if (!found && hasReactiveCalls(checker, child)) {
61
61
  found = true;
62
62
  }
@@ -73,7 +73,7 @@ function visit(ctx: FindRemainingContext, node: ts.Node): void {
73
73
  });
74
74
  }
75
75
 
76
- ts.forEachChild(node, n => visit(ctx, n));
76
+ node.forEachChild(n => visit(ctx, n));
77
77
  }
78
78
 
79
79
 
@@ -28,7 +28,7 @@ interface ReactiveObjectCall {
28
28
  interface VisitContext {
29
29
  bindings: Bindings;
30
30
  calls: ReactiveObjectCall[];
31
- checker: ts.TypeChecker | undefined;
31
+ checker: ts.Checker | undefined;
32
32
  sourceFile: ts.SourceFile;
33
33
  }
34
34
 
@@ -51,11 +51,11 @@ function analyzeProperty(prop: ts.ObjectLiteralElementLike, sourceFile: ts.Sourc
51
51
  value = unwrapped,
52
52
  valueText = value.getText(sourceFile);
53
53
 
54
- while (ts.isAsExpression(unwrapped) || ts.isTypeAssertionExpression(unwrapped) || ts.isParenthesizedExpression(unwrapped)) {
54
+ while (ts.isAsExpression(unwrapped) || ts.isTypeAssertion(unwrapped) || ts.isParenthesizedExpression(unwrapped)) {
55
55
  unwrapped = unwrapped.expression;
56
56
  }
57
57
 
58
- if (ts.isAsExpression(value) || ts.isTypeAssertionExpression(value)) {
58
+ if (ts.isAsExpression(value) || ts.isTypeAssertion(value)) {
59
59
  let type = (value as ts.AsExpression).type;
60
60
 
61
61
  if (
@@ -216,7 +216,7 @@ function isStaticValue(node: ts.Node): boolean {
216
216
  (ts.isPrefixUnaryExpression(node) && ts.isNumericLiteral(node.operand));
217
217
  }
218
218
 
219
- function isReactiveCall(checker: ts.TypeChecker | undefined, node: ts.Node): node is ts.CallExpression {
219
+ function isReactiveCall(checker: ts.Checker | undefined, node: ts.Node): node is ts.CallExpression {
220
220
  if (!ts.isCallExpression(node) || !ts.isIdentifier(node.expression)) {
221
221
  return false;
222
222
  }
@@ -250,14 +250,14 @@ function visit(ctx: VisitContext, node: ts.Node): void {
250
250
  let prop = props[i];
251
251
 
252
252
  if (ts.isSpreadAssignment(prop)) {
253
- ts.forEachChild(node, n => visit(ctx, n));
253
+ node.forEachChild(n => visit(ctx, n));
254
254
  return;
255
255
  }
256
256
 
257
257
  let analyzed = analyzeProperty(prop, ctx.sourceFile);
258
258
 
259
259
  if (!analyzed) {
260
- ts.forEachChild(node, n => visit(ctx, n));
260
+ node.forEachChild(n => visit(ctx, n));
261
261
  return;
262
262
  }
263
263
 
@@ -278,11 +278,11 @@ function visit(ctx: VisitContext, node: ts.Node): void {
278
278
  }
279
279
  }
280
280
 
281
- ts.forEachChild(node, n => visit(ctx, n));
281
+ node.forEachChild(n => visit(ctx, n));
282
282
  }
283
283
 
284
284
 
285
- export default (sourceFile: ts.SourceFile, bindings: Bindings, checker?: ts.TypeChecker): ObjectTransformResult => {
285
+ export default (sourceFile: ts.SourceFile, bindings: Bindings, checker?: ts.Checker): ObjectTransformResult => {
286
286
  let ctx: VisitContext = {
287
287
  bindings,
288
288
  calls: [],
@@ -67,7 +67,7 @@ function visit(ctx: TransformContext, node: ts.Node): void {
67
67
  else {
68
68
  let unwrapped = arg;
69
69
 
70
- while (ts.isAsExpression(unwrapped) || ts.isParenthesizedExpression(unwrapped) || ts.isTypeAssertionExpression(unwrapped)) {
70
+ while (ts.isAsExpression(unwrapped) || ts.isParenthesizedExpression(unwrapped) || ts.isTypeAssertion(unwrapped)) {
71
71
  unwrapped = unwrapped.expression;
72
72
  }
73
73
 
@@ -80,7 +80,7 @@ function visit(ctx: TransformContext, node: ts.Node): void {
80
80
  generate: () => `${NAMESPACE}.reactive`,
81
81
  node: call.expression
82
82
  });
83
- ts.forEachChild(node, n => visit(ctx, n));
83
+ node.forEachChild(n => visit(ctx, n));
84
84
  return;
85
85
  }
86
86
  }
@@ -148,7 +148,7 @@ function visit(ctx: TransformContext, node: ts.Node): void {
148
148
  !(ts.isVariableDeclaration(node.parent) && node.parent.name === node)
149
149
  ) {
150
150
  if (ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) {
151
- ts.forEachChild(node, n => visit(ctx, n));
151
+ node.forEachChild(n => visit(ctx, n));
152
152
  return;
153
153
  }
154
154
 
@@ -251,7 +251,7 @@ function visit(ctx: TransformContext, node: ts.Node): void {
251
251
  }
252
252
  }
253
253
 
254
- ts.forEachChild(node, n => visit(ctx, n));
254
+ node.forEachChild(n => visit(ctx, n));
255
255
  }
256
256
 
257
257
 
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import { ts } from '@esportsplus/typescript';
3
+ import { languageService } from '@esportsplus/typescript/compiler';
3
4
  import type { ReplacementIntent } from '@esportsplus/typescript/compiler';
4
5
  import { NAMESPACE } from '~/compiler/constants';
5
6
  import type { Bindings } from '~/compiler/types';
@@ -30,7 +31,7 @@ function isReactiveCall(node: ts.Node): boolean {
30
31
  }
31
32
 
32
33
  function parse(code: string): ts.SourceFile {
33
- return ts.createSourceFile('test.ts', code, ts.ScriptTarget.Latest, true);
34
+ return languageService.parse(process.cwd() + '/test.ts', code);
34
35
  }
35
36
 
36
37
  function transformPrimitives(code: string): { bindings: Bindings; output: string } {