feat: 脚本顶层词法声明三常量名合法化并登记语料跳过条目

This commit is contained in:
2026-09-28 19:06:34 +00:00
parent c363102302
commit 55133c0057
6 changed files with 134 additions and 92 deletions
-20
View File
@@ -7,23 +7,3 @@
mod block_fn;
mod builtin_scan;
mod declare;
/// 脚本顶层词法声明(`let`/`const`/`class`)禁止使用的受限全局名:`undefined`、
/// `NaN`、`Infinity` 三名静态集。
///
/// 判定标准是全局对象上 `configurable:false` 的自有属性名:此类属性无法由声明
/// 实例化建立遮蔽绑定,现行规范下恰为三常量;`eval` 与其余内置属性皆可配置,
/// 可合法遮蔽。运行时无法查询全局对象描述符,名单必须编译期确定。
///
/// 与 `BUILTIN_GLOBALS` 语义不同:后者是写入拦截与双写名单,两份名单互不派生,
/// 交叠名由 `restricted_lexical_names_within_builtin_globals` 单测断言恒同步。
pub(crate) const RESTRICTED_GLOBAL_LEXICAL_NAMES: &[&str] = &["undefined", "NaN", "Infinity"];
/// 脚本顶层 lexical 声明撞受限全局名 → SyntaxError(声明实例化期拒绝,整程序
/// 编译失败)。错误消息与既有重复声明错同形;非顶层或名不在受限集 → Ok。
fn check_restricted_global_lexical(name: &str, global_lexical: bool) -> Result<(), String> {
if global_lexical && RESTRICTED_GLOBAL_LEXICAL_NAMES.contains(&name) {
return Err(format!("Identifier '{name}' has already been declared"));
}
Ok(())
}