Commit 97313f10 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Print warnings for globals

parent d627b02b
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ module JsDuck
    def create_global_class
      return if @orphans.length == 0

      add_empty_class("global")
      add_empty_class("global", "Global variables and functions.")
      @orphans.each do |orph|
        orph[:member] = "global"
        add_member(orph)
@@ -149,17 +149,24 @@ module JsDuck
      @orphans = []
    end

    def add_empty_class(name)
      add_class({
    def add_empty_class(name, doc = "")
      cls = {
        :tagname => :class,
        :name => name,
        :doc => "",
        :cfg => [],
        :property => [],
        :method => [],
        :event => [],
        :css_var => [],
        :css_mixin => [],
      }
      add_source_data(cls, {
          :filename => "",
          :html_filename => "",
          :linenr => 0,
        })
      add_class(cls)
    end

    def result
+15 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ module JsDuck
      parsed_files = @timer.time(:parsing) { parallel_parse(@input_files) }
      result = @timer.time(:aggregating) { aggregate(parsed_files) }
      relations = @timer.time(:aggregating) { filter_classes(result) }
      warn_globals(relations)

      if @export == :json
        @timer.time(:generating) { write_json(@output_dir+"/output", relations) }
@@ -111,6 +112,20 @@ module JsDuck
      Relations.new(classes)
    end

    # print warning for each global member
    def warn_globals(relations)
      global = relations["global"]
      return unless global
      [:cfg, :property, :method, :event].each do |type|
        global.members(type).each do |member|
          name = member[:name]
          file = member[:filename]
          line = member[:linenr]
          puts "Warning: Global #{type}: #{name} in #{file} line #{line}"
        end
      end
    end

    # Given all classes, generates namespace tree and writes it
    # in JSON form into a file.
    def write_tree(filename, relations)