Skip to content

Commit

Permalink
fix trimStart is undefined bug (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix-stripe committed Sep 21, 2022
1 parent a18ffcc commit 593a654
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,27 @@ describe('Formatter', () => {
expect(format(null)).toBe('');
});

it('empty', () => {
check('', '');
stable('');
});

it('basics', () => {
check(source, expected);
stable(expected);
});

it('frontmatter', () => {
const source = `---
title: Title
subtitle: Subtitle
---
`;
check(source, source);
stable(source);
});

it('attribute edge cases', () => {
const source = `{% key id=$user.name class=default($y, "test") %}Child{% /key %}`;
const expected = `
Expand Down
6 changes: 4 additions & 2 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ function* formatFunction(f: Function) {
yield ')';
}

function* trimStart(g: Generator) {
function* trimStart(g: Generator<string>) {
let n;
do {
n = g.next().value.trimStart();
const { value, done } = g.next();
if (done) return;
n = value.trimStart();
} while (!n.length);
yield n;
yield* g;
Expand Down

0 comments on commit 593a654

Please sign in to comment.