gpt4 book ai didi

javascript - 在 ES6 中执行一个函数时,什么时候进行词法分析和解析(这采用什么形式)?

转载 作者:行者123 更新时间:2023-11-30 16:55:46 25 4
gpt4 key购买 nike

脚本评估规范部分is here .

第 10 步 执行函数内容的词法分析和解析是否正确?如果不是,何时进行词法分析和解析?

  1. Let result be GlobalDeclarationInstantiation(ScriptBody, globalEnv).

是否在此时(第 10 步)LexicalEnvironment 上的[[Scope]] 被声明的函数和变量填充?

step 11是函数中的代码真正被“执行”的步骤吗?

  1. If result.[[type]] is normal, then Let result be the result of evaluating ScriptBody.

最佳答案

不,ScriptBody 是一个已经解析过的抽象语法树。解析确实发生在评估之前,在 ScriptEvaluationJob (sourceText) 中:

  1. Parse sourceText using Script as the goal symbol and analyze the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let code be the resulting parse tree. Otherwise, let code be an indication of one or more parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation dependent manner. If more than one parse or early error is present, the number and ordering of reported errors is implementation dependent but at least one error must be reported.

从高亮的句子可以看出,ES并没有真正区分parsing和lexing。
当然,还有以下注释允许过早优化推测性解析或using cached compilation results :

An implementation may parse a sourceText as a Script and analyze it for Early Error conditions prior to the execution of the ScriptEvaluationJob for that sourceText.

解析源代码也发生在 PerformEval 的第 3 步中, 里面 Function and GeneratorFunction constructorssomewhen for modules .

关于javascript - 在 ES6 中执行一个函数时,什么时候进行词法分析和解析(这采用什么形式)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29750830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com