Commit 217d1868 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move /** */ removal to Lexer level.

So Lexer returns the same value for comment as does EsprimaParser.
parent 999d170e
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -50,9 +50,7 @@ module JsDuck
    # Extracts content inside /** ... */
    def purify(input)
      result = []
      # Remove the beginning /** and end */
      input = input.sub(/\A\/\*\* ?/, "").sub(/ ?\*\/\Z/, "")
      # Now we are left with only two types of lines:
      # We can have two types of lines:
      # - those beginning with *
      # - and those without it
      indent = nil
+1 −1
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ module JsDuck
              :type => :doc_comment,
              # Calculate current line number, starting with 1
              :linenr => @input.string[0...@input.pos].count("\n") + 1,
              :value => @input.scan_until(/\*\/|\Z/)
              :value => @input.scan_until(/\*\/|\Z/).sub(/\A\/\*\*/, "").sub(/\*\/\Z/, "")
            }
          elsif @input.check(/\/\*/)
            # skip multiline comment
+3 −9
Original line number Diff line number Diff line
@@ -9,12 +9,10 @@ describe JsDuck::DocParser do
  describe "simple method doc-comment" do
    before do
      @doc = parse_single(<<-EOS.strip)
        /**
         * @method foo
         * Some docs.
         * @param {Number} x doc for x
         * @return {String} resulting value
         */
      EOS
    end

@@ -74,9 +72,7 @@ describe JsDuck::DocParser do
  describe "@type without curlies" do
    before do
      @tag = parse_single(<<-EOS.strip)[0]
        /**
         * @type Boolean|String
         */
      EOS
    end
    it "detects tagname" do
@@ -89,7 +85,7 @@ describe JsDuck::DocParser do

  describe "single-line doc-comment" do
    before do
      @tag = parse_single("/** @event blah */")[0]
      @tag = parse_single("@event blah")[0]
    end
    it "detects tagname" do
      @tag[:tagname].should == :event
@@ -101,13 +97,13 @@ describe JsDuck::DocParser do

  describe "doc-comment without *-s on left side" do
    before do
      @tag = parse_single("/**
      @tag = parse_single("
        @event blah
        Some comment.
        More text.

            code sample
      */")[0]
        ")[0]
    end
    it "detects the @event tag" do
      @tag[:tagname].should == :event
@@ -120,9 +116,7 @@ describe JsDuck::DocParser do
  describe "type definition with nested {braces}" do
    before do
      @tag = parse_single(<<-EOS.strip)[0]
        /**
         * @param {{foo:{bar:Number}}} x
         */
      EOS
    end
    it "is parsed ensuring balanced braces" do
+2 −2
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ describe JsDuck::Lexer do
  end

  it "identifies doc-comments together with line numbers" do
    lex("/** foo */").should == [[:doc_comment, "/** foo */", 1]]
    lex("/** foo */").should == [[:doc_comment, " foo ", 1]]
  end

  it "counts line numbers correctly" do
@@ -157,7 +157,7 @@ describe JsDuck::Lexer do
    end

    it "doc-comment" do
      lex("/** ").should == [[:doc_comment, "/** ", 1]]
      lex("/** ").should == [[:doc_comment, " ", 1]]
    end

    it "regex" do