Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Increase test coverage (#175)
Browse files Browse the repository at this point in the history
* Increase test coverage

* Test for error when binding `this` in destructuring pattern

* Ignore coverage of inAsync check in parseAwait - already checked externally

* Ignore coverage of default case in checkPropClash

* Remove unused parameter isAsync from parseParenAndDistinguishExpression

* Ignore coverage of an `else` branch in flowParseTypeParameterDeclaration

* Flow: remove unused parameters to flowParseTypeAnnotatableIdentifier

* Flow: ignore coverage of pass-through throw statement in parseConditional

* Flow: Add test for error on property with type param

* Flow: ignore coverage of pass-through throw statements in parseMaybeAssign, parseArrow

* Add test for error on XML-style comment in module code

* Update test for error on method in object pattern

* Test for error: "Only '=' operator can be used for specifying default value"
  • Loading branch information
motiz88 authored and danez committed Oct 16, 2016
1 parent 490ae9a commit 7c18bf8
Show file tree
Hide file tree
Showing 38 changed files with 646 additions and 28 deletions.
12 changes: 5 additions & 7 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pp.checkPropClash = function (prop, propHash) {
name = String(key.value);
break;

// istanbul ignore next: non-computed property keys are always one of the above
default:
return;
}
Expand Down Expand Up @@ -555,7 +556,7 @@ pp.parseParenExpression = function () {
return val;
};

pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow, isAsync) {
pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow) {
startPos = startPos || this.state.start;
startLoc = startLoc || this.state.startLoc;

Expand Down Expand Up @@ -597,15 +598,11 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow
if (param.extra && param.extra.parenthesized) this.unexpected(param.extra.parenStart);
}

return this.parseArrowExpression(arrowNode, exprList, isAsync);
return this.parseArrowExpression(arrowNode, exprList);
}

if (!exprList.length) {
if (isAsync) {
return;
} else {
this.unexpected(this.state.lastTokStart);
}
this.unexpected(this.state.lastTokStart);
}
if (optionalCommaStart) this.unexpected(optionalCommaStart);
if (spreadStart) this.unexpected(spreadStart);
Expand Down Expand Up @@ -1025,6 +1022,7 @@ pp.parseIdentifier = function (liberal) {
// Parses await expression inside async function.

pp.parseAwait = function (node) {
// istanbul ignore next: this condition is checked at the call site so won't be hit here
if (!this.state.inAsync) {
this.unexpected();
}
Expand Down
1 change: 0 additions & 1 deletion src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ pp.parseClassBody = function (node) {

method.static = isMaybeStatic && !this.match(tt.parenL);
if (method.static) {
if (isGenerator) this.unexpected();
isGenerator = this.eat(tt.star);
this.parsePropertyName(method);
}
Expand Down
24 changes: 7 additions & 17 deletions src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pp.flowParseTypeParameter = function () {

let variance = this.flowParseVariance();

let ident = this.flowParseTypeAnnotatableIdentifier(false, false);
let ident = this.flowParseTypeAnnotatableIdentifier();
node.name = ident.name;
node.variance = variance;
node.bound = ident.typeAnnotation;
Expand All @@ -227,6 +227,7 @@ pp.flowParseTypeParameterDeclaration = function () {

this.state.inType = true;

// istanbul ignore else: this condition is already checked at all call sites
if (this.isRelational("<") || this.match(tt.jsxTagStart)) {
this.next();
} else {
Expand Down Expand Up @@ -705,26 +706,12 @@ pp.flowParseTypeAnnotation = function () {
return this.finishNode(node, "TypeAnnotation");
};

pp.flowParseTypeAnnotatableIdentifier = function (requireTypeAnnotation, canBeOptionalParam) {

pp.flowParseTypeAnnotatableIdentifier = function () {
let ident = this.parseIdentifier();
let isOptionalParam = false;

if (canBeOptionalParam && this.eat(tt.question)) {
this.expect(tt.question);
isOptionalParam = true;
}

if (requireTypeAnnotation || this.match(tt.colon)) {
if (this.match(tt.colon)) {
ident.typeAnnotation = this.flowParseTypeAnnotation();
this.finishNode(ident, ident.type);
}

if (isOptionalParam) {
ident.optional = true;
this.finishNode(ident, ident.type);
}

return ident;
};

Expand Down Expand Up @@ -824,6 +811,7 @@ export default function (instance) {
refNeedsArrowPos.start = err.pos || this.state.start;
return expr;
} else {
// istanbul ignore next: no such error is expected
throw err;
}
}
Expand Down Expand Up @@ -1208,6 +1196,7 @@ export default function (instance) {
this.state = state;
jsxError = err;
} else {
// istanbul ignore next: no such error is expected
throw err;
}
}
Expand Down Expand Up @@ -1262,6 +1251,7 @@ export default function (instance) {
if (err instanceof SyntaxError) {
this.state = state;
} else {
// istanbul ignore next: no such error is expected
throw err;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/jsx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ pp.jsxParseElementAt = function(startPos, startLoc) {

break;

// istanbul ignore next - should never happen
default:
this.unexpected();
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/core/categorized/label-kind-switch/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
a: switch (i) {
}
}
117 changes: 117 additions & 0 deletions test/fixtures/core/categorized/label-kind-switch/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"type": "File",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "BlockStatement",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "LabeledStatement",
"start": 4,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 3,
"column": 3
}
},
"body": {
"type": "SwitchStatement",
"start": 7,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 3,
"column": 3
}
},
"discriminant": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 13
},
"end": {
"line": 2,
"column": 14
},
"identifierName": "i"
},
"name": "i"
},
"cases": []
},
"label": {
"type": "Identifier",
"start": 4,
"end": 5,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "a"
},
"name": "a"
}
}
],
"directives": []
}
],
"directives": []
}
}
3 changes: 3 additions & 0 deletions test/fixtures/core/categorized/malformed-switch/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
switch (x) {
var y = 5;
}
3 changes: 3 additions & 0 deletions test/fixtures/core/categorized/malformed-switch/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (2:2)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class A {
x () {super()}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "super() outside of class constructor (2:8)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class A {
static prototype() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Classes may not have static property named prototype (2:9)"
}
3 changes: 3 additions & 0 deletions test/fixtures/es2015/class-methods/getter-signature/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class A {
get prop (arg) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "getter should have no params (2:2)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class A {
x () {
super - 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (3:10)"
}
1 change: 1 addition & 0 deletions test/fixtures/es2015/destructuring/binding-this/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var { this };
3 changes: 3 additions & 0 deletions test/fixtures/es2015/destructuring/binding-this/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Binding this (1:6)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
([a += a] = a)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Only '=' operator can be used for specifying default value. (1:3)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo <!--bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:4)"
}
3 changes: 3 additions & 0 deletions test/fixtures/es2017/async-functions/no-constructor/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class A {
async constructor() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Constructor can't be an async function (2:8)"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
({get a(){}})=0
({a(){}})=0
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Object pattern can't contain getter or setter (1:6)"
}
"throws": "Object pattern can't contain methods (1:2)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
async function * f () {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"throws": "Unexpected token (1:15)",
"plugins": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const s = {
p<T>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (3:0)"
}
1 change: 1 addition & 0 deletions test/fixtures/jsx/basic/entity/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<A>&#x1f4a9;</A>
Loading

0 comments on commit 7c18bf8

Please sign in to comment.