Loading lib/jsduck/esprima_parser.rb +8 −4 Original line number Diff line number Diff line Loading @@ -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 Loading spec/esprima_parser_spec.rb +22 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
lib/jsduck/esprima_parser.rb +8 −4 Original line number Diff line number Diff line Loading @@ -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 Loading
spec/esprima_parser_spec.rb +22 −0 Original line number Diff line number Diff line Loading @@ -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