Skip to content

Commit 17b4788

Browse files
committed
chore: improve coverage / add explicit ignore statements
1 parent b3089eb commit 17b4788

17 files changed

+222
-6
lines changed

jest.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ module.exports = {
77
coverageDirectory: "coverage/",
88
coverageThreshold: {
99
global: {
10-
statements: 95.6,
11-
branches: 89.6,
12-
functions: 99,
13-
lines: 96.1,
10+
statements: 96.4,
11+
branches: 90.1,
12+
functions: 99.4,
13+
lines: 96.9,
1414
},
1515
},
1616
projects: [

src/ast.js

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ AST.prototype.resolveLocations = function (target, first, last, parser) {
201201
if (target.loc.start.offset > first.loc.start.offset) {
202202
target.loc.start = first.loc.start;
203203
}
204+
/* istanbul ignore next */
204205
if (target.loc.end.offset < last.loc.end.offset) {
205206
target.loc.end = last.loc.end;
206207
}
@@ -392,6 +393,7 @@ AST.prototype.prepare = function (kind, docs, parser) {
392393
const astNode = Object.create(node.prototype);
393394
node.apply(astNode, args);
394395
result.instance = astNode;
396+
/* istanbul ignore next */
395397
if (result.trailingComments) {
396398
// buffer of trailingComments
397399
astNode.trailingComments = result.trailingComments;

src/ast/classconstant.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ ClassConstant.prototype.parseFlags = function (flags) {
4242
if (flags[0] === -1) {
4343
this.visibility = IS_UNDEFINED;
4444
} else if (flags[0] === null) {
45+
/* istanbul ignore next */
4546
this.visibility = null;
4647
} else if (flags[0] === 0) {
4748
this.visibility = IS_PUBLIC;

src/ast/declaration.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Declaration.prototype.parseFlags = function (flags) {
4343
if (flags[0] === -1) {
4444
this.visibility = IS_UNDEFINED;
4545
} else if (flags[0] === null) {
46+
/* istanbul ignore next */
4647
this.visibility = null;
4748
} else if (flags[0] === 0) {
4849
this.visibility = IS_PUBLIC;

src/ast/node.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Node.prototype.setTrailingComments = function (docs) {
4141
*/
4242
Node.prototype.destroy = function (node) {
4343
if (!node) {
44+
/* istanbul ignore next */
4445
throw new Error(
4546
"Node already initialized, you must swap with another node"
4647
);

src/lexer.js

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Lexer.prototype.setInput = function (input) {
177177
*/
178178
first_encaps_node: false,
179179
// for backward compatible
180+
/* istanbul ignore next */
180181
toString: function () {
181182
this.label;
182183
},
@@ -450,6 +451,7 @@ Lexer.prototype.begin = function (condition) {
450451
this.conditionStack.push(condition);
451452
this.curCondition = condition;
452453
this.stateCb = this["match" + condition];
454+
/* istanbul ignore next */
453455
if (typeof this.stateCb !== "function") {
454456
throw new Error('Undefined condition state "' + condition + '"');
455457
}
@@ -467,6 +469,7 @@ Lexer.prototype.popState = function () {
467469
const condition = n > 0 ? this.conditionStack.pop() : this.conditionStack[0];
468470
this.curCondition = this.conditionStack[this.conditionStack.length - 1];
469471
this.stateCb = this["match" + this.curCondition];
472+
/* istanbul ignore next */
470473
if (typeof this.stateCb !== "function") {
471474
throw new Error('Undefined condition state "' + this.curCondition + '"');
472475
}
@@ -508,6 +511,7 @@ Lexer.prototype.next = function () {
508511
if (this.offset >= this.size && this.tokens.length === 0) {
509512
this.done = true;
510513
}
514+
/* istanbul ignore next */
511515
if (this.debug) {
512516
let tName = token;
513517
if (typeof tName === "number") {

src/lexer/attribute.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
if (listDepth === 0) {
2222
this.popState();
2323
} else {
24+
/* istanbul ignore next */
2425
listDepth--;
2526
}
2627
return "]";
@@ -59,6 +60,7 @@ module.exports = {
5960
return this.consume_NUM();
6061
}
6162

63+
/* istanbul ignore next */
6264
throw new Error(
6365
`Bad terminal sequence "${ch}" at line ${this.yylineno} (offset ${this.offset})`
6466
);

src/lexer/property.js

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ module.exports = {
6666
this.consume_LABEL();
6767
return this.tok.T_VARIABLE;
6868
} else {
69+
/* istanbul ignore next */
6970
throw new Error("Unexpected terminal");
7071
}
7172
} else if (this.is_LABEL_START()) {
@@ -88,6 +89,7 @@ module.exports = {
8889
) {
8990
return ch;
9091
} else {
92+
/* istanbul ignore next */
9193
throw new Error("Unexpected terminal");
9294
}
9395
},

src/parser.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ Parser.prototype.parse = function (code, filename) {
310310
const result = program(childs, this._errors, this._docs, this._tokens);
311311
if (this.debug) {
312312
const errors = this.ast.checkNodes();
313+
/* istanbul ignore next */
313314
if (errors.length > 0) {
314315
errors.forEach(function (error) {
315316
if (error.position) {
@@ -372,6 +373,7 @@ Parser.prototype.error = function (expect) {
372373
if (this.token !== this.EOF) {
373374
if (isNumber(this.token)) {
374375
let symbol = this.text();
376+
/* istanbul ignore next */
375377
if (symbol.length > 10) {
376378
symbol = symbol.substring(0, 7) + "...";
377379
}
@@ -412,6 +414,7 @@ Parser.prototype.node = function (name) {
412414
if (this._docIndex < this._docs.length) {
413415
docs = this._docs.slice(this._docIndex);
414416
this._docIndex = this._docs.length;
417+
/* istanbul ignore next */
415418
if (this.debug) {
416419
// eslint-disable-next-line no-console
417420
console.log(new Error("Append docs on " + name));
@@ -514,11 +517,13 @@ Parser.prototype.showlog = function () {
514517
line = stack[offset].trim();
515518
let found = false;
516519
for (let i = 0; i < ignoreStack.length; i++) {
520+
/* istanbul ignore next */
517521
if (line.substring(3, 3 + ignoreStack[i].length) === ignoreStack[i]) {
518522
found = true;
519523
break;
520524
}
521525
}
526+
/* istanbul ignore next */
522527
if (!found) {
523528
break;
524529
}
@@ -629,7 +634,7 @@ Parser.prototype.lex = function () {
629634
if (this.extractTokens) {
630635
do {
631636
// the token
632-
this.token = this.lexer.lex() || this.EOF;
637+
this.token = this.lexer.lex() || /* istanbul ignore next */ this.EOF;
633638
if (this.token === this.EOF) return this;
634639
let entry = this.lexer.yytext;
635640
if (
@@ -672,7 +677,7 @@ Parser.prototype.lex = function () {
672677
this.token === this.tok.T_OPEN_TAG
673678
);
674679
} else {
675-
this.token = this.lexer.lex() || this.EOF;
680+
this.token = this.lexer.lex() || /* istanbul ignore next */ this.EOF;
676681
}
677682
return this;
678683
};
@@ -708,6 +713,7 @@ Parser.prototype.is = function (type) {
708713
require("./parser/variable.js"),
709714
].forEach(function (ext) {
710715
for (const k in ext) {
716+
/* istanbul ignore next */
711717
if (Object.prototype.hasOwnProperty.call(Parser.prototype, k)) {
712718
// @see https://github.com/glayzzle/php-parser/issues/234
713719
throw new Error("Function " + k + " is already defined - collision");

src/parser/expr.js

+2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ module.exports = {
277277
}
278278
}
279279
if (!hasItem) {
280+
/* istanbul ignore next */
280281
this.raiseError(
281282
"Fatal Error : Cannot use empty list on line " +
282283
this.lexer.yylloc.first_line
@@ -294,6 +295,7 @@ module.exports = {
294295
);
295296
} else {
296297
// error fallback : list($a, $b);
298+
/* istanbul ignore next */
297299
return result(assignList, false);
298300
}
299301
} else {

src/parser/utils.js

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
read_short_form: function (token) {
1515
const body = this.node("block");
1616
const items = [];
17+
/* istanbul ignore next */
1718
if (this.expect(":")) this.next();
1819
while (this.token != this.EOF && this.token !== token) {
1920
items.push(this.read_inner_statement());
@@ -25,6 +26,7 @@ module.exports = {
2526
) {
2627
items.push(this.node("noop")());
2728
}
29+
/* istanbul ignore next */
2830
if (this.expect(token)) this.next();
2931
this.expectEndOfStatement();
3032
return body(null, items);
@@ -150,6 +152,7 @@ module.exports = {
150152
const node = this.node("staticvariable");
151153
let variable = this.node("variable");
152154
// plain variable name
155+
/* istanbul ignore else */
153156
if (this.expect(this.tok.T_VARIABLE)) {
154157
const name = this.text().substring(1);
155158
this.next();

test/snapshot/__snapshots__/arrowfunc.test.js.snap

+79
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,85 @@ Program {
184184
}
185185
`;
186186

187+
exports[`arrow function error / arrow functions before PHP 7.4 1`] = `
188+
Program {
189+
"children": Array [
190+
ExpressionStatement {
191+
"expression": Assign {
192+
"kind": "assign",
193+
"left": Variable {
194+
"curly": false,
195+
"kind": "variable",
196+
"name": "fn1",
197+
},
198+
"operator": "=",
199+
"right": Call {
200+
"arguments": Array [
201+
Variable {
202+
"curly": false,
203+
"kind": "variable",
204+
"name": "x",
205+
},
206+
],
207+
"kind": "call",
208+
"what": Name {
209+
"kind": "name",
210+
"name": "fn",
211+
"resolution": "uqn",
212+
},
213+
},
214+
},
215+
"kind": "expressionstatement",
216+
},
217+
ExpressionStatement {
218+
"expression": undefined,
219+
"kind": "expressionstatement",
220+
},
221+
ExpressionStatement {
222+
"expression": Bin {
223+
"kind": "bin",
224+
"left": Variable {
225+
"curly": false,
226+
"kind": "variable",
227+
"name": "x",
228+
},
229+
"right": Variable {
230+
"curly": false,
231+
"kind": "variable",
232+
"name": "y",
233+
},
234+
"type": "+",
235+
},
236+
"kind": "expressionstatement",
237+
},
238+
],
239+
"errors": Array [
240+
Error {
241+
"expected": ";",
242+
"kind": "error",
243+
"line": 1,
244+
"message": "Parse Error : syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ';' on line 1",
245+
"token": "'=>' (T_DOUBLE_ARROW)",
246+
},
247+
Error {
248+
"expected": "EXPR",
249+
"kind": "error",
250+
"line": 1,
251+
"message": "Parse Error : syntax error, unexpected '=>' (T_DOUBLE_ARROW) on line 1",
252+
"token": "'=>' (T_DOUBLE_ARROW)",
253+
},
254+
Error {
255+
"expected": ";",
256+
"kind": "error",
257+
"line": 1,
258+
"message": "Parse Error : syntax error, unexpected '$x' (T_VARIABLE), expecting ';' on line 1",
259+
"token": "'$x' (T_VARIABLE)",
260+
},
261+
],
262+
"kind": "program",
263+
}
264+
`;
265+
187266
exports[`arrow function error / empty not allowed 1`] = `
188267
Program {
189268
"children": Array [

test/snapshot/__snapshots__/number.test.js.snap

+40
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,46 @@ Program {
182182
}
183183
`;
184184

185+
exports[`Test numbers multiple points 1`] = `
186+
Program {
187+
"children": Array [
188+
ExpressionStatement {
189+
"expression": Assign {
190+
"kind": "assign",
191+
"left": Variable {
192+
"curly": false,
193+
"kind": "variable",
194+
"name": "b",
195+
},
196+
"operator": "=",
197+
"right": Number {
198+
"kind": "number",
199+
"value": "1.0",
200+
},
201+
},
202+
"kind": "expressionstatement",
203+
},
204+
ExpressionStatement {
205+
"expression": Number {
206+
"kind": "number",
207+
"value": ".5",
208+
},
209+
"kind": "expressionstatement",
210+
},
211+
],
212+
"errors": Array [
213+
Error {
214+
"expected": ";",
215+
"kind": "error",
216+
"line": 1,
217+
"message": "Parse Error : syntax error, unexpected '.5' (T_DNUMBER), expecting ';' on line 1",
218+
"token": "'.5' (T_DNUMBER)",
219+
},
220+
],
221+
"kind": "program",
222+
}
223+
`;
224+
185225
exports[`Test numbers test common cases 1`] = `
186226
Program {
187227
"children": Array [

0 commit comments

Comments
 (0)