Commit 5f40da6f authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Fix handling of $ in JavaScript identifier names.

parent 247c61a5
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -118,8 +118,8 @@ module JsDuck
            :type => :operator,
            :value => @input.scan(/./)
          }
        elsif @input.check(/[a-zA-Z_]/)
          value = @input.scan(/\w+/)
        elsif @input.check(/[a-zA-Z_$]/)
          value = @input.scan(/[$\w]+/)
          return {
            :type => KEYWORDS[value] ? :keyword : :ident,
            :value => value
@@ -167,12 +167,6 @@ module JsDuck
            :type => :number,
            :value => nr
          }
        elsif @input.check(/\$/)
          value = @input.scan(/\$\w*/)
          return {
            :type => :ident,
            :value => value
          }
        elsif  @input.check(/./)
          return {
            :type => :operator,
+8 −0
Original line number Diff line number Diff line
@@ -25,6 +25,14 @@ describe JsDuck::Lexer do
    ]
  end

  it "handles $ in identifiers" do
    lex("$fo$o").should == [[:ident, "$fo$o"]]
  end

  it "handles numbers in identifiers" do
    lex("x2").should == [[:ident, "x2"]]
  end

  describe "differenciates regex from division" do

    it "when regex after operator" do