Skip to content

Instantly share code, notes, and snippets.

@alexevanczuk
Last active October 28, 2025 14:19
Show Gist options
  • Select an option

  • Save alexevanczuk/333505e72fa5002c8f5ab09153c0fa15 to your computer and use it in GitHub Desktop.

Select an option

Save alexevanczuk/333505e72fa5002c8f5ab09153c0fa15 to your computer and use it in GitHub Desktop.
bundle exec srb tc --no-config --quiet --print=rewrite-tree spec/tapioca/dsl/compilers/sorbet_typed_props_constructor_spec.rb
~/stripe/props - ae-bump-sorbet ! $ bundle exec srb tc --no-config --quiet --print=rewrite-tree spec/tapioca/dsl/compilers/sorbet_typed_props_constructor_spec.rb
class <emptyTree><<C <root>>> < (::<todo sym>)
<self>.require("tapioca/helpers/test/dsl_compiler")
<self>.require_relative("../../../../lib/tapioca/dsl/compilers/sorbet_typed_props_constructor")
class <emptyTree>::<C <describe 'SorbetTypedPropsConstructor'>><<C <todo sym>>> < (<emptyTree>::<C RSpec>::<C Core>::<C ExampleGroup>)
def sample_class<<todo method>>(&<blk>)
<emptyTree>::<C Class>.new() do ||
begin
<cast:<synthetic bind>>(<self>, <todo sym>, ::T::Class.[](::Object))
<cast:bind>(<self>, <todo sym>, <emptyTree>::<C T>.untyped())
<self>.include(<emptyTree>::<C SorbetTyped>::<C Props>)
<self>.prop(:name, <emptyTree>::<C String>)
<self>.prop(:age, <emptyTree>::<C Integer>, :default, 0)
<self>.prop(:email, <emptyTree>::<C String>, :factory, <emptyTree>::<C Kernel>.lambda() do ||
"[email protected]"
end)
<self>.const(:active, <emptyTree>::<C T>::<C Boolean>, :default, true)
end
end
end
def <before><<todo method>>(&<blk>)
<self>.stub_const("SamplePropsClass", <self>.sample_class())
end
<runtime method definition of sample_class>
class <emptyTree>::<C <describe '#gather_constants'>><<C <todo sym>>> < (<self>)
def <it 'returns classes that include SorbetTyped::Props'><<todo method>>(&<blk>)
begin
constants = <emptyTree>::<C Tapioca>::<C Dsl>::<C Compilers>::<C SorbetTypedPropsConstructor>.gather_constants()
<self>.expect(constants).to(<self>.include(<self>.sample_class()))
end
end
end
class <emptyTree>::<C <describe '#decorate'>><<C <todo sym>>> < (<self>)
def compiler<<todo method>>(&<blk>)
<emptyTree>::<C Tapioca>::<C Dsl>::<C Compilers>::<C SorbetTypedPropsConstructor>.new(<self>.instance_double(<emptyTree>::<C Tapioca>::<C Dsl>::<C Pipeline>), <self>.root(), <self>.sample_class())
end
def root<<todo method>>(&<blk>)
<emptyTree>::<C RBI>::<C Tree>.new()
end
def <before><<todo method>>(&<blk>)
<self>.compiler().decorate()
end
<runtime method definition of compiler>
<runtime method definition of root>
class <emptyTree>::<C <describe 'the class signature'>><<C <todo sym>>> < (<self>)
def klass_node<<todo method>>(&<blk>)
<self>.root().nodes().find() do |c|
begin
&&$2 = c.is_a?(<emptyTree>::<C RBI>::<C Class>)
if &&$2
c.name().==("SamplePropsClass")
else
&&$2
end
end
end
end
def <it 'exists'><<todo method>>(&<blk>)
<self>.expect(<self>.klass_node()).not_to(<self>.be_nil())
end
<runtime method definition of klass_node>
module <emptyTree>::<C <shared_examples 'initializer signature'>><<C <todo sym>>> < ()
def klass_node<<todo method>>(&<blk>)
<self>.<untypedSuper>()
end
def init_method<<todo method>>(&<blk>)
<self>.klass_node().nodes().find() do |m|
begin
&&$3 = m.is_a?(<emptyTree>::<C RBI>::<C Method>)
if &&$3
m.name().==("initialize")
else
&&$3
end
end
end
end
def <it 'exists'><<todo method>>(&<blk>)
<self>.expect(<self>.init_method()).not_to(<self>.be_nil())
end
<runtime method definition of klass_node>
<runtime method definition of init_method>
<self>.it("has name parameter with correct type", :aggregate_failures) do ||
begin
param = <self>.init_method().params().find() do |p|
p.name().==("name")
end
param_sig = <self>.init_method().sigs().first().params().find() do |p|
p.name().==("name")
end
<self>.expect(param).to(<self>.be_a(<emptyTree>::<C RBI>::<C KwParam>))
<self>.expect(param_sig.type()).to(<self>.eq("String"))
end
end
<self>.it("has age parameter with correct type", :aggregate_failures) do ||
begin
param = <self>.init_method().params().find() do |p|
p.name().==("age")
end
param_sig = <self>.init_method().sigs().first().params().find() do |p|
p.name().==("age")
end
<self>.expect(param).to(<self>.be_a(<emptyTree>::<C RBI>::<C KwOptParam>))
<self>.expect(param.value()).to(<self>.eq("nil"))
<self>.expect(param_sig.type()).to(<self>.eq("T.nilable(Integer)"))
end
end
<self>.it("has email parameter with correct type", :aggregate_failures) do ||
begin
param = <self>.init_method().params().find() do |p|
p.name().==("email")
end
param_sig = <self>.init_method().sigs().first().params().find() do |p|
p.name().==("email")
end
<self>.expect(param).to(<self>.be_a(<emptyTree>::<C RBI>::<C KwOptParam>))
<self>.expect(param.value()).to(<self>.eq("nil"))
<self>.expect(param_sig.type()).to(<self>.eq("T.nilable(String)"))
end
end
<self>.it("has active parameter with correct type", :aggregate_failures) do ||
begin
param = <self>.init_method().params().find() do |p|
p.name().==("active")
end
param_sig = <self>.init_method().sigs().first().params().find() do |p|
p.name().==("active")
end
<self>.expect(param).to(<self>.be_a(<emptyTree>::<C RBI>::<C KwOptParam>))
<self>.expect(param.value()).to(<self>.eq("nil"))
<self>.expect(param_sig.type()).to(<self>.eq("T.nilable(T::Boolean)"))
end
end
end
class <emptyTree>::<C <describe 'the initializer signature'>><<C <todo sym>>> < (<self>)
<self>.it_behaves_like("initializer signature")
end
class <emptyTree>::<C <context 'with class with own initializer'>><<C <todo sym>>> < (<self>)
def sample_class<<todo method>>(&<blk>)
<emptyTree>::<C Class>.new() do ||
begin
<cast:<synthetic bind>>(<self>, <todo sym>, ::T::Class.[](::Object))
<cast:bind>(<self>, <todo sym>, <emptyTree>::<C T>.untyped())
<self>.include(<emptyTree>::<C SorbetTyped>::<C Props>)
<self>.prop(:name, <emptyTree>::<C String>)
<self>.prop(:age, <emptyTree>::<C Integer>, :default, 0)
<self>.prop(:email, <emptyTree>::<C String>, :factory, <emptyTree>::<C Kernel>.lambda() do ||
"[email protected]"
end)
<self>.const(:active, <emptyTree>::<C T>::<C Boolean>, :default, true)
<self>.define_method(:initialize) do |foo:|
<emptyTree>
end
end
end
end
def <it 'does not exist'><<todo method>>(&<blk>)
<self>.expect(<self>.klass_node()).to(<self>.be_nil())
end
<runtime method definition of sample_class>
end
class <emptyTree>::<C <context 'with class without any props'>><<C <todo sym>>> < (<self>)
def sample_class<<todo method>>(&<blk>)
<emptyTree>::<C Class>.new() do ||
begin
<cast:<synthetic bind>>(<self>, <todo sym>, ::T::Class.[](::Object))
<cast:bind>(<self>, <todo sym>, <emptyTree>::<C T>.untyped())
<self>.include(<emptyTree>::<C SorbetTyped>::<C Props>)
end
end
end
def <it 'does not exist'><<todo method>>(&<blk>)
<self>.expect(<self>.klass_node()).to(<self>.be_nil())
end
<runtime method definition of sample_class>
end
class <emptyTree>::<C <context 'with class inheriting from props class'>><<C <todo sym>>> < (<self>)
def parent_sample_class<<todo method>>(&<blk>)
<emptyTree>::<C Class>.new() do ||
begin
<cast:<synthetic bind>>(<self>, <todo sym>, ::T::Class.[](::Object))
<cast:bind>(<self>, <todo sym>, <emptyTree>::<C T>.untyped())
<self>.include(<emptyTree>::<C SorbetTyped>::<C Props>)
<self>.prop(:name, <emptyTree>::<C String>)
<self>.prop(:age, <emptyTree>::<C Integer>, :default, 0)
<self>.prop(:email, <emptyTree>::<C String>, :factory, <emptyTree>::<C Kernel>.lambda() do ||
"[email protected]"
end)
<self>.const(:active, <emptyTree>::<C T>::<C Boolean>, :default, true)
end
end
end
def sample_class<<todo method>>(&<blk>)
<emptyTree>::<C Class>.new(<self>.parent_sample_class())
end
<runtime method definition of parent_sample_class>
<runtime method definition of sample_class>
<self>.it_behaves_like("initializer signature")
class <emptyTree>::<C <context 'with additional props'>><<C <todo sym>>> < (<self>)
def sample_class<<todo method>>(&<blk>)
<emptyTree>::<C Class>.new(<self>.parent_sample_class()) do ||
<self>.prop(:last_name, <emptyTree>::<C String>)
end
end
<runtime method definition of sample_class>
<self>.it_behaves_like("initializer signature")
<self>.it("includes the additional props in the signature", :aggregate_failures) do ||
begin
init_method = <self>.klass_node().nodes().find() do |m|
begin
&&$4 = m.is_a?(<emptyTree>::<C RBI>::<C Method>)
if &&$4
m.name().==("initialize")
else
&&$4
end
end
end
param = init_method.params().find() do |p|
p.name().==("last_name")
end
param_sig = init_method.sigs().first().params().find() do |p|
p.name().==("last_name")
end
<self>.expect(param).to(<self>.be_a(<emptyTree>::<C RBI>::<C KwParam>))
<self>.expect(param_sig.type()).to(<self>.eq("String"))
end
end
end
end
end
end
end
end
No errors! Great job.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment