Commit 08324c75 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Replace Esprima+V8 with RKelly.

But instead of standard RKelly gem, use our own rkelly-remix fork.
parent bd7ba469
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -6,8 +6,7 @@ install:
  - gem install rdiscount
  - gem install json
  - gem install parallel
  - gem install execjs
  - gem install therubyracer -v 0.10.1
  - gem install rkelly-remix -v 0.0.1
  - gem install rspec
  - gem install rake
  - gem install dimensions
+1 −2
Original line number Diff line number Diff line
@@ -22,8 +22,7 @@ Gem::Specification.new do |s|
  s.add_dependency 'rdiscount'
  s.add_dependency 'json'
  s.add_dependency 'parallel'
  s.add_dependency 'execjs'
  s.add_dependency 'therubyracer', '>= 0.10.0'
  s.add_dependency 'rkelly-remix', '= 0.0.1'
  s.add_dependency 'dimensions'

  s.add_development_dependency 'rspec'

lib/jsduck/js/esprima.rb

deleted100644 → 0
+0 −54
Original line number Diff line number Diff line
require 'execjs'
require 'jsduck/util/json'
require 'jsduck/util/singleton'

module JsDuck
  module Js

    # Runs Esprima.js through JavaScript runtime selected by ExecJS.
    # Normally this will be V8 engine within therubyracer gem, but when
    # JSDuck is installed through some other means than rubygems, then
    # one could use any of the runtimes supported by ExecJS.  (NodeJS
    # for example.)
    #
    # Initialized as singleton to avoid loading the esprima.js more
    # than once - otherwise performace will severely suffer.
    class Esprima
      include Util::Singleton

      def initialize
        esprima_path = File.dirname(File.expand_path(__FILE__)) + "/esprima/esprima.js"
        esprima = IO.read(esprima_path)

        # Esprima attempts to assign to window.esprima, but our v8
        # engine has no global window variable defined.  So define our
        # own and then grab esprima out from it again.
        source = <<-EOJS
          if (typeof window === "undefined") {
              var window = {};
          }

          #{esprima}

          var esprima = window.esprima;

          function runEsprima(js) {
            return JSON.stringify(esprima.parse(js, {comment: true, range: true, raw: true}));
          }
        EOJS

        @context = ExecJS.compile(source)
      end

      # Parses JavaScript source code using Esprima.js
      #
      # Returns the resulting AST
      def parse(input)
        json = @context.call("runEsprima", input)
        return Util::Json.parse(json, :max_nesting => false)
      end

    end

  end
end

lib/jsduck/js/esprima/esprima.js

deleted100644 → 0
+0 −3706

File deleted.

Preview size limit exceeded, changes collapsed.

lib/jsduck/js/parser.rb

deleted100644 → 0
+0 −25
Original line number Diff line number Diff line
require 'jsduck/js/esprima'
require 'jsduck/js/associator'

module JsDuck
  module Js

    # JavaScript parser that internally uses Esprima.js
    class Parser

      # Initializes the parser with JavaScript source code to be parsed.
      def initialize(input, options = {})
        @input = input
      end

      # Parses JavaScript source code and associates comments with AST
      # nodes, returning array of docsets.
      def parse
        ast = Js::Esprima.parse(@input)
        Js::Associator.new(@input).associate(ast)
      end

    end

  end
end
Loading