@esportsplus/reactivity 0.38.0 → 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.
package/build/compiler/array.js
CHANGED
|
@@ -79,7 +79,9 @@ function length(access, replacements) {
|
|
|
79
79
|
: `${expr.getText(sf)}.$length = ${expr.getText(sf)}.length ${op} ${parent.right.getText(sf)}`
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
else if (parent &&
|
|
82
|
+
else if (parent &&
|
|
83
|
+
(ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) &&
|
|
84
|
+
(parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) {
|
|
83
85
|
let op = parent.operator === ts.SyntaxKind.PlusPlusToken ? '+' : '-';
|
|
84
86
|
replacements.push({
|
|
85
87
|
node: parent,
|
package/package.json
CHANGED
package/src/compiler/array.ts
CHANGED
|
@@ -133,7 +133,11 @@ function length(access: ts.PropertyAccessExpression, replacements: ReplacementIn
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
// arr.length++ / arr.length-- / ++arr.length / --arr.length
|
|
136
|
-
else if (
|
|
136
|
+
else if (
|
|
137
|
+
parent &&
|
|
138
|
+
(ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) &&
|
|
139
|
+
(parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)
|
|
140
|
+
) {
|
|
137
141
|
let op = parent.operator === ts.SyntaxKind.PlusPlusToken ? '+' : '-';
|
|
138
142
|
|
|
139
143
|
replacements.push({
|
|
@@ -347,6 +347,20 @@ describe('array transform', () => {
|
|
|
347
347
|
expect(output).toContain('arr.$length = arr.length + 3');
|
|
348
348
|
});
|
|
349
349
|
|
|
350
|
+
it('transforms arr.length++ and --arr.length to $length writes', () => {
|
|
351
|
+
expect(transformArray('let arr = reactive([1]); arr.length++;').output).toContain('arr.$length = arr.length + 1');
|
|
352
|
+
expect(transformArray('let arr = reactive([1]); --arr.length;').output).toContain('arr.$length = arr.length - 1');
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('transforms non-mutating unary operators on arr.length as reads', () => {
|
|
356
|
+
for (let op of ['!', '-', '+', '~']) {
|
|
357
|
+
let { output } = transformArray(`let arr = reactive([1]); let x = ${op}arr.length;`);
|
|
358
|
+
|
|
359
|
+
expect(output).toContain(`${op}arr.$length`);
|
|
360
|
+
expect(output).not.toContain('arr.$length =');
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
350
364
|
it('transforms every compound operator on arr.length with its own token', () => {
|
|
351
365
|
for (let op of ['<<', '>>', '>>>', '??', '||', '&&', '-', '*', '/', '%', '**', '&', '|', '^']) {
|
|
352
366
|
let { output } = transformArray(`let arr = reactive([1]); arr.length ${op}= 2;`);
|