Skip to content

Commit

Permalink
feat: Adding spaces allowed in parser
Browse files Browse the repository at this point in the history
Before that:

```html
<span>{{value}}</span> <!-- correct -->
<span>{{ value }}</span> <!-- doesn't correct -->
<span>{{  value  }}</span> <!-- doesn't correct -->
```

After that:

```html
<span>{{value}}</span> <!-- correct -->
<span>{{ value }}</span> <!-- correct -->
<span>{{  value  }}</span> <!-- correct -->
```
AlexWayfer committed Oct 2, 2016

Verified

This commit was signed with the committer’s verified signature.
re-taro Rintaro Itokawa
1 parent 1defba7 commit 9bd0c28
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parsebindings/_parserdata.js
Original file line number Diff line number Diff line change
@@ -33,11 +33,11 @@ calc(parserData, {
},
bindingReg: {
source: ['escLeftBracket', 'escRightBracket'],
handler: (left, right) => new RegExp(`${left}(.+?)${right}`, 'g')
handler: (left, right) => new RegExp(`${left}\\s*(.+?)\\s*${right}`, 'g')
},
strictBindingReg: {
source: ['escLeftBracket', 'escRightBracket'],
handler: (left, right) => new RegExp(`^${left}(.+?)${right}$`, 'g')
handler: (left, right) => new RegExp(`^${left}\\s*(.+?)\\s*${right}$`, 'g')
}
}, {
debounceCalc: false // we need to get new regexps immediately when brackets are changed
9 changes: 9 additions & 0 deletions test/spec/bindings/bindings_parser_spec.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,15 @@ describe('Bindings parser', () => {
expect(node.textContent).toEqual(obj.x);
});

it('should parse inner content with spaces', () => {
const node = parse('<span>{{ x }}</span>');
const obj = {};

parseBindings(obj, node, noDebounceFlag);
obj.x = 'foo';
expect(node.textContent).toEqual(obj.x);
});

it('should parse inner content and keep node empty if property value is not given', () => {
const node = parse('<span>{{x}}</span>');
const obj = {};

0 comments on commit 9bd0c28

Please sign in to comment.