Skip to content

Commit 1e0a01d

Browse files
committed
fix lexer state on ST_LOOKING_FOR_PROPERTY
1 parent 97fff46 commit 1e0a01d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/lexer/property.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
this.unput(1);
1515
} else if (this.is_LABEL_START()) {
1616
this.consume_LABEL();
17+
this.popState();
1718
return this.tok.T_STRING;
1819
}
1920
this.popState();

test/stringTests.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,24 @@ describe('Test strings', function() {
3030
it('...', function() {
3131
var ast = parser.parseEval('echo "~\'.{{$expectedLength}}\'\\$~s";');
3232
});
33-
it('...', function() {
34-
var ast = parser.parseEval('echo "Hello \\"$obj->name\\" !";');
33+
it('test encapsed variable', function() {
34+
var ast = parser.parseEval([
35+
'echo "Hello $obj->name !";',
36+
'echo "Hello $obj->foo->bar !";',
37+
'echo "Hello $obj[1]->foo !";'
38+
].join('\n'));
39+
40+
ast.children[0].arguments[0].kind.should.be.exactly('encapsed');
41+
ast.children[0].arguments[0].value[0].value.should.be.exactly('Hello ');
42+
ast.children[0].arguments[0].value[2].value.should.be.exactly(' !');
43+
44+
ast.children[1].arguments[0].kind.should.be.exactly('encapsed');
45+
ast.children[1].arguments[0].value[0].value.should.be.exactly('Hello ');
46+
ast.children[1].arguments[0].value[2].value.should.be.exactly('->bar !');
47+
48+
ast.children[2].arguments[0].kind.should.be.exactly('encapsed');
49+
ast.children[2].arguments[0].value[0].value.should.be.exactly('Hello ');
50+
ast.children[2].arguments[0].value[2].value.should.be.exactly('->foo !');
3551
});
3652
it('...', function() {
3753
var ast = parser.parseEval('echo "Hello {".$obj->name."} !";');

0 commit comments

Comments
 (0)