Class: Opal::Nodes::CallNode::DependencyResolver
- Defined in:
- opal/lib/opal/nodes/call.rb
Instance Method Summary collapse
- #expand_path(path, base = '') ⇒ Object
- #handle_part(sexp) ⇒ Object
-
#initialize(compiler, sexp) ⇒ DependencyResolver
constructor
A new instance of DependencyResolver.
- #resolve ⇒ Object
Constructor Details
#initialize(compiler, sexp) ⇒ DependencyResolver
Returns a new instance of DependencyResolver
144 145 146 147 |
# File 'opal/lib/opal/nodes/call.rb', line 144 def initialize(compiler, sexp) @compiler = compiler @sexp = sexp end |
Instance Method Details
#expand_path(path, base = '') ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'opal/lib/opal/nodes/call.rb', line 183 def (path, base = '') "#{base}/#{path}".split("/").inject([]) do |p, part| if part == '' # we had '//', so ignore elsif part == '..' p.pop else p << part end p end.join "/" end |
#handle_part(sexp) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'opal/lib/opal/nodes/call.rb', line 153 def handle_part(sexp) type = sexp.type if type == :str return sexp[1] elsif type == :call _, recv, meth, args = sexp parts = args[1..-1].map { |s| handle_part s } if recv == [:const, :File] if meth == :expand_path return (*parts) elsif meth == :join return parts.join('/') elsif meth == :dirname return parts[0].split('/')[0...-1].join('/') end end end msg = "Cannot handle dynamic require" case @compiler.dynamic_require_severity when :error @compiler.error msg when :warning @compiler.warning msg end end |
#resolve ⇒ Object
149 150 151 |
# File 'opal/lib/opal/nodes/call.rb', line 149 def resolve handle_part @sexp end |