module Opal
def self.add_opal_location_to_error(opal_location, error)
def self.add_opal_location_to_error(opal_location, error) backtrace = error.backtrace.to_a backtrace.unshift opal_location.to_s error.set_backtrace backtrace error end
def self.append_path(path)
here should only be paths which contain code targeted at being compiled by
has access to should add a load path through this method. Load paths added
Add a file path to opals load path. Any gem containing ruby code that Opal
def self.append_path(path) append_paths(path) end
def self.append_paths(*paths)
def self.append_paths(*paths) @paths.concat(paths) nil end
def self.cache
def self.cache @cache ||= if RUBY_ENGINE == 'opal' || ENV['OPAL_CACHE_DISABLE'] || !Cache::FileCache.find_dir Cache::NullCache.new else Cache::FileCache.new end end
def self.compile(source, options = {})
-
(String)
- javascript code
Parameters:
-
options
(Hash
) -- compiler options -
source
(String
) -- ruby source
Other tags:
- See: Opal::Compiler.new - for compiler options
def self.compile(source, options = {}) Compiler.new(source, options).compile end
def self.core_dir
def self.core_dir File.expand_path('../../../opal', __FILE__) end
def self.dependent_files
All files that Opal depends on while compiling (for cache keying and
def self.dependent_files # We want to ensure the compiler and any Gemfile/gemspec (for development) # stays untouched opal_path = File.expand_path('..', Opal.gem_dir) files = Dir["#{opal_path}/{Gemfile*,*.gemspec,lib/**/*}"] # Also check if parser wasn't changed: files += $LOADED_FEATURES.grep(%r{lib/(parser|ast)}) files end
def self.gem_dir
We use this file from inside Opal as well, and __dir__ is not yet supported.
def self.gem_dir File.expand_path('../..', __FILE__) end
def self.opal_location_from_error(error)
def self.opal_location_from_error(error) opal_location = OpalBacktraceLocation.new opal_location.location = error.location if error.respond_to?(:location) opal_location.diagnostic = error.diagnostic if error.respond_to?(:diagnostic) opal_location end
def self.paths
def self.paths @paths.freeze end
def self.reset_paths!
Resets Opal.paths to the default value
def self.reset_paths! @paths = [core_dir, std_dir, gem_dir] if RUBY_ENGINE != 'opal' use_gem 'ast' use_gem 'parser' end nil end
def self.std_dir
def self.std_dir File.expand_path('../../../stdlib', __FILE__) end