Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/playwright/src/transform/babelBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ function babelTransformOptions(isTypeScript: boolean, isModule: boolean, plugins

if (isTypeScript) {
plugins.push(
// Strip "declare" class fields before these plugins run:
// - plugin-proposal-decorators
// - plugin-transform-class-properties
// - plugin-transform-private-methods
// See https://github.com/microsoft/playwright/issues/38586
[
(): PluginObj => ({
name: 'strip-declare-class-fields',
visitor: {
Class(path) {
for (const member of path.get('body.body')) {
if (member.isClassProperty() && member.node.declare)
member.remove();
}
}
}
})
],
[require('@babel/plugin-proposal-decorators'), { version: '2023-05' }],
[require('@babel/plugin-transform-class-properties')],
[require('@babel/plugin-transform-class-static-block')],
Expand Down
31 changes: 31 additions & 0 deletions tests/playwright-test/babel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ test('should succeed', async ({ runInlineTest }) => {
expect(result.failed).toBe(0);
});

test('should support declare class fields', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/38586' },
}, async ({ runInlineTest }) => {
const result = await runInlineTest({
'one-success.spec.ts': `
import { test, expect } from '@playwright/test';
class Base {
constructor(p1, p2) {
this.p1 = p1;
this.p2 = p2;
}
}
class Derived extends Base {
p1: string;
declare p2: string;
}
test('works', () => {
const d = new Derived('value1', 'value2');
expect(d.p1).toBe(undefined);
expect(d.p2).toBe('value2');
})
`
});
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
expect(result.failed).toBe(0);
});

test('should treat enums equally', async ({ runInlineTest }) => {
const result = await runInlineTest({
'component.tsx': `
Expand Down
Loading