@esportsplus/reactivity 0.23.0 → 0.23.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.
Files changed (39) hide show
  1. package/build/transformer/detector.js +38 -0
  2. package/build/transformer/{core/index.d.ts → index.d.ts} +1 -1
  3. package/build/transformer/plugins/esbuild.js +3 -2
  4. package/build/transformer/plugins/tsc.js +1 -1
  5. package/build/transformer/plugins/vite.js +2 -2
  6. package/build/transformer/transforms/auto-dispose.js +119 -0
  7. package/build/transformer/{core/transforms → transforms}/reactive-array.d.ts +1 -1
  8. package/build/transformer/transforms/reactive-array.js +93 -0
  9. package/build/transformer/{core/transforms → transforms}/reactive-object.d.ts +1 -1
  10. package/build/transformer/transforms/reactive-object.js +164 -0
  11. package/build/transformer/{core/transforms → transforms}/reactive-primitives.d.ts +1 -1
  12. package/build/transformer/transforms/reactive-primitives.js +335 -0
  13. package/build/transformer/{core/transforms → transforms}/utilities.d.ts +1 -2
  14. package/build/transformer/transforms/utilities.js +73 -0
  15. package/package.json +8 -12
  16. package/src/transformer/detector.ts +65 -0
  17. package/src/transformer/{core/index.ts → index.ts} +1 -5
  18. package/src/transformer/plugins/esbuild.ts +3 -2
  19. package/src/transformer/plugins/tsc.ts +1 -1
  20. package/src/transformer/plugins/vite.ts +2 -4
  21. package/src/transformer/transforms/auto-dispose.ts +191 -0
  22. package/src/transformer/transforms/reactive-array.ts +143 -0
  23. package/src/transformer/{core/transforms → transforms}/reactive-object.ts +101 -92
  24. package/src/transformer/transforms/reactive-primitives.ts +461 -0
  25. package/src/transformer/transforms/utilities.ts +119 -0
  26. package/build/transformer/core/detector.js +0 -6
  27. package/build/transformer/core/transforms/auto-dispose.js +0 -116
  28. package/build/transformer/core/transforms/reactive-array.js +0 -89
  29. package/build/transformer/core/transforms/reactive-object.js +0 -155
  30. package/build/transformer/core/transforms/reactive-primitives.js +0 -325
  31. package/build/transformer/core/transforms/utilities.js +0 -57
  32. package/src/transformer/core/detector.ts +0 -12
  33. package/src/transformer/core/transforms/auto-dispose.ts +0 -194
  34. package/src/transformer/core/transforms/reactive-array.ts +0 -140
  35. package/src/transformer/core/transforms/reactive-primitives.ts +0 -459
  36. package/src/transformer/core/transforms/utilities.ts +0 -95
  37. /package/build/transformer/{core/detector.d.ts → detector.d.ts} +0 -0
  38. /package/build/transformer/{core/index.js → index.js} +0 -0
  39. /package/build/transformer/{core/transforms → transforms}/auto-dispose.d.ts +0 -0
