mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 12:51:57 +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`
|
// Logic for scope hoisting `var`
|
||||||
|
|
||||||
let mut var_scope_ids = vec![];
|
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) {
|
for scope_id in builder.scope.ancestors(current_scope_id).skip(1) {
|
||||||
if builder.scope.get_flags(scope_id).is_var() {
|
if builder.scope.get_flags(scope_id).is_var() {
|
||||||
var_scope_ids.push(scope_id);
|
var_scope_ids.push(scope_id);
|
||||||
|
|
@ -106,8 +106,7 @@ impl<'a> Binder for Function<'a> {
|
||||||
fn bind(&self, builder: &mut SemanticBuilder) {
|
fn bind(&self, builder: &mut SemanticBuilder) {
|
||||||
let current_scope_id = builder.current_scope_id;
|
let current_scope_id = builder.current_scope_id;
|
||||||
if let Some(ident) = &self.id {
|
if let Some(ident) = &self.id {
|
||||||
let flags = builder.scope.get_flags(current_scope_id);
|
if !builder.current_scope_flags().is_strict_mode()
|
||||||
if !flags.is_strict_mode()
|
|
||||||
&& matches!(
|
&& matches!(
|
||||||
builder.nodes.parent_kind(builder.current_node_id),
|
builder.nodes.parent_kind(builder.current_node_id),
|
||||||
Some(AstKind::IfStatement(_))
|
Some(AstKind::IfStatement(_))
|
||||||
|
|
@ -158,7 +157,7 @@ impl<'a> Binder for Function<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind scope flags: Constructor | GetAccessor | SetAccessor
|
// 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) {
|
if let Some(kind) = builder.nodes.parent_kind(builder.current_node_id) {
|
||||||
match kind {
|
match kind {
|
||||||
AstKind::MethodDefinition(def) => {
|
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 {
|
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)
|
|| self.current_node_flags.contains(NodeFlags::Class)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue