Skip to content

Commit

Permalink
Fix source map generation for the encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdotdesign authored and Namek committed Apr 25, 2021
1 parent e3a72e9 commit 04585ae
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/utils/object_serializer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Mint
Codegen.join ["((_)=>", js.class_of(node.name), ".encode(_))"]
end

def encoder(node : TypeChecker::Variable)
def encoder(node : TypeChecker::Variable) : Codegen::Node
# This should never happen because of the typechecker!
raise "Cannot generate an encoder for a type variable!"
end
Expand All @@ -47,11 +47,20 @@ module Mint
when "Time"
"Encoder.time"
when "Array"
"Encoder.array(#{encoder(node.parameters.first)})"
item_encoder =
(encoder(node.parameters.first) || "").as(Codegen::Node)

Codegen.join ["Encoder.array(", item_encoder, ")"]
when "Maybe"
"Encoder.maybe(#{encoder(node.parameters.first)})"
item_encoder =
(encoder(node.parameters.first) || "").as(Codegen::Node)

Codegen.join ["Encoder.maybe(", item_encoder, ")"]
when "Map"
"Encoder.map(#{encoder(node.parameters.last)})"
item_encoder =
(encoder(node.parameters.last) || "").as(Codegen::Node)

Codegen.join ["Encoder.map(", item_encoder, ")"]
end
end

Expand Down

0 comments on commit 04585ae

Please sign in to comment.