@@ -0,0 +1,335 @@
1
+ import { uid } from '@esportsplus/typescript/transformer';
2
+ import { addMissingImports, applyReplacements } from './utilities.js';
3
+ import ts from 'typescript';
4
+ function classifyReactiveArg(arg) {
5
+ if (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) {
6
+ return 'computed';
7
+ }
8
+ if (ts.isObjectLiteralExpression(arg) || ts.isArrayLiteralExpression(arg)) {
9
+ return null;
10
+ }
11
+ return 'signal';
12
+ }
13
+ function findBinding(bindings, name, node) {
14
+ for (let i = 0, n = bindings.length; i < n; i++) {
15
+ let b = bindings[i];
16
+ if (b.name === name && isInScope(node, b)) {
17
+ return b;
18
+ }
19
+ }
20
+ return undefined;
21
+ }
22
+ function findEnclosingScope(node) {
23
+ let current = node.parent;
24
+ while (current) {
25
+ if (ts.isBlock(current) ||
26
+ ts.isSourceFile(current) ||
27
+ ts.isFunctionDeclaration(current) ||
28
+ ts.isFunctionExpression(current) ||
29
+ ts.isArrowFunction(current) ||
30
+ ts.isForStatement(current) ||
31
+ ts.isForInStatement(current) ||
32
+ ts.isForOfStatement(current)) {
33
+ return current;
34
+ }
35
+ current = current.parent;
36
+ }
37
+ return node.getSourceFile();
38
+ }
39
+ function getCompoundOperator(kind) {
40
+ if (kind === ts.SyntaxKind.PlusEqualsToken) {
41
+ return '+';
42
+ }
43
+ else if (kind === ts.SyntaxKind.MinusEqualsToken) {
44
+ return '-';
45
+ }
46
+ else if (kind === ts.SyntaxKind.AsteriskEqualsToken) {
47
+ return '*';
48
+ }
49
+ else if (kind === ts.SyntaxKind.SlashEqualsToken) {
50
+ return '/';
51
+ }
52
+ else if (kind === ts.SyntaxKind.PercentEqualsToken) {
53
+ return '%';
54
+ }
55
+ else if (kind === ts.SyntaxKind.AsteriskAsteriskEqualsToken) {
56
+ return '**';
57
+ }
58
+ else if (kind === ts.SyntaxKind.AmpersandEqualsToken) {
59
+ return '&';
60
+ }
61
+ else if (kind === ts.SyntaxKind.BarEqualsToken) {
62
+ return '|';
63
+ }
64
+ else if (kind === ts.SyntaxKind.CaretEqualsToken) {
65
+ return '^';
66
+ }
67
+ else if (kind === ts.SyntaxKind.LessThanLessThanEqualsToken) {
68
+ return '<<';
69
+ }
70
+ else if (kind === ts.SyntaxKind.GreaterThanGreaterThanEqualsToken) {
71
+ return '>>';
72
+ }
73
+ else if (kind === ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken) {
74
+ return '>>>';
75
+ }
76
+ else if (kind === ts.SyntaxKind.AmpersandAmpersandEqualsToken) {
77
+ return '&&';
78
+ }
79
+ else if (kind === ts.SyntaxKind.BarBarEqualsToken) {
80
+ return '||';
81
+ }
82
+ else if (kind === ts.SyntaxKind.QuestionQuestionEqualsToken) {
83
+ return '??';
84
+ }
85
+ else {
86
+ return '+';
87
+ }
88
+ }
89
+ function isInComputedRange(ranges, start, end) {
90
+ for (let i = 0, n = ranges.length; i < n; i++) {
91
+ let r = ranges[i];
92
+ if (start >= r.start && end <= r.end) {
93
+ return true;
94
+ }
95
+ }
96
+ return false;
97
+ }
98
+ function isInDeclarationInit(node) {
99
+ let parent = node.parent;
100
+ if (ts.isVariableDeclaration(parent) && parent.initializer === node) {
101
+ return true;
102
+ }
103
+ return false;
104
+ }
105
+ function isInScope(reference, binding) {
106
+ let current = reference;
107
+ while (current) {
108
+ if (current === binding.scope) {
109
+ return true;
110
+ }
111
+ current = current.parent;
112
+ }
113
+ return false;
114
+ }
115
+ function isReactiveReassignment(node) {
116
+ let parent = node.parent;
117
+ if (ts.isBinaryExpression(parent) &&
118
+ parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
119
+ parent.right === node &&
120
+ ts.isCallExpression(node) &&
121
+ ts.isIdentifier(node.expression) &&
122
+ node.expression.text === 'reactive') {
123
+ return true;
124
+ }
125
+ return false;
126
+ }
127
+ function isWriteContext(node) {
128
+ let parent = node.parent;
129
+ if (ts.isBinaryExpression(parent) && parent.left === node) {
130
+ let op = parent.operatorToken.kind;
131
+ if (op === ts.SyntaxKind.EqualsToken) {
132
+ return 'simple';
133
+ }
134
+ if (op >= ts.SyntaxKind.PlusEqualsToken && op <= ts.SyntaxKind.CaretEqualsToken) {
135
+ return 'compound';
136
+ }
137
+ if (op === ts.SyntaxKind.AmpersandAmpersandEqualsToken ||
138
+ op === ts.SyntaxKind.BarBarEqualsToken ||
139
+ op === ts.SyntaxKind.QuestionQuestionEqualsToken) {
140
+ return 'compound';
141
+ }
142
+ }
143
+ if (ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) {
144
+ let op = parent.operator;
145
+ if (op === ts.SyntaxKind.PlusPlusToken || op === ts.SyntaxKind.MinusMinusToken) {
146
+ return 'increment';
147
+ }
148
+ }
149
+ return false;
150
+ }
151
+ function visit(ctx, node) {
152
+ if (ts.isImportDeclaration(node) &&
153
+ ts.isStringLiteral(node.moduleSpecifier) &&
154
+ node.moduleSpecifier.text.includes('@esportsplus/reactivity')) {
155
+ let clause = node.importClause;
156
+ if (clause?.namedBindings && ts.isNamedImports(clause.namedBindings)) {
157
+ for (let i = 0, n = clause.namedBindings.elements.length; i < n; i++) {
158
+ if (clause.namedBindings.elements[i].name.text === 'reactive') {
159
+ ctx.hasReactiveImport = true;
160
+ break;
161
+ }
162
+ }
163
+ }
164
+ }
165
+ if (ctx.hasReactiveImport &&
166
+ ts.isCallExpression(node) &&
167
+ ts.isIdentifier(node.expression) &&
168
+ node.expression.text === 'reactive' &&
169
+ node.arguments.length > 0) {
170
+ let arg = node.arguments[0], classification = classifyReactiveArg(arg);
171
+ if (classification) {
172
+ let varName = null;
173
+ if (ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
174
+ varName = node.parent.name.text;
175
+ }
176
+ else if (ts.isBinaryExpression(node.parent) &&
177
+ node.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
178
+ ts.isIdentifier(node.parent.left)) {
179
+ varName = node.parent.left.text;
180
+ }
181
+ if (varName) {
182
+ let scope = findEnclosingScope(node);
183
+ ctx.scopedBindings.push({ name: varName, scope, type: classification });
184
+ ctx.bindings.set(varName, classification);
185
+ }
186
+ if (classification === 'computed') {
187
+ ctx.computedArgRanges.push({
188
+ end: arg.end,
189
+ start: arg.getStart(ctx.sourceFile)
190
+ });
191
+ let argCtx = {
192
+ argStart: arg.getStart(ctx.sourceFile),
193
+ innerReplacements: [],
194
+ neededImports: ctx.neededImports,
195
+ scopedBindings: ctx.scopedBindings,
196
+ sourceFile: ctx.sourceFile
197
+ };
198
+ visitArg(argCtx, arg);
199
+ let argText = applyReplacements(arg.getText(ctx.sourceFile), argCtx.innerReplacements);
200
+ ctx.replacements.push({
201
+ end: node.end,
202
+ newText: `computed(${argText})`,
203
+ start: node.pos
204
+ });
205
+ ctx.neededImports.add('computed');
206
+ }
207
+ else {
208
+ let argText = arg.getText(ctx.sourceFile);
209
+ ctx.replacements.push({
210
+ end: node.end,
211
+ newText: `signal(${argText})`,
212
+ start: node.pos
213
+ });
214
+ ctx.neededImports.add('signal');
215
+ }
216
+ }
217
+ }
218
+ if (ts.isIdentifier(node) && !isInDeclarationInit(node.parent)) {
219
+ if (ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) {
220
+ ts.forEachChild(node, n => visit(ctx, n));
221
+ return;
222
+ }
223
+ let nodeStart = node.getStart(ctx.sourceFile);
224
+ if (isInComputedRange(ctx.computedArgRanges, nodeStart, node.end)) {
225
+ ts.forEachChild(node, n => visit(ctx, n));
226
+ return;
227
+ }
228
+ let binding = findBinding(ctx.scopedBindings, node.text, node), name = node.text;
229
+ if (binding) {
230
+ if (!isReactiveReassignment(node.parent) &&
231
+ !(ts.isTypeOfExpression(node.parent) && node.parent.expression === node)) {
232
+ let writeCtx = isWriteContext(node);
233
+ if (writeCtx) {
234
+ if (binding.type !== 'computed') {
235
+ ctx.neededImports.add('set');
236
+ let parent = node.parent;
237
+ if (writeCtx === 'simple' && ts.isBinaryExpression(parent)) {
238
+ let valueText = parent.right.getText(ctx.sourceFile);
239
+ ctx.replacements.push({
240
+ end: parent.end,
241
+ newText: `set(${name}, ${valueText})`,
242
+ start: parent.pos
243
+ });
244
+ }
245
+ else if (writeCtx === 'compound' && ts.isBinaryExpression(parent)) {
246
+ let op = getCompoundOperator(parent.operatorToken.kind), valueText = parent.right.getText(ctx.sourceFile);
247
+ ctx.replacements.push({
248
+ end: parent.end,
249
+ newText: `set(${name}, ${name}.value ${op} ${valueText})`,
250
+ start: parent.pos
251
+ });
252
+ }
253
+ else if (writeCtx === 'increment') {
254
+ let isPrefix = ts.isPrefixUnaryExpression(parent), op = parent.operator, delta = op === ts.SyntaxKind.PlusPlusToken ? '+ 1' : '- 1';
255
+ if (ts.isExpressionStatement(parent.parent)) {
256
+ ctx.replacements.push({
257
+ end: parent.end,
258
+ newText: `set(${name}, ${name}.value ${delta})`,
259
+ start: parent.pos
260
+ });
261
+ }
262
+ else if (isPrefix) {
263
+ ctx.replacements.push({
264
+ end: parent.end,
265
+ newText: `(set(${name}, ${name}.value ${delta}), ${name}.value)`,
266
+ start: parent.pos
267
+ });
268
+ }
269
+ else {
270
+ let tmp = uid('tmp');
271
+ ctx.replacements.push({
272
+ end: parent.end,
273
+ newText: `((${tmp}) => (set(${name}, ${tmp} ${delta}), ${tmp}))(${name}.value)`,
274
+ start: parent.pos
275
+ });
276
+ }
277
+ }
278
+ }
279
+ }
280
+ else {
281
+ ctx.neededImports.add('read');
282
+ ctx.replacements.push({
283
+ end: node.end,
284
+ newText: `read(${name})`,
285
+ start: node.pos
286
+ });
287
+ }
288
+ }
289
+ }
290
+ }
291
+ ts.forEachChild(node, n => visit(ctx, n));
292
+ }
293
+ function visitArg(ctx, node) {
294
+ if (ts.isIdentifier(node)) {
295
+ if (ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) {
296
+ ts.forEachChild(node, n => visitArg(ctx, n));
297
+ return;
298
+ }
299
+ if (ts.isCallExpression(node.parent) && node.parent.expression === node) {
300
+ ts.forEachChild(node, n => visitArg(ctx, n));
301
+ return;
302
+ }
303
+ let binding = findBinding(ctx.scopedBindings, node.text, node);
304
+ if (binding) {
305
+ ctx.neededImports.add('read');
306
+ ctx.innerReplacements.push({
307
+ end: node.end - ctx.argStart,
308
+ newText: `read(${node.text})`,
309
+ start: node.getStart(ctx.sourceFile) - ctx.argStart
310
+ });
311
+ }
312
+ }
313
+ ts.forEachChild(node, n => visitArg(ctx, n));
314
+ }
315
+ const transformReactivePrimitives = (sourceFile, bindings) => {
316
+ let code = sourceFile.getFullText(), ctx = {
317
+ bindings,
318
+ computedArgRanges: [],
319
+ hasReactiveImport: false,
320
+ neededImports: new Set(),
321
+ replacements: [],
322
+ scopedBindings: [],
323
+ sourceFile
324
+ };
325
+ visit(ctx, sourceFile);
326
+ if (ctx.replacements.length === 0) {
327
+ return code;
328
+ }
329
+ let result = applyReplacements(code, ctx.replacements);
330
+ if (ctx.neededImports.size > 0) {
331
+ result = addMissingImports(result, ctx.neededImports);
332
+ }
333
+ return result;
334
+ };
335
+ export { transformReactivePrimitives };
@@ -1,5 +1,4 @@
1
- import type { Replacement } from '@esportsplus/typescript/transformer';
2
- import { applyReplacements } from '@esportsplus/typescript/transformer';
1
+ import { applyReplacements, type Replacement } from '@esportsplus/typescript/transformer';
3
2
  type ExtraImport = {
4
3
  module: string;
5
4
  specifier: string;
@@ -0,0 +1,73 @@
1
+ import { applyReplacements } from '@esportsplus/typescript/transformer';
2
+ import ts from 'typescript';
3
+ function findReactivityImport(sourceFile) {
4
+ for (let i = 0, n = sourceFile.statements.length; i < n; i++) {
5
+ let stmt = sourceFile.statements[i];
6
+ if (ts.isImportDeclaration(stmt) &&
7
+ ts.isStringLiteral(stmt.moduleSpecifier) &&
8
+ stmt.moduleSpecifier.text === '@esportsplus/reactivity' &&
9
+ stmt.importClause?.namedBindings &&
10
+ ts.isNamedImports(stmt.importClause.namedBindings)) {
11
+ return stmt;
12
+ }
13
+ }
14
+ return null;
15
+ }
16
+ function getExistingSpecifiers(namedImports) {
17
+ let existing = new Set();
18
+ for (let i = 0, n = namedImports.elements.length; i < n; i++) {
19
+ let el = namedImports.elements[i], name = el.propertyName?.text ?? el.name.text;
20
+ existing.add(name);
21
+ }
22
+ return existing;
23
+ }
24
+ function getFirstImportPos(sourceFile) {
25
+ for (let i = 0, n = sourceFile.statements.length; i < n; i++) {
26
+ if (ts.isImportDeclaration(sourceFile.statements[i])) {
27
+ return sourceFile.statements[i].getStart(sourceFile);
28
+ }
29
+ }
30
+ return 0;
31
+ }
32
+ const addMissingImports = (code, needed, extraImports) => {
33
+ let sourceFile = ts.createSourceFile('temp.ts', code, ts.ScriptTarget.Latest, true), reactivityImport = findReactivityImport(sourceFile);
34
+ if (!reactivityImport) {
35
+ return code;
36
+ }
37
+ let extraSpecifiers = new Set(), namedImports = reactivityImport.importClause.namedBindings, existing = getExistingSpecifiers(namedImports), toAdd = [];
38
+ if (extraImports) {
39
+ for (let i = 0, n = extraImports.length; i < n; i++) {
40
+ extraSpecifiers.add(extraImports[i].specifier);
41
+ }
42
+ }
43
+ for (let imp of needed) {
44
+ if (!extraSpecifiers.has(imp) && !existing.has(imp)) {
45
+ toAdd.push(imp);
46
+ }
47
+ }
48
+ if (toAdd.length > 0) {
49
+ let combined = [];
50
+ for (let item of existing) {
51
+ combined.push(item);
52
+ }
53
+ for (let i = 0, n = toAdd.length; i < n; i++) {
54
+ combined.push(toAdd[i]);
55
+ }
56
+ combined.sort();
57
+ let newSpecifiers = `{ ${combined.join(', ')} }`, bindingsStart = namedImports.getStart(sourceFile), bindingsEnd = namedImports.getEnd();
58
+ code = code.substring(0, bindingsStart) + newSpecifiers + code.substring(bindingsEnd);
59
+ }
60
+ if (extraImports) {
61
+ let insertPos = getFirstImportPos(ts.createSourceFile('temp.ts', code, ts.ScriptTarget.Latest, true));
62
+ for (let i = 0, n = extraImports.length; i < n; i++) {
63
+ let extra = extraImports[i];
64
+ if (needed.has(extra.specifier) && !code.includes(extra.module)) {
65
+ code = code.substring(0, insertPos) +
66
+ `import { ${extra.specifier} } from '${extra.module}';\n` +
67
+ code.substring(insertPos);
68
+ }
69
+ }
70
+ }
71
+ return code;
72
+ };
73
+ export { addMissingImports, applyReplacements };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "@esportsplus/utilities": "^0.27.2"
5
5
  },
