From 04585aec9740d56d74b4ed94d10c70bfb25b63e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guszt=C3=A1v=20Szikszai?= Date: Fri, 15 Jan 2021 10:41:11 +0100 Subject: [PATCH] Fix source map generation for the encoder. --- src/utils/object_serializer.cr | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/utils/object_serializer.cr b/src/utils/object_serializer.cr index 1f53caf07..b487c2609 100644 --- a/src/utils/object_serializer.cr +++ b/src/utils/object_serializer.cr @@ -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 @@ -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