Module: Opal

Extended by:
Deprecations, UseGem
Defined in:
opal/lib/opal.rb,
opal/lib/opal/cli.rb,
opal/lib/opal/erb.rb,
opal/lib/opal/util.rb,
opal/lib/tilt/opal.rb,
opal/lib/opal/paths.rb,
opal/lib/opal/config.rb,
opal/lib/opal/errors.rb,
opal/lib/opal/parser.rb,
opal/lib/opal/builder.rb,
opal/lib/opal/version.rb,
opal/lib/opal/ast/node.rb,
opal/lib/opal/compiler.rb,
opal/lib/opal/fragment.rb,
opal/lib/opal/nodes/if.rb,
opal/lib/opal/rewriter.rb,
opal/lib/opal/nodes/def.rb,
opal/lib/opal/nodes/top.rb,
opal/lib/opal/nodes/base.rb,
opal/lib/opal/nodes/call.rb,
opal/lib/opal/nodes/case.rb,
opal/lib/opal/nodes/defs.rb,
opal/lib/opal/nodes/hash.rb,
opal/lib/opal/nodes/iter.rb,
opal/lib/opal/source_map.rb,
opal/lib/opal/ast/builder.rb,
opal/lib/opal/cli_options.rb,
opal/lib/opal/cli_runners.rb,
opal/lib/opal/eof_content.rb,
opal/lib/opal/nodes/array.rb,
opal/lib/opal/nodes/class.rb,
opal/lib/opal/nodes/csend.rb,
opal/lib/opal/nodes/logic.rb,
opal/lib/opal/nodes/masgn.rb,
opal/lib/opal/nodes/scope.rb,
opal/lib/opal/nodes/super.rb,
opal/lib/opal/nodes/while.rb,
opal/lib/opal/nodes/yield.rb,
opal/lib/opal/path_reader.rb,
opal/lib/opal/deprecations.rb,
opal/lib/opal/nodes/module.rb,
opal/lib/opal/nodes/rescue.rb,
opal/lib/opal/nodes/arglist.rb,
opal/lib/opal/nodes/defined.rb,
opal/lib/opal/nodes/helpers.rb,
opal/lib/opal/nodes/literal.rb,
opal/lib/opal/regexp_anchors.rb,
opal/lib/opal/rewriters/base.rb,
opal/lib/opal/nodes/constants.rb,
opal/lib/opal/nodes/variables.rb,
opal/lib/opal/nodes/args/kwarg.rb,
opal/lib/opal/nodes/args/optarg.rb,
opal/lib/opal/nodes/definitions.rb,
opal/lib/opal/nodes/inline_args.rb,
opal/lib/opal/builder_processors.rb,
opal/lib/opal/cli_runners/chrome.rb,
opal/lib/opal/cli_runners/nodejs.rb,
opal/lib/opal/cli_runners/server.rb,
opal/lib/opal/nodes/args/mlhsarg.rb,
opal/lib/opal/nodes/args/normarg.rb,
opal/lib/opal/nodes/args/restarg.rb,
opal/lib/opal/nodes/call_special.rb,
opal/lib/opal/cli_runners/nashorn.rb,
opal/lib/opal/nodes/args/kwoptarg.rb,
opal/lib/opal/nodes/args/kwrestarg.rb,
opal/lib/opal/nodes/args/post_args.rb,
opal/lib/opal/nodes/node_with_args.rb,
opal/lib/opal/nodes/runtime_helpers.rb,
opal/lib/opal/nodes/singleton_class.rb,
opal/lib/opal/nodes/args/post_kwargs.rb,
opal/lib/opal/rewriters/break_finder.rb,
opal/lib/opal/rewriters/for_rewriter.rb,
opal/lib/opal/cli_runners/applescript.rb,
opal/lib/opal/rewriters/block_to_iter.rb,
opal/lib/opal/rewriters/dot_js_syntax.rb,
opal/lib/opal/rewriters/js_reserved_words.rb,
opal/lib/opal/rewriters/opal_engine_check.rb,
opal/lib/opal/nodes/args/initialize_kwargs.rb,
opal/lib/opal/rewriters/explicit_writer_return.rb,
opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb,
opal/lib/opal/rewriters/binary_operator_assignment.rb,
opal/lib/opal/rewriters/logical_operator_assignment.rb,
opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb

Overview

Opal is a ruby to javascript compiler, with a runtime for running in any JavaScript environment.

Defined Under Namespace

Modules: AST, BuilderProcessors, CliRunners, Config, Deprecations, ERB, Nodes, Rewriters, Rubyspec, Source, UseGem, Util Classes: Builder, CLI, CLIOptions, Compiler, EofContent, Fragment, GemNotFound, Parser, PathReader, Rewriter, SimpleServer, SourceMap, TiltTemplate

Constant Summary

