Skip to content

Commit

Permalink
feat(@formatjs/cli): support template literal, trim trailing/leading …
Browse files Browse the repository at this point in the history
…spaces, newlines &

consecutive whitespaces
Spaces are locale-specific, in the sense that not only some languages
don't use spaces and/or different space character (e.g full-width space
vs non-breaking space). With that said:
1. Trimming whitespaces: we've seen leading/trailing whitespaces
used as positioning tool, which is a footgun since this will be removed
in certain locales and/or replaced.
2. Consecutive whitespaces: same as above, but this is also a byproduct
of template literal, e.g:

    defineMessage({
      defaultMessage: `this is too
      long so I broke it up`
    })

In this case there're unintentional whitespaces in the middle of the
sentence due to code formatting. This will be replaced with single
space.

fix #2028
  • Loading branch information
longlho committed Sep 3, 2020
1 parent 6eaa774 commit 8a52eb5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/cli/tests/extract/__snapshots__/integration.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Object {
\\"description\\": \\"inline description\\"
},
\\"trailing.ws\\": {
\\"defaultMessage\\": \\" Some whitespace \\",
\\"defaultMessage\\": \\"Some whitespace\\",
\\"description\\": \\"Whitespace\\"
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ Object {
"description": "inline description",
},
"trailing.ws": Object {
"defaultMessage": " Some whitespace ",
"defaultMessage": "Some whitespace",
"description": "Whitespace",
},
}
Expand Down Expand Up @@ -145,7 +145,7 @@ Object {
},
"trailing.ws": Object {
"col": 21,
"defaultMessage": " Some whitespace ",
"defaultMessage": "Some whitespace",
"description": "Whitespace",
"end": 650,
"file": "defineMessages/actual.js",
Expand Down Expand Up @@ -184,7 +184,7 @@ Object {
\\"description\\": \\"inline description\\"
},
\\"trailing.ws\\": {
\\"defaultMessage\\": \\" Some whitespace \\",
\\"defaultMessage\\": \\"Some whitespace\\",
\\"description\\": \\"Whitespace\\"
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ Object {
"description": "inline description",
},
"trailing.ws": Object {
"defaultMessage": " Some whitespace ",
"defaultMessage": "Some whitespace",
"description": "Whitespace",
},
}
Expand Down Expand Up @@ -320,7 +320,7 @@ Object {
\\"description\\": \\"foo\\"
},
\\"trailing.ws\\": {
\\"defaultMessage\\": \\" Some whitespace \\",
\\"defaultMessage\\": \\"Some whitespace\\",
\\"description\\": \\"Whitespace\\"
}
}
Expand Down Expand Up @@ -360,7 +360,7 @@ Object {
\\"description\\": \\"foo\\"
},
\\"trailing.ws\\": {
\\"defaultMessage\\": \\" Some whitespace \\",
\\"defaultMessage\\": \\"Some whitespace\\",
\\"description\\": \\"Whitespace\\"
}
}
Expand Down Expand Up @@ -401,7 +401,7 @@ Object {
},
\\"trailing.ws\\": {
\\"description\\": \\"Whitespace\\",
\\"message\\": \\" Some whitespace \\"
\\"message\\": \\"Some whitespace\\"
}
}
",
Expand Down Expand Up @@ -441,7 +441,7 @@ Object {
},
\\"trailing.ws\\": {
\\"comment\\": \\"Whitespace\\",
\\"string\\": \\" Some whitespace \\"
\\"string\\": \\"Some whitespace\\"
}
}
",
Expand Down Expand Up @@ -481,7 +481,7 @@ Object {
},
\\"trailing.ws\\": {
\\"notes\\": \\"Whitespace\\",
\\"translation\\": \\" Some whitespace \\"
\\"translation\\": \\"Some whitespace\\"
}
}
",
Expand All @@ -499,7 +499,7 @@ Object {
\\"foo.bar.baz\\": \\"Hello World!\\",
\\"foo.bar.biff\\": \\"Hello Nurse!\\",
\\"inline\\": \\"formatted message\\",
\\"trailing.ws\\": \\" Some whitespace \\"
\\"trailing.ws\\": \\"Some whitespace\\"
}
",
}
Expand Down Expand Up @@ -548,7 +548,7 @@ Object {
},
\\"trailing.ws\\": {
\\"description\\": \\"Whitespace\\",
\\"message\\": \\" Some whitespace \\"
\\"message\\": \\"Some whitespace\\"
}
}
",
Expand Down Expand Up @@ -588,7 +588,7 @@ Object {
},
\\"trailing.ws\\": {
\\"developer_comment\\": \\"Whitespace\\",
\\"string\\": \\" Some whitespace \\"
\\"string\\": \\"Some whitespace\\"
}
}
",
Expand Down

0 comments on commit 8a52eb5

Please sign in to comment.