Sha256: b1a5ca2603d9481f6f438ff5525ecd32cc59809f7193f0bd74c4d735e0e20498

Contents?: true

Size: 881 Bytes

Versions: 5

Compression:

Stored size: 881 Bytes

Contents

# frozen_string_literal: true

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

        line "  var self = $klass($base, $super, '#{name}');"
        in_scope do
          scope.name = name
          compile_body
        end

        if await_encountered
          await_begin = '(await '
          await_end = ')'
          async = 'async '
          parent.await_encountered = true
        else
          await_begin, await_end, async = '', '', ''
        end

        unshift "#{await_begin}(#{async}function($base, $super, $parent_nesting) {"
        line '})(', base, ', ', super_code, ", $nesting)#{await_end}"
      end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opal-1.3.2 lib/opal/nodes/class.rb
opal-1.3.1 lib/opal/nodes/class.rb
opal-1.3.0 lib/opal/nodes/class.rb
opal-1.3.0.rc1 lib/opal/nodes/class.rb
opal-1.3.0.alpha1 lib/opal/nodes/class.rb