@esportsplus/reactivity 0.25.13 → 0.26.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,4 +1,4 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import type { Bindings } from '../../types.js';
2
+ import type { Bindings } from '../types.js';
3
3
  declare const _default: (sourceFile: ts.SourceFile, bindings: Bindings, _ns: string) => string;
4
4
  export default _default;
@@ -1,40 +1,13 @@
1
- import { code as c } from '@esportsplus/typescript/transformer';
1
+ import { ast, code as c } from '@esportsplus/typescript/compiler';
2
2
  import { ts } from '@esportsplus/typescript';
3
- import { COMPILER_TYPES } from '../../constants.js';
4
- function getExpressionName(node) {
5
- if (ts.isIdentifier(node)) {
6
- return node.text;
7
- }
8
- if (ts.isPropertyAccessExpression(node)) {
9
- return getPropertyPath(node);
10
- }
11
- return null;
12
- }
13
- function getPropertyPath(node) {
14
- let current = node, parts = [];
15
- while (ts.isPropertyAccessExpression(current)) {
16
- parts.push(current.name.text);
17
- current = current.expression;
18
- }
19
- if (ts.isIdentifier(current)) {
20
- parts.push(current.text);
21
- return parts.reverse().join('.');
22
- }
23
- return null;
24
- }
25
- function isAssignmentTarget(node) {
26
- let parent = node.parent;
27
- return !!parent && ((ts.isBinaryExpression(parent) && parent.left === node) ||
28
- ts.isPostfixUnaryExpression(parent) ||
29
- ts.isPrefixUnaryExpression(parent));
30
- }
3
+ import { COMPILER_TYPES } from '../constants.js';
31
4
  function visit(ctx, node) {
32
5
  if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
33
6
  if (ts.isIdentifier(node.initializer) && ctx.bindings.get(node.initializer.text) === COMPILER_TYPES.Array) {
34
7
  ctx.bindings.set(node.name.text, COMPILER_TYPES.Array);
35
8
  }
36
9
  if (ts.isPropertyAccessExpression(node.initializer)) {
37
- let path = getPropertyPath(node.initializer);
10
+ let path = ast.getPropertyPathString(node.initializer);
38
11
  if (path && ctx.bindings.get(path) === COMPILER_TYPES.Array) {
39
12
  ctx.bindings.set(node.name.text, COMPILER_TYPES.Array);
40
13
  }
@@ -51,15 +24,17 @@ function visit(ctx, node) {
51
24
  }
52
25
  }
53
26
  }
