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 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_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
55 56 57 58 59 |
# File 'lib/ruby2js.rb', line 55 def initialize(comments) @comments = comments @ast = nil @exclude_methods = [] end |
Instance Method Details
#es2015 ⇒ Object
73 74 75 |
# File 'lib/ruby2js.rb', line 73 def es2015 [:eslevel] >= 2015 end |
#es2016 ⇒ Object
77 78 79 |
# File 'lib/ruby2js.rb', line 77 def es2016 [:eslevel] >= 2016 end |
#es2017 ⇒ Object
81 82 83 |
# File 'lib/ruby2js.rb', line 81 def es2017 [:eslevel] >= 2017 end |
#es2018 ⇒ Object
85 86 87 |
# File 'lib/ruby2js.rb', line 85 def es2018 [:eslevel] >= 2018 end |
#es2019 ⇒ Object
89 90 91 |
# File 'lib/ruby2js.rb', line 89 def es2019 [:eslevel] >= 2019 end |
#es2020 ⇒ Object
93 94 95 |
# File 'lib/ruby2js.rb', line 93 def es2020 [:eslevel] >= 2020 end |
#es2021 ⇒ Object
97 98 99 |
# File 'lib/ruby2js.rb', line 97 def es2021 [:eslevel] >= 2021 end |
#on_async(node) ⇒ Object
handle all of the ‘invented/synthetic’ ast types
115 |
# File 'lib/ruby2js.rb', line 115 def on_async(node); on_def(node); end |
#on_asyncs(node) ⇒ Object
116 |
# File 'lib/ruby2js.rb', line 116 def on_asyncs(node); on_defs(node); end |
#on_attr(node) ⇒ Object
117 |
# File 'lib/ruby2js.rb', line 117 def on_attr(node); on_send(node); end |
#on_autoreturn(node) ⇒ Object
118 |
# File 'lib/ruby2js.rb', line 118 def on_autoreturn(node); on_return(node); end |
#on_await(node) ⇒ Object
119 |
# File 'lib/ruby2js.rb', line 119 def on_await(node); on_send(node); end |
#on_call(node) ⇒ Object
120 |
# File 'lib/ruby2js.rb', line 120 def on_call(node); on_send(node); end |
#on_class_extend(node) ⇒ Object
121 |
# File 'lib/ruby2js.rb', line 121 def on_class_extend(node); on_send(node); end |
#on_class_module(node) ⇒ Object
122 |
# File 'lib/ruby2js.rb', line 122 def on_class_module(node); on_send(node); end |
#on_constructor(node) ⇒ Object
123 |
# File 'lib/ruby2js.rb', line 123 def on_constructor(node); on_def(node); end |
#on_defm(node) ⇒ Object
124 |
# File 'lib/ruby2js.rb', line 124 def on_defm(node); on_defs(node); end |
#on_defp(node) ⇒ Object
125 |
# File 'lib/ruby2js.rb', line 125 def on_defp(node); on_defs(node); end |
#on_export(node) ⇒ Object
135 |
# File 'lib/ruby2js.rb', line 135 def on_export(node); end |
#on_for_of(node) ⇒ Object
126 |
# File 'lib/ruby2js.rb', line 126 def on_for_of(node); on_for(node); end |
#on_import(node) ⇒ Object
136 |
# File 'lib/ruby2js.rb', line 136 def on_import(node); end |
#on_in?(node) ⇒ Boolean
127 |
# File 'lib/ruby2js.rb', line 127 def on_in?(node); on_send(node); end |
#on_method(node) ⇒ Object
128 |
# File 'lib/ruby2js.rb', line 128 def on_method(node); on_send(node); end |
#on_nil(node) ⇒ Object
133 |
# File 'lib/ruby2js.rb', line 133 def on_nil(node); end |
#on_prop(node) ⇒ Object
129 |
# File 'lib/ruby2js.rb', line 129 def on_prop(node); on_array(node); end |
#on_prototype(node) ⇒ Object
130 |
# File 'lib/ruby2js.rb', line 130 def on_prototype(node); on_begin(node); end |
#on_send(node) ⇒ Object
convert map(&:symbol) to a block
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ruby2js.rb', line 142 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
131 |
# File 'lib/ruby2js.rb', line 131 def on_sendw(node); on_send(node); end |
#on_sym(node) ⇒ Object
provide a method so filters can call ‘super’
139 |
# File 'lib/ruby2js.rb', line 139 def on_sym(node); node; end |
#on_undefined?(node) ⇒ Boolean
132 |
# File 'lib/ruby2js.rb', line 132 def on_undefined?(node); on_defined?(node); end |
#on_xnode(node) ⇒ Object
134 |
# File 'lib/ruby2js.rb', line 134 def on_xnode(node); end |
#options=(options) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby2js.rb', line 61 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
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ruby2js.rb', line 101 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 |