From 4e8b36adbfb0836cab340ef215eb7bca769b020e Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Mon, 29 Jul 2024 17:37:35 -0700 Subject: [PATCH] Fix auto-fixing of deprecated interpolated strings --- crates/compiler/parse/src/remove_spaces.rs | 2 +- ...ted_interpolated_string.expr.formatted.roc | 1 + ...ecated_interpolated_string.expr.result-ast | 17 ++ .../deprecated_interpolated_string.expr.roc | 1 + .../pass/pizza_bang.moduledefs.formatted.roc | 8 + .../pass/pizza_bang.moduledefs.result-ast | 168 ++++++++++++++++++ .../snapshots/pass/pizza_bang.moduledefs.roc | 8 + .../test_syntax/tests/test_snapshots.rs | 2 + 8 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.formatted.roc create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.result-ast create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.roc create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.formatted.roc create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.result-ast create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.roc diff --git a/crates/compiler/parse/src/remove_spaces.rs b/crates/compiler/parse/src/remove_spaces.rs index 96705783232..ff206e3e1df 100644 --- a/crates/compiler/parse/src/remove_spaces.rs +++ b/crates/compiler/parse/src/remove_spaces.rs @@ -593,7 +593,7 @@ impl<'a> RemoveSpaces<'a> for StrSegment<'a> { StrSegment::EscapedChar(c) => StrSegment::EscapedChar(c), StrSegment::Interpolated(t) => StrSegment::Interpolated(t.remove_spaces(arena)), StrSegment::DeprecatedInterpolated(t) => { - StrSegment::DeprecatedInterpolated(t.remove_spaces(arena)) + StrSegment::Interpolated(t.remove_spaces(arena)) } } } diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.formatted.roc b/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.formatted.roc new file mode 100644 index 00000000000..0ff8b60204f --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.formatted.roc @@ -0,0 +1 @@ +"$(e)" \ No newline at end of file diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.result-ast b/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.result-ast new file mode 100644 index 00000000000..31432b47f4a --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.result-ast @@ -0,0 +1,17 @@ +SpaceAfter( + Str( + Line( + [ + DeprecatedInterpolated( + @3-4 Var { + module_name: "", + ident: "e", + }, + ), + ], + ), + ), + [ + Newline, + ], +) diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.roc b/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.roc new file mode 100644 index 00000000000..b48439b918d --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/deprecated_interpolated_string.expr.roc @@ -0,0 +1 @@ +"\(e)" diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.formatted.roc b/crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.formatted.roc new file mode 100644 index 00000000000..2c5a82c0270 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.formatted.roc @@ -0,0 +1,8 @@ +main = + Arg.list! {} + |> List.dropFirst 1 + |> List.mapTry Str.toU8 + |> Task.fromResult! + |> List.sum + |> \total -> "Sum of numbers: $(Num.toStr total)" + |> Stdout.line! diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.result-ast b/crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.result-ast new file mode 100644 index 00000000000..45b2889f076 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.result-ast @@ -0,0 +1,168 @@ +Defs { + tags: [ + Index(2147483648), + ], + regions: [ + @0-189, + ], + space_before: [ + Slice(start = 0, length = 0), + ], + space_after: [ + Slice(start = 0, length = 1), + ], + spaces: [ + Newline, + ], + type_defs: [], + value_defs: [ + Body( + @0-4 Identifier { + ident: "main", + }, + @11-189 SpaceBefore( + BinOps( + [ + ( + @11-23 SpaceAfter( + Apply( + @11-19 TaskAwaitBang( + Var { + module_name: "Arg", + ident: "list", + }, + ), + [ + @21-23 Record( + [], + ), + ], + Space, + ), + [ + Newline, + ], + ), + @28-30 Pizza, + ), + ( + @31-47 SpaceAfter( + Apply( + @31-45 Var { + module_name: "List", + ident: "dropFirst", + }, + [ + @46-47 Num( + "1", + ), + ], + Space, + ), + [ + Newline, + ], + ), + @52-54 Pizza, + ), + ( + @55-75 SpaceAfter( + Apply( + @55-66 Var { + module_name: "List", + ident: "mapTry", + }, + [ + @67-75 Var { + module_name: "Str", + ident: "toU8", + }, + ], + Space, + ), + [ + Newline, + ], + ), + @80-82 Pizza, + ), + ( + @83-98 SpaceAfter( + TaskAwaitBang( + Var { + module_name: "Task", + ident: "fromResult", + }, + ), + [ + Newline, + ], + ), + @104-106 Pizza, + ), + ( + @107-115 SpaceAfter( + Var { + module_name: "List", + ident: "sum", + }, + [ + Newline, + ], + ), + @120-122 Pizza, + ), + ( + @123-169 SpaceAfter( + Closure( + [ + @124-129 Identifier { + ident: "total", + }, + ], + @133-169 Str( + Line( + [ + Plaintext( + "Sum of numbers: ", + ), + Interpolated( + @152-167 Apply( + @152-161 Var { + module_name: "Num", + ident: "toStr", + }, + [ + @162-167 Var { + module_name: "", + ident: "total", + }, + ], + Space, + ), + ), + ], + ), + ), + ), + [ + Newline, + ], + ), + @174-176 Pizza, + ), + ], + @177-188 TaskAwaitBang( + Var { + module_name: "Stdout", + ident: "line", + }, + ), + ), + [ + Newline, + ], + ), + ), + ], +} diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.roc b/crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.roc new file mode 100644 index 00000000000..177bf92dfab --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/pizza_bang.moduledefs.roc @@ -0,0 +1,8 @@ +main = + Arg.list! {} + |> List.dropFirst 1 + |> List.mapTry Str.toU8 + |> Task.fromResult! + |> List.sum + |> \total -> "Sum of numbers: $(Num.toStr total)" + |> Stdout.line! diff --git a/crates/compiler/test_syntax/tests/test_snapshots.rs b/crates/compiler/test_syntax/tests/test_snapshots.rs index c4ceb8de79e..27736ae7a61 100644 --- a/crates/compiler/test_syntax/tests/test_snapshots.rs +++ b/crates/compiler/test_syntax/tests/test_snapshots.rs @@ -304,6 +304,7 @@ mod test_snapshots { pass/dbg.expr, pass/dbg_multiline.expr, pass/defs_suffixed_middle_extra_indents.moduledefs, + pass/deprecated_interpolated_string.expr, pass/destructure_tag_assignment.expr, pass/docs.expr, pass/empty_app_header.header, @@ -438,6 +439,7 @@ mod test_snapshots { pass/pattern_as_list_rest.expr, pass/pattern_as_spaces.expr, pass/pattern_with_space_in_parens.expr, // https://github.com/roc-lang/roc/issues/929 + pass/pizza_bang.moduledefs, pass/plus_if.expr, pass/plus_when.expr, pass/pos_inf_float.expr,