Skip to content

Commit

Permalink
fix(ValidationParser): handle props that are only accessible via brac…
Browse files Browse the repository at this point in the history
…ket syntax

fixes aurelia#326
  • Loading branch information
jdanyow committed Sep 13, 2016
1 parent 7b13300 commit 8ef6182
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/implementation/validation-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ export class ValidationParser {
}

parseProperty<TObject, TValue>(property: string|PropertyAccessor<TObject, TValue>): RuleProperty {
let accessor: Expression;
if (isString(property)) {
accessor = this.parser.parse(<string>property);
} else {
accessor = this.getAccessorExpression(property.toString());
}
return { name: <string>property, displayName: null };
}
const accessor = this.getAccessorExpression(property.toString());
if (accessor instanceof AccessScope
|| accessor instanceof AccessMember && accessor.object instanceof AccessScope) {
return {
Expand Down
7 changes: 7 additions & 0 deletions test/validation-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ describe('Validator', () => {
expect(parse('_ => _.b')).toEqual(new AccessScope('b', 0));
expect(parse('$ => $.b')).toEqual(new AccessScope('b', 0));
});

it('parses properties', () => {
expect(parser.parseProperty('firstName')).toEqual({ name: 'firstName', displayName: null });
expect(parser.parseProperty('3_letter_id')).toEqual({ name: '3_letter_id', displayName: null });
expect(parser.parseProperty('. @$# ???')).toEqual({ name: '. @$# ???', displayName: null });
expect(parser.parseProperty((x: any) => x.firstName)).toEqual({ name: 'firstName', displayName: null });
});
});

0 comments on commit 8ef6182

Please sign in to comment.