From d303820d7d91e1c2d67251fbf434e971a3bb68ad Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 22 Mar 2024 18:02:19 +0000 Subject: [PATCH] add a test for decorator context names 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 --- .../class/decorator/context-name.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/language/statements/class/decorator/context-name.js diff --git a/test/language/statements/class/decorator/context-name.js b/test/language/statements/class/decorator/context-name.js new file mode 100644 index 00000000000..03081c3047a --- /dev/null +++ b/test/language/statements/class/decorator/context-name.js @@ -0,0 +1,30 @@ +/*--- +description: Decorator order of operations and access to context name +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]; + + @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()"], 'order of observable operations in evaluating class definition');