mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-27 12:11:12 +08:00
feat: import defer 阶段标志纳入模块哈希键
This commit is contained in:
@@ -98,6 +98,9 @@ pub(super) fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher, inc
|
||||
}
|
||||
Statement::ImportDeclaration(imp) => {
|
||||
imp.source.value.hash(h);
|
||||
// import 阶段标志(import defer / source-phase imports):同源声明
|
||||
// 语义不同,须区分缓存键,防 defer 与非 defer 碰撞复用错误字节码。
|
||||
imp.phase.map(|p| p as u8).hash(h);
|
||||
if let Some(specifiers) = &imp.specifiers {
|
||||
(specifiers.len() as u32).hash(h);
|
||||
for spec in specifiers {
|
||||
|
||||
@@ -86,6 +86,27 @@ fn import_expression_distinguished() {
|
||||
assert_ne!(compiled("import('./a.js')"), compiled("import('./a.js', { with: { type: 'json' } })"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_defer_distinguished() {
|
||||
// import defer 与普通 namespace import 语义不同(defer 不触发依赖求值):
|
||||
// 修复前 phase 不入 hash,两者哈希相同 → 缓存碰撞复用错误字节码。
|
||||
assert_ne!(
|
||||
compiled("import defer * as ns from './x.js'"),
|
||||
compiled("import * as ns from './x.js'"),
|
||||
"import defer vs plain namespace import must differ"
|
||||
);
|
||||
assert_ne!(
|
||||
structural("import defer * as ns from './x.js'"),
|
||||
structural("import * as ns from './x.js'"),
|
||||
"defer flag must be part of the structural key too"
|
||||
);
|
||||
// 同源等价回归
|
||||
assert_eq!(
|
||||
compiled("import defer * as ns from './x.js'"),
|
||||
compiled("import defer * as ns from './x.js'")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn structural_hash_ignores_binding_names() {
|
||||
// 结构哈希忽略绑定名:仅参数/变量改名后哈希相等。
|
||||
|
||||
Reference in New Issue
Block a user