Skip to content

Commit

Permalink
chore: better property access error message
Browse files Browse the repository at this point in the history
Throw during in the inferring type of computed property instead of letting the call expression parsing do it later.
  • Loading branch information
dinoboff committed Jan 24, 2017
1 parent 595fc2f commit 2f06922
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 2f06922

Please sign in to comment.