6
6
  "devDependencies": {
7
- "@esportsplus/typescript": "^0.11.0",
7
+ "@esportsplus/typescript": "^0.12.2",
8
8
  "@types/node": "^25.0.3",
9
9
  "esbuild": "^0.27.2",
10
10
  "typescript": "^5.9.3",
@@ -20,20 +20,16 @@
20
20
  "types": "./build/constants.d.ts"
21
21
  },
22
22
  "./plugins/esbuild": {
23
- "import": "./build/plugins/esbuild.js",
24
- "types": "./build/plugins/esbuild.d.ts"
23
+ "import": "./build/transformer/plugins/esbuild.js",
24
+ "types": "./build/transformer/plugins/esbuild.d.ts"
25
25
  },
26
26
  "./plugins/tsc": {
27
- "import": "./build/plugins/tsc.js",
28
- "types": "./build/plugins/tsc.d.ts"
27
+ "import": "./build/transformer/plugins/tsc.js",
28
+ "types": "./build/transformer/plugins/tsc.d.ts"
29
29
  },
30
30
  "./plugins/vite": {
31
- "import": "./build/plugins/vite.js",
32
- "types": "./build/plugins/vite.d.ts"
33
- },
34
- "./reactive/array": {
35
- "import": "./build/reactive/array.js",
36
- "types": "./build/reactive/array.d.ts"
31
+ "import": "./build/transformer/plugins/vite.js",
32
+ "types": "./build/transformer/plugins/vite.d.ts"
37
33
  }
