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

Make line comments merging work with new esprima.

The new esprima no more considers newlines as part of line comments.
parent b45a445c
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -62,10 +62,11 @@ module JsDuck
    end

    # Two comments can be merged if they are both line-comments and
    # they are separated only by whitespace (but no newlines)
    # they are separated only by whitespace (only one newline at the
    # end of the first comment is allowed)
    def mergeable?(c1, c2)
      if c1["type"] == "Line" && c2["type"] == "Line"
        /\A[ \t]*\Z/ =~ @input.slice((c1["range"][1])..(c2["range"][0]-1))
        /\A(\r\n|\n|\r)?[ \t]*\Z/ =~ @input.slice((c1["range"][1])..(c2["range"][0]-1))
      else
        false
      end
+11 −15
Original line number Diff line number Diff line
@@ -129,20 +129,6 @@ describe JsDuck::JsParser do
    end
  end

  shared_examples_for "three comments merged" do
    it "finds one comment" do
      @docs.length.should == 1
    end

    it "merges all the line-comments together" do
      @docs[0][:comment].should == " Very\n Long\n Comment"
    end

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

  describe "parsing three line comments before one function" do
    before do
      @docs = parse(<<-EOS)
@@ -154,7 +140,17 @@ describe JsDuck::JsParser do
      EOS
    end

    it_should_behave_like "three comments merged"
    it "finds one comment" do
      @docs.length.should == 1
    end

    it "merges all the line-comments together" do
      @docs[0][:comment].should == " Very\n Long\n Comment"
    end

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

  describe "parsing three separated line comments before one function" do