Class: Opal::Nodes::Base
- Inherits:
-
Object
show all
- Includes:
- Helpers
- Defined in:
- opal/lib/opal/nodes/base.rb
Direct Known Subclasses
AliasNode, ArglistNode, ArrayNode, BackrefNode, BaseYieldNode, BeginNode, BinaryOp, BlockNode, BlockPassNode, BreakNode, CallNode, CaseNode, ClassVarAssignNode, ClassVarDeclNode, ClassVariableNode, ConstAssignNode, ConstDeclarationNode, ConstGetNode, ConstNode, DefinedNode, DynamicRegexpNode, DynamicStringNode, DynamicSymbolNode, DynamicXStringNode, EnsureNode, ExclusiveRangeNode, ForNode, GlobalAssignNode, GlobalVariableNode, HashNode, IfNode, InclusiveRangeNode, InitializeKwargsNode, InlineArgs, InstanceAssignNode, InstanceVariableNode, JSReturnNode, JSTempNode, KwSplatNode, LocalAssignNode, LocalVariableNode, MassAssignNode, Match3Node, MlhsArgNode, NextNode, NormargNode, NotNode, NumericNode, OpAsgn1Node, OpAsgn2Node, OpAsgnAndNode, OpAsgnOrNode, OptargNode, ParenNode, PostArgsNode, PostKwargsNode, RedoNode, RegexpNode, ResBodyNode, RescueModNode, RescueNode, RestargNode, ReturnNode, RuntimeHelpers, ScopeNode, SplatNode, StringNode, SvalueNode, SymbolNode, TopConstAssignNode, TopConstNode, UndefNode, ValueNode, WhenNode, WhileNode, XStringNode
Constant Summary
Constants included
from Helpers
Helpers::BASIC_IDENTIFIER_RULES, Helpers::ES3_RESERVED_WORD_EXCLUSIVE, Helpers::ES51_RESERVED_WORD, Helpers::IMMUTABLE_PROPS, Helpers::PROTO_SPECIAL_METHODS, Helpers::PROTO_SPECIAL_PROPS, Helpers::RESERVED_FUNCTION_NAMES
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
#current_indent, #empty_line, #indent, #ivar, #js_falsy, #js_truthy, #js_truthy_optimize, #line, #lvar_to_js, #mid_to_jsid, #property, #valid_ivar_name?, #valid_name?, #variable
Constructor Details
#initialize(sexp, level, compiler) ⇒ Base
Returns a new instance of Base
[View source]
32
33
34
35
36
37
|
# File 'opal/lib/opal/nodes/base.rb', line 32
def initialize(sexp, level, compiler)
@sexp = sexp
@type = sexp.type
@level = level
@compiler = compiler
end
|
Instance Attribute Details
#compiler ⇒ Object
Returns the value of attribute compiler
30
31
32
|
# File 'opal/lib/opal/nodes/base.rb', line 30
def compiler
@compiler
end
|
#type ⇒ Object
Returns the value of attribute type
30
31
32
|
# File 'opal/lib/opal/nodes/base.rb', line 30
def type
@type
end
|
Class Method Details
.children(*names) ⇒ Object
[View source]
18
19
20
21
22
23
24
|
# File 'opal/lib/opal/nodes/base.rb', line 18
def self.children(*names)
names.each_with_index do |name, idx|
define_method(name) do
@sexp[idx + 1]
end
end
end
|
.handle(*types) ⇒ Object
[View source]
12
13
14
15
16
|
# File 'opal/lib/opal/nodes/base.rb', line 12
def self.handle(*types)
types.each do |type|
Base.handlers[type] = self
end
end
|
.handlers ⇒ Object
[View source]
8
9
10
|
# File 'opal/lib/opal/nodes/base.rb', line 8
def self.handlers
@handlers ||= {}
end
|
.truthy_optimize? ⇒ Boolean
[View source]
26
27
28
|
# File 'opal/lib/opal/nodes/base.rb', line 26
def self.truthy_optimize?
false
end
|
Instance Method Details
#add_gvar(name) ⇒ Object
[View source]
130
131
132
|
# File 'opal/lib/opal/nodes/base.rb', line 130
def add_gvar(name)
scope.add_scope_gvar name
end
|
#add_ivar(name) ⇒ Object
[View source]
126
127
128
|
# File 'opal/lib/opal/nodes/base.rb', line 126
def add_ivar(name)
scope.add_scope_ivar name
end
|
#add_local(name) ⇒ Object
[View source]
122
123
124
|
# File 'opal/lib/opal/nodes/base.rb', line 122
def add_local(name)
scope.add_scope_local name.to_sym
end
|
#add_temp(temp) ⇒ Object
[View source]
134
135
136
|
# File 'opal/lib/opal/nodes/base.rb', line 134
def add_temp(temp)
scope.add_scope_temp temp
end
|
#children ⇒ Object
[View source]
39
40
41
|
# File 'opal/lib/opal/nodes/base.rb', line 39
def children
@sexp[1..-1]
end
|
#compile ⇒ Object
[View source]
51
52
53
|
# File 'opal/lib/opal/nodes/base.rb', line 51
def compile
raise "Not Implemented"
end
|
#compile_to_fragments ⇒ Object
[View source]
43
44
45
46
47
48
49
|
# File 'opal/lib/opal/nodes/base.rb', line 43
def compile_to_fragments
return @fragments if defined?(@fragments)
@fragments = []
self.compile
@fragments
end
|
#error(msg) ⇒ Object
[View source]
78
79
80
|
# File 'opal/lib/opal/nodes/base.rb', line 78
def error(msg)
@compiler.error msg
end
|
#expr(sexp) ⇒ Object
[View source]
106
107
108
|
# File 'opal/lib/opal/nodes/base.rb', line 106
def expr(sexp)
@compiler.process sexp, :expr
end
|
#expr? ⇒ Boolean
[View source]
90
91
92
|
# File 'opal/lib/opal/nodes/base.rb', line 90
def expr?
@level == :expr
end
|
#expr_or_nil(sexp) ⇒ Object
[View source]
118
119
120
|
# File 'opal/lib/opal/nodes/base.rb', line 118
def expr_or_nil(sexp)
sexp ? expr(sexp) : "nil"
end
|
#fragment(str) ⇒ Object
[View source]
74
75
76
|
# File 'opal/lib/opal/nodes/base.rb', line 74
def fragment(str)
Opal::Fragment.new str, scope, @sexp
end
|
#has_rescue_else? ⇒ Boolean
[View source]
154
155
156
|
# File 'opal/lib/opal/nodes/base.rb', line 154
def has_rescue_else?
scope.has_rescue_else?
end
|
#helper(name) ⇒ Object
[View source]
138
139
140
|
# File 'opal/lib/opal/nodes/base.rb', line 138
def helper(name)
@compiler.helper name
end
|
#in_ensure(&block) ⇒ Object
[View source]
158
159
160
|
# File 'opal/lib/opal/nodes/base.rb', line 158
def in_ensure(&block)
scope.in_ensure(&block)
end
|
#in_ensure? ⇒ Boolean
[View source]
162
163
164
|
# File 'opal/lib/opal/nodes/base.rb', line 162
def in_ensure?
scope.in_ensure?
end
|
#in_while? ⇒ Boolean
[View source]
146
147
148
|
# File 'opal/lib/opal/nodes/base.rb', line 146
def in_while?
@compiler.in_while?
end
|
#process(sexp, level = :expr) ⇒ Object
[View source]
102
103
104
|
# File 'opal/lib/opal/nodes/base.rb', line 102
def process(sexp, level = :expr)
@compiler.process sexp, level
end
|
#push(*strs) ⇒ Object
[View source]
55
56
57
58
59
60
|
# File 'opal/lib/opal/nodes/base.rb', line 55
def push(*strs)
strs.each do |str|
str = fragment(str) if str.is_a?(String)
@fragments << str
end
end
|
#recv(sexp) ⇒ Object
[View source]
110
111
112
|
# File 'opal/lib/opal/nodes/base.rb', line 110
def recv(sexp)
@compiler.process sexp, :recv
end
|
#recv? ⇒ Boolean
[View source]
94
95
96
|
# File 'opal/lib/opal/nodes/base.rb', line 94
def recv?
@level == :recv
end
|
#s(*args) ⇒ Object
[View source]
86
87
88
|
# File 'opal/lib/opal/nodes/base.rb', line 86
def s(*args)
@compiler.s(*args)
end
|
#scope ⇒ Object
[View source]
82
83
84
|
# File 'opal/lib/opal/nodes/base.rb', line 82
def scope
@compiler.scope
end
|
#stmt(sexp) ⇒ Object
[View source]
114
115
116
|
# File 'opal/lib/opal/nodes/base.rb', line 114
def stmt(sexp)
@compiler.process sexp, :stmt
end
|
#stmt? ⇒ Boolean
[View source]
98
99
100
|
# File 'opal/lib/opal/nodes/base.rb', line 98
def stmt?
@level == :stmt
end
|
#unshift(*strs) ⇒ Object
[View source]
62
63
64
65
66
67
|
# File 'opal/lib/opal/nodes/base.rb', line 62
def unshift(*strs)
strs.reverse.each do |str|
str = fragment(str) if str.is_a?(String)
@fragments.unshift str
end
end
|
#while_loop ⇒ Object
[View source]
150
151
152
|
# File 'opal/lib/opal/nodes/base.rb', line 150
def while_loop
@compiler.instance_variable_get(:@while_loop)
end
|
#with_temp(&block) ⇒ Object
[View source]
142
143
144
|
# File 'opal/lib/opal/nodes/base.rb', line 142
def with_temp(&block)
@compiler.with_temp(&block)
end
|
#wrap(pre, post) ⇒ Object
[View source]
69
70
71
72
|
# File 'opal/lib/opal/nodes/base.rb', line 69
def wrap(pre, post)
unshift pre
push post
end
|