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:
Boshen 2023-10-24 17:25:12 +08:00 committed by GitHub
parent 64988f484b
commit a442fad3b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 21 deletions

View file

@ -138,6 +138,16 @@ impl<'a> Binder for Function<'a> {
excludes, excludes,
); );
ident.symbol_id.set(Some(symbol_id)); 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));
} }
} }

View file

@ -203,7 +203,7 @@ impl Case for Test262Case {
} }
fn are_all_identifiers_resolved(semantic: &oxc_semantic::Semantic<'_>) -> bool { fn are_all_identifiers_resolved(semantic: &oxc_semantic::Semantic<'_>) -> bool {
use oxc_ast::{ast, AstKind}; use oxc_ast::AstKind;
use oxc_semantic::AstNode; use oxc_semantic::AstNode;
let ast_nodes = semantic.nodes(); let ast_nodes = semantic.nodes();
@ -212,27 +212,11 @@ fn are_all_identifiers_resolved(semantic: &oxc_semantic::Semantic<'_>) -> bool {
AstKind::BindingIdentifier(id) => { AstKind::BindingIdentifier(id) => {
let mut parents = ast_nodes.iter_parents(node.id()).map(AstNode::kind); let mut parents = ast_nodes.iter_parents(node.id()).map(AstNode::kind);
parents.next(); // Exclude BindingIdentifier itself parents.next(); // Exclude BindingIdentifier itself
match parents.next() { if let (Some(AstKind::Function(_)), Some(AstKind::IfStatement(_))) =
Some(AstKind::Function(func)) (parents.next(), parents.next())
if func.r#type == ast::FunctionType::FunctionExpression => {
{ return false;
// FIXME: Currently, the name of `FunctionExpression` won't be assigned a `SymbolId`
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() id.symbol_id.get().is_none()
} }
AstKind::IdentifierReference(ref_id) => ref_id.reference_id.get().is_none(), AstKind::IdentifierReference(ref_id) => ref_id.reference_id.get().is_none(),