Sha256: c0be58a64e05850d6804122f8f660ae1e1a913456b0b684adaf253c0e1294491

Contents?: true

Size: 1.64 KB

Versions: 26

Compression:

Stored size: 1.64 KB

Contents

Foobara.require_project_file("type_declarations", "desugarizer")

module Foobara
  module TypeDeclarations
    module Handlers
      class RegisteredTypeDeclaration < TypeDeclarationHandler
        # type_symbol is basically just a flag that lets us know that type is fully qualified.
        # rather hacky but other potential workarounds seemed gnarlier
        class StrictStringifiedDesugarizer < TypeDeclarations::Desugarizer
          def applicable?(sugary_type_declaration)
            # TODO: we shouldn't have to check if this is a hash. This means some other desugarizer is unnecessarily
            # processing a type declaration as if it were sugary. Find and fix that to speed this up a tiny bit.
            return false unless sugary_type_declaration.is_a?(::Hash) && TypeDeclarations.strict_stringified?

            !sugary_type_declaration.dig(:_desugarized, :type_absolutified)
          end

          def desugarize(sugary_type_declaration)
            sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
            type_symbol = sugary_type_declaration[:type]

            type = Foobara.foobara_root_namespace.foobara_lookup_type!(type_symbol,
                                                                       mode: Namespace::LookupMode::ABSOLUTE)

            type_symbol = type.full_type_symbol

            desugarized = sugary_type_declaration[:_desugarized] || {}
            desugarized[:type_absolutified] = true
            sugary_type_declaration.merge(_desugarized: desugarized, type: type_symbol)
          end

          def priority
            Priority::FIRST
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.25 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.24 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.23 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.22 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.21 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.20 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.19 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.18 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.17 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.16 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.15 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.14 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.13 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.12 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.11 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.10 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.9 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.8 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
foobara-0.0.7 projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb