mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(semantic): add current_scope_flags function in SemanticBuilder (#1906)
This commit is contained in:
parent
a6d9356ffa
commit
b0569bc8e7
2 changed files with 8 additions and 5 deletions
|
|
@ -41,7 +41,7 @@ impl<'a> Binder for VariableDeclarator<'a> {
|
|||
// Logic for scope hoisting `var`
|
||||
|
||||
let mut var_scope_ids = vec![];
|
||||
if !builder.scope.get_flags(current_scope_id).is_var() {
|
||||
if !builder.current_scope_flags().is_var() {
|
||||
for scope_id in builder.scope.ancestors(current_scope_id).skip(1) {
|
||||
if builder.scope.get_flags(scope_id).is_var() {
|
||||
var_scope_ids.push(scope_id);
|
||||
|
|
@ -106,8 +106,7 @@ impl<'a> Binder for Function<'a> {
|
|||
fn bind(&self, builder: &mut SemanticBuilder) {
|
||||
let current_scope_id = builder.current_scope_id;
|
||||
if let Some(ident) = &self.id {
|
||||
let flags = builder.scope.get_flags(current_scope_id);
|
||||
if !flags.is_strict_mode()
|
||||
if !builder.current_scope_flags().is_strict_mode()
|
||||
&& matches!(
|
||||
builder.nodes.parent_kind(builder.current_node_id),
|
||||
Some(AstKind::IfStatement(_))
|
||||
|
|
@ -158,7 +157,7 @@ impl<'a> Binder for Function<'a> {
|
|||
}
|
||||
|
||||
// bind scope flags: Constructor | GetAccessor | SetAccessor
|
||||
debug_assert!(builder.scope.get_flags(current_scope_id).contains(ScopeFlags::Function));
|
||||
debug_assert!(builder.current_scope_flags().contains(ScopeFlags::Function));
|
||||
if let Some(kind) = builder.nodes.parent_kind(builder.current_node_id) {
|
||||
match kind {
|
||||
AstKind::MethodDefinition(def) => {
|
||||
|
|
|
|||
|
|
@ -219,8 +219,12 @@ impl<'a> SemanticBuilder<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn current_scope_flags(&self) -> ScopeFlags {
|
||||
self.scope.get_flags(self.current_scope_id)
|
||||
}
|
||||
|
||||
pub fn strict_mode(&self) -> bool {
|
||||
self.scope.get_flags(self.current_scope_id).is_strict_mode()
|
||||
self.current_scope_flags().is_strict_mode()
|
||||
|| self.current_node_flags.contains(NodeFlags::Class)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue