Commit 988c1cf4 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Switch Esprima.js to output raw values.

Discard the adjustRegexLiteral callback, winning back all the
performance we lost with adding it.
parent dddeecaa
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ module JsDuck
      when "Identifier"
        ast["name"]
      when "Literal"
        ast["value"].is_a?(Hash) ? ast["value"]["regex"].to_s : ast["value"].to_s
        ast["value"].to_s
      else
        @serializer.to_s(ast)
      end
+1 −9
Original line number Diff line number Diff line
@@ -15,14 +15,6 @@ module JsDuck
      @v8 = V8::Context.new
      esprima = File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))+"/esprima/esprima.js";
      @v8.load(esprima)
      @v8.eval(<<-EOS)
        function adjustRegexLiteral(key, value) {
            if (key === 'value' && value instanceof RegExp) {
                value = {regex: value.toString()};
            }
            return value;
        }
      EOS
    end

    # Parses JavaScript source code using Esprima.js
@@ -30,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}), adjustRegexLiteral)")
      json = @v8.eval("JSON.stringify(esprima.parse(js, {comment: true, range: true, raw: true}))")
      return JSON.parse(json, :max_nesting => false)
    end

+1 −9
Original line number Diff line number Diff line
@@ -155,15 +155,7 @@ module JsDuck
        ast["name"]

      when "Literal"
        if ast["value"] == nil
          "null"
        elsif ast["value"].is_a? String
          '"' + ast["value"] + '"'
        elsif ast["value"].is_a? Hash
          ast["value"]["regex"]
        else
          ast["value"].to_s
        end
        ast["raw"]

      else
        throw "Unknown node type: "+ast["type"]