Skip to content

Commit 04b6a17

Browse files
committed
rename ScopeCollector and give a detailed description
1 parent aed407b commit 04b6a17

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/swc.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ pub(crate) fn convert_span(span: Span) -> Range<u32> {
4141
span.lo.0..span.hi.0
4242
}
4343

44+
/// The ScopeCollector is responsible for collection function scopes and computing their names.
45+
///
46+
/// SWCs AST is based around the Visitor pattern. In this case our visitor has some
47+
/// method that act on different function-like AST nodes that we are interested in.
48+
/// From there, the node either has a name itself, or we infer its name from the
49+
/// "path" of parents.
50+
/// As a concrete example:
51+
/// `const name = () => {};`
52+
/// 1. The visitors `visit_arrow_expr` function is invoked for the arrow function
53+
/// on the right hand side. Arrow functions by definition do not have a name.
54+
/// 2. We use the "path" to walk up to the VariableDeclarator.
55+
/// 3. That declarator has a binding pattern on the left hand side, which we use
56+
/// to infer the `name` for the anonymous arrow function expression.
4457
struct ScopeCollector {
4558
scopes: Scopes,
4659
}

0 commit comments

Comments
 (0)