This repository has been archived by the owner. It is now read-only.
Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCleanup and splitup parser functions #295
Conversation
danez
added
Tag: Internal
Tag: Polish
PR: needs review
labels
Jan 14, 2017
This comment has been minimized.
This comment has been minimized.
codecov-io
commented
Jan 14, 2017
•
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
|
danez
requested review from
loganfsmyth
and
DrewML
Jan 16, 2017
danez
reviewed
Jan 16, 2017
@@ -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; |
This comment has been minimized.
This comment has been minimized.
return; | ||
} | ||
// It is either an Identifier or a String/NumericLiteral | ||
const name = key.type === "Identifier" ? key.name : String(key.value); |
This comment has been minimized.
This comment has been minimized.
danez
Jan 16, 2017
Author
Member
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"); | ||
} | ||
} | ||
}; |
This comment has been minimized.
This comment has been minimized.
danez
Jan 16, 2017
Author
Member
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) { |
This comment has been minimized.
This comment has been minimized.
@@ -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) { |
This comment has been minimized.
This comment has been minimized.
danez
Jan 16, 2017
Author
Member
parseObjPropValue
was split into parseObjectMethod
and parseObjectProperty
this.raise(start, "setter should have exactly one param"); | ||
} | ||
} | ||
this.parseMethod(prop); |
This comment has been minimized.
This comment has been minimized.
danez
Jan 16, 2017
Author
Member
removed second param, as now not needed (see comment in parseMethod
)
return stmt.type === "ExpressionStatement" && | ||
stmt.expression.type === "StringLiteral" && | ||
!stmt.expression.extra.parenthesized; | ||
}; |
This comment has been minimized.
This comment has been minimized.
(key.type === "Identifier" && key.name === "prototype") || | ||
(key.type === "StringLiteral" && key.value === "prototype") | ||
(key.name === "prototype") || // Identifier | ||
(key.value === "prototype") // Literal |
This comment has been minimized.
This comment has been minimized.
danez
Jan 16, 2017
Author
Member
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"); | ||
} | ||
} |
This comment has been minimized.
This comment has been minimized.
} else { | ||
this.raise(start, "setter should have exactly one param"); | ||
} | ||
} |
This comment has been minimized.
This comment has been minimized.
danez
force-pushed the
cleanup
branch
from
7304bb7
to
df858ab
Jan 20, 2017
danez
merged commit b6c3b5a
into
master
Jan 20, 2017
danez
deleted the
cleanup
branch
Jan 20, 2017
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
danez commentedJan 14, 2017
•
edited
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