Skip to content

Commit

Permalink
fix: include named exports in svelte 5 type
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Oct 9, 2024
1 parent 4dfb988 commit 896a7aa
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface ExportedName {
identifierText?: string;
required?: boolean;
doc?: string;
isNamedExport?: boolean;
}

export class ExportedNames {
Expand Down Expand Up @@ -127,9 +128,9 @@ export class ExportedNames {
if (ts.isNamedExports(exportClause)) {
for (const ne of exportClause.elements) {
if (ne.propertyName) {
this.addExport(ne.propertyName, false, ne.name);
this.addExport(ne.propertyName, false, ne.name, undefined, undefined, true);
} else {
this.addExport(ne.name, false);
this.addExport(ne.name, false, undefined, undefined, undefined, true);
}
}
//we can remove entire statement
Expand Down Expand Up @@ -552,24 +553,26 @@ export class ExportedNames {
isLet: boolean,
target: ts.Identifier = null,
type: ts.TypeNode = null,
required = false
required = false,
isNamedExport = false
): void {
const existingDeclaration = this.possibleExports.get(name.text);

if (target) {
this.exports.set(name.text, {
isLet: isLet || existingDeclaration?.isLet,
type: type?.getText() || existingDeclaration?.type,
identifierText: target.text,
required: required || existingDeclaration?.required,
doc: this.getDoc(target) || existingDeclaration?.doc
doc: this.getDoc(target) || existingDeclaration?.doc,
isNamedExport
});
} else {
this.exports.set(name.text, {
isLet: isLet || existingDeclaration?.isLet,
type: existingDeclaration?.type,
required: existingDeclaration?.required,
doc: existingDeclaration?.doc
doc: existingDeclaration?.doc,
isNamedExport
});
}

Expand Down Expand Up @@ -706,7 +709,7 @@ export class ExportedNames {
*/
createExportsStr(): string {
const names = Array.from(this.exports.entries());
const others = names.filter(([, { isLet }]) => !isLet);
const others = names.filter(([, { isLet, isNamedExport }]) => !isLet || isNamedExport);
const needsAccessors = this.usesAccessors && names.length > 0 && !this.usesRunes(); // runes mode doesn't support accessors

if (this.isSvelte5Plus) {
Expand Down

0 comments on commit 896a7aa

Please sign in to comment.