Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit eb321b5

Browse files
committed
fix: mutating a value should recompute the existence of the value
1 parent a1a69bc commit eb321b5

6 files changed

Lines changed: 136 additions & 39 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"benchmarks": "node build/benchmarks/index.js",
2424
"lint": "eslint . --ext=.ts",
2525
"format": "prettier --write .",
26-
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json adonisjs/validator"
26+
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json adonisjs/validator",
27+
"vscode:test": "node -r @adonisjs/require-ts/build/register bin/test.ts"
2728
},
2829
"types": "./build/adonis-typings/index.d.ts",
2930
"author": "virk,adonisjs",

src/Compiler/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class Compiler {
7373
* Returns the declaration for the undefined and the null check
7474
*/
7575
public getVariableExistsDeclaration(variableName: string) {
76-
return `const ${this.getVariableExistsName(variableName)} = ${
76+
return `let ${this.getVariableExistsName(variableName)} = ${
7777
this.COMPILER_REFERENCES.exists
7878
}(${variableName})`
7979
}
@@ -85,6 +85,9 @@ export class Compiler {
8585
public getMutationFnDeclararationExpression(variableName: string) {
8686
return `function ${this.getVariableMutationName(variableName)} (newValue) {
8787
${variableName} = newValue;
88+
${this.getVariableExistsName(variableName)} = ${
89+
this.COMPILER_REFERENCES.exists
90+
}(${variableName});
8891
}`
8992
}
9093

test/array-compiler.spec.ts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ test.group('Array Compiler', () => {
8282
.map((line) => line.trim()),
8383
`// Validate root['users']
8484
let val_0 = root['users'];
85-
const val_0_exists = helpers.exists(val_0);
85+
let val_0_exists = helpers.exists(val_0);
8686
function mutate_val_0 (newValue) {
8787
val_0 = newValue;
88+
val_0_exists = helpers.exists(val_0);
8889
}
8990
const val_0_options = {
9091
root,
@@ -103,9 +104,10 @@ test.group('Array Compiler', () => {
103104
104105
// Validate val_0[index_0]
105106
let val_1 = val_0[index_0];
106-
const val_1_exists = helpers.exists(val_1);
107+
let val_1_exists = helpers.exists(val_1);
107108
function mutate_val_1 (newValue) {
108109
val_1 = newValue;
110+
val_1_exists = helpers.exists(val_1);
109111
}
110112
const val_1_options = {
111113
root,
@@ -124,9 +126,10 @@ test.group('Array Compiler', () => {
124126
125127
// Validate val_1['username']
126128
let val_2 = val_1['username'];
127-
const val_2_exists = helpers.exists(val_2);
129+
let val_2_exists = helpers.exists(val_2);
128130
function mutate_val_2 (newValue) {
129131
val_2 = newValue;
132+
val_2_exists = helpers.exists(val_2);
130133
}
131134
const val_2_options = {
132135
root,
@@ -204,9 +207,10 @@ test.group('Array Compiler', () => {
204207
.map((line) => line.trim()),
205208
`// Validate root['users']
206209
let val_0 = root['users'];
207-
const val_0_exists = helpers.exists(val_0);
210+
let val_0_exists = helpers.exists(val_0);
208211
function mutate_val_0 (newValue) {
209212
val_0 = newValue;
213+
val_0_exists = helpers.exists(val_0);
210214
}
211215
const val_0_options = {
212216
root,
@@ -225,9 +229,10 @@ test.group('Array Compiler', () => {
225229
226230
// Validate val_0[index_0]
227231
let val_1 = val_0[index_0];
228-
const val_1_exists = helpers.exists(val_1);
232+
let val_1_exists = helpers.exists(val_1);
229233
function mutate_val_1 (newValue) {
230234
val_1 = newValue;
235+
val_1_exists = helpers.exists(val_1);
231236
}
232237
const val_1_options = {
233238
root,
@@ -319,9 +324,10 @@ test.group('Array Compiler', () => {
319324
.map((line) => line.trim()),
320325
`// Validate root['users']
321326
let val_0 = root['users'];
322-
const val_0_exists = helpers.exists(val_0);
327+
let val_0_exists = helpers.exists(val_0);
323328
function mutate_val_0 (newValue) {
324329
val_0 = newValue;
330+
val_0_exists = helpers.exists(val_0);
325331
}
326332
const val_0_options = {
327333
root,
@@ -410,9 +416,10 @@ test.group('Array Compiler', () => {
410416
.map((line) => line.trim()),
411417
`// Validate root['users']
412418
let val_0 = root['users'];
413-
const val_0_exists = helpers.exists(val_0);
419+
let val_0_exists = helpers.exists(val_0);
414420
function mutate_val_0 (newValue) {
415421
val_0 = newValue;
422+
val_0_exists = helpers.exists(val_0);
416423
}
417424
const val_0_options = {
418425
root,
@@ -431,9 +438,10 @@ test.group('Array Compiler', () => {
431438
432439
// Validate val_0[index_0]
433440
let val_1 = val_0[index_0];
434-
const val_1_exists = helpers.exists(val_1);
441+
let val_1_exists = helpers.exists(val_1);
435442
function mutate_val_1 (newValue) {
436443
val_1 = newValue;
444+
val_1_exists = helpers.exists(val_1);
437445
}
438446
const val_1_options = {
439447
root,
@@ -452,9 +460,10 @@ test.group('Array Compiler', () => {
452460
453461
// Validate val_1['username']
454462
let val_2 = val_1['username'];
455-
const val_2_exists = helpers.exists(val_2);
463+
let val_2_exists = helpers.exists(val_2);
456464
function mutate_val_2 (newValue) {
457465
val_2 = newValue;
466+
val_2_exists = helpers.exists(val_2);
458467
}
459468
const val_2_options = {
460469
root,
@@ -547,9 +556,10 @@ test.group('Array Compiler', () => {
547556
.map((line) => line.trim()),
548557
`// Validate root['users']
549558
let val_0 = root['users'];
550-
const val_0_exists = helpers.exists(val_0);
559+
let val_0_exists = helpers.exists(val_0);
551560
function mutate_val_0 (newValue) {
552561
val_0 = newValue;
562+
val_0_exists = helpers.exists(val_0);
553563
}
554564
const val_0_options = {
555565
root,
@@ -568,9 +578,10 @@ test.group('Array Compiler', () => {
568578
569579
// Validate val_0[index_0]
570580
let val_1 = val_0[index_0];
571-
const val_1_exists = helpers.exists(val_1);
581+
let val_1_exists = helpers.exists(val_1);
572582
function mutate_val_1 (newValue) {
573583
val_1 = newValue;
584+
val_1_exists = helpers.exists(val_1);
574585
}
575586
const val_1_options = {
576587
root,
@@ -589,9 +600,10 @@ test.group('Array Compiler', () => {
589600
590601
// Validate val_1['username']
591602
let val_2 = val_1['username'];
592-
const val_2_exists = helpers.exists(val_2);
603+
let val_2_exists = helpers.exists(val_2);
593604
function mutate_val_2 (newValue) {
594605
val_2 = newValue;
606+
val_2_exists = helpers.exists(val_2);
595607
}
596608
const val_2_options = {
597609
root,
@@ -682,9 +694,10 @@ test.group('Array Compiler', () => {
682694
.map((line) => line.trim()),
683695
`// Validate root['geolocation']
684696
let val_0 = root['geolocation'];
685-
const val_0_exists = helpers.exists(val_0);
697+
let val_0_exists = helpers.exists(val_0);
686698
function mutate_val_0 (newValue) {
687699
val_0 = newValue;
700+
val_0_exists = helpers.exists(val_0);
688701
}
689702
const val_0_options = {
690703
root,
@@ -703,9 +716,10 @@ test.group('Array Compiler', () => {
703716
704717
// Validate val_0[index_0]
705718
let val_1 = val_0[index_0];
706-
const val_1_exists = helpers.exists(val_1);
719+
let val_1_exists = helpers.exists(val_1);
707720
function mutate_val_1 (newValue) {
708721
val_1 = newValue;
722+
val_1_exists = helpers.exists(val_1);
709723
}
710724
const val_1_options = {
711725
root,
@@ -725,9 +739,10 @@ test.group('Array Compiler', () => {
725739
726740
// Validate val_1[index_1]
727741
let val_2 = val_1[index_1];
728-
const val_2_exists = helpers.exists(val_2);
742+
let val_2_exists = helpers.exists(val_2);
729743
function mutate_val_2 (newValue) {
730744
val_2 = newValue;
745+
val_2_exists = helpers.exists(val_2);
731746
}
732747
const val_2_options = {
733748
root,
@@ -834,9 +849,10 @@ test.group('Array Compiler', () => {
834849
.map((line) => line.trim()),
835850
`// Validate root['users']
836851
let val_0 = root['users'];
837-
const val_0_exists = helpers.exists(val_0);
852+
let val_0_exists = helpers.exists(val_0);
838853
function mutate_val_0 (newValue) {
839854
val_0 = newValue;
855+
val_0_exists = helpers.exists(val_0);
840856
}
841857
const val_0_options = {
842858
root,
@@ -855,9 +871,10 @@ test.group('Array Compiler', () => {
855871
856872
// Validate val_0[index_0]
857873
let val_1 = val_0[index_0];
858-
const val_1_exists = helpers.exists(val_1);
874+
let val_1_exists = helpers.exists(val_1);
859875
function mutate_val_1 (newValue) {
860876
val_1 = newValue;
877+
val_1_exists = helpers.exists(val_1);
861878
}
862879
const val_1_options = {
863880
root,
@@ -876,9 +893,10 @@ test.group('Array Compiler', () => {
876893
877894
// Validate val_1['scores']
878895
let val_2 = val_1['scores'];
879-
const val_2_exists = helpers.exists(val_2);
896+
let val_2_exists = helpers.exists(val_2);
880897
function mutate_val_2 (newValue) {
881898
val_2 = newValue;
899+
val_2_exists = helpers.exists(val_2);
882900
}
883901
const val_2_options = {
884902
root,
@@ -898,9 +916,10 @@ test.group('Array Compiler', () => {
898916
899917
// Validate val_2[index_1]
900918
let val_3 = val_2[index_1];
901-
const val_3_exists = helpers.exists(val_3);
919+
let val_3_exists = helpers.exists(val_3);
902920
function mutate_val_3 (newValue) {
903921
val_3 = newValue;
922+
val_3_exists = helpers.exists(val_3);
904923
}
905924
const val_3_options = {
906925
root,

test/literal-compiler.spec.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ test.group('Literal Compiler', () => {
8282
.map((line) => line.trim()),
8383
`// Validate root['username']
8484
let val_0 = root['username'];
85-
const val_0_exists = helpers.exists(val_0);
85+
let val_0_exists = helpers.exists(val_0);
8686
function mutate_val_0 (newValue) {
8787
val_0 = newValue;
88+
val_0_exists = helpers.exists(val_0);
8889
}
8990
const val_0_options = {
9091
root,
@@ -144,9 +145,10 @@ test.group('Literal Compiler', () => {
144145
.map((line) => line.trim()),
145146
`// Validate root['username']
146147
let val_0 = root['username'];
147-
const val_0_exists = helpers.exists(val_0);
148+
let val_0_exists = helpers.exists(val_0);
148149
function mutate_val_0 (newValue) {
149150
val_0 = newValue;
151+
val_0_exists = helpers.exists(val_0);
150152
}
151153
const val_0_options = {
152154
root,
@@ -206,9 +208,10 @@ test.group('Literal Compiler', () => {
206208
.map((line) => line.trim()),
207209
`// Validate root['username']
208210
let val_0 = root['username'];
209-
const val_0_exists = helpers.exists(val_0);
211+
let val_0_exists = helpers.exists(val_0);
210212
function mutate_val_0 (newValue) {
211213
val_0 = newValue;
214+
val_0_exists = helpers.exists(val_0);
212215
}
213216
const val_0_options = {
214217
root,
@@ -268,9 +271,10 @@ test.group('Literal Compiler', () => {
268271
.map((line) => line.trim()),
269272
`// Validate root['username']
270273
let val_0 = root['username'];
271-
const val_0_exists = helpers.exists(val_0);
274+
let val_0_exists = helpers.exists(val_0);
272275
function mutate_val_0 (newValue) {
273276
val_0 = newValue;
277+
val_0_exists = helpers.exists(val_0);
274278
}
275279
const val_0_options = {
276280
root,
@@ -325,7 +329,7 @@ test.group('Literal Compiler', () => {
325329
.map((line) => line.trim()),
326330
`// Validate root['username']
327331
let val_0 = root['username'];
328-
const val_0_exists = helpers.exists(val_0);`
332+
let val_0_exists = helpers.exists(val_0);`
329333
.split('\n')
330334
.map((line) => line.trim())
331335
)
@@ -372,9 +376,10 @@ test.group('Literal Compiler', () => {
372376
.map((line) => line.trim()),
373377
`// Validate root['username']
374378
let val_0 = root['username'];
375-
const val_0_exists = helpers.exists(val_0);
379+
let val_0_exists = helpers.exists(val_0);
376380
function mutate_val_0 (newValue) {
377381
val_0 = newValue;
382+
val_0_exists = helpers.exists(val_0);
378383
}
379384
const val_0_options = {
380385
root,
@@ -431,9 +436,10 @@ test.group('Literal Compiler', () => {
431436
.map((line) => line.trim()),
432437
`// Validate root['username']
433438
let val_0 = root['username'];
434-
const val_0_exists = helpers.exists(val_0);
439+
let val_0_exists = helpers.exists(val_0);
435440
function mutate_val_0 (newValue) {
436441
val_0 = newValue;
442+
val_0_exists = helpers.exists(val_0);
437443
}
438444
const val_0_options = {
439445
root,

0 commit comments

Comments
 (0)