Esempio n. 1
0
        private static void Walk([NotNull] Agent agent, [NotNull] BlockStatementNode blockStatement, bool isStrict)
        {
            //https://tc39.github.io/ecma262/#sec-block-static-semantics-early-errors

            var lexicalNames = LexicallyDeclaredNamesWalker.Walk(blockStatement);

            if (lexicalNames.Count > 0)
            {
                var set           = new HashSet <string>();
                var variableNames = VarDeclaredNamesWalker.Walk(blockStatement);

                foreach (var name in lexicalNames)
                {
                    if (!set.Add(name))
                    {
                        throw agent.CreateSyntaxError("Duplicate lexical declaration at " + blockStatement.Location);
                    }
                }

                foreach (var name in variableNames)
                {
                    if (!set.Add(name))
                    {
                        throw agent.CreateSyntaxError("Variable declaration when a lexical declaration already exists at " + blockStatement.Location);
                    }
                }
            }

            foreach (var node in blockStatement.Body)
            {
                Walk(agent, node, isStrict);
            }
        }
Esempio n. 2
0
        public static void Walk([NotNull] Agent agent, [NotNull] ProgramNode program, bool isStrict)
        {
            //https://tc39.github.io/ecma262/#sec-scripts-static-semantics-early-errors
            var lexicalNames = LexicallyDeclaredNamesWalker.Walk(program);

            if (ContainsDuplicate(lexicalNames))
            {
                throw agent.CreateSyntaxError();
            }

            foreach (var baseNode in program.Body)
            {
                Walk(agent, baseNode, isStrict);
            }
        }