Skip to content

Commit f02fea4

Browse files
committed
#511 - "const" into classconstant node
1 parent 262c848 commit f02fea4

File tree

4 files changed

+137
-5
lines changed

4 files changed

+137
-5
lines changed

src/parser/class.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ module.exports = {
178178
* ```
179179
*/
180180
read_constant_list: function(flags) {
181+
const result = this.node("classconstant");
181182
if (this.expect(this.tok.T_CONST)) {
182183
this.next();
183184
}
184-
const result = this.node("classconstant");
185185
const items = this.read_list(
186186
/**
187187
* Reads a constant declaration

test/snapshot/__snapshots__/acid.test.js.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -816,11 +816,11 @@ Program {
816816
"line": 31,
817817
"offset": 561,
818818
},
819-
"source": "FOOBAR = 'BARFOO'",
819+
"source": "const FOOBAR = 'BARFOO'",
820820
"start": Position {
821-
"column": 10,
821+
"column": 4,
822822
"line": 31,
823-
"offset": 544,
823+
"offset": 538,
824824
},
825825
},
826826
"visibility": "",

test/snapshot/__snapshots__/location.test.js.snap

+131
Original file line numberDiff line numberDiff line change
@@ -10972,6 +10972,137 @@ Program {
1097210972
}
1097310973
`;
1097410974
10975+
exports[`Test locations test start location for class constants 1`] = `
10976+
Program {
10977+
"children": Array [
10978+
Class {
10979+
"body": Array [
10980+
ClassConstant {
10981+
"constants": Array [
10982+
Constant {
10983+
"kind": "constant",
10984+
"loc": Location {
10985+
"end": Position {
10986+
"column": 25,
10987+
"line": 1,
10988+
"offset": 25,
10989+
},
10990+
"source": "bar = 1",
10991+
"start": Position {
10992+
"column": 18,
10993+
"line": 1,
10994+
"offset": 18,
10995+
},
10996+
},
10997+
"name": Identifier {
10998+
"kind": "identifier",
10999+
"loc": Location {
11000+
"end": Position {
11001+
"column": 21,
11002+
"line": 1,
11003+
"offset": 21,
11004+
},
11005+
"source": "bar",
11006+
"start": Position {
11007+
"column": 18,
11008+
"line": 1,
11009+
"offset": 18,
11010+
},
11011+
},
11012+
"name": "bar",
11013+
},
11014+
"value": Number {
11015+
"kind": "number",
11016+
"loc": Location {
11017+
"end": Position {
11018+
"column": 25,
11019+
"line": 1,
11020+
"offset": 25,
11021+
},
11022+
"source": "1",
11023+
"start": Position {
11024+
"column": 24,
11025+
"line": 1,
11026+
"offset": 24,
11027+
},
11028+
},
11029+
"value": "1",
11030+
},
11031+
},
11032+
],
11033+
"kind": "classconstant",
11034+
"loc": Location {
11035+
"end": Position {
11036+
"column": 25,
11037+
"line": 1,
11038+
"offset": 25,
11039+
},
11040+
"source": "const bar = 1",
11041+
"start": Position {
11042+
"column": 12,
11043+
"line": 1,
11044+
"offset": 12,
11045+
},
11046+
},
11047+
"visibility": "",
11048+
},
11049+
],
11050+
"extends": null,
11051+
"implements": null,
11052+
"isAbstract": false,
11053+
"isAnonymous": false,
11054+
"isFinal": false,
11055+
"kind": "class",
11056+
"loc": Location {
11057+
"end": Position {
11058+
"column": 28,
11059+
"line": 1,
11060+
"offset": 28,
11061+
},
11062+
"source": "class foo { const bar = 1; }",
11063+
"start": Position {
11064+
"column": 0,
11065+
"line": 1,
11066+
"offset": 0,
11067+
},
11068+
},
11069+
"name": Identifier {
11070+
"kind": "identifier",
11071+
"loc": Location {
11072+
"end": Position {
11073+
"column": 9,
11074+
"line": 1,
11075+
"offset": 9,
11076+
},
11077+
"source": "foo",
11078+
"start": Position {
11079+
"column": 6,
11080+
"line": 1,
11081+
"offset": 6,
11082+
},
11083+
},
11084+
"name": "foo",
11085+
},
11086+
},
11087+
],
11088+
"errors": Array [],
11089+
"kind": "program",
11090+
"loc": Location {
11091+
"end": Position {
11092+
"column": 28,
11093+
"line": 1,
11094+
"offset": 28,
11095+
},
11096+
"source": "class foo { const bar = 1; }",
11097+
"start": Position {
11098+
"column": 0,
11099+
"line": 1,
11100+
"offset": 0,
11101+
},
11102+
},
11103+
}
11104+
`;
11105+
1097511106
exports[`Test locations test static 1`] = `
1097611107
Program {
1097711108
"children": Array [

test/snapshot/location.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ string";`
207207
`
208208
],
209209
["assign []", `$var[] = $var`],
210-
["single call", `call();`]
210+
["single call", `call();`],
211+
["start location for class constants", "class foo { const bar = 1; }"]
211212
])("test %s", (_, code) => {
212213
expect(
213214
parser.parseEval(code, {

0 commit comments

Comments
 (0)