Skip to content

Commit 97fff46

Browse files
committed
let top statements in T_DECLARE bodies
1 parent 26c187b commit 97fff46

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/parser/statement.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -279,22 +279,25 @@ module.exports = {
279279
if (this.token === ':') {
280280
this.nextWithComments();
281281
while(this.token != this.EOF && this.token !== this.tok.T_ENDDECLARE) {
282-
body.push(this.read_statement());
282+
// @todo : check declare_statement from php / not valid
283+
body.push(this.read_top_statement());
283284
}
284285
this.expect(this.tok.T_ENDDECLARE) && this.next();
285286
this.expectEndOfStatement();
286287
mode = this.ast.declare.MODE_SHORT;
287288
} else if (this.token === '{') {
288289
this.nextWithComments();
289290
while(this.token != this.EOF && this.token !== '}') {
290-
body.push(this.read_statement());
291+
// @todo : check declare_statement from php / not valid
292+
body.push(this.read_top_statement());
291293
}
292294
this.expect('}') && this.next();
293295
mode = this.ast.declare.MODE_BLOCK;
294296
} else {
295297
this.expect(';') && this.next();
296298
while(this.token != this.EOF && this.token !== this.tok.T_DECLARE) {
297-
body.push(this.read_statement());
299+
// @todo : check declare_statement from php / not valid
300+
body.push(this.read_top_statement());
298301
}
299302
mode = this.ast.declare.MODE_NONE;
300303
}

test/namespaceTest.js

+13
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,17 @@ describe('Test namespace statements', function() {
8282
nsKeyword.children[0].what.name.should.be.exactly('foo');
8383
// @todo : test second child
8484
});
85+
86+
it('should work with declare statement', function() {
87+
var ast = parser.parseEval([
88+
'declare(strict_types=1);',
89+
'namespace foo;',
90+
'class bar {}'
91+
].join('\n'), {
92+
parser: {
93+
debug: false
94+
}
95+
});
96+
// @todo : make assertions
97+
});
8598
});

0 commit comments

Comments
 (0)