Skip to content

Commit 2e043c5

Browse files
committed
glayzzle#41 - add node types on constants and properties
1 parent dcb0db3 commit 2e043c5

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

src/parser/class.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,17 @@ module.exports = {
192192
* </ebnf>
193193
*/
194194
,read_variable_declaration: function() {
195-
var varName = this.node(this.text());
196-
this.expect(this.tok.T_VARIABLE).next();
195+
var result = this.node('var');
196+
var name = this.expect(this.tok.T_VARIABLE).text();
197+
this.next();
197198
if (this.token === ';' || this.token === ',') {
198-
return varName(null);
199+
return result(name, null);
199200
} else if(this.token === '=') {
200201
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L815
201-
return varName(this.next().read_expr());
202+
return result(name, this.next().read_expr());
202203
} else {
203204
this.expect([',', ';', '=']);
204-
return varName(null);
205+
return result(name, null);
205206
}
206207
}
207208
/**
@@ -225,14 +226,10 @@ module.exports = {
225226
* </ebnf>
226227
*/
227228
,read_constant_declaration: function() {
228-
var name = this.node(this.text());
229-
var value = this.expect(this.tok.T_STRING)
230-
.next()
231-
.expect('=')
232-
.next()
233-
.read_expr()
234-
;
235-
return name(value);
229+
var result = this.node('const');
230+
var name = this.expect(this.tok.T_STRING).text();
231+
var value = this.next().expect('=').next().read_expr();
232+
return result(name, value);
236233
}
237234
/**
238235
* Read member flags

test/functional/commentTests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ describe('Test comments', function() {
9696
var body = ast[1][1][5];
9797
body.properties[0][0].should.be.exactly("comment");
9898
body.properties[0][1][0].should.be.exactly("// @var test\n");
99-
body.properties[0][2][0].should.be.exactly("$test");
99+
body.properties[0][2][1].should.be.exactly("$test");
100100

101101
body.properties[1][0].should.be.exactly("comment");
102-
body.properties[1][2][0].should.be.exactly("$toto");
102+
body.properties[1][2][1].should.be.exactly("$toto");
103103

104104
body.properties[2][0].should.be.exactly("doc")
105-
body.properties[2][2][0].should.be.exactly("$foo");
105+
body.properties[2][2][1].should.be.exactly("$foo");
106106

107107
body.methods[0][0].should.be.exactly("doc");
108108
body.methods[0][1].should.be.exactly("/**\n * @return void\n */");
109-
body.methods[0][2][0].should.be.exactly("function");
109+
body.methods[0][2][1].should.be.exactly("void");
110110
});
111111
});
112112

test/functional/gracefulTests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ describe('Test graceful mode', function() {
4949
ast[1][0][0].should.be.exactly('class');
5050
ast[1][0][1].should.be.exactly('foo');
5151
ast[1][0][5].constants.length.should.be.exactly(1);
52-
ast[1][0][5].constants[0][0].should.be.exactly('A');
53-
ast[1][0][5].constants[0][1][1].should.be.exactly('1');
52+
ast[1][0][5].constants[0][1].should.be.exactly('A');
53+
ast[1][0][5].constants[0][2][1].should.be.exactly('1');
5454

5555
});
5656

0 commit comments

Comments
 (0)