Skip to content
Open
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
1 change: 1 addition & 0 deletions packages/react-native-babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@babel/plugin-transform-async-to-generator": "^7.24.7",
"@babel/plugin-transform-block-scoping": "^7.25.0",
"@babel/plugin-transform-class-properties": "^7.25.4",
"@babel/plugin-transform-class-static-block": "^7.26.0",
"@babel/plugin-transform-classes": "^7.25.4",
"@babel/plugin-transform-destructuring": "^7.24.8",
"@babel/plugin-transform-flow-strip-types": "^7.25.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,84 @@ describe('react-native-babel-preset transform snapshots', () => {
expect(result).toContain('_classPrivateFieldLooseKey');
});

it('transforms class static blocks without unstable_preserveClassPrivate', () => {
const code = `
class Config {
static value = 0;
static {
Config.value = 2;
}
}
`;
const result = transformCode(code, {
dev: false,
unstable_transformProfile: 'hermes-stable',
});
expect(result).not.toContain('static {');
expect(result).toContain('Config.value = 2');
});

it('transforms class static blocks when the profile lowers classes', () => {
const code = `
class Config {
static value = 0;
static {
Config.value = 2;
}
}
`;
const result = transformCode(code, {
dev: false,
unstable_transformProfile: 'hermes-legacy',
customTransformOptions: {
unstable_preserveClassPrivate: true,
},
});
expect(result).not.toContain('static {');
expect(result).toContain('Config.value = 2');
});

it('transforms class static blocks that use private fields and super', () => {
const code = `
class Base {
static base = 1;
}
class Config extends Base {
static #secret = 1;
static value = 0;
static {
Config.value = Config.#secret + super.base;
}
}
`;
const result = transformCode(code, {
dev: false,
unstable_transformProfile: 'hermes-stable',
});
expect(result).not.toContain('static {');
expect(result).not.toContain('#secret');
});

it('preserves class static blocks with unstable_preserveClassPrivate', () => {
const code = `
class Config {
static #secret = 1;
static {
Config.value = Config.#secret;
}
}
`;
const result = transformCode(code, {
dev: false,
unstable_transformProfile: 'hermes-stable',
customTransformOptions: {
unstable_preserveClassPrivate: true,
},
});
expect(result).toContain('static {');
expect(result).toContain('#secret');
});

it('preserves async/await with unstable_preserveAsync', () => {
const code = `
async function fetchData() {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-babel-preset/src/configs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ const getPreset = (src, options, babel) => {
...(preserveClassPrivate
? []
: [
[require('@babel/plugin-transform-class-static-block')],
[require('@babel/plugin-transform-private-methods'), {loose}],
[
require('@babel/plugin-transform-private-property-in-object'),
Expand Down
Loading