Class: Oxc::Options
- Inherits:
-
Object
- Object
- Oxc::Options
- Defined in:
- lib/oxc/options.rb,
sig/oxc/options.rbs
Constant Summary collapse
- MINIFY =
[ :filename, :lang, :source_type, :compress, :mangle, :codegen, :sourcemap, :strict ].freeze
- TRANSFORM =
[ :filename, :lang, :source_type, :cwd, :target, :jsx, :typescript, :assumptions, :decorator, :helpers, :define, :inject, :minify, :codegen, :sourcemap, :strict ].freeze
- PARSE =
[ :filename, :lang, :source_type, :ast_type, :ast, :ranges, :preserve_parens, :comments, :module_record, :symbols, :semantic_errors ].freeze
- KNOWN =
(MINIFY | TRANSFORM | PARSE).freeze
- RUBY_ONLY =
[:strict].freeze
- UNSUPPORTED =
TODO: support mangle_props. It needs
lazy-regexandrustc-hashas direct dependencies of the Rust crate, becauseoxc_minifier::ManglePropertiesOptionstypesincludeandexcludeaslazy_regex::RegexandreservedasFxHashSet<CompactStr>. [:mangle_props].freeze
Instance Attribute Summary collapse
- #to_h ⇒ Hash[Symbol, untyped] readonly
Class Method Summary collapse
-
.serialize(options, allowed = KNOWN, subject = "a call") ⇒ String
: (Hash[Symbol, untyped], ?Array, ?String) -> String.
Instance Method Summary collapse
-
#initialize(options, allowed = KNOWN, subject = "a call") ⇒ Options
constructor
: (Hash[Symbol, untyped], ?Array, ?String) -> void.
-
#inspect ⇒ String
: () -> String.
-
#normalize(options) ⇒ Hash[Symbol, untyped]
: (Hash[Symbol, untyped]) -> Hash[Symbol, untyped].
-
#to_json(state = nil) ⇒ String
: (?JSON::options?) -> String.
- #validate!(names, allowed, subject) ⇒ void
Constructor Details
#initialize(options, allowed = KNOWN, subject = "a call") ⇒ Options
: (Hash[Symbol, untyped], ?Array, ?String) -> void
65 66 67 68 69 70 71 72 73 |
# File 'lib/oxc/options.rb', line 65 def initialize(, allowed = KNOWN, subject = "a call") given = .transform_keys(&:to_sym) validate!(given.keys, allowed, subject) @to_h = normalize(given).freeze freeze end |
Instance Attribute Details
#to_h ⇒ Hash[Symbol, untyped] (readonly)
57 58 59 |
# File 'lib/oxc/options.rb', line 57 def to_h @to_h end |
Class Method Details
Instance Method Details
#inspect ⇒ String
: () -> String
81 82 83 |
# File 'lib/oxc/options.rb', line 81 def inspect "#<#{self.class.name} #{to_h.inspect}>" end |
#normalize(options) ⇒ Hash[Symbol, untyped]
: (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
105 106 107 108 109 110 111 |
# File 'lib/oxc/options.rb', line 105 def normalize() normalized = .dup RUBY_ONLY.each { |name| normalized.delete(name) } normalized.compact end |
#to_json(state = nil) ⇒ String
: (?JSON::options?) -> String
76 77 78 |
# File 'lib/oxc/options.rb', line 76 def to_json(state = nil) state ? JSON.generate(to_h, state) : JSON.generate(to_h) end |
#validate!(names, allowed, subject) ⇒ void
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/oxc/options.rb', line 88 def validate!(names, allowed, subject) unsupported = names & UNSUPPORTED raise OptionError, "#{unsupported.join(", ")} is not supported yet" if unsupported.any? unknown = names - KNOWN raise OptionError, "Unknown option#{"s" if unknown.length > 1}: #{unknown.join(", ")}" if unknown.any? unsupported = names - allowed return if unsupported.empty? raise OptionError, "#{unsupported.join(", ")} #{unsupported.one? ? "is not an option" : "are not options"} for #{subject}" end |