38
34
  },
39
35
  "main": "build/index.js",
@@ -45,7 +41,7 @@
45
41
  },
46
42
  "type": "module",
47
43
  "types": "build/index.d.ts",
48
- "version": "0.23.0",
44
+ "version": "0.23.1",
49
45
  "scripts": {
50
46
  "build": "tsc && tsc-alias",
51
47
  "build:test": "pnpm build && vite build --config test/vite.config.ts",
@@ -0,0 +1,65 @@
1
+ import { mightNeedTransform as checkTransform } from '@esportsplus/typescript/transformer';
2
+ import ts from 'typescript';
3
+
4
+
5
+ interface DetectContext {
6
+ hasImport: boolean;
7
+ hasUsage: boolean;
8
+ }
9
+
10
+
11
+ const REACTIVE_REGEX = /\breactive\b/;
12
+
13
+
14
+ function visit(ctx: DetectContext, node: ts.Node): void {
15
+ if (ctx.hasImport && ctx.hasUsage) {
16
+ return;
17
+ }
18
+
19
+ if (
20
+ ts.isImportDeclaration(node) &&
21
+ node.importClause?.namedBindings &&
22
+ ts.isNamedImports(node.importClause.namedBindings)
23
+ ) {
24
+ let elements = node.importClause.namedBindings.elements;
25
+
26
+ for (let i = 0, n = elements.length; i < n; i++) {
27
+ let el = elements[i],
28
+ name = el.propertyName?.text ?? el.name.text;
29
+
30
+ if (name === 'reactive') {
31
+ ctx.hasImport = true;
32
+ break;
33
+ }
34
+ }
35
+ }
36
+
37
+ if (
38
+ ts.isCallExpression(node) &&
39
+ ts.isIdentifier(node.expression) &&
40
+ node.expression.text === 'reactive'
41
+ ) {
42
+ ctx.hasUsage = true;
43
+ }
44
+
45
+ ts.forEachChild(node, n => visit(ctx, n));
46
+ }
47
+
48
+
49
+ const mightNeedTransform = (code: string): boolean => {
50
+ if (!checkTransform(code, { regex: REACTIVE_REGEX })) {
51
+ return false;
52
+ }
53
+
54
+ let ctx: DetectContext = {
55
+ hasImport: false,
56
+ hasUsage: false
57
+ };
58
+
59
+ visit(ctx, ts.createSourceFile('detect.ts', code, ts.ScriptTarget.Latest, false));
60
+
61
+ return ctx.hasImport && ctx.hasUsage;
62
+ };
63
+
64
+
65
+ export { mightNeedTransform };
@@ -17,11 +17,7 @@ const createTransformer = (options?: TransformOptions): ts.TransformerFactory<ts
17
17
  };
