Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored and Dunqing committed Nov 25, 2024
1 parent 0bb2c8b commit ea274bc
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1,443 deletions.
11 changes: 6 additions & 5 deletions crates/oxc_traverse/scripts/lib/walk.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,19 @@ function generateWalkForStruct(type, types) {
// In final version, we should not make `scope_id` fields `Cell`s to prevent this.

// const Var = Self::Top.bits() | Self::Function.bits() | Self::ClassStaticBlock.bits() | Self::TsModuleBlock.bits();
let isVarHoistingScope = type.name == "Function" || ["Top", "Function", "ClassStaticBlock", "TsModuleBlock"]
.some(flag => scopeArgs.flags.includes(flag));
let isVarHoistingScope = type.name == 'Function' || ['Top', 'Function', 'ClassStaticBlock', 'TsModuleBlock']
.some(flag => scopeArgs.flags.includes(flag));

console.log("isVarHoistingScope", type.name, isVarHoistingScope, scopeArgs);
enterScopeCode = `
let previous_scope_id = ctx.current_scope_id();
${isVarHoistingScope ? `let previous_var_hoisting_scope_id = ctx.scoping.current_var_hoisting_scope_id();` : ''}
let current_scope_id = (*(${makeFieldCode(scopeIdField)})).get().unwrap();
ctx.set_current_scope_id(current_scope_id, ${isVarHoistingScope ? "Some(current_scope_id)" : "None"});
ctx.set_current_scope_id(current_scope_id, ${isVarHoistingScope ? 'Some(current_scope_id)' : 'None'});
`;

exitScopeCode = `ctx.set_current_scope_id(previous_scope_id, ${isVarHoistingScope ? "Some(previous_var_hoisting_scope_id)" : "None"} );`;
exitScopeCode = `ctx.set_current_scope_id(previous_scope_id, ${
isVarHoistingScope ? 'Some(previous_var_hoisting_scope_id)' : 'None'
} );`;
}

const fieldsCodes = visitedFields.map((field, index) => {
Expand Down
15 changes: 8 additions & 7 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl TraverseScoping {
self.current_scope_id
}

/// Get current scope ID
/// Get current var hoisting scope ID
#[inline]
pub(crate) fn current_var_hoisting_scope_id(&self) -> ScopeId {
self.current_var_hoisting_scope_id
Expand Down Expand Up @@ -171,17 +171,18 @@ impl TraverseScoping {
self.scopes.delete_scope(scope_id);
}

pub fn add_binding(
/// Add binding to specified scope, If the binding can be hoisted, it will be added to the current var hoisting scope.
pub(crate) fn add_binding(
&mut self,
scope_id: ScopeId,
name: CompactStr,
flags: SymbolFlags,
) -> SymbolId {
// println!(
// "{name:?} {scope_id:?} {:?} {:?}",
// self.scopes.get_flags(scope_id),
// self.current_var_hoisting_scope_id
// );
// Determine whether to add the binding to the current scope or the var hoisting scope.
// 1. Check if the scope_id is the current var hoisting scope id.
// 2. Check if the symbol flags are not exactly SymbolFlags::FunctionScopedVariable (which means it cannot be hoisted).
// 3. Check if the scope_id is a var scope (which means the scope is already at the top of the var hoisting scope).
// If any of the above conditions are true, then the symbol does not need to be hoisted.
let scope_id = if scope_id == self.current_var_hoisting_scope_id
|| flags != SymbolFlags::FunctionScopedVariable
|| self.scopes.get_flags(scope_id).is_var()
Expand Down
Loading

0 comments on commit ea274bc

Please sign in to comment.