Commit 04b82ebe authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Extend --external option to type definitions.

List of multiple classes can be now provided to --external option.
The Error class is now automatically included to externals list.
parent 795de083
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ def run_jsduck(extra_options)
  # Pass multiple arguments to system, so we'll take advantage of the built-in escaping
  system(*[
    "ruby", "bin/jsduck",
    # --external=Error to ignore the Error class that Ext.Error extends.
    "--external", "Error",
    "--welcome", "template/welcome.html",
    "--guides", "#{SDK_DIR}/guides/guides.json",
    "--videos", "#{SDK_DIR}/guides/videos.json",
+27 −7
Original line number Diff line number Diff line
@@ -41,7 +41,28 @@ module JsDuck

      @output_dir = nil
      @ignore_global = false
      @external_classes = []
      @external_classes = [
        # JavaScript builtins
        "Object",
        "String",
        "Number",
        "Boolean",
        "RegExp",
        "Function",
        "Array",
        "Arguments",
        "Date",
        "Error",
        # DOM
        "HTMLElement",
        "XMLElement",
        "NodeList",
        "TextNode",
        "CSSStyleSheet",
        "CSSStyleRule",
        "Event",
      ]

      @warnings = true
      @verbose = false

@@ -91,12 +112,11 @@ module JsDuck
          @ignore_global = true
        end

        opts.on('--external=CLASSNAME',
          "Declares an external class.  When declared as",
          "external, inheriting from this class will not",
          "trigger warnings.  Useful when you are extending",
          "a class for which you can not supply source code.", " ") do |classname|
          @external_classes << classname
        opts.on('--external=Foo,Bar,Baz', Array,
          "Declares list of external classes.  These classes",
          "will then not generate warnings when used in type",
          "definitions or inherited from.", " ") do |classes|
          @external_classes += classes
        end

        opts.on('--no-warnings', "Turns off warnings.", " ") do
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ module JsDuck

    def initialize(classes = [], ignorables = [])
      @classes = classes
      @ignorables = {"Object" => true}
      @ignorables = {}
      ignorables.each {|classname| @ignorables[classname] = true }

      # First build class lookup table; building lookup tables for
+1 −23
Original line number Diff line number Diff line
@@ -24,28 +24,6 @@ module JsDuck
    # Initializes the parser with hash of valid type names
    def initialize(relations={})
      @relations = relations
      @builtins = {
        # JavaScript builtins
        "Object" => true,
        "String" => true,
        "Number" => true,
        "Boolean" => true,
        "RegExp" => true,
        "Function" => true,
        "Array" => true,
        "Arguments" => true,
        "Date" => true,
        "Error" => true,
        "undefined" => true,
        # DOM
        "HTMLElement" => true,
        "XMLElement" => true,
        "NodeList" => true,
        "TextNode" => true,
        "CSSStyleSheet" => true,
        "CSSStyleRule" => true,
        "Event" => true,
      }
    end

    def parse(str)
@@ -81,7 +59,7 @@ module JsDuck

    def exists?(type)
      stype = type.sub(/\[\]$/, "")
      if @builtins[stype] || @relations[stype]
      if @relations[stype] || @relations.ignore?(stype) || stype == "undefined"
        true
      else
        @error = :name
+9 −5
Original line number Diff line number Diff line
require "jsduck/relations"
require "jsduck/type_parser"

describe JsDuck::TypeParser do

  def parse(str)
    types = {
      "Ext.form.Panel" => true,
      "Ext.Element" => true,
    }
    JsDuck::TypeParser.new(types).parse(str)
    relations = JsDuck::Relations.new([], [
      "String",
      "Number",
      "RegExp",
      "Ext.form.Panel",
      "Ext.Element",
    ])
    JsDuck::TypeParser.new(relations).parse(str)
  end

  it "matches simple type" do