Skip to content

Commit

Permalink
add accessor setters ordering test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 3, 2023
1 parent 9ed66d5 commit f2adf05
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
var log = [];

function push(x) {
log.push(x);
return x;
}

function logClassDecoratorRun(a, b, c) {
push(a);
return function (el, { addInitializer }) {
push(b);
addInitializer(function () {
push(c);
});
return el;
};
}

function logAccessorDecoratorRun(a, b, c, d, e, f) {
push(a);
return function ({ set }, { addInitializer }) {
push(b);
addInitializer(function () {
push(c);
});
return {
init: () => push(d),
set(v) { push(e); const result = set.call(this, v); push(f); return result; }
};
};
}

function logFieldDecoratorRun(a, b) {
push(a);
return function (el) { push(b); return el; };
}

@logClassDecoratorRun(0, 11, 13)
@logClassDecoratorRun(1, 10, 12)
class A {
@logAccessorDecoratorRun(2, 7, 15, 19, 22, 25)
@logAccessorDecoratorRun(3, 6, 14, 18, 23, 24)
accessor a;

@logAccessorDecoratorRun(4, 9, 17, 21, 26, 29)
@logAccessorDecoratorRun(5, 8, 16, 20, 27, 28)
accessor #b;

constructor() {
this.a = null;
this.#b = null;
}
}

var nums = Array.from({ length: 14 }, (_, i) => i);
expect(log).toEqual(nums);

new A();

var nums = Array.from({ length: 30 }, (_, i) => i);
expect(log).toEqual(nums);
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
var log = [];

function push(x) {
log.push(x);
return x;
}

function logClassDecoratorRun(a, b, c) {
push(a);
return function (el, { addInitializer }) {
push(b);
addInitializer(function () {
push(c);
});
return el;
};
}

function logAccessorDecoratorRun(a, b, c, d, e, f) {
push(a);
return function ({ set }, { addInitializer }) {
push(b);
addInitializer(function () {
push(c);
});
return {
init: () => push(d),
set(v) { push(e); const result = set.call(this, v); push(f); return result; }
};
};
}

function logFieldDecoratorRun(a, b) {
push(a);
return function (el) { push(b); return el; };
}

@logClassDecoratorRun(0, 11, 13)
@logClassDecoratorRun(1, 10, 12)
class A {
@logAccessorDecoratorRun(2, 7, 15, 19, 22, 25)
@logAccessorDecoratorRun(3, 6, 14, 18, 23, 24)
accessor a;

@logAccessorDecoratorRun(4, 9, 17, 21, 26, 29)
@logAccessorDecoratorRun(5, 8, 16, 20, 27, 28)
accessor #b;

constructor() {
this.a = null;
this.#b = null;
}
}

var nums = Array.from({ length: 14 }, (_, i) => i);
expect(log).toEqual(nums);

new A();

var nums = Array.from({ length: 30 }, (_, i) => i);
expect(log).toEqual(nums);

0 comments on commit f2adf05

Please sign in to comment.