From 78e9e4565e93ceb8aa75398fe4a70fec3f76c535 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 13:52:29 -0700 Subject: [PATCH] only coalesce if subbed --- d2ir/compile.go | 11 +- .../TestCLI_E2E/internal_linked_pdf.exp.pdf | Bin 80096 -> 80096 bytes .../TestCompile/array-classes.exp.json | 15 +- .../TestCompile/basic_icon.exp.json | 3 +- .../TestCompile/basic_sequence.exp.json | 3 +- .../TestCompile/basic_shape.exp.json | 3 +- .../TestCompile/class-shape-class.exp.json | 9 +- .../TestCompile/class_paren.exp.json | 9 +- .../TestCompile/class_style.exp.json | 6 +- .../d2compiler/TestCompile/classes.exp.json | 33 ++- .../dimensions_on_containers.exp.json | 24 +- .../dimensions_on_nonimage.exp.json | 3 +- .../edge_arrowhead_fields.exp.json | 6 +- .../edge_arrowhead_primary.exp.json | 3 +- .../TestCompile/edge_chain.exp.json | 3 +- .../TestCompile/edge_chain_map.exp.json | 3 +- .../TestCompile/edge_column_index.exp.json | 18 +- .../TestCompile/edge_flat_arrowhead.exp.json | 3 +- .../edge_flat_label_arrowhead.exp.json | 3 +- .../TestCompile/edge_index.exp.json | 6 +- .../TestCompile/edge_index_map.exp.json | 3 +- .../TestCompile/edge_index_nested.exp.json | 6 +- .../edge_index_nested_cross_scope.exp.json | 6 +- .../d2compiler/TestCompile/edge_map.exp.json | 3 +- .../TestCompile/edge_map_arrowhead.exp.json | 3 +- .../TestCompile/edge_mixed_arrowhead.exp.json | 6 +- .../edge_non_shape_arrowhead.exp.json | 3 +- .../edge_semiflat_arrowhead.exp.json | 3 +- .../TestCompile/fill-pattern.exp.json | 3 +- .../icon-near-composite-together.exp.json | 3 +- .../TestCompile/image_style.exp.json | 9 +- .../label-near-composite-separate.exp.json | 6 +- .../label-near-composite-together.exp.json | 3 +- .../TestCompile/label-near-parent.exp.json | 3 +- .../TestCompile/link-board-mixed.exp.json | 18 +- .../TestCompile/missing-class.exp.json | 3 +- .../TestCompile/near_constant.exp.json | 3 +- .../TestCompile/nested-array-classes.exp.json | 3 +- .../TestCompile/nested_sql.exp.json | 9 +- .../d2compiler/TestCompile/path_link.exp.json | 3 +- .../TestCompile/reordered-classes.exp.json | 9 +- .../reserved_icon_near_style.exp.json | 12 +- .../TestCompile/root_direction.exp.json | 3 +- .../TestCompile/root_sequence.exp.json | 3 +- .../TestCompile/sequence-timestamp.exp.json | 3 +- .../TestCompile/sequence_container.exp.json | 3 +- .../TestCompile/sequence_container_2.exp.json | 3 +- .../sequence_grouped_note.exp.json | 3 +- .../TestCompile/sequence_scoping.exp.json | 3 +- .../TestCompile/set_direction.exp.json | 3 +- .../single_dimension_on_circle.exp.json | 3 +- .../TestCompile/sql-constraints.exp.json | 6 +- .../TestCompile/sql-regression.exp.json | 6 +- .../d2compiler/TestCompile/sql_paren.exp.json | 9 +- .../table_connection_attr.exp.json | 6 +- .../TestCompile/table_style.exp.json | 6 +- .../TestCompile/table_style_map.exp.json | 9 +- .../TestCompile/text-transform.exp.json | 12 +- .../underscore_edge_existing.exp.json | 6 +- .../underscore_edge_index.exp.json | 6 +- .../underscore_parent_preference_1.exp.json | 6 +- .../underscore_parent_preference_2.exp.json | 6 +- .../d2compiler/TestCompile/url_link.exp.json | 3 +- ..._and_not_url_tooltip_concurrently.exp.json | 6 +- .../url_link_non_url_tooltip_ok.exp.json | 6 +- .../TestCompile/url_tooltip.exp.json | 3 +- .../TestCompile/wrong_column_index.exp.json | 33 ++- .../TestCompile2/boards/isFolderOnly.exp.json | 9 +- .../TestCompile2/vars/basic/combined.exp.json | 3 +- .../vars/basic/double-quoted.exp.json | 3 +- .../vars/basic/edge_label.exp.json | 3 +- .../TestCompile2/vars/basic/label.exp.json | 3 +- .../TestCompile2/vars/basic/nested.exp.json | 3 +- .../vars/basic/single-quoted.exp.json | 3 +- .../TestCompile2/vars/basic/style.exp.json | 3 +- .../TestCompile2/vars/boards/layer.exp.json | 6 +- .../TestCompile2/vars/boards/overlay.exp.json | 21 +- .../TestCompile2/vars/boards/replace.exp.json | 9 +- .../vars/boards/scenario.exp.json | 6 +- .../TestCompile2/vars/override/label.exp.json | 6 +- .../d2ir/TestCompile/classes/basic.exp.json | 15 +- .../TestCompile/classes/inherited.exp.json | 240 ++++++++++++------ .../TestCompile/classes/layer-modify.exp.json | 48 ++-- .../d2ir/TestCompile/classes/merge.exp.json | 30 ++- .../d2ir/TestCompile/classes/nested.exp.json | 45 ++-- .../d2ir/TestCompile/fields/label.exp.json | 6 +- .../d2ir/TestCompile/fields/nested.exp.json | 9 +- .../TestCompile/imports/nested/map.exp.json | 12 +- .../imports/nested/scalar.exp.json | 3 +- .../d2ir/TestCompile/imports/spread.exp.json | 6 +- .../d2ir/TestCompile/imports/value.exp.json | 12 +- .../d2ir/TestCompile/imports/vars/1.exp.json | 9 +- .../TestCreate/make_scope_multiline.exp.json | 3 +- .../make_scope_multiline_spacing_1.exp.json | 3 +- .../make_scope_multiline_spacing_2.exp.json | 3 +- .../TestDelete/arrowhead_label.exp.json | 3 +- testdata/d2oracle/TestDelete/chaos_1.exp.json | 9 +- .../children_edge_conflicts.exp.json | 3 +- .../children_edges_flat_conflicts.exp.json | 6 +- .../children_flat_conflicts.exp.json | 3 +- .../children_multiple_conflicts.exp.json | 3 +- ...ldren_nested_referenced_conflicts.exp.json | 6 +- .../children_referenced_conflicts.exp.json | 3 +- .../TestDelete/container_near.exp.json | 6 +- .../delete_container_of_near.exp.json | 6 +- .../d2oracle/TestDelete/delete_icon.exp.json | 3 +- .../TestDelete/edge_decrement.exp.json | 12 +- .../d2oracle/TestDelete/multi_near.exp.json | 6 +- .../only_delete_edge_reserved.exp.json | 3 +- .../only_delete_obj_reserved.exp.json | 3 +- .../d2oracle/TestDelete/save_map.exp.json | 3 +- .../TestDelete/save_map_with_primary.exp.json | 3 +- .../TestDelete/shape_sql_table.exp.json | 6 +- .../d2oracle/TestDelete/table_refs.exp.json | 3 +- .../TestMove/append_multiple_styles.exp.json | 3 +- .../container_conflicts_generated.exp.json | 18 +- .../d2oracle/TestMove/container_near.exp.json | 3 +- testdata/d2oracle/TestMove/duplicate.exp.json | 3 +- .../d2oracle/TestMove/flat_merge.exp.json | 3 +- testdata/d2oracle/TestMove/flat_near.exp.json | 3 +- .../flat_reparent_with_map_value.exp.json | 3 +- ...lat_reparent_with_mixed_map_value.exp.json | 3 +- .../flat_reparent_with_value.exp.json | 3 +- .../d2oracle/TestMove/flat_style.exp.json | 3 +- testdata/d2oracle/TestMove/gnarly_1.exp.json | 6 +- .../include_descendants_near.exp.json | 3 +- ...ude_descendants_nested_reserved_2.exp.json | 3 +- ...ude_descendants_nested_reserved_3.exp.json | 3 +- .../TestMove/include_descendants_sql.exp.json | 6 +- .../into_container_with_flat_keys.exp.json | 6 +- .../d2oracle/TestMove/map_transplant.exp.json | 3 +- .../d2oracle/TestMove/map_with_label.exp.json | 3 +- .../d2oracle/TestMove/merge_reserved.exp.json | 6 +- testdata/d2oracle/TestMove/near.exp.json | 3 +- .../TestMove/nested_reserved_2.exp.json | 3 +- .../TestMove/nested_reserved_3.exp.json | 3 +- .../d2oracle/TestMove/parentheses.exp.json | 6 +- .../d2oracle/TestMove/slice_style.exp.json | 3 +- .../TestMove/underscore_merge.exp.json | 6 +- .../TestReconnectEdge/indexed_ref.exp.json | 3 +- .../preserve_old_obj.exp.json | 3 +- .../TestReconnectEdge/second_index.exp.json | 6 +- .../d2oracle/TestRename/container.exp.json | 9 +- testdata/d2oracle/TestRename/edges.exp.json | 3 +- testdata/d2oracle/TestRename/near.exp.json | 3 +- .../d2oracle/TestSet/classes-style.exp.json | 9 +- .../TestSet/dupe-classes-style.exp.json | 9 +- testdata/d2oracle/TestSet/edge.exp.json | 3 +- testdata/d2oracle/TestSet/edge_chain.exp.json | 6 +- .../TestSet/edge_chain_nested_set.exp.json | 3 +- .../edge_flat_merge_arrowhead.exp.json | 3 +- .../d2oracle/TestSet/edge_index_case.exp.json | 3 +- .../TestSet/edge_index_nested.exp.json | 3 +- .../TestSet/edge_merge_arrowhead.exp.json | 3 +- .../TestSet/edge_nested_label_set.exp.json | 3 +- .../TestSet/edge_replace_arrowhead.exp.json | 3 +- .../edge_replace_arrowhead_indexed.exp.json | 3 +- .../TestSet/edge_set_arrowhead.exp.json | 3 +- testdata/d2oracle/TestSet/icon.exp.json | 3 +- .../d2oracle/TestSet/inline_style.exp.json | 3 +- testdata/d2oracle/TestSet/label.exp.json | 3 +- .../d2oracle/TestSet/label_replace.exp.json | 3 +- .../d2oracle/TestSet/map_key_missing.exp.json | 3 +- .../d2oracle/TestSet/nested_alex.exp.json | 9 +- .../TestSet/replace_arrowhead.exp.json | 3 +- .../TestSet/replace_arrowhead_map.exp.json | 3 +- .../TestSet/replace_fill_pattern.exp.json | 3 +- .../d2oracle/TestSet/replace_link.exp.json | 3 +- .../d2oracle/TestSet/replace_shape.exp.json | 3 +- .../TestSet/replace_style_edgecase.exp.json | 3 +- .../d2oracle/TestSet/replace_tooltip.exp.json | 3 +- .../TestSet/scenarios-arrowhead.exp.json | 9 +- .../scenarios-label-primary-missing.exp.json | 6 +- ...scenarios-nested-usable-ref-style.exp.json | 3 +- .../scenarios-usable-ref-style.exp.json | 3 +- .../TestSet/set_fill_pattern.exp.json | 3 +- .../d2oracle/TestSet/set_tooltip.exp.json | 3 +- testdata/d2oracle/TestSet/shape.exp.json | 3 +- .../unapplied-classes-style-2.exp.json | 6 +- .../TestSet/unapplied-classes-style.exp.json | 6 +- 180 files changed, 869 insertions(+), 459 deletions(-) diff --git a/d2ir/compile.go b/d2ir/compile.go index 9b880b767..90c21d060 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -108,6 +108,7 @@ func (c *compiler) resolveSubstitutions(refctx *RefContext) { varsMap = vars.Map() } + subbed := false switch { case refctx.Key.Value.UnquotedString != nil: for i, box := range refctx.Key.Value.UnquotedString.Value { @@ -115,20 +116,26 @@ func (c *compiler) resolveSubstitutions(refctx *RefContext) { resolvedField := c.resolveSubstitution(varsMap, refctx.Key, box.Substitution) if resolvedField != nil { refctx.Key.Value.UnquotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + subbed = true } } } - refctx.Key.Value.UnquotedString.Coalesce() + if subbed { + refctx.Key.Value.UnquotedString.Coalesce() + } case refctx.Key.Value.DoubleQuotedString != nil: for i, box := range refctx.Key.Value.DoubleQuotedString.Value { if box.Substitution != nil { resolvedField := c.resolveSubstitution(varsMap, refctx.Key, box.Substitution) if resolvedField != nil { refctx.Key.Value.DoubleQuotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + subbed = true } } } - refctx.Key.Value.DoubleQuotedString.Coalesce() + if subbed { + refctx.Key.Value.DoubleQuotedString.Coalesce() + } } } diff --git a/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf b/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf index c3f44895dd54e116e5a1400d3a6fee089be81b9d..7f3e137b3e86af39639573844a36ae259461e050 100644 GIT binary patch delta 50 zcmaFxk>$ZhmWC~iPfZm}4NNUHx%7SWQ(O{DQWZ2@tc(ndj19~U4GoP!a@$$W7;iHH E0LMZPN&o-= delta 50 zcmaFxk>$ZhmWC~iPfZm}OpMGlx%7SWQ(O{DQWZ2@tc(ndj19~U4GoP!a@$$W7;iHH E0LI7