mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Disallow usage of "NativeProps" symbol in internal components (#51889)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51889 Changelog: [Internal] Reviewed By: huntie Differential Revision: D76244543 fbshipit-source-id: 0ccbc29f99e3fac992b8f0040e16a73f72350969
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b649791920
commit
daff0c99d5
@@ -30,6 +30,16 @@ describe('ensureNoUnprefixedProps', () => {
|
||||
await expect(translate(code)).rejects.toThrow();
|
||||
});
|
||||
|
||||
test('should throw when encountering unprefixed NativeProps type', async () => {
|
||||
const code = `type NativeProps = {}`;
|
||||
await expect(translate(code)).rejects.toThrow();
|
||||
});
|
||||
|
||||
test('should throw when encountering unprefixed NativeProps interface', async () => {
|
||||
const code = `interface NativeProps {}`;
|
||||
await expect(translate(code)).rejects.toThrow();
|
||||
});
|
||||
|
||||
test('should not throw when encountering prefixed Props type', async () => {
|
||||
const code = `type ViewProps = {}`;
|
||||
await expect(translate(code)).resolves.toBeDefined();
|
||||
|
||||
@@ -16,25 +16,24 @@ const {transformAST} = require('hermes-transform/dist/transform/transformAST');
|
||||
|
||||
const visitors: TransformVisitor = context => ({
|
||||
TypeAlias(node): void {
|
||||
if (node.id.name === 'Props') {
|
||||
if (node.id.name === 'Props' || node.id.name === 'NativeProps') {
|
||||
throw new Error(
|
||||
`Type alias 'Props' is not allowed. Use more descriptive name.`,
|
||||
`Type aliases 'Props' and 'NativeProps' are not allowed. Use more descriptive name.`,
|
||||
);
|
||||
}
|
||||
},
|
||||
InterfaceDeclaration(node): void {
|
||||
if (node.id.name === 'Props') {
|
||||
if (node.id.name === 'Props' || node.id.name === 'NativeProps') {
|
||||
throw new Error(
|
||||
`Type alias 'Props' is not allowed. Use more descriptive name.`,
|
||||
`Type aliases 'Props' and 'NativeProps' are not allowed. Use more descriptive name.`,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* flow-api-translator doesn't translate empty type to never due to difference
|
||||
* in semantics between the two. This is desirable behavtior in this case,
|
||||
* as it's the closest approximation of the empty type.
|
||||
* Prevents the usage of 'Props' and 'NativeProps' type aliases across the
|
||||
* public API of React Native.
|
||||
*/
|
||||
async function ensureNoUnprefixedProps(
|
||||
source: ParseResult,
|
||||
|
||||
Reference in New Issue
Block a user