Skip to content

Commit

Permalink
fix(linter): global variable check should always check builtin variables
Browse files Browse the repository at this point in the history
closes #3374
  • Loading branch information
Boshen committed Jun 29, 2024
1 parent 3c72ab7 commit f960ae1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/oxc_linter/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,16 @@ impl<'a> LintContext<'a> {
}

pub fn env_contains_var(&self, var: &str) -> bool {
if GLOBALS["builtin"].contains_key("var") {
return true;
}
for env in self.env().iter() {
let env = GLOBALS.get(env).unwrap_or(&GLOBALS["builtin"]);
if env.get(var).is_some() {
return true;
if let Some(env) = GLOBALS.get(env) {
if env.contains_key(var) {
return true;
}
}
}

false
}

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules/eslint/no_undef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ fn test() {
"class C { static { a; let a; } }",
"class C { static { function a() {} a; } }",
"class C { static { a; function a() {} } }",
"String;Array;Boolean;"
];

let fail = vec![
Expand Down

0 comments on commit f960ae1

Please sign in to comment.