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.
-
#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_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?, 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 73 74 75 76 77 |
# File 'lib/ruby2js.rb', line 66 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.
64 65 66 |
# File 'lib/ruby2js.rb', line 64 def disable_autoimports @disable_autoimports end |
#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
91 92 93 |
# File 'lib/ruby2js.rb', line 91 def es2015 @options[:eslevel] >= 2015 end |
#es2016 ⇒ Object
95 96 97 |
# File 'lib/ruby2js.rb', line 95 def es2016 @options[:eslevel] >= 2016 end |
#es2017 ⇒ Object
99 100 101 |
# File 'lib/ruby2js.rb', line 99 def es2017 @options[:eslevel] >= 2017 end |
#es2018 ⇒ Object
103 104 105 |
# File 'lib/ruby2js.rb', line 103 def es2018 @options[:eslevel] >= 2018 end |
#es2019 ⇒ Object
107 108 109 |
# File 'lib/ruby2js.rb', line 107 def es2019 @options[:eslevel] >= 2019 end |
#es2020 ⇒ Object
111 112 113 |
# File 'lib/ruby2js.rb', line 111 def es2020 @options[:eslevel] >= 2020 end |
#es2021 ⇒ Object
115 116 117 |
# File 'lib/ruby2js.rb', line 115 def es2021 @options[:eslevel] >= 2021 end |
#on_async(node) ⇒ Object
handle all of the ‘invented/synthetic’ ast types
133 |
# File 'lib/ruby2js.rb', line 133 def on_async(node); on_def(node); end |
#on_asyncs(node) ⇒ Object
134 |
# File 'lib/ruby2js.rb', line 134 def on_asyncs(node); on_defs(node); end |
#on_attr(node) ⇒ Object
135 |
# File 'lib/ruby2js.rb', line 135 def on_attr(node); on_send(node); end |
#on_autoreturn(node) ⇒ Object
136 |
# File 'lib/ruby2js.rb', line 136 def on_autoreturn(node); on_return(node); end |
#on_await(node) ⇒ Object
137 |
# File 'lib/ruby2js.rb', line 137 def on_await(node); on_send(node); end |
#on_call(node) ⇒ Object
138 |
# File 'lib/ruby2js.rb', line 138 def on_call(node); on_send(node); end |
#on_class_extend(node) ⇒ Object
139 |
# File 'lib/ruby2js.rb', line 139 def on_class_extend(node); on_send(node); end |
#on_class_module(node) ⇒ Object
140 |
# File 'lib/ruby2js.rb', line 140 def on_class_module(node); on_send(node); end |
#on_constructor(node) ⇒ Object
141 |
# File 'lib/ruby2js.rb', line 141 def on_constructor(node); on_def(node); end |
#on_defm(node) ⇒ Object
142 |
# File 'lib/ruby2js.rb', line 142 def on_defm(node); on_defs(node); end |
#on_defp(node) ⇒ Object
143 |
# File 'lib/ruby2js.rb', line 143 def on_defp(node); on_defs(node); end |
#on_export(node) ⇒ Object
154 |
# File 'lib/ruby2js.rb', line 154 def on_export(node); end |
#on_for_of(node) ⇒ Object
144 |
# File 'lib/ruby2js.rb', line 144 def on_for_of(node); on_for(node); end |
#on_import(node) ⇒ Object
155 |
# File 'lib/ruby2js.rb', line 155 def on_import(node); end |
#on_in?(node) ⇒ Boolean
145 |
# File 'lib/ruby2js.rb', line 145 def on_in?(node); on_send(node); end |
#on_method(node) ⇒ Object
146 |
# File 'lib/ruby2js.rb', line 146 def on_method(node); on_send(node); end |
#on_nil(node) ⇒ Object
152 |
# File 'lib/ruby2js.rb', line 152 def on_nil(node); end |
#on_prop(node) ⇒ Object
147 |
# File 'lib/ruby2js.rb', line 147 def on_prop(node); on_array(node); end |
#on_prototype(node) ⇒ Object
148 |
# File 'lib/ruby2js.rb', line 148 def on_prototype(node); on_begin(node); end |
#on_send(node) ⇒ Object
convert map(&:symbol) to a block
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ruby2js.rb', line 162 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
149 |
# File 'lib/ruby2js.rb', line 149 def on_send!(node); on_send(node); end |
#on_sendw(node) ⇒ Object
150 |
# File 'lib/ruby2js.rb', line 150 def on_sendw(node); on_send(node); end |
#on_sym(node) ⇒ Object
provide a method so filters can call ‘super’
159 |
# File 'lib/ruby2js.rb', line 159 def on_sym(node); node; end |
#on_taglit(node) ⇒ Object
156 |
# File 'lib/ruby2js.rb', line 156 def on_taglit(node); end |
#on_undefined?(node) ⇒ Boolean
151 |
# File 'lib/ruby2js.rb', line 151 def on_undefined?(node); on_defined?(node); end |
#on_xnode(node) ⇒ Object
153 |
# File 'lib/ruby2js.rb', line 153 def on_xnode(node); end |
#options=(options) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ruby2js.rb', line 79 def () @options = @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
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/ruby2js.rb', line 119 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 |