mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(semantic): simplify inherit scope flags from parent scope (#4664)
close: #3862 This is reaming last part of close #3862
This commit is contained in:
parent
e8b662a314
commit
6e453db3f7
2 changed files with 8 additions and 18 deletions
|
|
@ -510,10 +510,9 @@ impl<'a> SemanticBuilder<'a> {
|
|||
|
||||
impl<'a> Visit<'a> for SemanticBuilder<'a> {
|
||||
// NB: Not called for `Program`
|
||||
fn enter_scope(&mut self, flags: ScopeFlags, scope_id: &Cell<Option<ScopeId>>) {
|
||||
fn enter_scope(&mut self, mut flags: ScopeFlags, scope_id: &Cell<Option<ScopeId>>) {
|
||||
let parent_scope_id = self.current_scope_id;
|
||||
|
||||
let mut flags = flags;
|
||||
if !flags.is_strict_mode() && self.current_node_flags.has_class() {
|
||||
// NOTE A class definition is always strict mode code.
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
|
|
|
|||
|
|
@ -116,27 +116,18 @@ impl ScopeTree {
|
|||
&mut self.flags[scope_id]
|
||||
}
|
||||
|
||||
pub fn get_new_scope_flags(&self, flags: ScopeFlags, parent_scope_id: ScopeId) -> ScopeFlags {
|
||||
let mut strict_mode = self.root_flags().is_strict_mode();
|
||||
let parent_scope_flags = self.get_flags(parent_scope_id);
|
||||
|
||||
// Inherit strict mode for functions
|
||||
pub fn get_new_scope_flags(
|
||||
&self,
|
||||
mut flags: ScopeFlags,
|
||||
parent_scope_id: ScopeId,
|
||||
) -> ScopeFlags {
|
||||
// https://tc39.es/ecma262/#sec-strict-mode-code
|
||||
if !strict_mode
|
||||
&& (parent_scope_flags.is_function() || parent_scope_flags.is_ts_module_block())
|
||||
&& parent_scope_flags.is_strict_mode()
|
||||
{
|
||||
strict_mode = true;
|
||||
}
|
||||
let parent_scope_flags = self.get_flags(parent_scope_id);
|
||||
flags |= parent_scope_flags & ScopeFlags::StrictMode;
|
||||
|
||||
// inherit flags for non-function scopes
|
||||
let mut flags = flags;
|
||||
if !flags.contains(ScopeFlags::Function) {
|
||||
flags |= parent_scope_flags & ScopeFlags::Modifiers;
|
||||
};
|
||||
|
||||
if strict_mode {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
|
||||
flags
|
||||
|
|
|
|||
Loading…
Reference in a new issue