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
Constants included from Ruby2JS::Filter
Instance Attribute Summary collapse
-
#disable_autoimports ⇒ Object
Returns the value of attribute disable_autoimports.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#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
- #es2022 ⇒ Object
-
#initialize(comments) ⇒ Processor
constructor
A new instance of Processor.
-
#on_assign(node) ⇒ Object
handle all of the ‘invented/synthetic’ ast types.
- #on_async(node) ⇒ Object
- #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_hash(node) ⇒ Object
- #on_class_module(node) ⇒ Object
- #on_constructor(node) ⇒ Object
- #on_deff(node) ⇒ Object
- #on_defineProps(node) ⇒ Object
- #on_defm(node) ⇒ Object
- #on_defp(node) ⇒ Object
- #on_export(node) ⇒ Object
- #on_for_of(node) ⇒ Object
- #on_hide(node) ⇒ Object
- #on_import(node) ⇒ Object
- #on_in?(node) ⇒ Boolean
- #on_method(node) ⇒ Object
- #on_module_hash(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_send!(node) ⇒ Object
- #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?, excluded_methods, #include, include, include_all, #include_all, include_only, #include_only, included_methods
Constructor Details
#initialize(comments) ⇒ Processor
Returns a new instance of Processor.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ruby2js.rb', line 72 def initialize(comments) @comments = comments # check if magic comment is present: first_comment = @comments.values.first&.map(&:text)&.first @disable_autoimports = first_comment&.include?(" autoimports: false") @disable_autoexports = first_comment&.include?(" autoexports: false") @ast = nil @exclude_methods = [] @prepend_list = Set.new end |
Instance Attribute Details
#disable_autoimports ⇒ Object
Returns the value of attribute disable_autoimports.
70 71 72 |
# File 'lib/ruby2js.rb', line 70 def disable_autoimports @disable_autoimports end |
#namespace ⇒ Object
Returns the value of attribute namespace.
70 71 72 |
# File 'lib/ruby2js.rb', line 70 def namespace @namespace end |
#prepend_list ⇒ Object
Returns the value of attribute prepend_list.
70 71 72 |
# File 'lib/ruby2js.rb', line 70 def prepend_list @prepend_list end |
Instance Method Details
#es2015 ⇒ Object
97 98 99 |
# File 'lib/ruby2js.rb', line 97 def es2015 @options[:eslevel] >= 2015 end |
#es2016 ⇒ Object
101 102 103 |
# File 'lib/ruby2js.rb', line 101 def es2016 @options[:eslevel] >= 2016 end |
#es2017 ⇒ Object
105 106 107 |
# File 'lib/ruby2js.rb', line 105 def es2017 @options[:eslevel] >= 2017 end |
#es2018 ⇒ Object
109 110 111 |
# File 'lib/ruby2js.rb', line 109 def es2018 @options[:eslevel] >= 2018 end |
#es2019 ⇒ Object
113 114 115 |
# File 'lib/ruby2js.rb', line 113 def es2019 @options[:eslevel] >= 2019 end |
#es2020 ⇒ Object
117 118 119 |
# File 'lib/ruby2js.rb', line 117 def es2020 @options[:eslevel] >= 2020 end |
#es2021 ⇒ Object
121 122 123 |
# File 'lib/ruby2js.rb', line 121 def es2021 @options[:eslevel] >= 2021 end |
#es2022 ⇒ Object
125 126 127 |
# File 'lib/ruby2js.rb', line 125 def es2022 @options[:eslevel] >= 2022 end |
#on_assign(node) ⇒ Object
handle all of the ‘invented/synthetic’ ast types
143 |
# File 'lib/ruby2js.rb', line 143 def on_assign(node); end |
#on_async(node) ⇒ Object
144 |
# File 'lib/ruby2js.rb', line 144 def on_async(node); on_def(node); end |
#on_asyncs(node) ⇒ Object
145 |
# File 'lib/ruby2js.rb', line 145 def on_asyncs(node); on_defs(node); end |
#on_attr(node) ⇒ Object
146 |
# File 'lib/ruby2js.rb', line 146 def on_attr(node); on_send(node); end |
#on_autoreturn(node) ⇒ Object
147 |
# File 'lib/ruby2js.rb', line 147 def on_autoreturn(node); on_return(node); end |
#on_await(node) ⇒ Object
148 |
# File 'lib/ruby2js.rb', line 148 def on_await(node); on_send(node); end |
#on_call(node) ⇒ Object
149 |
# File 'lib/ruby2js.rb', line 149 def on_call(node); on_send(node); end |
#on_class_extend(node) ⇒ Object
150 |
# File 'lib/ruby2js.rb', line 150 def on_class_extend(node); on_send(node); end |
#on_class_hash(node) ⇒ Object
151 |
# File 'lib/ruby2js.rb', line 151 def on_class_hash(node); on_class(node); end |
#on_class_module(node) ⇒ Object
152 |
# File 'lib/ruby2js.rb', line 152 def on_class_module(node); on_send(node); end |
#on_constructor(node) ⇒ Object
153 |
# File 'lib/ruby2js.rb', line 153 def on_constructor(node); on_def(node); end |
#on_deff(node) ⇒ Object
154 |
# File 'lib/ruby2js.rb', line 154 def on_deff(node); on_def(node); end |
#on_defineProps(node) ⇒ Object
166 |
# File 'lib/ruby2js.rb', line 166 def on_defineProps(node); end |
#on_defm(node) ⇒ Object
155 |
# File 'lib/ruby2js.rb', line 155 def on_defm(node); on_defs(node); end |
#on_defp(node) ⇒ Object
156 |
# File 'lib/ruby2js.rb', line 156 def on_defp(node); on_defs(node); end |
#on_export(node) ⇒ Object
170 |
# File 'lib/ruby2js.rb', line 170 def on_export(node); end |
#on_for_of(node) ⇒ Object
157 |
# File 'lib/ruby2js.rb', line 157 def on_for_of(node); on_for(node); end |
#on_hide(node) ⇒ Object
167 |
# File 'lib/ruby2js.rb', line 167 def on_hide(node); on_begin(node); end |
#on_import(node) ⇒ Object
171 |
# File 'lib/ruby2js.rb', line 171 def on_import(node); end |
#on_in?(node) ⇒ Boolean
158 |
# File 'lib/ruby2js.rb', line 158 def on_in?(node); on_send(node); end |
#on_method(node) ⇒ Object
159 |
# File 'lib/ruby2js.rb', line 159 def on_method(node); on_send(node); end |
#on_module_hash(node) ⇒ Object
160 |
# File 'lib/ruby2js.rb', line 160 def on_module_hash(node); on_module(node); end |
#on_nil(node) ⇒ Object
168 |
# File 'lib/ruby2js.rb', line 168 def on_nil(node); end |
#on_prop(node) ⇒ Object
161 |
# File 'lib/ruby2js.rb', line 161 def on_prop(node); on_array(node); end |
#on_prototype(node) ⇒ Object
162 |
# File 'lib/ruby2js.rb', line 162 def on_prototype(node); on_begin(node); end |
#on_send(node) ⇒ Object
convert map(&:symbol) to a block
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/ruby2js.rb', line 178 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_send!(node) ⇒ Object
163 |
# File 'lib/ruby2js.rb', line 163 def on_send!(node); on_send(node); end |
#on_sendw(node) ⇒ Object
164 |
# File 'lib/ruby2js.rb', line 164 def on_sendw(node); on_send(node); end |
#on_sym(node) ⇒ Object
provide a method so filters can call ‘super’
175 |
# File 'lib/ruby2js.rb', line 175 def on_sym(node); node; end |
#on_taglit(node) ⇒ Object
172 |
# File 'lib/ruby2js.rb', line 172 def on_taglit(node); end |
#on_undefined?(node) ⇒ Boolean
165 |
# File 'lib/ruby2js.rb', line 165 def on_undefined?(node); on_defined?(node); end |
#on_xnode(node) ⇒ Object
169 |
# File 'lib/ruby2js.rb', line 169 def on_xnode(node); end |
#options=(options) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ruby2js.rb', line 85 def () @options = @included = Filter.included_methods @excluded = Filter.excluded_methods include_all if [:include_all] include_only([:include_only]) if [:include_only] include([:include]) if [:include] exclude([:exclude]) if [:exclude] end |
#process(node) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ruby2js.rb', line 129 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 |