In the ECMAScript spec, what are the semantic rules of VarScopedDeclarations and VarDeclaredNames of a non-empty block statement?

I’m studying the ECMAScript spec to find out what the expected behavior of vars statements inside a block is according to the spec:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>function test() {
console.log('before block', bar);
{
console.log('in block before declaration', bar);
var bar = 30;
console.log('in block after declaration', bar);
}
console.log('after block', bar);
}
test();</code>
<code>function test() { console.log('before block', bar); { console.log('in block before declaration', bar); var bar = 30; console.log('in block after declaration', bar); } console.log('after block', bar); } test();</code>
function test() {
    console.log('before block', bar);
    {
      console.log('in block before declaration', bar);
      var bar = 30;
      console.log('in block after declaration', bar); 
    }
    console.log('after block', bar);
}

test();

I know that var is not block-scoped. But I’m curious about how the spec uses concrete definitions of steps to achieve it.

I’ve read the semantics of the DeclarationInstantiation of function and global. They take static semantics VarDeclaredNames and VarScopedDeclarations of function body or script to create bindings to the environment record. But I can’t find the definition in these static semantics of how to deal with the block statement with the nested StatementList. The spec only defined the production for empty block (without any statement):

Or should Block: { StatementList } be seen as a StatementList directly?

But in 14.2 it is defined as a single statement?

I found other semantics include instructions for the production Block { statementList }, so I expect to see something like:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Block: { StatementList }
1. Return VarDeclaredNames of StatementList.
</code>
<code>Block: { StatementList } 1. Return VarDeclaredNames of StatementList. </code>
Block: { StatementList }
  1. Return VarDeclaredNames of StatementList.

Here’s the example defined instructions of production Block { statementList } in evaluation operation:

6

I expect to see something like:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Block: { StatementList }
1. Return VarDeclaredNames of StatementList.
</code>
<code>Block: { StatementList } 1. Return VarDeclaredNames of StatementList. </code>
Block: { StatementList }
  1. Return VarDeclaredNames of StatementList.

Your expectation is well-founded, but it would be rather boring and arduous to define VarDeclaredNames for every single syntactic element, doing nothing other than recursing into its descendant element.

So the spec authors decided to only provide an implicit definition for these Syntax-Directed Operations:

Unless explicitly specified otherwise, all chain
productions
have an implicit definition for every operation that might be applied
to that production’s left-hand side nonterminal. The implicit
definition simply reapplies the same operation with the same
parameters, if any, to the chain
production’s
sole right-hand side nonterminal and then returns the result.

See also the example following that paragraph.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật