Loading lib/jsduck/js/ast.rb +2 −2 Original line number Diff line number Diff line require "jsduck/js/function" require "jsduck/js/returns" require "jsduck/js/fires" require "jsduck/js/method_calls" require "jsduck/js/node" Loading Loading @@ -337,7 +337,7 @@ module JsDuck def chainable?(ast) if ast.function? && !ast.ext_empty_fn? Js::Function.return_types(ast.raw) == [:this] Js::Returns.chainable?(ast.raw) else false end Loading lib/jsduck/js/function.rb→lib/jsduck/js/returns.rb +8 −3 Original line number Diff line number Diff line Loading @@ -3,10 +3,15 @@ require "jsduck/util/singleton" module JsDuck module Js # Analyzes the AST of a FunctionDeclaration or FunctionExpression. class Function # Analyzes the AST of a Function for possible return values. class Returns include Util::Singleton # True when function always finishes with returning this. def chainable?(ast) detect(ast) == [:this] end # Detects possible return types of the given function. # # For now there are three possible detected return values: Loading @@ -18,7 +23,7 @@ module JsDuck # # * :other - some other value is returned. # def return_types(ast) def detect(ast) h = return_types_hash(ast["body"]["body"]) # Replace the special :void value that signifies possibility of Loading spec/js_function_spec.rb→spec/js_returns_spec.rb +3 −3 Original line number Diff line number Diff line require "jsduck/js/parser" require "jsduck/js/function" require "jsduck/js/returns" describe "JsDuck::Js::Function#return_types" do describe "JsDuck::Js::Returns#detect" do def returns(string) node = JsDuck::Js::Parser.new(string).parse[0] return JsDuck::Js::Function::return_types(node[:code]) return JsDuck::Js::Returns::detect(node[:code]) end describe "returns [:this] when function body" do Loading Loading
lib/jsduck/js/ast.rb +2 −2 Original line number Diff line number Diff line require "jsduck/js/function" require "jsduck/js/returns" require "jsduck/js/fires" require "jsduck/js/method_calls" require "jsduck/js/node" Loading Loading @@ -337,7 +337,7 @@ module JsDuck def chainable?(ast) if ast.function? && !ast.ext_empty_fn? Js::Function.return_types(ast.raw) == [:this] Js::Returns.chainable?(ast.raw) else false end Loading
lib/jsduck/js/function.rb→lib/jsduck/js/returns.rb +8 −3 Original line number Diff line number Diff line Loading @@ -3,10 +3,15 @@ require "jsduck/util/singleton" module JsDuck module Js # Analyzes the AST of a FunctionDeclaration or FunctionExpression. class Function # Analyzes the AST of a Function for possible return values. class Returns include Util::Singleton # True when function always finishes with returning this. def chainable?(ast) detect(ast) == [:this] end # Detects possible return types of the given function. # # For now there are three possible detected return values: Loading @@ -18,7 +23,7 @@ module JsDuck # # * :other - some other value is returned. # def return_types(ast) def detect(ast) h = return_types_hash(ast["body"]["body"]) # Replace the special :void value that signifies possibility of Loading
spec/js_function_spec.rb→spec/js_returns_spec.rb +3 −3 Original line number Diff line number Diff line require "jsduck/js/parser" require "jsduck/js/function" require "jsduck/js/returns" describe "JsDuck::Js::Function#return_types" do describe "JsDuck::Js::Returns#detect" do def returns(string) node = JsDuck::Js::Parser.new(string).parse[0] return JsDuck::Js::Function::return_types(node[:code]) return JsDuck::Js::Returns::detect(node[:code]) end describe "returns [:this] when function body" do Loading