Permalink
Browse files

fix(ParserImplementation): allow use of $parent with | or & expressions

  • Loading branch information...
AshleyGrant authored and jdanyow committed Sep 7, 2017
1 parent a961498 commit a18fd33e33eaa4cf3d307183d4c1fd12cc4b6fd8
Showing with 69 additions and 13 deletions.
  1. +2 −0 src/parser.js
  2. +67 −13 test/parser.spec.js
View
@@ -330,6 +330,8 @@ export class ParserImplementation {
|| this.peek.text === '['
|| this.peek.text === '}'
|| this.peek.text === ','
|| this.peek.text === '|'
|| this.peek.text === '&'
) {
return new AccessThis(ancestor);
} else {
View
@@ -1,4 +1,4 @@
import {Parser} from '../src/parser';
import { Parser } from '../src/parser';
import {
LiteralString,
LiteralPrimitive,
@@ -178,6 +178,60 @@ describe('Parser', () => {
}
});
it('parses $parent before value converter', () => {
let child = '';
for (let i = 1; i < 10; i++) {
let s = `$parent${child} | foo`;
let expression = parser.parse(s);
expect(expression instanceof ValueConverter).toBe(true);
expect(expression.name).toBe('foo');
expect(expression.expression instanceof AccessThis).toBe(true);
expect(expression.expression.ancestor).toBe(i);
child += '.$parent';
}
});
it('parses $parent.foo before value converter', () => {
let child = '';
for (let i = 1; i < 10; i++) {
let s = `$parent${child}.bar | foo`;
let expression = parser.parse(s);
expect(expression instanceof ValueConverter).toBe(true);
expect(expression.name).toBe('foo');
expect(expression.expression instanceof AccessScope).toBe(true);
expect(expression.expression.name).toBe('bar');
expect(expression.expression.ancestor).toBe(i);
child += '.$parent';
}
});
it('parses $parent before binding behavior', () => {
let child = '';
for (let i = 1; i < 10; i++) {
let s = `$parent${child} & foo`;
let expression = parser.parse(s);
expect(expression instanceof BindingBehavior).toBe(true);
expect(expression.name).toBe('foo');
expect(expression.expression instanceof AccessThis).toBe(true);
expect(expression.expression.ancestor).toBe(i);
child += '.$parent';
}
});
it('parses $parent.foo before binding behavior', () => {
let child = '';
for (let i = 1; i < 10; i++) {
let s = `$parent${child}.bar & foo`;
let expression = parser.parse(s);
expect(expression instanceof BindingBehavior).toBe(true);
expect(expression.name).toBe('foo');
expect(expression.expression instanceof AccessScope).toBe(true);
expect(expression.expression.name).toBe('bar');
expect(expression.expression.ancestor).toBe(i);
child += '.$parent';
}
});
it('translates $parent.foo to AccessScope', () => {
let s = '$parent.foo';
for (let i = 1; i < 10; i++) {
@@ -266,17 +320,17 @@ describe('Parser', () => {
});
it('does not parse invalid shorthand properties', () => {
let pass = false;
try {
parser.parse('{ foo.bar, bar.baz }');
pass = true;
} catch (e) { pass = false; }
expect(pass).toBe(false);
try {
parser.parse('{ "foo.bar" }');
pass = true;
} catch (e) { pass = false; }
expect(pass).toBe(false);
let pass = false;
try {
parser.parse('{ foo.bar, bar.baz }');
pass = true;
} catch (e) { pass = false; }
expect(pass).toBe(false);
try {
parser.parse('{ "foo.bar" }');
pass = true;
} catch (e) { pass = false; }
expect(pass).toBe(false);
});
});

0 comments on commit a18fd33

Please sign in to comment.