use std::sync::Arc;
use tsz_binder::SymbolId;
use super::CheckerContext;
impl<'a> CheckerContext<'a> {
pub fn has_promise_in_lib(&self) -> bool {
for lib_ctx in &self.lib_contexts {
if lib_ctx.binder.file_locals.has("Promise") {
return true;
}
}
if self.binder.current_scope.has("Promise") {
return true;
}
if self.binder.file_locals.has("Promise") {
return true;
}
false
}
pub fn has_promise_constructor_in_scope(&self) -> bool {
use tsz_binder::symbol_flags;
if self.has_name_in_lib("PromiseConstructor") {
return true;
}
let check_symbol_has_value =
|sym_id: tsz_binder::SymbolId, binder: &tsz_binder::BinderState| -> bool {
if let Some(sym) = binder.symbols.get(sym_id) {
(sym.flags & symbol_flags::VALUE) != 0
} else {
false
}
};
for lib_ctx in &self.lib_contexts {
if let Some(sym_id) = lib_ctx.binder.file_locals.get("Promise")
&& check_symbol_has_value(sym_id, &lib_ctx.binder)
{
return true;
}
}
if let Some(sym_id) = self.binder.current_scope.get("Promise")
&& check_symbol_has_value(sym_id, self.binder)
{
return true;
}
if let Some(sym_id) = self.binder.file_locals.get("Promise")
&& check_symbol_has_value(sym_id, self.binder)
{
return true;
}
false
}
pub fn has_symbol_in_lib(&self) -> bool {
for lib_ctx in &self.lib_contexts {
if lib_ctx.binder.file_locals.has("Symbol") {
return true;
}
}
if self.binder.current_scope.has("Symbol") {
return true;
}
if self.binder.file_locals.has("Symbol") {
return true;
}
false
}
pub fn has_name_in_lib(&self, name: &str) -> bool {
for lib_ctx in &self.lib_contexts {
if lib_ctx.binder.file_locals.has(name) {
return true;
}
}
if self.binder.current_scope.has(name) {
return true;
}
if self.binder.file_locals.has(name) {
return true;
}
false
}
pub fn symbol_is_from_lib(&self, sym_id: SymbolId) -> bool {
let Some(symbol_arena) = self.binder.symbol_arenas.get(&sym_id) else {
return false;
};
self.lib_contexts
.iter()
.any(|lib_ctx| Arc::ptr_eq(&lib_ctx.arena, symbol_arena))
}
pub fn is_known_global_type(&self, name: &str) -> bool {
use tsz_binder::lib_loader;
if lib_loader::is_es2015_plus_type(name) {
return true;
}
matches!(
name,
"Object"
| "Function"
| "Array"
| "String"
| "Number"
| "Boolean"
| "Date"
| "RegExp"
| "Error"
| "Math"
| "JSON"
| "console"
| "window"
| "document"
| "ArrayBuffer"
| "DataView"
| "Int8Array"
| "Uint8Array"
| "Uint8ClampedArray"
| "Int16Array"
| "Uint16Array"
| "Int32Array"
| "Uint32Array"
| "Float32Array"
| "Float64Array"
| "this"
| "globalThis"
| "IArguments"
)
}
}