Commit 63e52cc8 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Minimize the number of params passed to #detect methods.

Calculate exp and var locally as needed.
parent 5477e451
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -50,16 +50,13 @@ module JsDuck
      def detect(node)
        ast = Js::Node.create(node)

        exp = ast.expression_statement? ? ast["expression"] : nil
        var = ast.variable_declaration? ? ast["declarations"][0] : nil

        if doc = Js::Class.detect(ast, exp, var, @docs)
        if doc = Js::Class.detect(ast, @docs)
          doc
        elsif doc = Js::Method.detect(ast, exp, var)
        elsif doc = Js::Method.detect(ast)
          doc
        elsif doc = Js::Event.detect(ast, exp, var)
        elsif doc = Js::Event.detect(ast)
          doc
        elsif doc = Js::Property.detect(ast, exp, var)
        elsif doc = Js::Property.detect(ast)
          doc
        else
          Js::Property.make()
+4 −1
Original line number Diff line number Diff line
@@ -13,9 +13,12 @@ module JsDuck
      # Checks if AST node is a class, and if so, returns doc-hash
      # with clas name and various auto-detected attributes.
      # When not a class returns nil.
      def detect(ast, exp, var, docs)
      def detect(ast, docs)
        @docs = docs

        exp = ast.expression_statement? ? ast["expression"] : nil
        var = ast.variable_declaration? ? ast["declarations"][0] : nil

        # Ext.define("Class", {})
        if exp && exp.ext_define?
          make(exp["arguments"][0].to_value, exp)
+3 −1
Original line number Diff line number Diff line
@@ -10,7 +10,9 @@ module JsDuck
      # Checks if AST node is an event, and if so, returns doc-hash
      # with event name and various auto-detected properties.
      # When not an event returns nil.
      def detect(ast, exp, var)
      def detect(ast)
        exp = ast.expression_statement? ? ast["expression"] : nil

        # this.fireEvent("foo", ...)
        if exp && exp.fire_event?
          make(exp["arguments"][0].to_value)
+4 −1
Original line number Diff line number Diff line
@@ -13,7 +13,10 @@ module JsDuck
      # Checks if AST node is a method, and if so, returns doc-hash
      # with method name and various auto-detected properties.
      # When not a method returns nil.
      def detect(ast, exp, var)
      def detect(ast)
        exp = ast.expression_statement? ? ast["expression"] : nil
        var = ast.variable_declaration? ? ast["declarations"][0] : nil

        # function foo() {}
        if ast.function?
          make(ast["id"].to_s || "", ast)
+4 −1
Original line number Diff line number Diff line
@@ -10,7 +10,10 @@ module JsDuck
      # Checks if AST node is a property, and if so, returns doc-hash
      # with property name and various auto-detected attributes.
      # When not a property returns nil.
      def detect(ast, exp, var)
      def detect(ast)
        exp = ast.expression_statement? ? ast["expression"] : nil
        var = ast.variable_declaration? ? ast["declarations"][0] : nil

        # foo = ...
        if exp && exp.assignment_expression?
          make(exp["left"].to_s, exp["right"])