Loading lib/jsduck/js_parser.rb +10 −1 Original line number Diff line number Diff line Loading @@ -138,13 +138,22 @@ module JsDuck maybe_assignment end # <maybe-assignment> := <ident-chain> [ "=" <expression> ] # <maybe-assignment> := <ident-chain> ( "=" <expression> | ";" | "," ) def maybe_assignment left = ident_chain if look("=") match("=") right = expression elsif look(";") match(";") right = nil elsif look(",") match(",") right = nil else return {:type => :nop} end return { :type => :assignment, :left => left, Loading spec/aggregator_cfgs_and_properties_spec.rb +42 −0 Original line number Diff line number Diff line Loading @@ -284,4 +284,46 @@ describe JsDuck::Aggregator do it_should_behave_like "cfg or property" end describe "doc-comment before variable without assignment" do before do @doc = parse(<<-EOS)[0] /** * Some documentation. */ var foo; EOS end it "should detect the variable name" do @doc[:name].should == "foo" end end describe "doc-comment before multiple variables" do before do @doc = parse(<<-EOS)[0] /** * Some documentation. */ var foo, bar, baz; EOS end it "should detect the first variable name" do @doc[:name].should == "foo" end end describe "doc-comment before function call" do before do @doc = parse(<<-EOS)[0] /** * Some documentation. */ Ext.createAlias(class, "foo", "bar"); EOS end it "should fail detecting name of the property" do @doc[:name].should == "" end end end Loading
lib/jsduck/js_parser.rb +10 −1 Original line number Diff line number Diff line Loading @@ -138,13 +138,22 @@ module JsDuck maybe_assignment end # <maybe-assignment> := <ident-chain> [ "=" <expression> ] # <maybe-assignment> := <ident-chain> ( "=" <expression> | ";" | "," ) def maybe_assignment left = ident_chain if look("=") match("=") right = expression elsif look(";") match(";") right = nil elsif look(",") match(",") right = nil else return {:type => :nop} end return { :type => :assignment, :left => left, Loading
spec/aggregator_cfgs_and_properties_spec.rb +42 −0 Original line number Diff line number Diff line Loading @@ -284,4 +284,46 @@ describe JsDuck::Aggregator do it_should_behave_like "cfg or property" end describe "doc-comment before variable without assignment" do before do @doc = parse(<<-EOS)[0] /** * Some documentation. */ var foo; EOS end it "should detect the variable name" do @doc[:name].should == "foo" end end describe "doc-comment before multiple variables" do before do @doc = parse(<<-EOS)[0] /** * Some documentation. */ var foo, bar, baz; EOS end it "should detect the first variable name" do @doc[:name].should == "foo" end end describe "doc-comment before function call" do before do @doc = parse(<<-EOS)[0] /** * Some documentation. */ Ext.createAlias(class, "foo", "bar"); EOS end it "should fail detecting name of the property" do @doc[:name].should == "" end end end