Skip to content

Commit

Permalink
Merge pull request #117 from dinoboff/chore/better-property-access-error
Browse files Browse the repository at this point in the history
chore: better property access error message
  • Loading branch information
dinoboff authored Jan 24, 2017
2 parents 595fc2f + 2f06922 commit a699d69
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/parser/statement/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,27 @@ class MemberNode extends Node {
return this.property.inferredType;
}

if (this.property.type !== 'Literal') {
const msg = 'Invalid property access.';
const objectType = this.object.inferredType;

if (types.isFuzzy(objectType)) {
return 'any';
}

const scope = MemberNode.properties[this.object.inferredType];
if (this.property.type !== 'Literal') {
throw new ParseError(this, msg);
}

const scope = MemberNode.properties[objectType];

if (scope == null) {
return 'any';
throw new ParseError(this, msg);
}

const type = scope[this.property.value];

if (type == null) {
throw new ParseError(this, 'Invalid property access.');
throw new ParseError(this, msg);
}

return type;
Expand Down
5 changes: 5 additions & 0 deletions test/spec/lib/parser/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,11 @@
"failAtRuntime": false,
"evaluateTo": true
},
{
"rule": "root[\"doesNotExist\"]() == true",
"user": "unauth",
"isValid": false
},
{
"rule": "root[\"exi\" + \"sts\"]() == false",
"user": "unauth",
Expand Down

0 comments on commit a699d69

Please sign in to comment.