Sha256: 73a690477a5247b10b813de2ad7ee4bfa9ff20eca6bca874d6abd9dfac7f2874

Contents?: true

Size: 880 Bytes

Versions: 39

Compression:

Stored size: 880 Bytes

Contents

require 'opal/nodes/module'

module Opal
  module Nodes
    class ClassNode < ModuleNode
      handle :class

      children :cid, :sup, :body

      def compile
        name, base = name_and_base
        helper :klass

        push "(function($base, $super) {"
        line "  function $#{name}(){};"
        line "  var self = $#{name} = $klass($base, $super, '#{name}', $#{name});"

        in_scope do
          scope.name = name
          add_temp "#{scope.proto} = self.$$proto"
          add_temp "$scope = self.$$scope"

          body_code = self.body_code
          empty_line

          line scope.to_vars
          line body_code
        end

        line "})(", base, ", ", self.super_code, ")"
      end

      def super_code
        sup ? expr(sup) : 'null'
      end

      def body_code
        stmt(compiler.returns(body || s(:nil)))
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 3 rubygems

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