use phf::phf_set;
static JS_GLOBALS_SET: phf::Set<&'static str> = phf_set! {
"Infinity",
"undefined",
"NaN",
"Array",
"Boolean",
"Date",
"Error",
"Function",
"JSON",
"Math",
"Number",
"Object",
"Promise",
"Proxy",
"Reflect",
"RegExp",
"Set",
"String",
"Symbol",
"Map",
"WeakMap",
"WeakSet",
"BigInt",
"parseInt",
"parseFloat",
"isNaN",
"isFinite",
"decodeURI",
"decodeURIComponent",
"encodeURI",
"encodeURIComponent",
"arguments",
"console",
"window",
"document",
"navigator",
"globalThis",
"require",
"import",
"exports",
"module",
};
static RENDER_LOCALS_SET: phf::Set<&'static str> = phf_set! {
"_ctx", "_cache", "_push", "_parent", };
static EVENT_LOCALS_SET: phf::Set<&'static str> = phf_set! {
"$event",
};
static VUE_BUILTINS_SET: phf::Set<&'static str> = phf_set! {
"$slots",
"$refs",
"$parent",
"$root",
"$emit",
"$attrs",
"$data",
"$props",
"$el",
"$options",
"$forceUpdate",
"$nextTick",
"$watch",
};
static BUILTIN_COMPONENTS_SET: phf::Set<&'static str> = phf_set! {
"Transition",
"TransitionGroup",
"KeepAlive",
"Suspense",
"Teleport",
"BaseTransition",
"transition",
"transition-group",
"keep-alive",
"suspense",
"teleport",
"base-transition",
"component",
"slot",
"template",
};
static GLOBAL_ALLOWLIST_SET: phf::Set<&'static str> = phf_set! {
"Infinity", "undefined", "NaN",
"Array", "Boolean", "Date", "Error", "Function", "JSON", "Math",
"Number", "Object", "Promise", "Proxy", "Reflect", "RegExp",
"Set", "String", "Symbol", "Map", "WeakMap", "WeakSet", "BigInt",
"parseInt", "parseFloat", "isNaN", "isFinite",
"decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent",
"arguments", "console", "window", "document", "navigator", "globalThis",
"require", "import", "exports", "module",
"_ctx", "_cache", "_push", "_parent",
"$event",
"_toNumber",
};
#[inline]
pub fn is_js_global(name: &str) -> bool {
JS_GLOBALS_SET.contains(name)
}
#[inline]
pub fn is_render_local(name: &str) -> bool {
RENDER_LOCALS_SET.contains(name)
}
#[inline]
pub fn is_event_local(name: &str) -> bool {
EVENT_LOCALS_SET.contains(name)
}
#[inline]
pub fn is_vue_builtin(name: &str) -> bool {
VUE_BUILTINS_SET.contains(name)
}
#[inline]
pub fn is_builtin_component(name: &str) -> bool {
BUILTIN_COMPONENTS_SET.contains(name)
}
#[inline]
pub fn is_global_allowed(name: &str) -> bool {
GLOBAL_ALLOWLIST_SET.contains(name)
}
#[cfg(test)]
mod tests {
use super::{
is_builtin_component, is_event_local, is_global_allowed, is_js_global, is_render_local,
is_vue_builtin,
};
#[test]
fn test_js_globals() {
assert!(is_js_global("Array"));
assert!(is_js_global("Object"));
assert!(is_js_global("console"));
assert!(!is_js_global("myVar"));
}
#[test]
fn test_render_locals() {
assert!(is_render_local("_ctx"));
assert!(is_render_local("_cache"));
assert!(!is_render_local("_myLocal"));
}
#[test]
fn test_event_locals() {
assert!(is_event_local("$event"));
assert!(!is_event_local("event"));
}
#[test]
fn test_vue_builtins() {
assert!(is_vue_builtin("$slots"));
assert!(is_vue_builtin("$emit"));
assert!(is_vue_builtin("$attrs"));
assert!(!is_vue_builtin("count"));
}
#[test]
fn test_builtin_components() {
assert!(is_builtin_component("Transition"));
assert!(is_builtin_component("KeepAlive"));
assert!(!is_builtin_component("MyComponent"));
}
#[test]
fn test_global_allowed() {
assert!(is_global_allowed("Array"));
assert!(is_global_allowed("console"));
assert!(is_global_allowed("_ctx"));
assert!(is_global_allowed("_cache"));
assert!(is_global_allowed("$event"));
assert!(!is_global_allowed("$slots"));
assert!(!is_global_allowed("$emit"));
assert!(!is_global_allowed("myVar"));
}
}