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

Add line numbers to auto-detected configs.

The simplest way to implement this was to use the loc:true option of
EsprimaJS which includes line and column number data to each AST node.
Unfortunately the data is rather large, especially when you compare it
to the compact "range" data:

    {
        "type": "SomeNode",
        "loc": {
            "start": {"line": 2, "column": 5},
            "end": {"line": 8, "column": 12}
        },
	"range": [28, 16]
    }

Sadly, having this enabled drags down performance quite drastically.
Parsing full src/ dir of Sencha Touch before and after this change:

before: 4.5 seconds
after:  7.9 seconds
parent d2daf1de
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -252,6 +252,7 @@ module JsDuck
        else
          cfg[:inheritdoc] = {}
          cfg[:autodetected] = true
          cfg[:linenr] = p["loc"]["start"]["line"]
          configs << cfg
        end
      end
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ module JsDuck
            :type => :no_comment,
            :comment => [],
            :code => m,
            :linenr => docset[:linenr],
            :linenr => m[:linenr],
          }
        end
      end
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ module JsDuck
    # Returns the resulting AST
    def parse(input)
      @v8['js'] = input
      json = @v8.eval("JSON.stringify(esprima.parse(js, {comment: true, range: true, raw: true}))")
      json = @v8.eval("JSON.stringify(esprima.parse(js, {comment: true, range: true, loc: true, raw: true}))")
      return JSON.parse(json, :max_nesting => false)
    end

+4 −0
Original line number Diff line number Diff line
@@ -168,6 +168,10 @@ describe JsDuck::Aggregator do
      it "with :autodetected flag" do
        cfg[0][:autodetected].should == true
      end

      it "with :linenr field" do
        cfg[0][:linenr].should == 6
      end
    end

    describe "documented config" do