Skip to content

Commit

Permalink
add a test for decorator context names
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Mar 22, 2024
1 parent 0b1abd5 commit ec0d5a1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/language/statements/class/decorator/context-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*---
description: Decorator @ DecoratorCallExpression (Valid syntax for decorator on class.)
esid: pending
features: [class, decorators]
includes: [compareArray.js]
info: |
This was taken from the babel test suite https://github.com/babel/babel/blob/87ec4fc3d2cf44c30ef007f7da47d7177e07ffec/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-accessors/context-name/input.js#L1
---*/

const logs = [];
const dec = (value, context) => { logs.push(context.name) };
const f = () => { logs.push("computing f"); return { [Symbol.toPrimitive]: () => (logs.push("calling toPrimitive"), "f()") }; };
class Foo {
@dec static accessor a;
@dec static accessor #a;

@dec static accessor "b"
@dec static accessor ["c"];

@dec static accessor 0;
@dec static accessor [1];

// TODO these two throw an error with SyntaxError: Unexpected token ILLEGAL but they pass on babel's test suite. should we remove them?
@dec static accessor 2n;
@dec static accessor [3n];

@dec static accessor [f()];
}

assert.compareArray(logs, ["computing f", "calling toPrimitive", "a", "#a", "b", "c", "0", "1", "2", "3", "f()"], 'did it work>');

0 comments on commit ec0d5a1

Please sign in to comment.