Class: Ruby2JS::Filter::Processor
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- Ruby2JS::Filter::Processor
- Includes:
- Ruby2JS::Filter
- Defined in:
- lib/ruby2js.rb
Constant Summary collapse
- BINARY_OPERATORS =
Converter::OPERATORS[2..-1].flatten
Constants included from Ruby2JS::Filter
Instance Attribute Summary collapse
-
#prepend_list ⇒ Object
Returns the value of attribute prepend_list.
Instance Method Summary collapse
- #es2015 ⇒ Object
- #es2016 ⇒ Object
- #es2017 ⇒ Object
- #es2018 ⇒ Object
- #es2019 ⇒ Object
- #es2020 ⇒ Object
- #es2021 ⇒ Object
-
#initialize(comments) ⇒ Processor
constructor
A new instance of Processor.
-
#on_async(node) ⇒ Object
handle all of the ‘invented/synthetic’ ast types.
- #on_asyncs(node) ⇒ Object
- #on_attr(node) ⇒ Object
- #on_autoreturn(node) ⇒ Object
- #on_await(node) ⇒ Object
- #on_call(node) ⇒ Object
- #on_class_extend(node) ⇒ Object
- #on_class_module(node) ⇒ Object
- #on_constructor(node) ⇒ Object
- #on_defm(node) ⇒ Object
- #on_defp(node) ⇒ Object
- #on_export(node) ⇒ Object
- #on_for_of(node) ⇒ Object
- #on_import(node) ⇒ Object
- #on_in?(node) ⇒ Boolean
- #on_method(node) ⇒ Object
- #on_nil(node) ⇒ Object
- #on_prop(node) ⇒ Object
- #on_prototype(node) ⇒ Object
-
#on_send(node) ⇒ Object
convert map(&:symbol) to a block.
- #on_sendw(node) ⇒ Object
-
#on_sym(node) ⇒ Object
provide a method so filters can call ‘super’.
- #on_taglit(node) ⇒ Object
- #on_undefined?(node) ⇒ Boolean
- #on_xnode(node) ⇒ Object
- #options=(options) ⇒ Object
- #process(node) ⇒ Object
Methods included from Ruby2JS::Filter
exclude, #exclude, #excluded?, include, #include, include_all, #include_all, #include_only, include_only
Constructor Details
#initialize(comments) ⇒ Processor
Returns a new instance of Processor.
66 67 68 69 70 71 72 |
# File 'lib/ruby2js.rb', line 66 def initialize(comments) @comments = comments @ast = nil @exclude_methods = [] @esm = false @prepend_list = Set.new end |
Instance Attribute Details
#prepend_list ⇒ Object
Returns the value of attribute prepend_list.
64 65 66 |
# File 'lib/ruby2js.rb', line 64 def prepend_list @prepend_list end |
Instance Method Details
#es2015 ⇒ Object
86 87 88 |
# File 'lib/ruby2js.rb', line 86 def es2015 [:eslevel] >= 2015 end |
#es2016 ⇒ Object
90 91 92 |
# File 'lib/ruby2js.rb', line 90 def es2016 [:eslevel] >= 2016 end |
#es2017 ⇒ Object
94 95 96 |
# File 'lib/ruby2js.rb', line 94 def es2017 [:eslevel] >= 2017 end |
#es2018 ⇒ Object
98 99 100 |
# File 'lib/ruby2js.rb', line 98 def es2018 [:eslevel] >= 2018 end |
#es2019 ⇒ Object
102 103 104 |
# File 'lib/ruby2js.rb', line 102 def es2019 [:eslevel] >= 2019 end |
#es2020 ⇒ Object
106 107 108 |
# File 'lib/ruby2js.rb', line 106 def es2020 [:eslevel] >= 2020 end |
#es2021 ⇒ Object
110 111 112 |
# File 'lib/ruby2js.rb', line 110 def es2021 [:eslevel] >= 2021 end |
#on_async(node) ⇒ Object
handle all of the ‘invented/synthetic’ ast types
128 |
# File 'lib/ruby2js.rb', line 128 def on_async(node); on_def(node); end |
#on_asyncs(node) ⇒ Object
129 |
# File 'lib/ruby2js.rb', line 129 def on_asyncs(node); on_defs(node); end |
#on_attr(node) ⇒ Object
130 |
# File 'lib/ruby2js.rb', line 130 def on_attr(node); on_send(node); end |
#on_autoreturn(node) ⇒ Object
131 |
# File 'lib/ruby2js.rb', line 131 def on_autoreturn(node); on_return(node); end |
#on_await(node) ⇒ Object
132 |
# File 'lib/ruby2js.rb', line 132 def on_await(node); on_send(node); end |
#on_call(node) ⇒ Object
133 |
# File 'lib/ruby2js.rb', line 133 def on_call(node); on_send(node); end |
#on_class_extend(node) ⇒ Object
134 |
# File 'lib/ruby2js.rb', line 134 def on_class_extend(node); on_send(node); end |
#on_class_module(node) ⇒ Object
135 |
# File 'lib/ruby2js.rb', line 135 def on_class_module(node); on_send(node); end |
#on_constructor(node) ⇒ Object
136 |
# File 'lib/ruby2js.rb', line 136 def on_constructor(node); on_def(node); end |
#on_defm(node) ⇒ Object
137 |
# File 'lib/ruby2js.rb', line 137 def on_defm(node); on_defs(node); end |
#on_defp(node) ⇒ Object
138 |
# File 'lib/ruby2js.rb', line 138 def on_defp(node); on_defs(node); end |
#on_export(node) ⇒ Object
148 |
# File 'lib/ruby2js.rb', line 148 def on_export(node); end |
#on_for_of(node) ⇒ Object
139 |
# File 'lib/ruby2js.rb', line 139 def on_for_of(node); on_for(node); end |
#on_import(node) ⇒ Object
149 |
# File 'lib/ruby2js.rb', line 149 def on_import(node); end |
#on_in?(node) ⇒ Boolean
140 |
# File 'lib/ruby2js.rb', line 140 def on_in?(node); on_send(node); end |
#on_method(node) ⇒ Object
141 |
# File 'lib/ruby2js.rb', line 141 def on_method(node); on_send(node); end |
#on_nil(node) ⇒ Object
146 |
# File 'lib/ruby2js.rb', line 146 def on_nil(node); end |
#on_prop(node) ⇒ Object
142 |
# File 'lib/ruby2js.rb', line 142 def on_prop(node); on_array(node); end |
#on_prototype(node) ⇒ Object
143 |
# File 'lib/ruby2js.rb', line 143 def on_prototype(node); on_begin(node); end |
#on_send(node) ⇒ Object
convert map(&:symbol) to a block
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/ruby2js.rb', line 156 def on_send(node) if node.children.length > 2 and node.children.last.type == :block_pass method = node.children.last.children.first.children.last if BINARY_OPERATORS.include? method return on_block s(:block, s(:send, *node.children[0..-2]), s(:args, s(:arg, :a), s(:arg, :b)), s(:return, process(s(:send, s(:lvar, :a), method, s(:lvar, :b))))) else return on_block s(:block, s(:send, *node.children[0..-2]), s(:args, s(:arg, :item)), s(:return, process(s(:attr, s(:lvar, :item), method)))) end end super end |
#on_sendw(node) ⇒ Object
144 |
# File 'lib/ruby2js.rb', line 144 def on_sendw(node); on_send(node); end |
#on_sym(node) ⇒ Object
provide a method so filters can call ‘super’
153 |
# File 'lib/ruby2js.rb', line 153 def on_sym(node); node; end |
#on_taglit(node) ⇒ Object
150 |
# File 'lib/ruby2js.rb', line 150 def on_taglit(node); end |
#on_undefined?(node) ⇒ Boolean
145 |
# File 'lib/ruby2js.rb', line 145 def on_undefined?(node); on_defined?(node); end |
#on_xnode(node) ⇒ Object
147 |
# File 'lib/ruby2js.rb', line 147 def on_xnode(node); end |
#options=(options) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ruby2js.rb', line 74 def () = @included = @@included @excluded = @@excluded include_all if [:include_all] include_only([:include_only]) if [:include_only] include([:include]) if [:include] exclude([:exclude]) if [:exclude] end |
#process(node) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ruby2js.rb', line 114 def process(node) ast, @ast = @ast, node replacement = super if replacement != node and @comments[node] @comments[replacement] = @comments[node] end replacement ensure @ast = ast end |