mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix suggesting components from types_generated directory (#51101)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51101 TS LSP suggests importing/using components from `types_generated` directory which are exported under slightly different name than root exports. Prefixing default exports with `$$` fixes the issue. Changelog: [Internal] Reviewed By: huntie Differential Revision: D74177107 fbshipit-source-id: 86a6869c2aa7a113915184e4857a7882710b1db4
This commit is contained in:
committed by
React Native Bot
parent
f70a146699
commit
d5c6afaae0
@@ -35,9 +35,9 @@ describe('replaceDefaultExportName', () => {
|
||||
const code = `export default Foo;`;
|
||||
const result = await translate(code, 'mock/path/to/module/Foo.js');
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"declare const Foo_DEFAULT: typeof Foo;
|
||||
declare type Foo_DEFAULT = typeof Foo_DEFAULT;
|
||||
export default Foo_DEFAULT;"
|
||||
"declare const $$Foo: typeof Foo;
|
||||
declare type $$Foo = typeof $$Foo;
|
||||
export default $$Foo;"
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,7 +19,10 @@ function createReplaceDefaultExportName(filePath: string): PluginObj<mixed> {
|
||||
const moduleName = fileName.split('.')[0];
|
||||
|
||||
if (node.node.name === '$$EXPORT_DEFAULT_DECLARATION$$') {
|
||||
node.node.name = `${moduleName}_DEFAULT`;
|
||||
// Prefixing with $$ prevents the TS LSP server from (incorrectly)
|
||||
// discovering identifiers outside of package.json "exports" in
|
||||
// autocomplete.
|
||||
node.node.name = `$$${moduleName}`;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user