What's the difference between VarDeclaredNames and VarScopedDeclarations?

我与影子孤独终老i 提交于 2019-12-01 14:48:45

Those two static semantic rules search the AST for the same kinds of things: VariableDeclarations, ForBindings, FunctionDeclarations and GeneratorDeclarations. There's a lot of duplication (especially in methodology) indeed.

However, as @loganfsmyth mentions in the comments, they do return different data - different types of lists. While VarDeclaredNames returns a list of names (strings), VarScopedDeclarations does return a list of declarations (i.e. AST nodes).

This is apparent in the sections where something is actually appended to the lists: §13.3.2.2, §13.7.4.5, §13.7.5.7, and §13.2.9 all do refer to the BoundNames of the respective element, while §13.3.2.3, §13.7.4.6, §13.7.5.8, and §13.2.10 do refer to the respective declaration itself.

Why is this distinction needed? The VarDeclaredNames are used to create the bindings in the scope, while the VarScopedDeclarations are used to find the function declarations to create (and initialise the bindings with those values).

Could it have been simpler? Yes, surely - for lexical declarations, the scope initialisation description just iterates the declarations and gets the BoundNames of each. You might want to submit a bug to spec authors to use this approach for function-level declarations as well. See issue 1203 discussing this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!