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.
- #modules_enabled? ⇒ Boolean
-
#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
108 109 110 |
# File 'lib/ruby2js.rb', line 108 def es2015 @options[:eslevel] >= 2015 end |
#es2016 ⇒ Object
112 113 114 |
# File 'lib/ruby2js.rb', line 112 def es2016 @options[:eslevel] >= 2016 end |
#es2017 ⇒ Object
116 117 118 |
# File 'lib/ruby2js.rb', line 116 def es2017 @options[:eslevel] >= 2017 end |
#es2018 ⇒ Object
120 121 122 |
# File 'lib/ruby2js.rb', line 120 def es2018 @options[:eslevel] >= 2018 end |
#es2019 ⇒ Object
124 125 126 |
# File 'lib/ruby2js.rb', line 124 def es2019 @options[:eslevel] >= 2019 end |
#es2020 ⇒ Object
128 129 130 |
# File 'lib/ruby2js.rb', line 128 def es2020 @options[:eslevel] >= 2020 end |
#es2021 ⇒ Object
132 133 134 |
# File 'lib/ruby2js.rb', line 132 def es2021 @options[:eslevel] >= 2021 end |
#es2022 ⇒ Object
136 137 138 |
# File 'lib/ruby2js.rb', line 136 def es2022 @options[:eslevel] >= 2022 end |
#modules_enabled? ⇒ Boolean
104 105 106 |
# File 'lib/ruby2js.rb', line 104 def modules_enabled? @modules_enabled end |
#on_assign(node) ⇒ Object
handle all of the ‘invented/synthetic’ ast types
154 |
# File 'lib/ruby2js.rb', line 154 def on_assign(node); end |
#on_async(node) ⇒ Object
155 |
# File 'lib/ruby2js.rb', line 155 def on_async(node); on_def(node); end |
#on_asyncs(node) ⇒ Object
156 |
# File 'lib/ruby2js.rb', line 156 def on_asyncs(node); on_defs(node); end |
#on_attr(node) ⇒ Object
157 |
# File 'lib/ruby2js.rb', line 157 def on_attr(node); on_send(node); end |
#on_autoreturn(node) ⇒ Object
158 |
# File 'lib/ruby2js.rb', line 158 def on_autoreturn(node); on_return(node); end |
#on_await(node) ⇒ Object
159 |
# File 'lib/ruby2js.rb', line 159 def on_await(node); on_send(node); end |
#on_call(node) ⇒ Object
160 |
# File 'lib/ruby2js.rb', line 160 def on_call(node); on_send(node); end |
#on_class_extend(node) ⇒ Object
161 |
# File 'lib/ruby2js.rb', line 161 def on_class_extend(node); on_send(node); end |
#on_class_hash(node) ⇒ Object
162 |
# File 'lib/ruby2js.rb', line 162 def on_class_hash(node); on_class(node); end |
#on_class_module(node) ⇒ Object
163 |
# File 'lib/ruby2js.rb', line 163 def on_class_module(node); on_send(node); end |
#on_constructor(node) ⇒ Object
164 |
# File 'lib/ruby2js.rb', line 164 def on_constructor(node); on_def(node); end |
#on_deff(node) ⇒ Object
165 |
# File 'lib/ruby2js.rb', line 165 def on_deff(node); on_def(node); end |
#on_defineProps(node) ⇒ Object
177 |
# File 'lib/ruby2js.rb', line 177 def on_defineProps(node); end |
#on_defm(node) ⇒ Object
166 |
# File 'lib/ruby2js.rb', line 166 def on_defm(node); on_defs(node); end |
#on_defp(node) ⇒ Object
167 |
# File 'lib/ruby2js.rb', line 167 def on_defp(node); on_defs(node); end |
#on_export(node) ⇒ Object
181 |
# File 'lib/ruby2js.rb', line 181 def on_export(node); end |
#on_for_of(node) ⇒ Object
168 |
# File 'lib/ruby2js.rb', line 168 def on_for_of(node); on_for(node); end |
#on_hide(node) ⇒ Object
178 |
# File 'lib/ruby2js.rb', line 178 def on_hide(node); on_begin(node); end |
#on_import(node) ⇒ Object
182 |
# File 'lib/ruby2js.rb', line 182 def on_import(node); end |
#on_in?(node) ⇒ Boolean
169 |
# File 'lib/ruby2js.rb', line 169 def on_in?(node); on_send(node); end |
#on_method(node) ⇒ Object
170 |
# File 'lib/ruby2js.rb', line 170 def on_method(node); on_send(node); end |
#on_module_hash(node) ⇒ Object
171 |
# File 'lib/ruby2js.rb', line 171 def on_module_hash(node); on_module(node); end |
#on_nil(node) ⇒ Object
179 |
# File 'lib/ruby2js.rb', line 179 def on_nil(node); end |
#on_prop(node) ⇒ Object
172 |
# File 'lib/ruby2js.rb', line 172 def on_prop(node); on_array(node); end |
#on_prototype(node) ⇒ Object
173 |
# File 'lib/ruby2js.rb', line 173 def on_prototype(node); on_begin(node); end |
#on_send(node) ⇒ Object
convert map(&:symbol) to a block
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/ruby2js.rb', line 189 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))))) elsif node.children.last.children.first.type == :sym 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)))) else super end end super end |
#on_send!(node) ⇒ Object
174 |
# File 'lib/ruby2js.rb', line 174 def on_send!(node); on_send(node); end |
#on_sendw(node) ⇒ Object
175 |
# File 'lib/ruby2js.rb', line 175 def on_sendw(node); on_send(node); end |
#on_sym(node) ⇒ Object
provide a method so filters can call ‘super’
186 |
# File 'lib/ruby2js.rb', line 186 def on_sym(node); node; end |
#on_taglit(node) ⇒ Object
183 |
# File 'lib/ruby2js.rb', line 183 def on_taglit(node); on_pair(node); end |
#on_undefined?(node) ⇒ Boolean
176 |
# File 'lib/ruby2js.rb', line 176 def on_undefined?(node); on_defined?(node); end |
#on_xnode(node) ⇒ Object
180 |
# File 'lib/ruby2js.rb', line 180 def on_xnode(node); end |
#options=(options) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# 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] filters = [:filters] || DEFAULTS @modules_enabled = (defined? Ruby2JS::Filter::ESM and filters.include? Ruby2JS::Filter::ESM) or (defined? Ruby2JS::Filter::CJS and filters.include? Ruby2JS::Filter::CJS) end |
#process(node) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ruby2js.rb', line 140 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 |