@esportsplus/reactivity 0.37.2 → 0.38.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.
@@ -1,5 +1,12 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
2
  import type { ReplacementIntent } from '@esportsplus/typescript/compiler';
3
3
  import type { Bindings, IsReactiveCall } from './types.js';
4
+ import type { Failure } from './primitives.js';
5
+ type ArrayTransformResult = {
6
+ failures: Failure[];
7
+ namespaced: boolean;
8
+ reactive: ts.Expression[];
9
+ replacements: ReplacementIntent[];
10
+ };
4
11
  export default _default;
5
- declare function _default(sourceFile: ts.SourceFile, bindings: Bindings, isReactiveCall: IsReactiveCall): ReplacementIntent[];
12
+ declare function _default(sourceFile: ts.SourceFile, bindings: Bindings, isReactiveCall: IsReactiveCall): ArrayTransformResult;
@@ -1,6 +1,24 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { COMPOUND_OPERATORS, NAMESPACE, TYPES } from './constants.js';
2
+ import { COMPOUND_OPERATORS, NAMESPACE } from './constants.js';
3
3
  import scope from './bindings.js';
4
+ function collect(node, candidates) {
5
+ if (ts.isTypeNode(node)) {
6
+ return;
7
+ }
8
+ if (ts.isPropertyAccessExpression(node) && node.name.text === 'length') {
9
+ candidates.lengths.push(node);
10
+ }
11
+ else if (ts.isElementAccessExpression(node) && isWritten(node)) {
12
+ candidates.writes.push(node);
13
+ }
14
+ else if (ts.isBinaryExpression(node) &&
15
+ node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
16
+ ts.isIdentifier(node.left) &&
17
+ ts.isArrayLiteralExpression(scope.unwrap(node.right))) {
18
+ candidates.reassignments.push(node);
19
+ }
20
+ node.forEachChild(child => collect(child, candidates));
21
+ }
4
22
  function declare(ctx, node) {
5
23
  if (ctx.isReactiveCall(node) && node.arguments.length > 0) {
6
24
  let arg = node.arguments[0], expression = ts.isAsExpression(arg) ? arg.expression : arg;
@@ -12,9 +30,6 @@ function declare(ctx, node) {
12
30
  else if (node.parent && ts.isVariableDeclaration(node.parent) && node.parent.type) {
13
31
  elementType = getElementTypeText(node.parent.type, ctx.sourceFile);
14
32
  }
15
- if (node.parent && ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
16
- scope.declare(ctx.bindings, node.parent.name, TYPES.Array);
17
- }
18
33
  let typeParam = elementType ? `<${elementType}>` : '';
19
34
  ctx.replacements.push({
20
35
  node,
@@ -24,25 +39,6 @@ function declare(ctx, node) {
24
39
  });
25
40
  }
26
41
  }
27
- if (ts.isVariableDeclaration(node) &&
28
- ts.isIdentifier(node.name) &&
29
- node.initializer &&
30
- (ts.isIdentifier(node.initializer) || ts.isPropertyAccessExpression(node.initializer)) &&
31
- scope.isArray(ctx.bindings, node.initializer)) {
32
- scope.declare(ctx.bindings, node.name, TYPES.Array);
33
- }
34
- if ((ts.isFunctionDeclaration(node) || ts.isArrowFunction(node)) && node.parameters) {
35
- for (let i = 0, n = node.parameters.length; i < n; i++) {
36
- let param = node.parameters[i];
37
- if (ts.isIdentifier(param.name) &&
38
- param.type &&
39
- ts.isTypeReferenceNode(param.type) &&
40
- ts.isIdentifier(param.type.typeName) &&
41
- param.type.typeName.text === 'ReactiveArray') {
42
- scope.declare(ctx.bindings, param.name, TYPES.Array);
43
- }
44
- }
45
- }
46
42
  node.forEachChild(child => declare(ctx, child));
47
43
  }
48
44
  function getElementTypeText(typeNode, sourceFile) {
@@ -58,82 +54,104 @@ function getElementTypeText(typeNode, sourceFile) {
58
54
  }
59
55
  return null;
60
56
  }
61
- function rewrite(ctx, node) {
62
- if (ts.isTypeNode(node)) {
63
- return;
57
+ function isWritten(access) {
58
+ let parent = access.parent;
59
+ if (!parent) {
60
+ return false;
64
61
  }
65
- if (ts.isPropertyAccessExpression(node) && node.name.text === 'length' && scope.isArray(ctx.bindings, node.expression)) {
66
- let expr = node.expression, parent = node.parent;
67
- if (parent && ts.isBinaryExpression(parent) && parent.left === node && (parent.operatorToken.kind === ts.SyntaxKind.EqualsToken || COMPOUND_OPERATORS.has(parent.operatorToken.kind))) {
68
- let op = COMPOUND_OPERATORS.get(parent.operatorToken.kind);
69
- if (op === undefined) {
70
- ctx.replacements.push({
71
- node: parent,
72
- generate: (sf) => `${expr.getText(sf)}.$length = ${parent.right.getText(sf)}`
73
- });
74
- }
75
- else {
76
- ctx.replacements.push({
77
- node: parent,
78
- generate: (sf) => `${expr.getText(sf)}.$length = ${expr.getText(sf)}.length ${op} ${parent.right.getText(sf)}`
79
- });
80
- }
81
- }
82
- else if (parent && (ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent))) {
83
- let op = parent.operator === ts.SyntaxKind.PlusPlusToken ? '+' : '-';
84
- ctx.replacements.push({
85
- node: parent,
86
- generate: (sf) => `${expr.getText(sf)}.$length = ${expr.getText(sf)}.length ${op} 1`
87
- });
88
- }
89
- else {
90
- ctx.replacements.push({
91
- node,
92
- generate: (sf) => `${expr.getText(sf)}.$length`
93
- });
94
- }
62
+ if (ts.isBinaryExpression(parent)) {
63
+ let op = parent.operatorToken.kind;
64
+ return parent.left === access && (op === ts.SyntaxKind.EqualsToken || COMPOUND_OPERATORS.has(op));
95
65
  }
96
- if (ts.isBinaryExpression(node) &&
97
- node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
98
- ts.isElementAccessExpression(node.left) &&
99
- scope.isArray(ctx.bindings, node.left.expression)) {
100
- let element = node.left;
66
+ if (ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) {
67
+ return parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken;
68
+ }
69
+ return ts.isDeleteExpression(parent);
70
+ }
71
+ function length(access, replacements) {
72
+ let expr = access.expression, parent = access.parent;
73
+ if (parent && ts.isBinaryExpression(parent) && parent.left === access && (parent.operatorToken.kind === ts.SyntaxKind.EqualsToken || COMPOUND_OPERATORS.has(parent.operatorToken.kind))) {
74
+ let op = COMPOUND_OPERATORS.get(parent.operatorToken.kind);
75
+ replacements.push({
76
+ node: parent,
77
+ generate: (sf) => op === undefined
78
+ ? `${expr.getText(sf)}.$length = ${parent.right.getText(sf)}`
79
+ : `${expr.getText(sf)}.$length = ${expr.getText(sf)}.length ${op} ${parent.right.getText(sf)}`
80
+ });
81
+ }
82
+ else if (parent &&
83
+ (ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) &&
84
+ (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) {
85
+ let op = parent.operator === ts.SyntaxKind.PlusPlusToken ? '+' : '-';
86
+ replacements.push({
87
+ node: parent,
88
+ generate: (sf) => `${expr.getText(sf)}.$length = ${expr.getText(sf)}.length ${op} 1`
89
+ });
90
+ }
91
+ else {
92
+ replacements.push({
93
+ node: access,
94
+ generate: (sf) => `${expr.getText(sf)}.$length`
95
+ });
96
+ }
97
+ }
98
+ function write(access, ctx) {
99
+ let parent = access.parent, array = (sf) => access.expression.getText(sf), index = (sf) => access.argumentExpression.getText(sf);
100
+ if (ts.isDeleteExpression(parent)) {
101
+ ctx.failures.push({ message: 'an element of a reactive array cannot be deleted; use splice()', node: parent });
102
+ return;
103
+ }
104
+ if (ts.isBinaryExpression(parent)) {
105
+ let op = COMPOUND_OPERATORS.get(parent.operatorToken.kind), right = parent.right;
101
106
  ctx.replacements.push({
102
- node,
103
- generate: (sf) => `${element.expression.getText(sf)}.$set(
104
- ${element.argumentExpression.getText(sf)},
105
- ${node.right.getText(sf)}
106
- )`
107
+ node: parent,
108
+ generate: (sf) => op === undefined
109
+ ? `${array(sf)}.$set(${index(sf)}, ${right.getText(sf)})`
110
+ : `((_a, _k) => _a.$set(_k, _a[_k] ${op} (${right.getText(sf)})))(${array(sf)}, ${index(sf)})`
107
111
  });
112
+ return;
108
113
  }
109
- if (ts.isBinaryExpression(node) &&
110
- node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
111
- ts.isIdentifier(node.left) &&
112
- scope.isArray(ctx.bindings, node.left)) {
113
- let name = node.left.text, right = node.right;
114
- while (ts.isAsExpression(right) || ts.isTypeAssertion(right)) {
115
- right = right.expression;
114
+ let unary = parent, op = unary.operator === ts.SyntaxKind.PlusPlusToken ? '+' : '-';
115
+ ctx.replacements.push({
116
+ node: unary,
117
+ generate: (sf) => ts.isPrefixUnaryExpression(unary)
118
+ ? `((_a, _k) => (_a.$set(_k, _a[_k] ${op} 1), _a[_k]))(${array(sf)}, ${index(sf)})`
119
+ : `((_a, _k, _v) => (_a.$set(_k, _v ${op} 1), _v))(${array(sf)}, ${index(sf)}, ${array(sf)}[${index(sf)}])`
120
+ });
121
+ }
122
+ export default (sourceFile, bindings, isReactiveCall) => {
123
+ let candidates = { lengths: [], reassignments: [], writes: [] }, result = { failures: [], namespaced: false, reactive: [], replacements: [] };
124
+ declare({ isReactiveCall, replacements: result.replacements, sourceFile }, sourceFile);
125
+ result.namespaced = result.replacements.length > 0;
126
+ collect(sourceFile, candidates);
127
+ let reactive = scope.arrays(bindings, [
128
+ ...candidates.lengths.map(access => access.expression),
129
+ ...candidates.reassignments.map(assignment => assignment.left),
130
+ ...candidates.writes.map(access => access.expression)
131
+ ]);
132
+ result.reactive = [...reactive];
133
+ for (let i = 0, n = candidates.lengths.length; i < n; i++) {
134
+ if (reactive.has(candidates.lengths[i].expression)) {
135
+ length(candidates.lengths[i], result.replacements);
116
136
  }
117
- if (ts.isArrayLiteralExpression(right)) {
118
- let elements = right;
119
- ctx.replacements.push({
120
- node,
121
- generate: (sf) => elements.elements.length > 0
122
- ? `${name}.splice(0, ${name}.length, ...${elements.getText(sf)})`
123
- : `${name}.splice(0, ${name}.length)`
124
- });
137
+ }
138
+ for (let i = 0, n = candidates.writes.length; i < n; i++) {
139
+ if (reactive.has(candidates.writes[i].expression)) {
140
+ write(candidates.writes[i], result);
125
141
  }
126
142
  }
127
- node.forEachChild(child => rewrite(ctx, child));
128
- }
129
- export default (sourceFile, bindings, isReactiveCall) => {
130
- let ctx = {
131
- bindings,
132
- isReactiveCall,
133
- replacements: [],
134
- sourceFile
135
- };
136
- declare(ctx, sourceFile);
137
- rewrite(ctx, sourceFile);
138
- return ctx.replacements;
143
+ for (let i = 0, n = candidates.reassignments.length; i < n; i++) {
144
+ let assignment = candidates.reassignments[i];
145
+ if (!reactive.has(assignment.left) || isReactiveCall(scope.unwrap(assignment.right))) {
146
+ continue;
147
+ }
148
+ let name = assignment.left.text, elements = scope.unwrap(assignment.right);
149
+ result.replacements.push({
150
+ node: assignment,
151
+ generate: (sf) => elements.elements.length > 0
152
+ ? `${name}.splice(0, ${name}.length, ...${elements.getText(sf)})`
153
+ : `${name}.splice(0, ${name}.length)`
154
+ });
155
+ }
156
+ return result;
139
157
  };
@@ -1,19 +1,25 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
+ import type { Origin } from '@esportsplus/typescript/compiler';
2
3
  import { TYPES } from './constants.js';
3
4
  import type { Bindings } from './types.js';
4
- declare const create: (checker: ts.Checker) => Bindings;
5
- declare const declare: (bindings: Bindings, identifier: ts.Identifier, type: TYPES) => void;
6
- declare const declarePath: (bindings: Bindings, identifier: ts.Identifier, path: string) => void;
7
- declare const isArray: (bindings: Bindings, expression: ts.Expression) => boolean;
8
- declare const resolve: (bindings: Bindings, identifier: ts.Identifier) => {
9
- symbol: ts.Symbol;
10
- type: TYPES;
11
- } | null;
5
+ declare const arrays: (bindings: Bindings, nodes: ts.Node[]) => Set<ts.Node>;
6
+ declare const classify: (bindings: Bindings, call: ts.CallExpression) => TYPES | null;
7
+ declare const create: (checker: ts.Checker, program: ts.Program, sourceFile: ts.SourceFile) => Bindings;
8
+ declare const denotes: (bindings: Bindings, expression: ts.Expression) => boolean;
9
+ declare const holds: (bindings: Bindings, found: Origin | null) => boolean;
10
+ declare const isReactiveCall: (bindings: Bindings, node: ts.Node) => node is ts.CallExpression;
11
+ declare const kind: (bindings: Bindings, found: Origin | null) => TYPES | null;
12
+ declare const origin: (bindings: Bindings, node: ts.Node) => Origin | null;
13
+ declare const unwrap: (expression: ts.Expression) => ts.Expression;
12
14
  declare const _default: {
15
+ arrays: typeof arrays;
16
+ classify: typeof classify;
13
17
  create: typeof create;
14
- declare: typeof declare;
15
- declarePath: typeof declarePath;
16
- isArray: typeof isArray;
17
- resolve: typeof resolve;
18
+ denotes: typeof denotes;
19
+ holds: typeof holds;
20
+ isReactiveCall: typeof isReactiveCall;
21
+ kind: typeof kind;
22
+ origin: typeof origin;
23
+ unwrap: typeof unwrap;
18
24
  };
19
25
  export default _default;
@@ -1,65 +1,185 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { TYPES } from './constants.js';
3
- function root(expression) {
4
- let parts = [];
5
- while (ts.isPropertyAccessExpression(expression)) {
6
- parts.push(expression.name.text);
7
- expression = expression.expression;
8
- }
9
- if (!ts.isIdentifier(expression) || parts.length === 0) {
10
- return null;
2
+ import { references } from '@esportsplus/typescript/compiler';
3
+ import { ENTRYPOINT, PACKAGE_NAME, TYPES } from './constants.js';
4
+ const ARRAY_BRAND = 'once';
5
+ const REACTIVE_ARRAY = 'ReactiveArray';
6
+ let caches = new WeakMap();
7
+ function assignments(bindings, file) {
8
+ let cache = cachesOf(bindings.program).assignments, found = cache.get(file.fileName);
9
+ if (found) {
10
+ return found;
11
11
  }
12
- return { path: parts.reverse().join('.'), root: expression };
12
+ let result = new Map(), visit = (node) => {
13
+ if (ts.isBinaryExpression(node) &&
14
+ node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
15
+ ts.isIdentifier(node.left)) {
16
+ let call = unwrap(node.right);
17
+ if (ts.isCallExpression(call)) {
18
+ let list = result.get(node.left.text);
19
+ if (!list) {
20
+ list = [];
21
+ result.set(node.left.text, list);
22
+ }
23
+ list.push({ call, target: node.left });
24
+ }
25
+ }
26
+ node.forEachChild(visit);
27
+ };
28
+ visit(file);
29
+ cache.set(file.fileName, result);
30
+ return result;
13
31
  }
14
- function symbolOf(bindings, identifier) {
15
- let parent = identifier.parent;
16
- if (parent && ts.isShorthandPropertyAssignment(parent) && parent.name === identifier) {
17
- return bindings.checker.getShorthandAssignmentValueSymbol(parent);
32
+ function cachesOf(program) {
33
+ let found = caches.get(program);
34
+ if (!found) {
35
+ found = { arrays: new Map(), assignments: new Map(), kinds: new Map() };
36
+ caches.set(program, found);
18
37
  }
19
- return bindings.checker.getSymbolAtLocation(identifier);
38
+ return found;
20
39
  }
21
- const create = (checker) => ({
22
- checker,
23
- names: new Set(),
24
- paths: new Map(),
25
- symbols: new Map()
26
- });
27
- const declare = (bindings, identifier, type) => {
28
- let symbol = bindings.checker.getSymbolAtLocation(identifier);
29
- if (symbol) {
30
- bindings.names.add(identifier.text);
31
- bindings.symbols.set(symbol, type);
40
+ function kindOf(checker, type) {
41
+ let members = (type.flags & ts.TypeFlags.Union) !== 0 ? type.getTypes() : [type], result = null;
42
+ for (let i = 0, n = members.length; i < n; i++) {
43
+ let kind = kindOfType(checker, members[i]);
44
+ if (kind === null || (result !== null && result !== kind)) {
45
+ return null;
46
+ }
47
+ result = kind;
32
48
  }
49
+ return result;
50
+ }
51
+ function kindOfType(checker, type) {
52
+ if ((type.flags & ts.TypeFlags.TypeParameter) !== 0) {
53
+ let constraint = checker.getBaseConstraintOfType(type);
54
+ return constraint && constraint !== type ? kindOf(checker, constraint) : null;
55
+ }
56
+ if ((type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Never | ts.TypeFlags.Unknown)) !== 0) {
57
+ return null;
58
+ }
59
+ if ((type.flags & (ts.TypeFlags.BigIntLike |
60
+ ts.TypeFlags.BooleanLike |
61
+ ts.TypeFlags.EnumLike |
62
+ ts.TypeFlags.ESSymbolLike |
63
+ ts.TypeFlags.Null |
64
+ ts.TypeFlags.NumberLike |
65
+ ts.TypeFlags.StringLike |
66
+ ts.TypeFlags.TemplateLiteral |
67
+ ts.TypeFlags.Undefined |
68
+ ts.TypeFlags.Void)) !== 0) {
69
+ return TYPES.Signal;
70
+ }
71
+ if (checker.isArrayType(type) || checker.isTupleType(type)) {
72
+ return TYPES.Array;
73
+ }
74
+ if (checker.getSignaturesOfType(type, ts.SignatureKind.Call).length > 0) {
75
+ return TYPES.Computed;
76
+ }
77
+ return (type.flags & (ts.TypeFlags.Intersection | ts.TypeFlags.NonPrimitive | ts.TypeFlags.Object)) !== 0 ? TYPES.Object : null;
78
+ }
79
+ const arrays = (bindings, nodes) => {
80
+ let result = new Set();
81
+ if (nodes.length === 0) {
82
+ return result;
83
+ }
84
+ let files = new Set(references.exported(bindings.checker, bindings.program, PACKAGE_NAME, REACTIVE_ARRAY).map(declaration => declaration.path));
85
+ if (files.size === 0) {
86
+ return result;
87
+ }
88
+ let cache = cachesOf(bindings.program).arrays, types = bindings.checker.getTypeAtLocation(nodes);
89
+ for (let i = 0, n = nodes.length; i < n; i++) {
90
+ let type = types[i];
91
+ if (!type) {
92
+ continue;
93
+ }
94
+ let branded = cache.get(type.id);
95
+ if (branded === undefined) {
96
+ let property = bindings.checker.getPropertyOfType(bindings.checker.getNonNullableType(type) ?? type, ARRAY_BRAND);
97
+ branded = property?.declarations?.some(declaration => files.has(declaration.path)) === true;
98
+ cache.set(type.id, branded);
99
+ }
100
+ if (branded) {
101
+ result.add(nodes[i]);
102
+ }
103
+ }
104
+ return result;
33
105
  };
34
- const declarePath = (bindings, identifier, path) => {
35
- let symbol = bindings.checker.getSymbolAtLocation(identifier);
36
- if (!symbol) {
37
- return;
38
- }
39
- let paths = bindings.paths.get(symbol);
40
- if (!paths) {
41
- paths = new Set();
42
- bindings.paths.set(symbol, paths);
43
- }
44
- bindings.names.add(identifier.text);
45
- paths.add(path);
46
- };
47
- const isArray = (bindings, expression) => {
48
- if (ts.isIdentifier(expression)) {
49
- return resolve(bindings, expression)?.type === TYPES.Array;
106
+ const classify = (bindings, call) => {
107
+ let arg = call.arguments[0];
108
+ if (!arg || call.arguments.length !== 1 || ts.isSpreadElement(arg)) {
109
+ return null;
110
+ }
111
+ let value = unwrap(arg);
112
+ if (ts.isArrowFunction(value) || ts.isFunctionExpression(value)) {
113
+ return TYPES.Computed;
50
114
  }
51
- let access = root(expression);
52
- if (!access || !bindings.names.has(access.root.text)) {
53
- return false;
115
+ if (ts.isArrayLiteralExpression(value)) {
116
+ return TYPES.Array;
54
117
  }
55
- let symbol = symbolOf(bindings, access.root);
56
- return symbol !== undefined && bindings.paths.get(symbol)?.has(access.path) === true;
118
+ if (ts.isObjectLiteralExpression(value)) {
119
+ return TYPES.Object;
120
+ }
121
+ let type = bindings.checker.getTypeAtLocation(arg);
122
+ return type ? kindOf(bindings.checker, type) : null;
123
+ };
124
+ const create = (checker, program, sourceFile) => ({
125
+ checker,
126
+ entries: new Set(references.exported(checker, program, PACKAGE_NAME, ENTRYPOINT).map(references.key)),
127
+ origins: references.origins(checker, program, sourceFile),
128
+ program,
129
+ sourceFile
130
+ });
131
+ const denotes = (bindings, expression) => {
132
+ return references.denotes(bindings.checker, bindings.program, expression, bindings.entries);
133
+ };
134
+ const holds = (bindings, found) => {
135
+ return references.holds(bindings.checker, bindings.program, found, bindings.entries);
136
+ };
137
+ const isReactiveCall = (bindings, node) => {
138
+ return ts.isCallExpression(node) && denotes(bindings, node.expression);
57
139
  };
58
- const resolve = (bindings, identifier) => {
59
- if (!bindings.names.has(identifier.text)) {
140
+ const kind = (bindings, found) => {
141
+ if (!found) {
60
142
  return null;
61
143
  }
62
- let symbol = symbolOf(bindings, identifier), type = symbol && bindings.symbols.get(symbol);
63
- return symbol && type !== undefined ? { symbol, type } : null;
144
+ let declaration = found.declaration;
145
+ if ((declaration.kind !== ts.SyntaxKind.VariableDeclaration && declaration.kind !== ts.SyntaxKind.ExportAssignment) ||
146
+ declaration.path.endsWith('.d.ts')) {
147
+ return null;
148
+ }
149
+ let cache = cachesOf(bindings.program).kinds, key = references.key(declaration), known = cache.get(key);
150
+ if (known !== undefined) {
151
+ return known;
152
+ }
153
+ cache.set(key, null);
154
+ let node = declaration.resolve(), result = null;
155
+ if (node && ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
156
+ let initializer = node.initializer && unwrap(node.initializer);
157
+ if (initializer && isReactiveCall(bindings, initializer)) {
158
+ result = classify(bindings, initializer);
159
+ }
160
+ else {
161
+ let candidates = assignments(bindings, node.getSourceFile()).get(node.name.text) ?? [];
162
+ for (let i = 0, n = candidates.length; i < n && result === null; i++) {
163
+ let { call, target } = candidates[i], assigned = origin(bindings, target);
164
+ if (assigned && references.key(assigned.declaration) === key && isReactiveCall(bindings, call)) {
165
+ result = classify(bindings, call);
166
+ }
167
+ }
168
+ }
169
+ }
170
+ else if (node && ts.isExportAssignment(node)) {
171
+ let expression = unwrap(node.expression);
172
+ if (isReactiveCall(bindings, expression)) {
173
+ result = classify(bindings, expression);
174
+ }
175
+ }
176
+ cache.set(key, result);
177
+ return result;
178
+ };
179
+ const origin = (bindings, node) => {
180
+ return bindings.origins.get(node) ?? references.origin(bindings.checker, bindings.program, node);
181
+ };
182
+ const unwrap = (expression) => {
183
+ return references.unwrap(expression);
64
184
  };
65
- export default { create, declare, declarePath, isArray, resolve };
185
+ export default { arrays, classify, create, denotes, holds, isReactiveCall, kind, origin, unwrap };
@@ -5,6 +5,7 @@ declare const NAMESPACE: string;
5
5
  declare const TYPES: {
6
6
  readonly Array: 0;
7
7
  readonly Computed: 1;
8
+ readonly Object: 3;
8
9
  readonly Signal: 2;
9
10
  };
10
11
  type TYPES = typeof TYPES[keyof typeof TYPES];
@@ -22,6 +22,7 @@ const NAMESPACE = uid('reactivity');
22
22
  const TYPES = {
23
23
  Array: 0,
24
24
  Computed: 1,
25
+ Object: 3,
25
26
  Signal: 2
26
27
  };
27
28
  export { COMPOUND_OPERATORS, ENTRYPOINT, NAMESPACE, TYPES };
@@ -1,6 +1,14 @@
1
- import type { TransformContext } from '@esportsplus/typescript/compiler';
1
+ import type { ImportIntent, ReplacementIntent, TransformContext } from '@esportsplus/typescript/compiler';
2
2
  declare const _default: {
3
- patterns: string[];
4
- transform: (ctx: TransformContext) => {};
3
+ transform: (ctx: TransformContext) => {
4
+ dependencies: string[];
5
+ } | {
6
+ dependencies?: undefined;
7
+ } | {
8
+ imports: ImportIntent[];
9
+ prepend: string[];
10
+ replacements: ReplacementIntent[];
11
+ dependencies: string[];
12
+ };
5
13
  };
6
14
  export default _default;