mirror of
https://gitee.com/openharmony/third_party_typescript
synced 2024-11-23 06:50:54 +00:00
fix(39410): don't remove variables with type definition during converting named export to default (#39505)
This commit is contained in:
parent
3a75838cb7
commit
38cedc5b5f
@ -110,10 +110,11 @@ namespace ts.refactor {
|
||||
changes.insertNodeAfter(exportingSourceFile, exportKeyword, factory.createToken(SyntaxKind.DefaultKeyword));
|
||||
break;
|
||||
case SyntaxKind.VariableStatement:
|
||||
// If 'x' isn't used in this file, `export const x = 0;` --> `export default 0;`
|
||||
if (!FindAllReferences.Core.isSymbolReferencedInFile(exportName, checker, exportingSourceFile)) {
|
||||
// If 'x' isn't used in this file and doesn't have type definition, `export const x = 0;` --> `export default 0;`
|
||||
const decl = first(exportNode.declarationList.declarations);
|
||||
if (!FindAllReferences.Core.isSymbolReferencedInFile(exportName, checker, exportingSourceFile) && !decl.type) {
|
||||
// We checked in `getInfo` that an initializer exists.
|
||||
changes.replaceNode(exportingSourceFile, exportNode, factory.createExportDefault(Debug.checkDefined(first(exportNode.declarationList.declarations).initializer, "Initializer was previously known to be present")));
|
||||
changes.replaceNode(exportingSourceFile, exportNode, factory.createExportDefault(Debug.checkDefined(decl.initializer, "Initializer was previously known to be present")));
|
||||
break;
|
||||
}
|
||||
// falls through
|
||||
|
@ -28,6 +28,9 @@
|
||||
////export const x = 0;
|
||||
////x;
|
||||
|
||||
// @Filename: /var_with_type.ts
|
||||
////export const fn: (n: number) => number = (n) => 1;
|
||||
|
||||
const tests: { [fileName: string]: string | undefined } = {
|
||||
fn: `export default function f() {}`,
|
||||
|
||||
@ -59,6 +62,11 @@ export default T;
|
||||
`const x = 0;
|
||||
export default x;
|
||||
x;`,
|
||||
|
||||
var_with_type:
|
||||
`const fn: (n: number) => number = (n) => 1;
|
||||
export default fn;
|
||||
`,
|
||||
};
|
||||
|
||||
for (const name in tests) {
|
||||
|
Loading…
Reference in New Issue
Block a user