Skip to content

Commit

Permalink
Merge pull request #6937 from joshuawarner32/fix-deprecated-interpola…
Browse files Browse the repository at this point in the history
…ted-formatting

Fix auto-fixing of deprecated interpolated strings
  • Loading branch information
lukewilliamboswell authored Jul 30, 2024
2 parents a66e686 + ca037c5 commit 8888e0a
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/compiler/parse/src/remove_spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"$(e)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SpaceAfter(
Str(
Line(
[
DeprecatedInterpolated(
@3-4 Var {
module_name: "",
ident: "e",
},
),
],
),
),
[
Newline,
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"\(e)"
Original file line number Diff line number Diff line change
@@ -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!
Original file line number Diff line number Diff line change
@@ -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,
],
),
),
],
}
Original file line number Diff line number Diff line change
@@ -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!
2 changes: 2 additions & 0 deletions crates/compiler/test_syntax/tests/test_snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8888e0a

Please sign in to comment.