Loading lib/jsduck/ast.rb +2 −3 Original line number Diff line number Diff line Loading @@ -8,10 +8,9 @@ module JsDuck # Analyzes the AST produced by EsprimaParser. class Ast # Should be initialized with EsprimaParser#parse result. def initialize(docs = [], options = {}) def initialize(docs = []) @serializer = JsDuck::Serializer.new @evaluator = JsDuck::Evaluator.new @ext_patterns = JsDuck::ExtPatterns.new(options[:ext_namespaces] || ["Ext"]) @docs = docs end Loading Loading @@ -174,7 +173,7 @@ module JsDuck end def ext_pattern?(pattern, ast) @ext_patterns.matches?(pattern, to_s(ast)) ExtPatterns.matches?(pattern, to_s(ast)) end def fire_event?(ast) Loading lib/jsduck/ext_patterns.rb +19 −9 Original line number Diff line number Diff line require "jsduck/util/singleton" module JsDuck # Identifies Ext JS builtins like Ext.define and Ext.extend, taking Loading @@ -15,17 +17,14 @@ module JsDuck # The matches? method will take care of identifying all these four # cases: # # ps = ExtPatterns.new(["Ext", "MyApp"]) # matches?("Ext.define", "MyApp.define") --> true # ExtPatterns.set(["Ext", "MyApp"]) # ExtPatterns.matches?("Ext.define", "MyApp.define") --> true # class ExtPatterns def initialize(namespaces) @patterns = { "Ext.define" => build_patterns(namespaces, [".define", ".ClassManager.create"]), "Ext.extend" => build_patterns(namespaces, [".extend"]), "Ext.override" => build_patterns(namespaces, [".override"]), "Ext.emptyFn" => build_patterns(namespaces, [".emptyFn"]), } include Util::Singleton def initialize set(["Ext"]) end # True when string matches the given pattern type. Loading @@ -36,6 +35,17 @@ module JsDuck @patterns[pattern].include?(string) end # Reconfigures ExtPatterns with different set of namespaces. # Called when --ext-namespaces option is passed to JSDuck. def set(namespaces) @patterns = { "Ext.define" => build_patterns(namespaces, [".define", ".ClassManager.create"]), "Ext.extend" => build_patterns(namespaces, [".extend"]), "Ext.override" => build_patterns(namespaces, [".override"]), "Ext.emptyFn" => build_patterns(namespaces, [".emptyFn"]), } end private # Given Array of alternate Ext namespaces builds list of patterns Loading lib/jsduck/options.rb +2 −3 Original line number Diff line number Diff line Loading @@ -125,7 +125,6 @@ module JsDuck @data_path = nil # This gets assigned in JsDuck::WebWriter after writing the data file. @local_storage_db = "docs" @touch_examples_ui = false @ext_namespaces = ["Ext"] @imports = [] @new_since = nil Loading Loading @@ -527,8 +526,8 @@ module JsDuck "In such case pass --ext-namespaces=Ext,YourNS option", "and JSDuck will recognize both Ext.define() and", "YourNs.define() plus few other things that depend on", "Ext namespace like Ext.emptyFn.") do |ns| @ext_namespaces = ns "Ext namespace like Ext.emptyFn.") do |namespaces| ExtPatterns.set(namespaces) end opts.on('--touch-examples-ui', Loading lib/jsduck/source/file_parser.rb +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ module JsDuck docs = CssParser.new(contents, options).parse else docs = JsParser.new(contents, options).parse docs = Ast.new(docs, options).detect_all! docs = Ast.new(docs).detect_all! end end Loading spec/ext_namespaces_spec.rb +10 −1 Original line number Diff line number Diff line require "jsduck/js_parser" require "jsduck/ast" require "jsduck/ext_patterns" describe "--ext-namespaces=Ext,MyNs,MyNs.Foo.Bar" do before do JsDuck::ExtPatterns.set(["Ext", "MyNs", "MyNs.Foo.Bar"]) end after do JsDuck::ExtPatterns.set(["Ext"]) end def parse(string) docs = JsDuck::JsParser.new(string).parse JsDuck::Ast.new(docs, {:ext_namespaces => ["Ext", "MyNs", "MyNs.Foo.Bar"]}).detect_all! JsDuck::Ast.new(docs).detect_all! end it "allows detecting Ext.define()" do Loading Loading
lib/jsduck/ast.rb +2 −3 Original line number Diff line number Diff line Loading @@ -8,10 +8,9 @@ module JsDuck # Analyzes the AST produced by EsprimaParser. class Ast # Should be initialized with EsprimaParser#parse result. def initialize(docs = [], options = {}) def initialize(docs = []) @serializer = JsDuck::Serializer.new @evaluator = JsDuck::Evaluator.new @ext_patterns = JsDuck::ExtPatterns.new(options[:ext_namespaces] || ["Ext"]) @docs = docs end Loading Loading @@ -174,7 +173,7 @@ module JsDuck end def ext_pattern?(pattern, ast) @ext_patterns.matches?(pattern, to_s(ast)) ExtPatterns.matches?(pattern, to_s(ast)) end def fire_event?(ast) Loading
lib/jsduck/ext_patterns.rb +19 −9 Original line number Diff line number Diff line require "jsduck/util/singleton" module JsDuck # Identifies Ext JS builtins like Ext.define and Ext.extend, taking Loading @@ -15,17 +17,14 @@ module JsDuck # The matches? method will take care of identifying all these four # cases: # # ps = ExtPatterns.new(["Ext", "MyApp"]) # matches?("Ext.define", "MyApp.define") --> true # ExtPatterns.set(["Ext", "MyApp"]) # ExtPatterns.matches?("Ext.define", "MyApp.define") --> true # class ExtPatterns def initialize(namespaces) @patterns = { "Ext.define" => build_patterns(namespaces, [".define", ".ClassManager.create"]), "Ext.extend" => build_patterns(namespaces, [".extend"]), "Ext.override" => build_patterns(namespaces, [".override"]), "Ext.emptyFn" => build_patterns(namespaces, [".emptyFn"]), } include Util::Singleton def initialize set(["Ext"]) end # True when string matches the given pattern type. Loading @@ -36,6 +35,17 @@ module JsDuck @patterns[pattern].include?(string) end # Reconfigures ExtPatterns with different set of namespaces. # Called when --ext-namespaces option is passed to JSDuck. def set(namespaces) @patterns = { "Ext.define" => build_patterns(namespaces, [".define", ".ClassManager.create"]), "Ext.extend" => build_patterns(namespaces, [".extend"]), "Ext.override" => build_patterns(namespaces, [".override"]), "Ext.emptyFn" => build_patterns(namespaces, [".emptyFn"]), } end private # Given Array of alternate Ext namespaces builds list of patterns Loading
lib/jsduck/options.rb +2 −3 Original line number Diff line number Diff line Loading @@ -125,7 +125,6 @@ module JsDuck @data_path = nil # This gets assigned in JsDuck::WebWriter after writing the data file. @local_storage_db = "docs" @touch_examples_ui = false @ext_namespaces = ["Ext"] @imports = [] @new_since = nil Loading Loading @@ -527,8 +526,8 @@ module JsDuck "In such case pass --ext-namespaces=Ext,YourNS option", "and JSDuck will recognize both Ext.define() and", "YourNs.define() plus few other things that depend on", "Ext namespace like Ext.emptyFn.") do |ns| @ext_namespaces = ns "Ext namespace like Ext.emptyFn.") do |namespaces| ExtPatterns.set(namespaces) end opts.on('--touch-examples-ui', Loading
lib/jsduck/source/file_parser.rb +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ module JsDuck docs = CssParser.new(contents, options).parse else docs = JsParser.new(contents, options).parse docs = Ast.new(docs, options).detect_all! docs = Ast.new(docs).detect_all! end end Loading
spec/ext_namespaces_spec.rb +10 −1 Original line number Diff line number Diff line require "jsduck/js_parser" require "jsduck/ast" require "jsduck/ext_patterns" describe "--ext-namespaces=Ext,MyNs,MyNs.Foo.Bar" do before do JsDuck::ExtPatterns.set(["Ext", "MyNs", "MyNs.Foo.Bar"]) end after do JsDuck::ExtPatterns.set(["Ext"]) end def parse(string) docs = JsDuck::JsParser.new(string).parse JsDuck::Ast.new(docs, {:ext_namespaces => ["Ext", "MyNs", "MyNs.Foo.Bar"]}).detect_all! JsDuck::Ast.new(docs).detect_all! end it "allows detecting Ext.define()" do Loading