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
230 231 232 233 |
# File 'opal/lib/opal/nodes/call.rb', line 230 def initialize(compiler, sexp) @compiler = compiler @sexp = sexp end |
Instance Method Details
#expand_path(path, base = '') ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'opal/lib/opal/nodes/call.rb', line 269 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
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'opal/lib/opal/nodes/call.rb', line 239 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, @sexp.line when :warning @compiler.warning msg, @sexp.line end end |
#resolve ⇒ Object
235 236 237 |
# File 'opal/lib/opal/nodes/call.rb', line 235 def resolve handle_part @sexp end |