fix(linter) Fix panic when linting declaration files (#1014)

When linting declaration files, it panics here 


6628fc8d9c/crates/oxc_linter/src/rules/eslint/no_global_assign.rs (L57)

with this error:
```
index out of bounds: the len is 0 but the index is 0
```

Because it expects the array to have the root scope id inside (non zero
len)


0fcad27515/crates/oxc_semantic/src/scope.rs (L52-L54)
This commit is contained in:
Cameron 2023-10-21 02:25:32 +01:00 committed by GitHub
parent d31a667e23
commit c4a2084f27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -151,7 +151,9 @@ impl<'a> SemanticBuilder<'a> {
}
pub fn build(mut self, program: &Program<'a>) -> SemanticBuilderReturn<'a> {
if !self.source_type.is_typescript_definition() {
if self.source_type.is_typescript_definition() {
self.scope.add_scope(None, ScopeFlags::Top);
} else {
self.visit_program(program);
// Checking syntax error on module record requires scope information from the previous AST pass