1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Vue's template-expression globals, separate from host JavaScript scopes.
//!
//! A name may exist on the browser/Node host while still resolving through the
//! component proxy in a Vue template. Keep this compiler policy independent of
//! Croquis' broader semantic global inventory.
//!
//! Reference: vuejs/core v3.5.41 packages/shared/src/globalsAllowList.ts.
/// Whether Vue leaves an authored template global unprefixed.
#[inline]
pub fn is_vue_template_global(name: &str) -> bool {
matches!(
name,
"Infinity"
| "undefined"
| "NaN"
| "isFinite"
| "isNaN"
| "parseFloat"
| "parseInt"
| "decodeURI"
| "decodeURIComponent"
| "encodeURI"
| "encodeURIComponent"
| "Math"
| "Number"
| "Date"
| "Array"
| "Object"
| "Boolean"
| "String"
| "RegExp"
| "Map"
| "Set"
| "JSON"
| "Intl"
| "BigInt"
| "console"
| "Error"
| "Symbol"
)
}
#[cfg(test)]
mod tests {
use super::is_vue_template_global;
#[test]
fn host_globals_do_not_extend_the_vue_template_allowlist() {
for name in [
"document",
"window",
"navigator",
"globalThis",
"Promise",
"Proxy",
"Function",
"Reflect",
"WeakMap",
"WeakSet",
"module",
"exports",
"TypeError",
"Uint8Array",
] {
assert!(!is_vue_template_global(name), "{name}");
}
for name in ["Math", "Intl", "Array", "console", "undefined", "Symbol"] {
assert!(is_vue_template_global(name), "{name}");
}
}
}