diff --git a/compiler/src/import_path_expand.ts b/compiler/src/import_path_expand.ts index 8a4c98582f519b180f906d945061df6e590eace9..63109115c634a13ef2a149f926faa7384059b33b 100644 --- a/compiler/src/import_path_expand.ts +++ b/compiler/src/import_path_expand.ts @@ -34,7 +34,8 @@ interface ImportInfo { interface SymbolInfo { filePath: string, isDefault: boolean, - skipTransform: boolean + skipTransform: boolean, + exportName?: string } interface SeparatedImportInfos { @@ -121,7 +122,7 @@ function processDefaultImport(checker: ts.TypeChecker, importMap: Map m.kind === ts.SyntaxKind.ExportKeyword)) { + return [false, symbol.name]; + } } const sourceFile = decl.getSourceFile(); for (const stmt of sourceFile.statements) { - if (isDefaultExportAssignment(stmt, symbol)) { - return true; - } - if (isNamedDefaultExport(stmt, symbol)) { - return true; - } - if (isNamedDefaultDecl(stmt, decl, symbol)) { - return true; + if (ts.isExportAssignment(stmt) && !stmt.isExportEquals && ts.isIdentifier(stmt.expression) && stmt.expression.text === symbol.name) { + return [true, 'default']; } - } - return false; -} - -function isDefaultExportAssignment(stmt: ts.Statement, symbol: ts.Symbol): boolean { - return ts.isExportAssignment(stmt) && - !stmt.isExportEquals && - ts.isIdentifier(stmt.expression) && - stmt.expression.text === symbol.name; -} - -function isNamedDefaultExport(stmt: ts.Statement, symbol: ts.Symbol): boolean { - if (!ts.isExportDeclaration(stmt) || !stmt.exportClause || !ts.isNamedExports(stmt.exportClause)) { - return false; - } - for (const specifier of stmt.exportClause.elements) { - if (specifier.name.text === 'default' && specifier.propertyName?.text === symbol.name) { - return true; + if (ts.isExportDeclaration(stmt) && stmt.exportClause && ts.isNamedExports(stmt.exportClause)) { + for (const specifier of stmt.exportClause.elements) { + if (specifier.name.text === 'default' && specifier.propertyName?.text === symbol.name) { + return [true, 'default']; + } + if (specifier.name.text === 'default' && !specifier.propertyName) { + return [false, '']; + } + if (specifier.name.text !== 'default' && specifier.propertyName?.text === symbol.name) { + return [false, specifier.name.text]; + } + if (specifier.name.text !== 'default' && specifier.name.text === symbol.name) { + return [false, symbol.name]; + } + } } - if (specifier.name.text === 'default' && !specifier.propertyName) { - return false; + if (stmt.modifiers?.some(m => m.kind === ts.SyntaxKind.ExportKeyword) && stmt.name?.text === decl.name?.getText()) { + if (stmt.modifiers?.some(m => m.kind === ts.SyntaxKind.DefaultKeyword)) { + return [true, 'default']; + } + return [false, stmt.name?.text]; } } - return false; -} - -function isNamedDefaultDecl(stmt: ts.Statement, decl: ts.Declaration, symbol: ts.Symbol): boolean { - return symbol.name === 'default' && - (ts.isFunctionDeclaration(stmt) || ts.isClassDeclaration(stmt)) && - stmt.modifiers?.some(m => m.kind === ts.SyntaxKind.DefaultKeyword) && - stmt.name?.text === decl.name?.getText(); + return [false, '']; } \ No newline at end of file