27
+ let parent = node.parent;
54
28
  if (ts.isPropertyAccessExpression(node) &&
55
29
  node.name.text === 'length' &&
56
- !isAssignmentTarget(node)) {
57
- let name = getExpressionName(node.expression);
30
+ (!!parent && ((ts.isBinaryExpression(parent) && parent.left === node) ||
31
+ ts.isPostfixUnaryExpression(parent) ||
32
+ ts.isPrefixUnaryExpression(parent))) === false) {
33
+ let name = ast.getExpressionName(node.expression);
58
34
  if (name && ctx.bindings.get(name) === COMPILER_TYPES.Array) {
59
- let objText = node.expression.getText(ctx.sourceFile);
60
35
  ctx.replacements.push({
61
36
  end: node.end,
62
- newText: `${objText}.$length()`,
37
+ newText: `${node.expression.getText(ctx.sourceFile)}.$length()`,
63
38
  start: node.pos
64
39
  });
65
40
  }
@@ -67,12 +42,12 @@ function visit(ctx, node) {
67
42
  if (ts.isBinaryExpression(node) &&
68
43
  node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
69
44
  ts.isElementAccessExpression(node.left)) {
70
- let elemAccess = node.left, objName = getExpressionName(elemAccess.expression);
45
+ let elemAccess = node.left, objName = ast.getExpressionName(elemAccess.expression);
71
46
  if (objName && ctx.bindings.get(objName) === COMPILER_TYPES.Array) {
72
- let indexText = elemAccess.argumentExpression.getText(ctx.sourceFile), objText = elemAccess.expression.getText(ctx.sourceFile), valueText = node.right.getText(ctx.sourceFile);
47
+ let index = elemAccess.argumentExpression.getText(ctx.sourceFile), obj = elemAccess.expression.getText(ctx.sourceFile), value = node.right.getText(ctx.sourceFile);
73
48
  ctx.replacements.push({
74
49
  end: node.end,
75
- newText: `${objText}.$set(${indexText}, ${valueText})`,
50
+ newText: `${obj}.$set(${index}, ${value})`,
76
51
  start: node.pos
77
52
  });
78
53
  }
@@ -1,9 +1,9 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { code as c } from '@esportsplus/typescript/transformer';
2
+ import { code as c } from '@esportsplus/typescript/compiler';
3
3
  import { COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REGEX, COMPILER_NAMESPACE } from '../constants.js';
4
- import array from './transforms/array.js';
5
- import object from './transforms/object.js';
6
- import primitives from './transforms/primitives.js';
4
+ import array from './array.js';
5
+ import object from './object.js';
6
+ import primitives from './primitives.js';
7
7
  let transforms = [object, array, primitives];
8
8
  function contains(code) {
9
9
  if (!c.contains(code, { regex: COMPILER_ENTRYPOINT_REGEX })) {
@@ -1,4 +1,4 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import type { Bindings } from '../../types.js';
2
+ import type { Bindings } from '../types.js';
3
3
  declare const _default: (sourceFile: ts.SourceFile, bindings: Bindings, ns: string) => string;
4
4
  export default _default;
@@ -1,6 +1,6 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { code as c } from '@esportsplus/typescript/transformer';
3
- import { COMPILER_TYPES, PACKAGE } from '../../constants.js';
2
+ import { code as c } from '@esportsplus/typescript/compiler';
3
+ import { COMPILER_TYPES, PACKAGE } from '../constants.js';
4
4
  function analyzeProperty(prop, sourceFile) {
5
5
  if (!ts.isPropertyAssignment(prop)) {
6
6
  return null;
@@ -35,18 +35,18 @@ function buildClassCode(className, properties, ns) {
35
35
  let { key, type, valueText } = properties[i];
36
36
  if (type === COMPILER_TYPES.Signal) {
37
37
  let param = `_v${paramCounter++}`;
38
- fields.push(`#${key} = ${ns}.signal(${valueText});`);
39
38
  accessors.push(`get ${key}() { return ${ns}.read(this.#${key}); }`);
40
39
  accessors.push(`set ${key}(${param}) { ${ns}.write(this.#${key}, ${param}); }`);
40
+ fields.push(`#${key} = ${ns}.signal(${valueText});`);
41
41
  }
42
42
  else if (type === COMPILER_TYPES.Array) {
43
- fields.push(`${key} = new ${ns}.ReactiveArray(${valueText});`);
44
43
  disposeStatements.push(`this.${key}.dispose();`);
44
+ fields.push(`${key} = new ${ns}.ReactiveArray(${valueText});`);
45
45
  }
46
46
  else if (type === COMPILER_TYPES.Computed) {
47
- fields.push(`#${key} = null;`);
48
47
  accessors.push(`get ${key}() { return ${ns}.read(this.#${key} ??= ${ns}.computed(${valueText})); }`);
49
48
  disposeStatements.push(`if (this.#${key}) ${ns}.dispose(this.#${key});`);
49
+ fields.push(`#${key} = null;`);
50
50
  }
51
51
  }
52
52
  return `
@@ -1,3 +1,3 @@
1
- import { plugin } from '@esportsplus/typescript/transformer';
1
+ import { plugin } from '@esportsplus/typescript/compiler';
2
2
  declare const _default: ReturnType<typeof plugin.tsc>;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
- import { plugin } from '@esportsplus/typescript/transformer';
1
+ import { plugin } from '@esportsplus/typescript/compiler';
2
2
  import { transform } from '../index.js';
3
3
  export default plugin.tsc(transform);
@@ -1,5 +1,5 @@
1
1
  import { PACKAGE } from '../../constants.js';
2
- import { plugin } from '@esportsplus/typescript/transformer';
2
+ import { plugin } from '@esportsplus/typescript/compiler';
3
3
  import { transform } from '../index.js';
4
4
  export default plugin.vite({
5
5
  name: PACKAGE,
@@ -1,4 +1,4 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import type { Bindings } from '../../types.js';
2
+ import type { Bindings } from '../types.js';
3
3
  declare const _default: (sourceFile: ts.SourceFile, bindings: Bindings, ns: string) => string;
4
4
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { code as c } from '@esportsplus/typescript/transformer';
3
- import { COMPILER_ENTRYPOINT, COMPILER_TYPES, PACKAGE } from '../../constants.js';
4
- let COMPOUND_OPERATORS = new Map([
2
+ import { ast, code as c } from '@esportsplus/typescript/compiler';
3
+ import { COMPILER_ENTRYPOINT, COMPILER_TYPES, PACKAGE } from '../constants.js';
4
+ const COMPOUND_OPERATORS = new Map([
5
5
  [ts.SyntaxKind.AmpersandAmpersandEqualsToken, '&&'],
6
6
  [ts.SyntaxKind.AmpersandEqualsToken, '&'],
7
7
  [ts.SyntaxKind.AsteriskAsteriskEqualsToken, '**'],
@@ -18,15 +18,6 @@ let COMPOUND_OPERATORS = new Map([
18
18
  [ts.SyntaxKind.QuestionQuestionEqualsToken, '??'],
19
19
  [ts.SyntaxKind.SlashEqualsToken, '/']
20
20
  ]);
21
- function classifyReactiveArg(arg) {
22
- if (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) {
23
- return COMPILER_TYPES.Computed;
24
- }
25
- if (ts.isObjectLiteralExpression(arg) || ts.isArrayLiteralExpression(arg)) {
26
- return null;
27
- }
28
- return COMPILER_TYPES.Signal;
29
- }
30
21
  function findBinding(bindings, name, node) {
31
22
  for (let i = 0, n = bindings.length; i < n; i++) {
32
23
  let b = bindings[i];
@@ -53,15 +44,6 @@ function findEnclosingScope(node) {
53
44
  }
54
45
  return node.getSourceFile();
55
46
  }
56
- function isInComputedRange(ranges, start, end) {
57
- for (let i = 0, n = ranges.length; i < n; i++) {
58
- let r = ranges[i];
59
- if (start >= r.start && end <= r.end) {
60
- return true;
61
- }
62
- }
63
- return false;
64
- }
65
47
  function isInDeclarationInit(node) {
66
48
  let parent = node.parent;
67
49
  return ts.isVariableDeclaration(parent) && parent.initializer === node;
@@ -126,7 +108,13 @@ function visit(ctx, node) {
126
108
  ts.isIdentifier(node.expression) &&
127
109
  node.expression.text === COMPILER_ENTRYPOINT &&
128
110
  node.arguments.length > 0) {
129
- let arg = node.arguments[0], classification = classifyReactiveArg(arg);
111
+ let arg = node.arguments[0], classification = COMPILER_TYPES.Signal;
112
+ if (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) {
113
+ classification = COMPILER_TYPES.Computed;
114
+ }
115
+ else if (ts.isObjectLiteralExpression(arg) || ts.isArrayLiteralExpression(arg)) {
116
+ classification = null;
117
+ }
130
118
  if (classification) {
131
119
  let varName = null;
132
120
  if (node.parent && ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
@@ -176,7 +164,7 @@ function visit(ctx, node) {
176
164
  return;
177
165
  }
178
166
  let nodeStart = node.getStart(ctx.sourceFile);
179
- if (isInComputedRange(ctx.computedArgRanges, nodeStart, node.end)) {
167
+ if (ast.inRange(ctx.computedArgRanges, nodeStart, node.end)) {
180
168
  ts.forEachChild(node, n => visit(ctx, n));
181
169
  return;
182
170
  }
@@ -1,4 +1,4 @@
1
- import { uid } from '@esportsplus/typescript/transformer';
1
+ import { uid } from '@esportsplus/typescript/compiler';
2
2
  const COMPILER_ENTRYPOINT = 'reactive';
3
3
  const COMPILER_ENTRYPOINT_REGEX = /\breactive\b/;
4
4
  const COMPILER_NAMESPACE = uid(COMPILER_ENTRYPOINT);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "@esportsplus/utilities": "^0.27.2"
5
5
  },
6
6
  "devDependencies": {
7
- "@esportsplus/typescript": "^0.18.0",
7
+ "@esportsplus/typescript": "^0.21.0",
8
8
  "@types/node": "^25.0.3",
9
9
  "vite": "^7.3.0"
10
10
  },
@@ -13,18 +13,14 @@
13
13
  "import": "./build/index.js",
14
14
  "types": "./build/index.d.ts"
15
15
  },
16
- "./constants": {
17
- "import": "./build/constants.js",
18
- "types": "./build/constants.d.ts"
16
+ "./compiler/tsc": {
17
+ "types": "./build/compiler/plugins/tsc.d.ts",
18
+ "import": "./build/compiler/plugins/tsc.js",
19
+ "require": "./build/compiler/plugins/tsc.js"
19
20
  },
20
- "./plugins/tsc": {
21
- "types": "./build/transformer/plugins/tsc.d.ts",
22
- "import": "./build/transformer/plugins/tsc.js",
23
- "require": "./build/transformer/plugins/tsc.js"
24
- },
25
- "./plugins/vite": {
26
- "types": "./build/transformer/plugins/vite.d.ts",
27
- "import": "./build/transformer/plugins/vite.js"
21
+ "./compiler/vite": {
22
+ "types": "./build/compiler/plugins/vite.d.ts",
23
+ "import": "./build/compiler/plugins/vite.js"
28
24
  }
29
25
  },
30
26
  "main": "build/index.js",
@@ -36,7 +32,7 @@
36
32
  },
37
33
  "type": "module",
38
34
  "types": "build/index.d.ts",
39
- "version": "0.25.13",
35
+ "version": "0.26.0",
40
36
  "scripts": {
41
37
  "build": "tsc",
42
38
  "build:test": "pnpm build && vite build --config test/vite.config.ts",
@@ -1,48 +1,9 @@
1
- import { code as c, type Replacement } from '@esportsplus/typescript/transformer';
1
+ import { ast, code as c, type Replacement } from '@esportsplus/typescript/compiler';
2
2
  import { ts } from '@esportsplus/typescript';
3
3
  import { COMPILER_TYPES } from '~/constants';
4
4
  import type { Bindings } from '~/types';
5
5
 
6
6
 
7
- function getExpressionName(node: ts.Expression): string | null {
8
- if (ts.isIdentifier(node)) {
9
- return node.text;
10
- }
11
-
12
- if (ts.isPropertyAccessExpression(node)) {
13
- return getPropertyPath(node);
14
- }
15
-
16
- return null;
17
- }
18
-
19
- function getPropertyPath(node: ts.PropertyAccessExpression): string | null {
20
- let current: ts.Node = node,
21
- parts: string[] = [];
22
-
23
- while (ts.isPropertyAccessExpression(current)) {
24
- parts.push(current.name.text);
25
- current = current.expression;
26
- }
27
-
28
- if (ts.isIdentifier(current)) {
29
- parts.push(current.text);
30
- return parts.reverse().join('.');
31
- }
32
-
33
- return null;
34
- }
35
-
36
- function isAssignmentTarget(node: ts.Node): boolean {
37
- let parent = node.parent;
38
-
39
- return !!parent && (
40
- (ts.isBinaryExpression(parent) && parent.left === node) ||
41
- ts.isPostfixUnaryExpression(parent) ||
42
- ts.isPrefixUnaryExpression(parent)
43
- );
44
- }
45
-
46
7
  function visit(ctx: { bindings: Bindings, replacements: Replacement[], sourceFile: ts.SourceFile }, node: ts.Node): void {
47
8
  if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
48
9
  if (ts.isIdentifier(node.initializer) && ctx.bindings.get(node.initializer.text) === COMPILER_TYPES.Array) {
@@ -50,7 +11,7 @@ function visit(ctx: { bindings: Bindings, replacements: Replacement[], sourceFil
50
11
  }
51
12
 
52
13
  if (ts.isPropertyAccessExpression(node.initializer)) {
53
- let path = getPropertyPath(node.initializer);
14
+ let path = ast.getPropertyPathString(node.initializer);
54
15
 
55
16
  if (path && ctx.bindings.get(path) === COMPILER_TYPES.Array) {
56
17
  ctx.bindings.set(node.name.text, COMPILER_TYPES.Array);
@@ -73,19 +34,23 @@ function visit(ctx: { bindings: Bindings, replacements: Replacement[], sourceFil
73
34
  }
74
35
  }
75
36
 
37
+ let parent = node.parent;
38
+
76
39
  if (
77
40
  ts.isPropertyAccessExpression(node) &&
78
41
  node.name.text === 'length' &&
79
- !isAssignmentTarget(node)
42
+ (!!parent && (
43
+ (ts.isBinaryExpression(parent) && parent.left === node) ||
44
+ ts.isPostfixUnaryExpression(parent) ||
45
+ ts.isPrefixUnaryExpression(parent)
46
+ )) === false
80
47
  ) {
81
- let name = getExpressionName(node.expression);
48
+ let name = ast.getExpressionName(node.expression);
82
49
 
83
50
  if (name && ctx.bindings.get(name) === COMPILER_TYPES.Array) {
84
- let objText = node.expression.getText(ctx.sourceFile);
85
-
86
51
  ctx.replacements.push({
87
52
  end: node.end,
88
- newText: `${objText}.$length()`,
53
+ newText: `${node.expression.getText(ctx.sourceFile)}.$length()`,
89
54
  start: node.pos
90
55
  });
91
56
  }
@@ -97,16 +62,16 @@ function visit(ctx: { bindings: Bindings, replacements: Replacement[], sourceFil
97
62
  ts.isElementAccessExpression(node.left)
98
63
  ) {
99
64
  let elemAccess = node.left,
100
- objName = getExpressionName(elemAccess.expression);
65
+ objName = ast.getExpressionName(elemAccess.expression);
101
66
 
102
67
  if (objName && ctx.bindings.get(objName) === COMPILER_TYPES.Array) {
103
- let indexText = elemAccess.argumentExpression.getText(ctx.sourceFile),
104
- objText = elemAccess.expression.getText(ctx.sourceFile),
105
- valueText = node.right.getText(ctx.sourceFile);
68
+ let index = elemAccess.argumentExpression.getText(ctx.sourceFile),
69
+ obj = elemAccess.expression.getText(ctx.sourceFile),
70
+ value = node.right.getText(ctx.sourceFile);
106
71
 
107
72
  ctx.replacements.push({
108
73
  end: node.end,
109
- newText: `${objText}.$set(${indexText}, ${valueText})`,
74
+ newText: `${obj}.$set(${index}, ${value})`,
110
75
  start: node.pos
111
76
  });
112
77
  }
@@ -1,10 +1,10 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { code as c } from '@esportsplus/typescript/transformer';
2
+ import { code as c } from '@esportsplus/typescript/compiler';
3
3
  import { COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REGEX, COMPILER_NAMESPACE } from '~/constants';
4
4
  import type { Bindings, TransformResult } from '~/types';
5
- import array from './transforms/array';
6
- import object from './transforms/object';
7
- import primitives from './transforms/primitives';
5
+ import array from './array';
6
+ import object from './object';
7
+ import primitives from './primitives';
8
8
 
9
9
 
10
10
  let transforms = [object, array, primitives];
@@ -1,5 +1,5 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { code as c, type Replacement } from '@esportsplus/typescript/transformer';
2
+ import { code as c, type Replacement } from '@esportsplus/typescript/compiler';
3
3
  import { COMPILER_TYPES, PACKAGE } from '~/constants';
4
4
  import type { Bindings } from '~/types';
5
5
 
@@ -82,18 +82,18 @@ function buildClassCode(className: string, properties: AnalyzedProperty[], ns: s
82
82
  if (type === COMPILER_TYPES.Signal) {
83
83
  let param = `_v${paramCounter++}`;
84
84
 
85
- fields.push(`#${key} = ${ns}.signal(${valueText});`);
86
85
  accessors.push(`get ${key}() { return ${ns}.read(this.#${key}); }`);
87
86
  accessors.push(`set ${key}(${param}) { ${ns}.write(this.#${key}, ${param}); }`);
87
+ fields.push(`#${key} = ${ns}.signal(${valueText});`);
88
88
  }
89
89
  else if (type === COMPILER_TYPES.Array) {
90
- fields.push(`${key} = new ${ns}.ReactiveArray(${valueText});`);
91
90
  disposeStatements.push(`this.${key}.dispose();`);
91
+ fields.push(`${key} = new ${ns}.ReactiveArray(${valueText});`);
92
92
  }
93
93
  else if (type === COMPILER_TYPES.Computed) {
94
- fields.push(`#${key} = null;`);
95
94
  accessors.push(`get ${key}() { return ${ns}.read(this.#${key} ??= ${ns}.computed(${valueText})); }`);
96
95
  disposeStatements.push(`if (this.#${key}) ${ns}.dispose(this.#${key});`);
96
+ fields.push(`#${key} = null;`);
97
97
  }
98
98
  }
99
99
 
@@ -1,4 +1,4 @@
1
- import { plugin } from '@esportsplus/typescript/transformer';
1
+ import { plugin } from '@esportsplus/typescript/compiler';
2
2
  import { transform } from '..';
3
3
 
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { PACKAGE } from '../../constants';
2
- import { plugin } from '@esportsplus/typescript/transformer';
2
+ import { plugin } from '@esportsplus/typescript/compiler';
3
3
  import { transform } from '..';
4
4
 
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { ts } from '@esportsplus/typescript';
2
- import { code as c, type Range, type Replacement } from '@esportsplus/typescript/transformer';
2
+ import { ast, code as c, type Range, type Replacement } from '@esportsplus/typescript/compiler';
3
3
  import type { Bindings } from '~/types';
4
4
  import { COMPILER_ENTRYPOINT, COMPILER_TYPES, PACKAGE } from '~/constants';
5
5
 
@@ -30,36 +30,24 @@ interface TransformContext {
30
30
  }
31
31
 
32
32
 
33
- let COMPOUND_OPERATORS = new Map<ts.SyntaxKind, string>([
34
- [ts.SyntaxKind.AmpersandAmpersandEqualsToken, '&&'],
35
- [ts.SyntaxKind.AmpersandEqualsToken, '&'],
36
- [ts.SyntaxKind.AsteriskAsteriskEqualsToken, '**'],
37
- [ts.SyntaxKind.AsteriskEqualsToken, '*'],
38
- [ts.SyntaxKind.BarBarEqualsToken, '||'],
39
- [ts.SyntaxKind.BarEqualsToken, '|'],
40
- [ts.SyntaxKind.CaretEqualsToken, '^'],
41
- [ts.SyntaxKind.GreaterThanGreaterThanEqualsToken, '>>'],
42
- [ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken, '>>>'],
43
- [ts.SyntaxKind.LessThanLessThanEqualsToken, '<<'],
44
- [ts.SyntaxKind.MinusEqualsToken, '-'],
45
- [ts.SyntaxKind.PercentEqualsToken, '%'],
46
- [ts.SyntaxKind.PlusEqualsToken, '+'],
47
- [ts.SyntaxKind.QuestionQuestionEqualsToken, '??'],
48
- [ts.SyntaxKind.SlashEqualsToken, '/']
49
- ]);
50
-
51
-
52
- function classifyReactiveArg(arg: ts.Expression): COMPILER_TYPES | null {
53
- if (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) {
54
- return COMPILER_TYPES.Computed;
55
- }
56
-
57
- if (ts.isObjectLiteralExpression(arg) || ts.isArrayLiteralExpression(arg)) {
58
- return null;
59
- }
33
+ const COMPOUND_OPERATORS = new Map<ts.SyntaxKind, string>([
34
+ [ts.SyntaxKind.AmpersandAmpersandEqualsToken, '&&'],
35
+ [ts.SyntaxKind.AmpersandEqualsToken, '&'],
36
+ [ts.SyntaxKind.AsteriskAsteriskEqualsToken, '**'],
37
+ [ts.SyntaxKind.AsteriskEqualsToken, '*'],
38
+ [ts.SyntaxKind.BarBarEqualsToken, '||'],
39
+ [ts.SyntaxKind.BarEqualsToken, '|'],
40
+ [ts.SyntaxKind.CaretEqualsToken, '^'],
41
+ [ts.SyntaxKind.GreaterThanGreaterThanEqualsToken, '>>'],
42
+ [ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken, '>>>'],
43
+ [ts.SyntaxKind.LessThanLessThanEqualsToken, '<<'],
44
+ [ts.SyntaxKind.MinusEqualsToken, '-'],
45
+ [ts.SyntaxKind.PercentEqualsToken, '%'],
46
+ [ts.SyntaxKind.PlusEqualsToken, '+'],
47
+ [ts.SyntaxKind.QuestionQuestionEqualsToken, '??'],
48
+ [ts.SyntaxKind.SlashEqualsToken, '/']
49
+ ]);
60
50
 
61
- return COMPILER_TYPES.Signal;
62
- }
63
51
 
64
52
  function findBinding(bindings: ScopeBinding[], name: string, node: ts.Node): ScopeBinding | undefined {
65
53
  for (let i = 0, n = bindings.length; i < n; i++) {
@@ -96,18 +84,6 @@ function findEnclosingScope(node: ts.Node): ts.Node {
96
84
  return node.getSourceFile();
97
85
  }
98
86
 
99
- function isInComputedRange(ranges: Range[], start: number, end: number): boolean {
100
- for (let i = 0, n = ranges.length; i < n; i++) {
101
- let r = ranges[i];
102
-
103
- if (start >= r.start && end <= r.end) {
104
- return true;
105
- }
106
- }
107
-
108
- return false;
109
- }
110
-
111
87
  function isInDeclarationInit(node: ts.Node): boolean {
112
88
  let parent = node.parent;
113
89
 
@@ -197,7 +173,14 @@ function visit(ctx: TransformContext, node: ts.Node): void {
197
173
  node.arguments.length > 0
198
174
  ) {
199
175
  let arg = node.arguments[0],
200
- classification = classifyReactiveArg(arg);
176
+ classification: COMPILER_TYPES | null = COMPILER_TYPES.Signal;
177
+
178
+ if (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) {
179
+ classification = COMPILER_TYPES.Computed;
180
+ }
181
+ else if (ts.isObjectLiteralExpression(arg) || ts.isArrayLiteralExpression(arg)) {
182
+ classification = null;
183
+ }
201
184
 
202
185
  if (classification) {
203
186
  let varName: string | null = null;
@@ -262,7 +245,7 @@ function visit(ctx: TransformContext, node: ts.Node): void {
262
245
 
263
246
  let nodeStart = node.getStart(ctx.sourceFile);
264
247
 
265
- if (isInComputedRange(ctx.computedArgRanges, nodeStart, node.end)) {
248
+ if (ast.inRange(ctx.computedArgRanges, nodeStart, node.end)) {
266
249
  ts.forEachChild(node, n => visit(ctx, n));
267
250
  return;
268
251
  }
@@ -384,4 +367,4 @@ export default (sourceFile: ts.SourceFile, bindings: Bindings, ns: string): stri
384
367
  }
385
368
 
386
369
  return c.replace(code, ctx.replacements);
387
- };
370
+ };
package/src/constants.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { uid } from '@esportsplus/typescript/transformer';
1
+ import { uid } from '@esportsplus/typescript/compiler';
2
2
 
3
3
 
4
4
  const COMPILER_ENTRYPOINT = 'reactive';
File without changes