Commit ed6c7c6a authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Even more complex nested parsing test.

parent 329a23c0
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -82,10 +82,14 @@ module JsDuck
      case node["type"]
      when "Program", "BlockStatement"
        node["body"]
      when "FunctionDeclaration"
        # Always contains just a single BlockStatement,
        # so we just directly to the body of that.
        node["body"]["body"]
      when "FunctionDeclaration", "FunctionExpression", "ForStatement"
        [node["body"]]
      when "ExpressionStatement"
        [node["expression"]]
      when "CallExpression"
        [node["callee"]]
      when "IfStatement"
        [node["consequent"]]
      else
        puts "Unknown node type: "+node["type"]
      end
+22 −0
Original line number Diff line number Diff line
@@ -89,5 +89,27 @@ describe JsDuck::EsprimaParser do
    end
  end

  describe "parsing a heavily nested comment" do
    before do
      @docs = parse(<<-EOS)
        (function () {
            if (true) {
                var i;
                for (i=0; i<10; i++) {
                    // Function A
                    function a() {
                    }
                }
             }
        })();
      EOS
    end

    it "detects comment as belonging to the inner function" do
      @docs[0][:code]["type"].should == "FunctionDeclaration"
      @docs[0][:code]["id"]["name"].should == "a"
    end
  end

end