Skip to content

Commit cf18744

Browse files
committed
glayzzle#348 - disable byref on new tokens
1 parent 73a2f1f commit cf18744

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/parser/expr.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ module.exports = {
356356
let right;
357357
if (this.next().token == "&") {
358358
if (this.next().token === this.tok.T_NEW) {
359+
if (this.php7) {
360+
this.error();
361+
}
359362
right = this.read_new_expr();
360363
} else {
361364
right = this.read_variable(false, false, true);

test/snapshot/__snapshots__/new.test.js.snap

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`new #348 - byref usage deprecated 1`] = `
4+
Program {
5+
"children": Array [
6+
ExpressionStatement {
7+
"expression": Assign {
8+
"kind": "assign",
9+
"left": Variable {
10+
"byref": false,
11+
"curly": false,
12+
"kind": "variable",
13+
"name": "a",
14+
},
15+
"operator": "=",
16+
"right": New {
17+
"arguments": Array [],
18+
"kind": "new",
19+
"what": ClassReference {
20+
"kind": "classreference",
21+
"name": "Foo",
22+
"resolution": "uqn",
23+
},
24+
},
25+
},
26+
"kind": "expressionstatement",
27+
},
28+
],
29+
"errors": Array [
30+
Error {
31+
"expected": undefined,
32+
"kind": "error",
33+
"line": 1,
34+
"message": "Parse Error : syntax error, unexpected 'new' (T_NEW) on line 1",
35+
"token": "'new' (T_NEW)",
36+
},
37+
],
38+
"kind": "program",
39+
}
40+
`;
41+
342
exports[`new anonymous 1`] = `
443
Program {
544
"children": Array [

test/snapshot/new.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
const parser = require('../main');
22

33
describe("new", function() {
4+
it("#348 - byref usage deprecated", function() {
5+
expect(parser.parseEval('$a =& new Foo();', {
6+
parser: {
7+
suppressErrors: true
8+
}
9+
})).toMatchSnapshot();
10+
});
411
it("simple", function() {
512
expect(parser.parseEval('new Foo();')).toMatchSnapshot();
6-
});
13+
});
714
it("variable", function() {
815
expect(parser.parseEval('new $var;')).toMatchSnapshot();
916
});

0 commit comments

Comments
 (0)