fix: directive 序言字符串按源序先发射且完成值参与收敛

This commit is contained in:
2026-09-14 21:07:10 +00:00
parent 647fb31af7
commit ca5c27574e
3 changed files with 12 additions and 1 deletions
+6
View File
@@ -1870,6 +1870,12 @@ impl Emitter {
// 第二个 sub-pass:发其余所有语句。
let mut last_result: Option<u32> = None;
// directive 序言是 AST 独立字段(顶格字符串字面量,不在 body):作为语句
// 序列的头前缀按源序先于 body 发射。完成值即字符串值本身,参与"最后非空
// 完成值"收敛;严格模式标志由 has_use_strict_directive 独立处理,此处不涉。
for dir in &program.directives {
last_result = Some(self.emit_string_literal_expression(&dir.expression, &mut ctx)?);
}
for stmt in &program.body {
if matches!(stmt, Statement::FunctionDeclaration(_)) {
continue; // Already emitted above