Replace multiple spaces in bindings with one space (#14018)
* replace multiple spaces in bindings with one space * add some tests and update regex to account for strings * update regex to character based approach * simplify regex to only look for spaces after {{ --------- Co-authored-by: Michael Drury <me@michaeldrury.co.uk>
This commit is contained in:
parent
55440dca4a
commit
c417a5e627
2 changed files with 22 additions and 0 deletions
|
@ -7,6 +7,7 @@ export const PreprocessorNames = {
|
|||
SWAP_TO_DOT: "swap-to-dot-notation",
|
||||
FIX_FUNCTIONS: "fix-functions",
|
||||
FINALISE: "finalise",
|
||||
NORMALIZE_SPACES: "normalize-spaces",
|
||||
}
|
||||
|
||||
class Preprocessor {
|
||||
|
@ -50,6 +51,9 @@ export const processors = [
|
|||
return statement
|
||||
}),
|
||||
|
||||
new Preprocessor(PreprocessorNames.NORMALIZE_SPACES, (statement: string) => {
|
||||
return statement.replace(/{{(\s{2,})/g, "{{ ")
|
||||
}),
|
||||
new Preprocessor(
|
||||
PreprocessorNames.FINALISE,
|
||||
(statement: string, opts: { noHelpers: any }) => {
|
||||
|
|
|
@ -320,3 +320,21 @@ describe("should leave HBS blocks if not found using option", () => {
|
|||
expect(output).toBe("{{ a }}, 1")
|
||||
})
|
||||
})
|
||||
|
||||
describe("check multiple space behaviour", () => {
|
||||
it("should remove whitespace and use the helper correctly", async () => {
|
||||
const output = await processString("{{ add num1 num2 }}", {
|
||||
num1: 1,
|
||||
num2: 2,
|
||||
})
|
||||
expect(output).toEqual("3")
|
||||
})
|
||||
|
||||
it("should ensure that whitespace within a string is respected", async () => {
|
||||
const output = await processString("{{ trimRight 'test string ' }}", {
|
||||
num1: 1,
|
||||
num2: 2,
|
||||
})
|
||||
expect(output).toEqual("test string")
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue