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 66f2468
Showing 1 changed file with 11 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

0 comments on commit 66f2468

Please sign in to comment.