Module: Opal::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/opal/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#arity_check_enabledtrue, false

Enable arity check on the arguments passed to methods, procs and lambdas.

Returns:

  • (true, false)


89
# File 'lib/opal/config.rb', line 89

config_option :arity_check_enabled, false, compiler_option: :arity_check

#const_missing_enabledtrue, false

Enable const_missing support.

Returns:

  • (true, false)


84
# File 'lib/opal/config.rb', line 84

config_option :const_missing_enabled, true, compiler_option: :const_missing

#dynamic_require_severity:error, ...

Set the error severity for when a require can't be parsed at compile time.

  • :error will raise an error at compile time
  • :warning will print a warning on stderr at compile time
  • :ignore will skip the require silently at compile time

Examples:

# Opal code
require "foo" + some_dynamic_value

Returns:

  • (:error, :warning, :ignore)


112
# File 'lib/opal/config.rb', line 112

config_option :dynamic_require_severity, :warning, compiler_option: :dynamic_require_severity, valid_values: %i[error warning ignore]

#enable_file_source_embedtrue, false

Enable embedding source code to be read by applications.

Returns:

  • (true, false)


150
# File 'lib/opal/config.rb', line 150

config_option :enable_file_source_embed, false, compiler_option: :enable_file_source_embed

#enable_source_locationtrue, false

Enable source location embedded for methods and procs.

Returns:

  • (true, false)


145
# File 'lib/opal/config.rb', line 145

config_option :enable_source_location, false, compiler_option: :enable_source_location

#esmtrue, false

Build ECMAScript modules, instead of legacy JS

Returns:

  • (true, false)


99
# File 'lib/opal/config.rb', line 99

config_option :esm, false, compiler_option: :esm

#freezing_stubs_enabledtrue, false

Add stubs for methods related to freezing objects (for compatibility).

Returns:

  • (true, false)


94
# File 'lib/opal/config.rb', line 94

config_option :freezing_stubs_enabled, true, compiler_option: :freezing

#inline_operators_enabledtrue, false

Enable for inline operators optimizations.

Returns:

  • (true, false)


135
# File 'lib/opal/config.rb', line 135

config_option :inline_operators_enabled, true, compiler_option: :inline_operators

#irb_enabledtrue, false

Enable IRB support for making local variables across multiple compilations.

Returns:

  • (true, false)


130
# File 'lib/opal/config.rb', line 130

config_option :irb_enabled, false, compiler_option: :irb

#method_missing_enabledtrue, false

Enable method_missing support.

Returns:

  • (true, false)


79
# File 'lib/opal/config.rb', line 79

config_option :method_missing_enabled, true, compiler_option: :method_missing

#missing_require_severity:error, ...

Set the error severity for when a required file can't be found at build time.

  • :error will raise an error at compile time
  • :warning will print a warning on stderr at compile time
  • :ignore will skip the require silently at compile time

Examples:

# Opal code
require "some_non_existen_file"

Returns:

  • (:error, :warning, :ignore)


125
# File 'lib/opal/config.rb', line 125

config_option :missing_require_severity, :error, valid_values: %i[error warning ignore]

#source_map_enabledtrue, false

Enable source maps support.

Returns:

  • (true, false)


140
# File 'lib/opal/config.rb', line 140

config_option :source_map_enabled, true

#stubbed_filesSet

A set of stubbed files that will be marked as loaded and skipped during compilation. The value is expected to be mutated but it's ok to replace it.

Returns:

  • (Set)


157
# File 'lib/opal/config.rb', line 157

config_option :stubbed_files, -> { Set.new }, valid_values: [Set]

Instance Method Details

#compiler_optionsHash

Returns the configuration for Opal::Compiler.

Returns:

  • (Hash)

    the configuration for Opal::Compiler



55
56
57
58
59
60
61
62
# File 'lib/opal/config.rb', line 55

def compiler_options
  compiler_options = {}
  config_options.each do |name, options|
    compiler_option_name = options.fetch(:compiler)
    compiler_options[compiler_option_name] = config.fetch(name)
  end
  compiler_options
end

#configHash

Returns the current configuration, defaults to #default_config.

Returns:

  • (Hash)

    the current configuration, defaults to #default_config



65
66
67
# File 'lib/opal/config.rb', line 65

def config
  @config ||= default_config
end

#default_configHash

Returns the default configuration.

Returns:

  • (Hash)

    the default configuration



44
45
46
47
48
49
50
51
52
# File 'lib/opal/config.rb', line 44

def default_config
  default_config = {}
  config_options.each do |name, options|
    default_value = options.fetch(:default)
    default_value = Proc === default_value ? default_value.call : default_value
    default_config[name] = default_value
  end
  default_config
end

#reset!

This method returns an undefined value.

Resets the config to its default value



72
73
74
# File 'lib/opal/config.rb', line 72

def reset!
  @config = nil
end