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

Hack EsprimaJS to retrieve AST line numbers faster.

Created a fork of EsprimaJS which adds line number as 3rd item to
"range" array.  This way we can skip the "loc" option, which caused
a huge performance penalty. Now we're back to normal.

Parsing times for sencha touch source:

Initially:           4.5s
After adding loc:    7.9s
With hacked esprima: 4.6s

The fork is located at:

  https://github.com/nene/esprima/tree/linenr-in-range
parent ef81c54e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -252,7 +252,10 @@ module JsDuck
        else
          cfg[:inheritdoc] = {}
          cfg[:autodetected] = true
          cfg[:linenr] = p["loc"]["start"]["line"]
          # Get line number from third place at range array.
          # This third item exists in forked EsprimaJS at
          # https://github.com/nene/esprima/tree/linenr-in-range
          cfg[:linenr] = p["range"][2]
          configs << cfg
        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, loc: true, raw: true}))")
      json = @v8.eval("JSON.stringify(esprima.parse(js, {comment: true, range: true, raw: true}))")
      return JSON.parse(json, :max_nesting => false)
    end