Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/parser/expr.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ module.exports = {
let result = this.read_namespace_name(true);
if (this.token === this.tok.T_DOUBLE_COLON) {
result = this.read_static_getter(result);
return this.recursive_variable_chain_scan(result, true, false);
}
return result;
} else if (this.is("VARIABLE")) {
Expand Down
151 changes: 151 additions & 0 deletions test/snapshot/__snapshots__/new.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,157 @@ Program {
}
`;

exports[`new #1177 - explicit parens equivalent 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": New {
"arguments": [],
"kind": "new",
"what": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "baz",
},
"what": StaticLookup {
"kind": "staticlookup",
"offset": Variable {
"curly": false,
"kind": "variable",
"name": "bar",
},
"what": Name {
"kind": "name",
"name": "Foo",
"resolution": "uqn",
},
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`new #1177 - longer chain 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": New {
"arguments": [],
"kind": "new",
"what": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "qux",
},
"what": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "baz",
},
"what": StaticLookup {
"kind": "staticlookup",
"offset": Variable {
"curly": false,
"kind": "variable",
"name": "bar",
},
"what": Name {
"kind": "name",
"name": "Foo",
"resolution": "uqn",
},
},
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`new #1177 - nullsafe operator in chain 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": New {
"arguments": [],
"kind": "new",
"what": NullSafePropertyLookup {
"kind": "nullsafepropertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "baz",
},
"what": StaticLookup {
"kind": "staticlookup",
"offset": Variable {
"curly": false,
"kind": "variable",
"name": "bar",
},
"what": Name {
"kind": "name",
"name": "Foo",
"resolution": "uqn",
},
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`new #1177 - static property chain as class name 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": New {
"arguments": [],
"kind": "new",
"what": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "baz",
},
"what": StaticLookup {
"kind": "staticlookup",
"offset": Variable {
"curly": false,
"kind": "variable",
"name": "bar",
},
"what": Name {
"kind": "name",
"name": "Foo",
"resolution": "uqn",
},
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`new anonymous 1`] = `
Program {
"children": [
Expand Down
12 changes: 12 additions & 0 deletions test/snapshot/new.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,16 @@ describe("new", function () {
it("result from function with arguments", function () {
expect(parser.parseEval("$a = new (b('c')('d'))('e');")).toMatchSnapshot();
});
it("#1177 - static property chain as class name", function () {
expect(parser.parseEval("new Foo::$bar->baz();")).toMatchSnapshot();
});
it("#1177 - explicit parens equivalent", function () {
expect(parser.parseEval("new (Foo::$bar->baz)();")).toMatchSnapshot();
});
it("#1177 - nullsafe operator in chain", function () {
expect(parser.parseEval("new Foo::$bar?->baz();")).toMatchSnapshot();
});
it("#1177 - longer chain", function () {
expect(parser.parseEval("new Foo::$bar->baz->qux();")).toMatchSnapshot();
});
});
Loading