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

Merge branch 'rkelly' into doc-tags

parents 7ff24483 08324c75
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'
+7 −8
Original line number Diff line number Diff line
require 'jsduck/js/esprima'
require 'jsduck/logger'

module JsDuck
  module Js

    # JavaScript parser that internally uses Esprima.js
    class Parser
    # Associates comments with syntax nodes.
    class Associator

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

        # Initialize line number counting
@@ -16,7 +14,8 @@ module JsDuck
        @start_linenr = 1
      end

      # Parses JavaScript source code and returns array of hashes like this:
      # Analyzes the comments and AST nodes and returns array of
      # hashes like this:
      #
      #     {
      #         :comment => "The contents of the comment",
@@ -25,8 +24,8 @@ module JsDuck
      #         :type => :doc_comment, // or :plain_comment
      #     }
      #
      def parse
        @ast = Js::Esprima.parse(@input)
      def associate(ast)
        @ast = ast

        @ast["comments"] = merge_comments(@ast["comments"])
        locate_comments

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.

Loading