Loading lib/jsduck/esprima_parser.rb +12 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ module JsDuck # :comment => "The contents of the comment", # :code => {...AST data structure for code following the comment...}, # :linenr => 12, // Beginning with 1 # :type => :doc_comment, // or :plain_comment # } # def parse(input) Loading Loading @@ -80,10 +81,20 @@ module JsDuck @start_linenr = 1 @ast["comments"].map do |comment| # Detect comment type and strip * at the beginning of doc-comment value = comment["value"] if comment["type"] == "Block" && value =~ /\A\*/ type = :doc_comment value = value.slice(1, value.length-1) else type = :plain_comment end { :comment => comment["value"], :comment => value, :code => stuff_after(comment), :linenr => line_number(comment["range"][0]), :type => type, } end end Loading spec/esprima_parser_spec.rb +38 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,44 @@ describe JsDuck::EsprimaParser do end end describe "parsing line comment" do before do @docs = parse("// Hello world") end it "results in plain comment" do @docs[0][:type].should == :plain_comment end end describe "parsing block comment" do before do @docs = parse("/* Hello world */") end it "results in plain comment" do @docs[0][:type].should == :plain_comment end it "doesn't strip anything from the beginning of comment" do @docs[0][:comment].should == " Hello world " end end describe "parsing block comment beginning with /**" do before do @docs = parse("/** Hello world */") end it "results in doc comment" do @docs[0][:type].should == :doc_comment end it "strips * at the beginning of comment" do @docs[0][:comment].should == " Hello world " end end describe "parsing comment after function" do before do @docs = parse(<<-EOS) Loading Loading
lib/jsduck/esprima_parser.rb +12 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ module JsDuck # :comment => "The contents of the comment", # :code => {...AST data structure for code following the comment...}, # :linenr => 12, // Beginning with 1 # :type => :doc_comment, // or :plain_comment # } # def parse(input) Loading Loading @@ -80,10 +81,20 @@ module JsDuck @start_linenr = 1 @ast["comments"].map do |comment| # Detect comment type and strip * at the beginning of doc-comment value = comment["value"] if comment["type"] == "Block" && value =~ /\A\*/ type = :doc_comment value = value.slice(1, value.length-1) else type = :plain_comment end { :comment => comment["value"], :comment => value, :code => stuff_after(comment), :linenr => line_number(comment["range"][0]), :type => type, } end end Loading
spec/esprima_parser_spec.rb +38 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,44 @@ describe JsDuck::EsprimaParser do end end describe "parsing line comment" do before do @docs = parse("// Hello world") end it "results in plain comment" do @docs[0][:type].should == :plain_comment end end describe "parsing block comment" do before do @docs = parse("/* Hello world */") end it "results in plain comment" do @docs[0][:type].should == :plain_comment end it "doesn't strip anything from the beginning of comment" do @docs[0][:comment].should == " Hello world " end end describe "parsing block comment beginning with /**" do before do @docs = parse("/** Hello world */") end it "results in doc comment" do @docs[0][:type].should == :doc_comment end it "strips * at the beginning of comment" do @docs[0][:comment].should == " Hello world " end end describe "parsing comment after function" do before do @docs = parse(<<-EOS) Loading