18
18
  };
19
19
 
20
-
21
- const transform = (
22
- sourceFile: ts.SourceFile,
23
- options?: TransformOptions
24
- ): TransformResult => {
20
+ const transform = (sourceFile: ts.SourceFile, options?: TransformOptions): TransformResult => {
25
21
  let bindings: Bindings = new Map(),
26
22
  code = sourceFile.getFullText(),
27
23
  current = sourceFile,
@@ -1,4 +1,5 @@
1
- import { mightNeedTransform, transform } from '~/transformer/core';
1
+ import { TRANSFORM_PATTERN } from '@esportsplus/typescript/transformer';
2
+ import { mightNeedTransform, transform } from '~/transformer';
2
3
  import type { OnLoadArgs, Plugin, PluginBuild } from 'esbuild';
3
4
  import type { TransformOptions } from '~/types';
4
5
  import fs from 'fs';
@@ -10,7 +11,7 @@ export default (options?: TransformOptions): Plugin => {
10
11
  name: '@esportsplus/reactivity/plugin-esbuild',
11
12
 
12
13
  setup(build: PluginBuild) {
13
- build.onLoad({ filter: /\.[tj]sx?$/ }, async (args: OnLoadArgs) => {
14
+ build.onLoad({ filter: TRANSFORM_PATTERN }, async (args: OnLoadArgs) => {
14
15
  let code = await fs.promises.readFile(args.path, 'utf8');
15
16
 
16
17
  if (!mightNeedTransform(code)) {
@@ -1,4 +1,4 @@
1
- import { createTransformer } from '~/transformer/core';
1
+ import { createTransformer } from '~/transformer';
2
2
  import ts from 'typescript';
3
3
 
4
4
 
@@ -1,12 +1,10 @@
1
- import { mightNeedTransform, transform } from '~/transformer/core';
1
+ import { TRANSFORM_PATTERN } from '@esportsplus/typescript/transformer';
2
+ import { mightNeedTransform, transform } from '~/transformer';
2
3
  import type { Plugin } from 'vite';
3
4
  import type { TransformOptions } from '~/types';
4
5
  import ts from 'typescript';
5
6
 
6
7
 
7
- const TRANSFORM_PATTERN = /\.[tj]sx?$/;
8
-
9
-
10
8
  export default (options?: TransformOptions): Plugin => {
11
9
  return {
12
10
  enforce: 'pre',