Sha256: 0ea1443d8433a8d96b3d24e9ca318e88555986cf8fe2ee263489cc906c7f0a6f

Contents?: true

Size: 652 Bytes

Versions: 22

Compression:

Stored size: 652 Bytes

Contents

# frozen_string_literal: true

require 'opal/nodes/scope'

module Opal
  module Nodes
    class SingletonClassNode < ScopeNode
      handle :sclass

      children :object, :body

      def compile
        push '(function(self, $parent_nesting) {'

        in_scope do
          body_stmt = stmt(compiler.returns(body))

          add_temp '$nesting = [self].concat($parent_nesting)' if @define_nesting
          add_temp '$$ = Opal.$r($nesting)' if @define_relative_access

          line scope.to_vars
          line body_stmt
        end

        line '})(Opal.get_singleton_class(', recv(object), "), #{scope.nesting})"
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 lib/opal/nodes/singleton_class.rb
opal-1.8.2 lib/opal/nodes/singleton_class.rb
opal-1.8.1 lib/opal/nodes/singleton_class.rb
opal-1.8.0 lib/opal/nodes/singleton_class.rb
opal-1.8.0.beta1 lib/opal/nodes/singleton_class.rb
opal-1.7.4 lib/opal/nodes/singleton_class.rb
opal-1.8.0.alpha1 lib/opal/nodes/singleton_class.rb
opal-1.7.3 lib/opal/nodes/singleton_class.rb
opal-1.7.2 lib/opal/nodes/singleton_class.rb
opal-1.7.1 lib/opal/nodes/singleton_class.rb
opal-1.7.0 lib/opal/nodes/singleton_class.rb
opal-1.7.0.rc1 lib/opal/nodes/singleton_class.rb
opal-1.6.1 lib/opal/nodes/singleton_class.rb
opal-1.6.0 lib/opal/nodes/singleton_class.rb
opal-1.6.0.rc1 lib/opal/nodes/singleton_class.rb
opal-1.6.0.alpha1 lib/opal/nodes/singleton_class.rb
opal-1.5.1 lib/opal/nodes/singleton_class.rb
opal-1.5.0 lib/opal/nodes/singleton_class.rb
opal-1.5.0.rc1 lib/opal/nodes/singleton_class.rb
opal-1.4.1 lib/opal/nodes/singleton_class.rb