diff --git a/tests/e2e/builder/cases/decorator/latest/index.test.ts b/tests/e2e/builder/cases/decorator/latest/index.test.ts deleted file mode 100644 index a528e20de505..000000000000 --- a/tests/e2e/builder/cases/decorator/latest/index.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import path from 'path'; -import { expect } from '@modern-js/e2e/playwright'; -import { build, getHrefByEntryName } from '@scripts/shared'; -import { webpackOnlyTest } from '@scripts/helper'; - -webpackOnlyTest('decorator latest', async ({ page }) => { - const builder = await build({ - cwd: __dirname, - entry: { - index: path.resolve(__dirname, './src/index.js'), - }, - runServer: true, - builderConfig: { - output: { - enableLatestDecorators: true, - }, - }, - }); - - await page.goto(getHrefByEntryName('index', builder.port)); - expect(await page.evaluate('window.aaa')).toBe('hello world'); - - // swc... - if (builder.providerType !== 'rspack') { - expect(await page.evaluate('window.bbb')).toContain( - "Cannot assign to read only property 'message' of object", - ); - - expect(await page.evaluate('window.ccc')).toContain( - "Cannot assign to read only property 'message' of object", - ); - } - - builder.close(); -}); diff --git a/tests/e2e/builder/cases/decorator/latest/src/index.js b/tests/e2e/builder/cases/decorator/latest/src/index.js deleted file mode 100644 index 3c002075c6ad..000000000000 --- a/tests/e2e/builder/cases/decorator/latest/src/index.js +++ /dev/null @@ -1,51 +0,0 @@ -// only have one param -function readonly(elementDescriptor) { - elementDescriptor.descriptor.writable = false; - - return elementDescriptor; -} - -function decorator(value) { - return function (elementDescriptor) { - const original = elementDescriptor.descriptor.value; - - elementDescriptor.descriptor.value = function (...args) { - return original.apply(this, args) + value; - }; - - return elementDescriptor; - }; -} - -class TestClass { - @readonly - message = 'hello'; - - @decorator(' world') - targetMethod() { - return this.message; - } - - update() { - try { - this.message = 'aaaa'; - } catch (e) { - // eslint-disable-next-line no-undef - window.bbb = e.message; - } - } -} - -const instance = new TestClass(); - -// eslint-disable-next-line no-undef -window.aaa = instance.targetMethod(); - -instance.update(); - -try { - instance.message = 'bbbb'; -} catch (e) { - // eslint-disable-next-line no-undef - window.ccc = e.message; -} diff --git a/tests/integration/swc/fixtures/decorator/new/modern.config.ts b/tests/integration/swc/fixtures/decorator/new/modern.config.ts index 3b4896c36640..2bbd294588b9 100644 --- a/tests/integration/swc/fixtures/decorator/new/modern.config.ts +++ b/tests/integration/swc/fixtures/decorator/new/modern.config.ts @@ -2,14 +2,9 @@ import appTools, { defineConfig } from '@modern-js/app-tools'; import { swcPlugin } from '@modern-js/plugin-swc'; export default defineConfig({ - tools: { - swc: { - jsc: { - transform: { - /** use new decorator */ - legacyDecorator: false, - }, - }, + source: { + decorators: { + version: '2022-03', }, }, output: { diff --git a/tests/integration/swc/fixtures/decorator/new/src/index.js b/tests/integration/swc/fixtures/decorator/new/src/index.js index 7589b8ffefdb..cc3ff720f011 100644 --- a/tests/integration/swc/fixtures/decorator/new/src/index.js +++ b/tests/integration/swc/fixtures/decorator/new/src/index.js @@ -1,9 +1,9 @@ -function newDecorator() { +function newDecorator(value) { console.log('foo decorator'); } class Foo { - @newDecorator() + @newDecorator foo() { console.log('foo'); } diff --git a/tests/integration/swc/tests/decorator.test.ts b/tests/integration/swc/tests/decorator.test.ts index 24251ad87818..c9411ab253b3 100644 --- a/tests/integration/swc/tests/decorator.test.ts +++ b/tests/integration/swc/tests/decorator.test.ts @@ -6,7 +6,7 @@ const fixtures = path.resolve(__dirname, '../fixtures'); const getJsFiles = (appDir: string) => readdirSync(path.resolve(appDir, 'dist/static/js')) - .filter(filepath => /\.js$/.test(filepath)) + .filter(filepath => /\.js.map$/.test(filepath)) .map(filePath => readFileSync(path.join(appDir, 'dist/static/js', filePath)), ); @@ -19,7 +19,9 @@ describe('swc use new decorator', () => { const jsFiles = getJsFiles(appDir); expect( - jsFiles.some(item => item.includes('@swc/helpers/esm/_decorate.js')), + jsFiles.some(item => + item.includes('@swc/helpers/esm/_apply_decs_2203_r.js'), + ), ).toBeTruthy(); });