Class: StyleScript::ValueNode
- Inherits:
-
Node
- Object
- Node
- StyleScript::ValueNode
show all
- Defined in:
- lib/style_script/nodes.rb
Overview
A value, indexed or dotted into, or vanilla.
Constant Summary
collapse
- SOAK =
Soak up undefined properties and call attempts.
" == undefined ? undefined : "
Constants inherited
from Node
Node::TAB
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Node
#children, children, #compile, #compile_closure, #contains?, #idt, statement, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #write
Constructor Details
#initialize(base, properties = []) ⇒ ValueNode
Returns a new instance of ValueNode.
237
238
239
|
# File 'lib/style_script/nodes.rb', line 237
def initialize(base, properties=[])
@base, @properties = base, [properties].flatten
end
|
Instance Attribute Details
#last ⇒ Object
Returns the value of attribute last.
232
233
234
|
# File 'lib/style_script/nodes.rb', line 232
def last
@last
end
|
#source ⇒ Object
Returns the value of attribute source.
232
233
234
|
# File 'lib/style_script/nodes.rb', line 232
def source
@source
end
|
Instance Method Details
#<<(other) ⇒ Object
241
242
243
244
|
# File 'lib/style_script/nodes.rb', line 241
def <<(other)
@properties << other
self
end
|
#arguments? ⇒ Boolean
262
263
264
|
# File 'lib/style_script/nodes.rb', line 262
def arguments?
@base.to_s == 'arguments'
end
|
#array? ⇒ Boolean
250
251
252
|
# File 'lib/style_script/nodes.rb', line 250
def array?
@base.is_a?(ArrayNode) && !properties?
end
|
#compile_node(o) ⇒ Object
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
# File 'lib/style_script/nodes.rb', line 275
def compile_node(o)
soaked = false
only = o.delete(:only_first)
props = only ? @properties[0...-1] : @properties
baseline = @base.compile(o)
parts = [baseline.dup]
props.each do |prop|
if prop.is_a?(AccessorNode) && prop.soak
soaked = true
if @base.is_a?(CallNode) && prop == props.first
temp = o[:scope].free_variable
parts[-1] = "(#{temp} = #{baseline})#{SOAK}#{baseline = temp.to_s + prop.compile(o)}"
else
parts[-1] << "#{SOAK}#{baseline += prop.compile(o)}"
end
else
part = prop.compile(o)
baseline += part
parts << part
end
end
@last = parts.last
@source = parts.length > 1 ? parts[0...-1].join('') : nil
code = parts.join('').gsub(')())', '()))')
write(soaked ? "(#{code})" : code)
end
|
#object? ⇒ Boolean
254
255
256
|
# File 'lib/style_script/nodes.rb', line 254
def object?
@base.is_a?(ObjectNode) && !properties?
end
|
#properties? ⇒ Boolean
246
247
248
|
# File 'lib/style_script/nodes.rb', line 246
def properties?
return !@properties.empty? || @base.is_a?(ThisNode)
end
|
#splice? ⇒ Boolean
258
259
260
|
# File 'lib/style_script/nodes.rb', line 258
def splice?
properties? && @properties.last.is_a?(SliceNode)
end
|
#statement? ⇒ Boolean
Values are statements if their base is a statement.
271
272
273
|
# File 'lib/style_script/nodes.rb', line 271
def statement?
@base.is_a?(Node) && @base.statement? && !properties?
end
|
#unwrap ⇒ Object
266
267
268
|
# File 'lib/style_script/nodes.rb', line 266
def unwrap
@properties.empty? ? @base : self
end
|