Skip to content

Commit 579bac5

Browse files
committed
glayzzle#50 - cleanup src/*
1 parent 1e9f04a commit 579bac5

File tree

7 files changed

+22
-27
lines changed

7 files changed

+22
-27
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module.exports = {
99
env: {
1010
browser: true,
1111
node: true,
12-
mocha: true
12+
mocha: true,
13+
es6: true
1314
},
1415
rules: {
1516
"prettier/prettier": "error"

package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Parse PHP code and returns its AST",
55
"main": "src/index.js",
66
"scripts": {
7-
"lint": "eslint src/**/*.js",
7+
"lint": "eslint src/*.js src/**/*.js",
88
"test": "npm run lint && node node_modules/mocha/bin/mocha test --stack-size=5000",
99
"cover": "node --stack-size=5000 node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha"
1010
},
@@ -27,13 +27,6 @@
2727
],
2828
"author": "Ioan CHIRIAC",
2929
"license": "BSD-3-Clause",
30-
"xo": {
31-
"space": 2,
32-
"envs": [
33-
"node",
34-
"mocha"
35-
]
36-
},
3730
"devDependencies": {
3831
"coveralls": "^2.11.15",
3932
"eslint": "^4.14.0",

src/ast.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ AST.prototype.position = function(parser) {
126126

127127
// operators in ascending order of precedence
128128
AST.precedence = {};
129-
var binOperatorsPrecedence = [
129+
[
130130
["or"],
131131
["xor"],
132132
["and"],
@@ -158,13 +158,13 @@ var binOperatorsPrecedence = [
158158
* Check and fix precence, by default using right
159159
*/
160160
AST.prototype.resolvePrecedence = function(result) {
161-
var buffer;
161+
let buffer, lLevel, rLevel;
162162
// handling precendence
163163
if (result.kind === "bin") {
164164
if (result.right) {
165165
if (result.right.kind === "bin") {
166-
var lLevel = AST.precedence[result.type];
167-
var rLevel = AST.precedence[result.right.type];
166+
lLevel = AST.precedence[result.type];
167+
rLevel = AST.precedence[result.right.type];
168168
if (lLevel && rLevel && rLevel <= lLevel) {
169169
// https://github.com/glayzzle/php-parser/issues/79
170170
// shift precedence
@@ -174,8 +174,8 @@ AST.prototype.resolvePrecedence = function(result) {
174174
result = buffer;
175175
}
176176
} else if (result.right.kind === "retif") {
177-
var lLevel = AST.precedence[result.type];
178-
var rLevel = AST.precedence["?"];
177+
lLevel = AST.precedence[result.type];
178+
rLevel = AST.precedence["?"];
179179
if (lLevel && rLevel && rLevel <= lLevel) {
180180
buffer = result.right;
181181
result.right = result.right.test;
@@ -211,8 +211,8 @@ AST.prototype.resolvePrecedence = function(result) {
211211
} else if (result.kind === "assign") {
212212
// https://github.com/glayzzle/php-parser/issues/81
213213
if (result.right && result.right.kind === "bin") {
214-
var lLevel = AST.precedence["="];
215-
var rLevel = AST.precedence[result.right.type];
214+
lLevel = AST.precedence["="];
215+
rLevel = AST.precedence[result.right.type];
216216
// only shifts with and, xor, or
217217
if (lLevel && rLevel && rLevel < lLevel) {
218218
buffer = result.right;

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ var getStringBuffer = function(buffer) {
101101
* @param {Object} options
102102
* @return {Engine}
103103
* @private
104-
*/
104+
*/
105105
engine.create = function(options) {
106106
return new engine(options);
107107
};

src/lexer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ lexer.prototype.setInput = function(input) {
156156
/**
157157
* consumes and returns one char from the input
158158
*/
159-
lexer.prototype.input = function(size) {
159+
lexer.prototype.input = function() {
160160
var ch = this._input[this.offset];
161161
if (!ch) return "";
162162
this.yytext += ch;
@@ -430,7 +430,8 @@ lexer.prototype.next = function() {
430430
this.yytext +
431431
'"'
432432
);
433-
console.log(e.stack);
433+
// eslint-disable-next-line no-console
434+
console.error(e.stack);
434435
}
435436
return token;
436437
};

src/parser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,10 @@ parser.prototype.raiseError = function(message, msgExpect, expect, token) {
300300
* handling errors
301301
*/
302302
parser.prototype.error = function(expect) {
303-
var msg = "Parse Error : syntax error";
304-
token = this.getTokenName(this.token);
303+
let msg = "Parse Error : syntax error";
304+
let token = this.getTokenName(this.token);
305+
let msgExpect = "";
306+
305307
if (this.token !== this.EOF) {
306308
if (isNumber(this.token)) {
307309
var symbol = this.text();
@@ -312,14 +314,12 @@ parser.prototype.error = function(expect) {
312314
}
313315
msg += ", unexpected " + token;
314316
}
315-
var msgExpect = "";
316317
if (expect && !Array.isArray(expect)) {
317318
if (isNumber(expect) || expect.length === 1) {
318319
msgExpect = ", expecting " + this.getTokenName(expect);
319320
}
320321
msg += msgExpect;
321322
}
322-
this.token !== this.EOF;
323323
return this.raiseError(msg, msgExpect, expect, token);
324324
};
325325

@@ -372,7 +372,7 @@ parser.prototype.showlog = function() {
372372
break;
373373
}
374374
}
375-
375+
// eslint-disable-next-line no-console
376376
console.log(
377377
"Line " +
378378
this.lexer.yylloc.first_line +

src/parser/array.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
44
* @url http://glayzzle.com
55
*/
6-
var ArrayExpr = "array";
7-
var ArrayEntry = "entry";
6+
const ArrayExpr = "array";
7+
const ArrayEntry = "entry";
88

99
module.exports = {
1010
/**

0 commit comments

Comments
 (0)