From 638cd964260576ecacb6add97765d4ce9fd6f520 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 5 Dec 2024 20:12:07 +0000 Subject: [PATCH] test(transformer/class-properties): exec test for `this` in computed key --- .../snapshots/oxc_exec.snap.md | 13 +++++++---- .../fixtures/this-in-computed-key/exec.js | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tasks/transform_conformance/tests/babel-plugin-transform-class-properties/test/fixtures/this-in-computed-key/exec.js diff --git a/tasks/transform_conformance/snapshots/oxc_exec.snap.md b/tasks/transform_conformance/snapshots/oxc_exec.snap.md index 6d56660afcba59..6011c1f98042f7 100644 --- a/tasks/transform_conformance/snapshots/oxc_exec.snap.md +++ b/tasks/transform_conformance/snapshots/oxc_exec.snap.md @@ -1,8 +1,13 @@ commit: 54a8389f node: v22.11.0 -filter: fixtures/oxc -include: **/*.{test,spec}.?(c|m)[jt]s?(x) -exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**, **/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*, "" -No test files found, exiting with code 1 + RUN v2.1.2 /Users/jim/Programming/crates/oxc/tasks/transform_conformance + + ✓ fixtures/oxc/babel-plugin-transform-class-properties-test-fixtures-this-in-computed-key-exec.test.js (1 test) 2ms + + Test Files 1 passed (1) + Tests 1 passed (1) + Start at 20:11:31 + Duration 188ms (transform 13ms, setup 0ms, collect 7ms, tests 2ms, environment 0ms, prepare 37ms) + diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-class-properties/test/fixtures/this-in-computed-key/exec.js b/tasks/transform_conformance/tests/babel-plugin-transform-class-properties/test/fixtures/this-in-computed-key/exec.js new file mode 100644 index 00000000000000..c04fae047aa6d1 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-class-properties/test/fixtures/this-in-computed-key/exec.js @@ -0,0 +1,22 @@ +function createClassDeclaration() { + class C { + [this] = 1; + [this + 'bar'] = 2; + } + return C; +} + +function createClassExpression() { + return class { + [this] = 3; + [this + 'bar'] = 4; + }; +} + +const C = createClassDeclaration.call("foo"); +expect(new C().foo).toBe(1); +expect(new C().foobar).toBe(2); + +const D = createClassExpression.call("foo"); +expect(new D().foo).toBe(3); +expect(new D().foobar).toBe(4);