mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
feat(semantic): bind function expression name (#1049)
closes #1018 We'll eventually recover the mangling tests, which should cover this change.
This commit is contained in:
parent
64988f484b
commit
a442fad3b7
2 changed files with 15 additions and 21 deletions
|
|
@ -138,6 +138,16 @@ impl<'a> Binder for Function<'a> {
|
|||
excludes,
|
||||
);
|
||||
ident.symbol_id.set(Some(symbol_id));
|
||||
} else if self.r#type == FunctionType::FunctionExpression {
|
||||
// https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionexpression
|
||||
// 5. Perform ! funcEnv.CreateImmutableBinding(name, false).
|
||||
let symbol_id = builder.declare_symbol(
|
||||
ident.span,
|
||||
&ident.name,
|
||||
SymbolFlags::empty(),
|
||||
SymbolFlags::empty(),
|
||||
);
|
||||
ident.symbol_id.set(Some(symbol_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ impl Case for Test262Case {
|
|||
}
|
||||
|
||||
fn are_all_identifiers_resolved(semantic: &oxc_semantic::Semantic<'_>) -> bool {
|
||||
use oxc_ast::{ast, AstKind};
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_semantic::AstNode;
|
||||
|
||||
let ast_nodes = semantic.nodes();
|
||||
|
|
@ -212,27 +212,11 @@ fn are_all_identifiers_resolved(semantic: &oxc_semantic::Semantic<'_>) -> bool {
|
|||
AstKind::BindingIdentifier(id) => {
|
||||
let mut parents = ast_nodes.iter_parents(node.id()).map(AstNode::kind);
|
||||
parents.next(); // Exclude BindingIdentifier itself
|
||||
match parents.next() {
|
||||
Some(AstKind::Function(func))
|
||||
if func.r#type == ast::FunctionType::FunctionExpression =>
|
||||
{
|
||||
// FIXME: Currently, the name of `FunctionExpression` won't be assigned a `SymbolId`
|
||||
return false;
|
||||
}
|
||||
_ => {}
|
||||
if let (Some(AstKind::Function(_)), Some(AstKind::IfStatement(_))) =
|
||||
(parents.next(), parents.next())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let mut parents = ast_nodes.iter_parents(node.id()).map(AstNode::kind);
|
||||
parents.next(); // Exclude BindingIdentifier itself
|
||||
match (parents.next(), parents.next()) {
|
||||
// FIXME: case like `if (xx) ; else function test() {}`
|
||||
(Some(AstKind::Function(func)), Some(AstKind::IfStatement(_)))
|
||||
if func.r#type == ast::FunctionType::FunctionDeclaration =>
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
id.symbol_id.get().is_none()
|
||||
}
|
||||
AstKind::IdentifierReference(ref_id) => ref_id.reference_id.get().is_none(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue