[ruby/prism] Polyfill Kernel#warn category parameter
https://github.com/ruby/prism/commit/d85c72a1b9
This commit is contained in:
parent
b5e9a2da4c
commit
050ffab82b
@ -68,6 +68,7 @@ module Prism
|
|||||||
end
|
end
|
||||||
|
|
||||||
require_relative "prism/polyfill/byteindex"
|
require_relative "prism/polyfill/byteindex"
|
||||||
|
require_relative "prism/polyfill/warn"
|
||||||
require_relative "prism/node"
|
require_relative "prism/node"
|
||||||
require_relative "prism/node_ext"
|
require_relative "prism/node_ext"
|
||||||
require_relative "prism/parse_result"
|
require_relative "prism/parse_result"
|
||||||
|
@ -9,7 +9,7 @@ module Prism
|
|||||||
location = location[0].label if location
|
location = location[0].label if location
|
||||||
suggest = replacements.map { |replacement| "#{self.class}##{replacement}" }
|
suggest = replacements.map { |replacement| "#{self.class}##{replacement}" }
|
||||||
|
|
||||||
warn(<<~MSG)
|
warn(<<~MSG, uplevel: 1, category: :deprecated)
|
||||||
[deprecation]: #{self.class}##{location} is deprecated and will be \
|
[deprecation]: #{self.class}##{location} is deprecated and will be \
|
||||||
removed in the next major version. Use #{suggest.join("/")} instead.
|
removed in the next major version. Use #{suggest.join("/")} instead.
|
||||||
#{(caller(1, 3) || []).join("\n")}
|
#{(caller(1, 3) || []).join("\n")}
|
||||||
|
42
lib/prism/polyfill/warn.rb
Normal file
42
lib/prism/polyfill/warn.rb
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Polyfill for Kernel#warn with the category parameter. Not all Ruby engines
|
||||||
|
# have Method#parameters implemented, so we check the arity instead if
|
||||||
|
# necessary.
|
||||||
|
if (method = Kernel.instance_method(:warn)).respond_to?(:parameters) ? method.parameters.none? { |_, name| name == :category } : (method.arity == -1)
|
||||||
|
Kernel.prepend(
|
||||||
|
Module.new {
|
||||||
|
def warn(*msgs, uplevel: nil, category: nil) # :nodoc:
|
||||||
|
uplevel =
|
||||||
|
case uplevel
|
||||||
|
when nil
|
||||||
|
1
|
||||||
|
when Integer
|
||||||
|
uplevel + 1
|
||||||
|
else
|
||||||
|
uplevel.to_int + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
super(*msgs, uplevel: uplevel)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
Object.prepend(
|
||||||
|
Module.new {
|
||||||
|
def warn(*msgs, uplevel: nil, category: nil) # :nodoc:
|
||||||
|
uplevel =
|
||||||
|
case uplevel
|
||||||
|
when nil
|
||||||
|
1
|
||||||
|
when Integer
|
||||||
|
uplevel + 1
|
||||||
|
else
|
||||||
|
uplevel.to_int + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
super(*msgs, uplevel: uplevel)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
@ -89,6 +89,7 @@ Gem::Specification.new do |spec|
|
|||||||
"lib/prism/polyfill/append_as_bytes.rb",
|
"lib/prism/polyfill/append_as_bytes.rb",
|
||||||
"lib/prism/polyfill/byteindex.rb",
|
"lib/prism/polyfill/byteindex.rb",
|
||||||
"lib/prism/polyfill/unpack1.rb",
|
"lib/prism/polyfill/unpack1.rb",
|
||||||
|
"lib/prism/polyfill/warn.rb",
|
||||||
"lib/prism/reflection.rb",
|
"lib/prism/reflection.rb",
|
||||||
"lib/prism/relocation.rb",
|
"lib/prism/relocation.rb",
|
||||||
"lib/prism/serialize.rb",
|
"lib/prism/serialize.rb",
|
||||||
|
@ -60,7 +60,7 @@ module Prism
|
|||||||
#
|
#
|
||||||
def initialize(builder = Prism::Translation::Parser::Builder.new, parser: Prism)
|
def initialize(builder = Prism::Translation::Parser::Builder.new, parser: Prism)
|
||||||
if !builder.is_a?(Prism::Translation::Parser::Builder)
|
if !builder.is_a?(Prism::Translation::Parser::Builder)
|
||||||
warn(<<~MSG, uplevel: 1)
|
warn(<<~MSG, uplevel: 1, category: :deprecated)
|
||||||
[deprecation]: The builder passed to `Prism::Translation::Parser.new` is not a \
|
[deprecation]: The builder passed to `Prism::Translation::Parser.new` is not a \
|
||||||
`Prism::Translation::Parser::Builder` subclass. This will raise in the next major version.
|
`Prism::Translation::Parser::Builder` subclass. This will raise in the next major version.
|
||||||
MSG
|
MSG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user