Skip to main content

declared_name

Function declared_name 

Source
pub fn declared_name(decl: &Declaration, node: Node<'_>) -> Option<String>
Expand description

The name a declaration node declares, when it declares one.

None for an anonymous default export — export default 1, export default () => {} — which is a real shape rather than a gap: it has no name, so a symbolOf following a chain to it has nothing better to report than default.

None for a destructured declarator too: export const { e } = { e: 2 } binds a pattern, whose text is { e } — and reporting a shape where a spelling belongs would put exported: "{ e }" on a Symbol, which a rule comparing against a required export name would read as a mismatch on conforming code. walk_export falls back to the name the chain was asked for, which is what a shorthand destructuring exports.

A dotted namespace’s name is its first segment: namespace A.B {} declares A, the same name the resolver binds for it, and A.B is a spelling no import can write.