Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit 8e9a3b6

Browse files
fix: broken code
1 parent 19c1558 commit 8e9a3b6

File tree

8 files changed

+55
-44
lines changed

8 files changed

+55
-44
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
sourceType: "module"
66
},
77
plugins: ["prettier"],
8-
extends: ["eslint:recommended", "prettier"],
8+
extends: ["eslint:recommended"],
99
env: {
1010
browser: true,
1111
node: true,

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dist"
1010
],
1111
"scripts": {
12-
"lint": "prettier --write src/*.js src/**/*.js",
12+
"lint": "eslint 'src/**/*.js'",
1313
"pretest": "npm run lint",
1414
"test": "jest",
1515
"prebuild": "npm run test",
@@ -58,7 +58,8 @@
5858
"babel-loader": "^7",
5959
"babel-preset-es2015": "^6",
6060
"coveralls": "^3",
61-
"eslint-plugin-prettier": "^2.6.2",
61+
"eslint": "^5.8.0",
62+
"eslint-plugin-prettier": "^3.0.0",
6263
"jest": "^22.4",
6364
"jsdoc": "^3.5.5",
6465
"jsdoc-template": "github:braintree/jsdoc-template",

src/parser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ parser.prototype.node = function(name) {
355355
docs = this._docs.slice(this._docIndex);
356356
this._docIndex = this._docs.length;
357357
if (this.debug) {
358+
// eslint-disable-next-line no-console
358359
console.log(new Error("Append docs on " + name));
360+
// eslint-disable-next-line no-console
359361
console.log(docs);
360362
}
361363
}

src/parser/expr.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,9 @@ module.exports = {
417417
expr = this.read_scalar();
418418
if (expr.kind === "array" && expr.shortForm && this.token === "=") {
419419
// list assign
420-
let list = this.node("list")(expr.items, true);
420+
const list = this.node("list")(expr.items, true);
421421
if (expr.loc) list.loc = expr.loc;
422-
let right = this.next().read_expr();
422+
const right = this.next().read_expr();
423423
return result("assign", list, right, "=");
424424
} else {
425425
// see #189 - swap docs on nodes

src/parser/function.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = {
8080
returnType = null,
8181
nullable = false;
8282
if (type !== 1) {
83-
let nameNode = this.node("identifier");
83+
const nameNode = this.node("identifier");
8484
if (type === 2) {
8585
if (
8686
this.token === this.tok.T_STRING ||
@@ -241,13 +241,12 @@ module.exports = {
241241
*/
242242
read_type: function() {
243243
const result = this.node("typereference");
244-
let type = null;
245244
if (this.token === this.tok.T_ARRAY || this.token === this.tok.T_CALLABLE) {
246-
let type = this.text();
245+
const type = this.text();
247246
this.next();
248247
return result(type);
249248
} else if (this.token === this.tok.T_STRING) {
250-
let type = this.text();
249+
const type = this.text();
251250
const backup = [this.token, this.lexer.getState()];
252251
this.next();
253252
if (

src/parser/statement.js

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ module.exports = {
173173
* Reads statements
174174
*/
175175
read_statement: function() {
176-
let result, expr, items, current, label;
177176
switch (this.token) {
178177
case "{":
179178
return this.read_code_block(false);
@@ -202,19 +201,20 @@ module.exports = {
202201
case this.tok.T_DOC_COMMENT:
203202
return this.read_doc_comment();
204203

205-
case this.tok.T_RETURN:
206-
result = this.node("return");
207-
expr = null;
204+
case this.tok.T_RETURN: {
205+
const result = this.node("return");
206+
let expr = null;
208207
if (!this.next().is("EOS")) {
209208
expr = this.read_expr();
210209
}
211210
this.expectEndOfStatement();
212211
return result(expr);
212+
}
213213

214214
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L429
215215
case this.tok.T_BREAK:
216216
case this.tok.T_CONTINUE: {
217-
result = this.node(
217+
const result = this.node(
218218
this.token === this.tok.T_CONTINUE ? "continue" : "break"
219219
);
220220
let level = null;
@@ -226,31 +226,33 @@ module.exports = {
226226
return result(level);
227227
}
228228

229-
case this.tok.T_GLOBAL:
230-
result = this.node("global");
231-
items = this.next().read_list(this.read_simple_variable, ",");
229+
case this.tok.T_GLOBAL: {
230+
const result = this.node("global");
231+
const items = this.next().read_list(this.read_simple_variable, ",");
232232
this.expectEndOfStatement();
233233
return result(items);
234+
}
234235

235-
case this.tok.T_STATIC:
236-
current = [this.token, this.lexer.getState()];
237-
result = this.node();
236+
case this.tok.T_STATIC: {
237+
const current = [this.token, this.lexer.getState()];
238+
const result = this.node();
238239
if (this.next().token === this.tok.T_DOUBLE_COLON) {
239240
// static keyword for a class
240241
this.lexer.tokens.push(current);
241-
expr = this.next().read_expr();
242+
const expr = this.next().read_expr();
242243
this.expectEndOfStatement(expr);
243244
return result("expressionstatement", expr);
244245
}
245246
if (this.token === this.tok.T_FUNCTION) {
246247
return this.read_function(true, [0, 1, 0]);
247248
}
248-
items = this.read_variable_declarations();
249+
const items = this.read_variable_declarations();
249250
this.expectEndOfStatement();
250251
return result("static", items);
252+
}
251253

252254
case this.tok.T_ECHO: {
253-
result = this.node("echo");
255+
const result = this.node("echo");
254256
const text = this.text();
255257
const shortForm = text === "<?=" || text === "<%=";
256258
const expressions = this.next().read_list(this.read_expr, ",");
@@ -275,21 +277,22 @@ module.exports = {
275277
prevChar = "\r\n";
276278
}
277279
}
278-
result = this.node("inline");
280+
const result = this.node("inline");
279281
this.next();
280282
return result(value, fixFirstLine ? prevChar + value : value);
281283
}
282284

283-
case this.tok.T_UNSET:
284-
result = this.node("unset");
285+
case this.tok.T_UNSET: {
286+
const result = this.node("unset");
285287
this.next().expect("(") && this.next();
286288
const variables = this.read_list(this.read_variable, ",");
287289
this.expect(")") && this.next();
288290
this.expect(";") && this.next();
289291
return result(variables);
292+
}
290293

291294
case this.tok.T_DECLARE: {
292-
result = this.node("declare");
295+
const result = this.node("declare");
293296
const body = [];
294297
let mode;
295298
this.next().expect("(") && this.next();
@@ -325,20 +328,23 @@ module.exports = {
325328
case this.tok.T_TRY:
326329
return this.read_try();
327330

328-
case this.tok.T_THROW:
329-
result = this.node("throw");
330-
expr = this.next().read_expr();
331+
case this.tok.T_THROW: {
332+
const result = this.node("throw");
333+
const expr = this.next().read_expr();
331334
this.expectEndOfStatement();
332335
return result(expr);
336+
}
333337

334-
case ";": // ignore this (extra ponctuation)
338+
// ignore this (extra ponctuation)
339+
case ";": {
335340
this.next();
336341
return null;
342+
}
337343

338-
case this.tok.T_STRING:
339-
let result = this.node();
340-
current = [this.token, this.lexer.getState()];
341-
label = this.text();
344+
case this.tok.T_STRING: {
345+
const result = this.node();
346+
const current = [this.token, this.lexer.getState()];
347+
const label = this.text();
342348
// AST : https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L457
343349
if (this.next().token === ":") {
344350
this.next();
@@ -347,25 +353,28 @@ module.exports = {
347353

348354
// default fallback expr / T_STRING '::' (etc...)
349355
this.lexer.tokens.push(current);
350-
expr = this.next().read_expr();
356+
const expr = this.next().read_expr();
351357
this.expectEndOfStatement();
352358
return expr;
359+
}
353360

354-
case this.tok.T_GOTO:
355-
result = this.node("goto");
356-
label = null;
361+
case this.tok.T_GOTO: {
362+
const result = this.node("goto");
363+
let label = null;
357364
if (this.next().expect(this.tok.T_STRING)) {
358365
label = this.text();
359366
this.next().expectEndOfStatement();
360367
}
361368
return result(label);
369+
}
362370

363-
default:
371+
default: {
364372
// default fallback expr
365-
let statement = this.node("expressionstatement");
366-
expr = this.read_expr();
373+
const statement = this.node("expressionstatement");
374+
const expr = this.read_expr();
367375
this.expectEndOfStatement(expr);
368376
return statement(expr);
377+
}
369378
}
370379
},
371380
/**

src/parser/variable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ module.exports = {
175175
encapsed,
176176
dereferencable
177177
) {
178-
let name, node, offset;
178+
let node, offset;
179179
recursive_scan_loop: while (this.token != this.EOF) {
180180
switch (this.token) {
181181
case "(":

test/snapshot/__snapshots__/encapsed.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ exports[`encapsed variable curly (simple syntax) 1`] = `
296296
Program {
297297
"children": Array [
298298
Echo {
299-
"arguments": Array [
299+
"expressions": Array [
300300
Encapsed {
301301
"kind": "encapsed",
302302
"raw": "\\"string \${var} string\\"",

0 commit comments

Comments
 (0)