Server =
Opal::Sprockets::Server
VERSION =

WHEN RELEASING: Remember to update RUBY_ENGINE_VERSION in opal/corelib/constants.rb too!

'0.11.2'
REGEXP_START =
RUBY_ENGINE == 'opal' ? '^' : '\A'.freeze
REGEXP_END =
RUBY_ENGINE == 'opal' ? '$' : '\z'.freeze
FORBIDDEN_STARTING_IDENTIFIER_CHARS =

Unicode characters in ranges \u0001 - \u002F (blank unicode characters + space + !"#$%&'()*+,-./ chars) \u003A - \u0040 (:;<=>?@ chars) \u005B - \u005E ([]^ chars) \u0060 (` char) \u007B - \u007F ({|}~ chars}) are not allowed to be used in identifier in the beggining or middle of its name

"\\u0001-\\u002F\\u003A-\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F"
FORBIDDEN_ENDING_IDENTIFIER_CHARS =

Unicode characters in ranges \u0001 - \u0020 (blank unicode characters + space) \u0022 - \u002F ("#$%&'()*+,-./ chars) \u003A - \u003E (:;<=> chars) \u0040 (@ char) \u005B - \u005E ([]^ chars) \u0060 (` char) \u007B - \u007F ({|}~ chars}) are not allowed to be used in identifier in the end of its name In fact, FORBIDDEN_STARTING_IDENTIFIER_CHARS = FORBIDDEN_ENDING_IDENTIFIER_CHARS + \u0021 ('?') + \u003F ('!')

"\\u0001-\\u0020\\u0022-\\u002F\\u003A-\\u003E\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F"
INLINE_IDENTIFIER_REGEXP =
Regexp.new("[^#{FORBIDDEN_STARTING_IDENTIFIER_CHARS}]*[^#{FORBIDDEN_ENDING_IDENTIFIER_CHARS}]")
FORBIDDEN_CONST_NAME_CHARS =

For constants rules are pretty much the same, but ':' is allowed and '?!' are not. Plus it may start with a '::' which indicates that the constant comes from toplevel.

"\\u0001-\\u0020\\u0021-\\u002F\\u003B-\\u003F\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F"
CONST_NAME_REGEXP =
Regexp.new("#{REGEXP_START}(::)?[A-Z][^#{FORBIDDEN_CONST_NAME_CHARS}]*#{REGEXP_END}")

Instance Attribute Summary

Attributes included from Deprecations

#raise_on_deprecation

Class Method Summary collapse

Methods included from Deprecations

deprecation

Methods included from UseGem

use_gem

Class Method Details

.append_path(path) ⇒ Object

Add a file path to opals load path. Any gem containing ruby code that Opal has access to should add a load path through this method. Load paths added here should only be paths which contain code targeted at being compiled by Opal.



19
20
21
# File 'opal/lib/opal/paths.rb', line 19

def self.append_path(path)
  append_paths(path)
end

.append_paths(*paths) ⇒ Object

Same as #append_path but can take multiple paths.



24
25
26
27
# File 'opal/lib/opal/paths.rb', line 24

def self.append_paths(*paths)
  @paths.concat(paths)
  nil
end

.compile(source, options = {}) ⇒ String

Compile a string of ruby code into javascript.

Examples:


Opal.compile "ruby_code"
# => "string of javascript code"

Parameters:

  • source (String)

    ruby source

  • options (Hash) (defaults to: {})

    compiler options

Returns:

  • (String)

    javascript code

See Also:

  • for compiler options


22
23
24
# File 'opal/lib/opal/compiler.rb', line 22

def self.compile(source, options = {})
  Compiler.new(source, options).compile
end

.core_dirObject



7
8
9
# File 'opal/lib/opal/paths.rb', line 7

def self.core_dir
  File.expand_path("../../../opal", __FILE__.dup.untaint)
end

.gem_dirObject



3
4
5
# File 'opal/lib/opal/paths.rb', line 3

def self.gem_dir
  File.expand_path("../..", __FILE__.dup.untaint)
end

.pathsObject



66
67
68
# File 'opal/lib/opal/paths.rb', line 66

def self.paths
  @paths.dup.freeze
end

.reset_paths!Object

Resets Opal.paths to the default value (includes corelib, stdlib, opal/lib, ast gem and parser gem)



72
73
74
75
76
77
78
79
# File 'opal/lib/opal/paths.rb', line 72

def self.reset_paths!
  @paths = [core_dir.untaint, std_dir.untaint, gem_dir.untaint]
  if RUBY_ENGINE != 'opal'
    use_gem 'ast'
    use_gem 'parser'
  end
  nil
end

.std_dirObject



11
12
13
# File 'opal/lib/opal/paths.rb', line 11

def self.std_dir
  File.expand_path("../../../stdlib", __FILE__.dup.untaint)
end