This repository has been archived by the owner. It is now read-only.

Cleanup and splitup parser functions #295

Merged
merged 1 commit into from Jan 20, 2017

Conversation

Projects
None yet
2 participants
@danez
Copy link
Member

danez commented Jan 14, 2017

Q A
Bug fix? no
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? no
Tests added/pass? yes
Fixed tickets
License MIT

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

@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Jan 14, 2017

Current coverage is 97.27% (diff: 100%)

Merging #295 into master will increase coverage by 0.14%

@@             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   

Powered by Codecov. Last update 0a00aff...df858ab

@danez danez requested review from loganfsmyth and DrewML 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.

@danez

danez Jan 16, 2017

Author Member

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);

This comment has been minimized.

@danez

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.

@danez

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.

@danez

danez Jan 16, 2017

Author Member

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) {

This comment has been minimized.

@danez

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.

@danez

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.

@danez

danez Jan 16, 2017

Author Member

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

This comment has been minimized.

@danez

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.

@danez

danez Jan 16, 2017

Author Member

moved to checkGetterSetterParamCount

} else {
this.raise(start, "setter should have exactly one param");
}
}

This comment has been minimized.

@danez

danez Jan 16, 2017

Author Member

moved to checkGetterSetterParamCount

Daniel Tschinder
Cleanup and splitup parser functions
This makes it easier to integrate the estree plugin.

@danez danez force-pushed the cleanup branch from 7304bb7 to df858ab Jan 20, 2017

@danez danez merged commit b6c3b5a into master Jan 20, 2017

4 checks passed

codecov/patch 100% of diff hit (target 97.13%)
Details
codecov/project 97.27% (+0.14%) compared to 0a00aff
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@danez 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.