Sha256: e719274e5cc830b8036a017d85277e73b75f816e87b8925ffd23adbd0cc63033

Contents?: true

Size: 1.29 KB

Versions: 36

Compression:

Stored size: 1.29 KB

Contents

require 'opal/nodes/base'

module Opal
  module Nodes
    class ConstNode < Base
      handle :const

      children :name

      def compile
        if name == :DATA and compiler.eof_content
          push("$__END__")
        else
          push "$scope.get('#{name}')"
        end
      end
    end

    class ConstDeclarationNode < Base
      handle :cdecl

      children :name, :base

      def compile
        push expr(base)
        wrap "Opal.cdecl($scope, '#{name}', ", ")"
      end
    end

    class ConstAssignNode < Base
      handle :casgn

      children :base, :name, :value

      def compile
        push "Opal.casgn("
        push expr(base)
        push ", '#{name}', "
        push expr(value)
        push ")"
      end
    end

    class ConstGetNode < Base
      handle :colon2

      children :base, :name

      def compile
        push "(("
        push expr(base)
        push ").$$scope.get('#{name}'))"
      end
    end

    class TopConstNode < Base
      handle :colon3

      children :name

      def compile
        push "Opal.get('#{name}')"
      end
    end

    class TopConstAssignNode < Base
      handle :casgn3

      children :name, :value

      def compile
        push "Opal.casgn(Opal.Object, '#{name}', "
        push expr(value)
        push ")"
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
opal-0.10.6 lib/opal/nodes/constants.rb
opal-0.10.6.beta lib/opal/nodes/constants.rb
opal-0.10.5 lib/opal/nodes/constants.rb
opal-0.10.4 lib/opal/nodes/constants.rb
opal-0.10.3 lib/opal/nodes/constants.rb
opal-0.10.2 lib/opal/nodes/constants.rb
opal-0.10.1 lib/opal/nodes/constants.rb
opal-0.10.0 lib/opal/nodes/constants.rb
opal-0.10.0.rc2 lib/opal/nodes/constants.rb
opal-0.9.4 lib/opal/nodes/constants.rb
opal-0.9.3 lib/opal/nodes/constants.rb
opal-0.10.0.rc1 lib/opal/nodes/constants.rb
opal-0.10.0.beta5 lib/opal/nodes/constants.rb
opal-0.10.0.beta4 lib/opal/nodes/constants.rb
opal-0.10.0.beta3 lib/opal/nodes/constants.rb
opal-0.10.0.beta2 lib/opal/nodes/constants.rb
opal-0.10.0.beta1 lib/opal/nodes/constants.rb
opal-0.9.2 lib/opal/nodes/constants.rb
opal-0.9.0 lib/opal/nodes/constants.rb
opal-0.9.0.rc1 lib/opal/nodes/constants.rb