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
148 149 150 151 |
# File 'opal/lib/opal/nodes/call.rb', line 148 def initialize(compiler, sexp) @compiler = compiler @sexp = sexp end |
Instance Method Details
#expand_path(path, base = '') ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'opal/lib/opal/nodes/call.rb', line 187 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
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 182 183 184 185 |
# File 'opal/lib/opal/nodes/call.rb', line 157 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
153 154 155 |
# File 'opal/lib/opal/nodes/call.rb', line 153 def resolve handle_part @sexp end |