-
-
Notifications
You must be signed in to change notification settings - Fork 255
Cleanup and splitup parser functions #295
Conversation
Current coverage is 97.27% (diff: 100%)@@ master #295 diff @@
==========================================
Files 21 21
Lines 3487 3489 +2
Methods 400 406 +6
Messages 0 0
Branches 896 900 +4
==========================================
+ Hits 3387 3394 +7
+ Misses 44 40 -4
+ Partials 56 55 -1
|
@@ -30,26 +30,13 @@ const pp = Parser.prototype; | |||
// strict mode, init properties are also not allowed to be repeated. | |||
|
|||
pp.checkPropClash = function (prop, propHash) { | |||
if (prop.computed) return; | |||
if (prop.computed || prop.kind) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved from line 39, to exit earlier
return; | ||
} | ||
// It is either an Identifier or a String/NumericLiteral | ||
const name = key.type === "Identifier" ? key.name : String(key.value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing a switch case with two variant just do this one-liner. It will anyway only be Identifier or Literal.
this.raise(start, "setter should have exactly one param"); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New method to check if getters and setter have correct param count. Was duplicated in the code twice.
@@ -808,36 +795,57 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) { | |||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); | |||
}; | |||
|
|||
pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos) { | |||
pp.isGetterOrSetterMethod = function (prop, isPattern) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted from parseObjectMethod
to be more easier to follow.
@@ -808,36 +795,57 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) { | |||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); | |||
}; | |||
|
|||
pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseObjPropValue
was split into parseObjectMethod
and parseObjectProperty
this.raise(start, "setter should have exactly one param"); | ||
} | ||
} | ||
this.parseMethod(prop); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed second param, as now not needed (see comment in parseMethod
)
return stmt.type === "ExpressionStatement" && | ||
stmt.expression.type === "StringLiteral" && | ||
!stmt.expression.extra.parenthesized; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted for readability and to be overwriteable for estree
(key.type === "Identifier" && key.name === "prototype") || | ||
(key.type === "StringLiteral" && key.value === "prototype") | ||
(key.name === "prototype") || // Identifier | ||
(key.value === "prototype") // Literal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to check the types, just check the name/value. Helps with estree (StringLiteral != Literal)
} else { | ||
this.raise(start, "setter should have exactly one param"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to checkGetterSetterParamCount
} else { | ||
this.raise(start, "setter should have exactly one param"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to checkGetterSetterParamCount
This makes it easier to integrate the estree plugin.
This makes it easier to integrate plugins like the estree plugin. It was splitted out of #277 to make it easier to review.
No changes to the logic, just purely refactor.
Added inline comments, so it is easier to follow what has happened