Skip to content

Commit 195e937

Browse files
committed
Made static lookup on property more robust
1 parent 208d8cf commit 195e937

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/parser/variable.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,23 @@ module.exports = {
127127
result = node(result, offset);
128128
break;
129129
case this.tok.T_DOUBLE_COLON:
130-
result = this.read_static_getter(result, encapsed);
130+
var node = this.node('staticlookup'), offset;
131+
this.next();
132+
133+
if(this.is('IDENTIFIER') || this.token === this.tok.T_STRING
134+
|| this.token === this.tok.T_CLASS
135+
) {
136+
offset = this.node('constref');
137+
var name = this.text();
138+
this.next();
139+
offset = offset(name);
140+
141+
if(this.token === this.tok.T_OBJECT_OPERATOR || this.token === this.tok.T_DOUBLE_COLON) {
142+
this.error();
143+
}
144+
}
145+
146+
result = node(result, offset);
131147
break;
132148
case this.tok.T_OBJECT_OPERATOR:
133149
var node = this.node('propertylookup');

test/variableTests.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Test variables', function() {
4949
'foo::class;',
5050
'$this->foo();',
5151
'foo::$bar;',
52-
'$this->foo::bar'
52+
'$this->foo::bar["baz"]::qux();'
5353
].join('\n'), {
5454
parser: {
5555
// debug: true
@@ -105,14 +105,29 @@ describe('Test variables', function() {
105105
expr.offset.kind.should.be.exactly('variable');
106106
expr.offset.name.should.be.exactly('bar');
107107
});
108-
it('should be $this->foo::bar', function() {
108+
it('should be $this->foo::bar["baz"]::qux();', function() {
109109
var expr = ast.children[6];
110-
expr.kind.should.be.exactly('staticlookup');
111-
expr.what.kind.should.be.exactly('propertylookup');
112-
expr.what.what.kind.should.be.exactly('variable');
113-
expr.what.what.name.should.be.exactly('this');
114-
expr.what.offset.name.should.be.exactly('foo');
115-
expr.offset.name.should.be.exactly('bar');
110+
111+
expr.kind.should.be.exactly("call");
112+
expr.arguments.length.should.be.exactly(0);
113+
114+
expr.what.kind.should.be.exactly("staticlookup");
115+
expr.what.offset.kind.should.be.exactly("constref");
116+
expr.what.offset.name.should.be.exactly("qux");
117+
118+
expr.what.what.kind.should.be.exactly("offsetlookup");
119+
expr.what.what.offset.kind.should.be.exactly("string");
120+
expr.what.what.offset.value.should.be.exactly("baz");
121+
122+
expr.what.what.what.kind.should.be.exactly("staticlookup");
123+
expr.what.what.what.offset.kind.should.be.exactly("constref");
124+
expr.what.what.what.offset.name.should.be.exactly("bar");
125+
126+
expr.what.what.what.what.kind.should.be.exactly("propertylookup");
127+
expr.what.what.what.what.what.kind.should.be.exactly("variable");
128+
expr.what.what.what.what.what.name.should.be.exactly("this");
129+
expr.what.what.what.what.offset.kind.should.be.exactly("constref");
130+
expr.what.what.what.what.offset.name.should.be.exactly("foo");
116131
});
117132
});
118133

0 commit comments

Comments
 (0)