Skip to content

getImport fallbacks to return namespace #2083

@vangata-ve

Description

@vangata-ve

Even before the refactor, getImport fallbacks to return all namespace imports if it doesn't find any "named" or "direct" imports. When I refactored the getImport function and introduced getAllImports I kept that behaviour but now that makes me wonder is this the correct intended behaviour?

const namespaceImport = imports.find((m) => {
return m.getMatch("NAMESPACE_ALIAS");
});
if (namespaceImport) {
return {
alias: namespaceImport.getMatch("NAMESPACE_ALIAS")?.text() ?? "",
isNamespace: true,
moduleType: "esm" as const, // Namespace imports are always ESM
node: namespaceImport.getMatch("NAMESPACE_ALIAS")! as unknown as SgNode<T, "identifier">,
};
}

For reference the piece of code before the refactor ^

Changing anything related to this would be considered a breaking change for the end-users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions