forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transform that strips private properties in build types script
Summary: ## Changelog: [Internal] - Added transform that strips private properties in build-types script Differential Revision: D68892853
- Loading branch information
1 parent
252294b
commit 55b3c56
Showing
3 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
scripts/build/build-types/transforms/__tests__/stripPrivateProperties-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
const stripPrivateProperties = require('../stripPrivateProperties.js'); | ||
const {parse, print} = require('hermes-transform'); | ||
|
||
const prettierOptions = {parser: 'babel'}; | ||
|
||
async function translate(code: string): Promise<string> { | ||
const parsed = await parse(code); | ||
const result = await stripPrivateProperties(parsed); | ||
return print(result.ast, result.mutatedCode, prettierOptions); | ||
} | ||
|
||
describe('stripPrivateProperties', () => { | ||
it('should strip private properties', async () => { | ||
const code = `const Foo = { | ||
foo: 'foo', | ||
bar() {}, | ||
_privateFoo: 'privateFoo', | ||
_privateBar() {}, | ||
}`; | ||
const result = await translate(code); | ||
expect(result).toMatchInlineSnapshot(` | ||
"const Foo = { | ||
foo: \\"foo\\", | ||
bar() {}, | ||
}; | ||
" | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters