Skip to content

Commit 32d28f0

Browse files
refactor: avoid quote property on nowdoc nodes
1 parent e7c162b commit 32d28f0

11 files changed

+193
-28
lines changed

src/ast/nowdoc.js

-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ const KIND = "nowdoc";
1414
* @extends {Literal}
1515
* @property {String} label
1616
* @property {String} raw
17-
* @property {Boolean} quote
1817
*/
1918
module.exports = Literal.extends(KIND, function Nowdoc(
2019
value,
2120
raw,
2221
label,
23-
quote,
2422
docs,
2523
location
2624
) {
2725
Literal.apply(this, [KIND, value, raw, docs, location]);
2826
this.label = label;
29-
this.quote = quote;
3027
});

src/parser/scalar.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ module.exports = {
108108
switch (this.token) {
109109
// NUMERIC
110110
case this.tok.T_LNUMBER: // long
111-
case this.tok.T_DNUMBER: { // double
111+
case this.tok.T_DNUMBER: {
112+
// double
112113
const result = this.node("number");
113114
value = this.text();
114115
this.next();
@@ -139,12 +140,7 @@ module.exports = {
139140
start,
140141
this.lexer.yylloc.first_offset
141142
);
142-
node = node(
143-
value,
144-
raw,
145-
this.lexer.heredoc_label,
146-
raw[3] === '"' || raw[3] === "'"
147-
);
143+
node = node(value, raw, this.lexer.heredoc_label);
148144
return node;
149145
} else {
150146
return this.read_encapsed_string(this.tok.T_END_HEREDOC);

test.php

-3
This file was deleted.

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

-1
Original file line numberDiff line numberDiff line change
@@ -7528,7 +7528,6 @@ BAR",
75287528
"offset": 3089,
75297529
},
75307530
},
7531-
"quote": true,
75327531
"raw": "<<<'BAR'
75337532
$foo + $bar
75347533
BAR

test/snapshot/__snapshots__/heredoc.test.js.snap

+88
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,94 @@ using heredoc syntax.
314314
}
315315
`;
316316

317+
exports[`heredoc space between <<< and label 1`] = `
318+
Program {
319+
"children": Array [
320+
Echo {
321+
"expressions": Array [
322+
Encapsed {
323+
"kind": "encapsed",
324+
"label": "TEST",
325+
"raw": "<<< TEST
326+
a
327+
b
328+
c
329+
TEST",
330+
"type": "heredoc",
331+
"value": Array [
332+
EncapsedPart {
333+
"curly": false,
334+
"expression": String {
335+
"isDoubleQuote": false,
336+
"kind": "string",
337+
"raw": " a
338+
b
339+
c
340+
",
341+
"unicode": false,
342+
"value": " a
343+
b
344+
c
345+
",
346+
},
347+
"kind": "encapsedpart",
348+
},
349+
],
350+
},
351+
],
352+
"kind": "echo",
353+
"shortForm": false,
354+
},
355+
],
356+
"errors": Array [],
357+
"kind": "program",
358+
}
359+
`;
360+
361+
exports[`heredoc tab between <<< and label 1`] = `
362+
Program {
363+
"children": Array [
364+
Echo {
365+
"expressions": Array [
366+
Encapsed {
367+
"kind": "encapsed",
368+
"label": "TEST",
369+
"raw": "<<< TEST
370+
a
371+
b
372+
c
373+
TEST",
374+
"type": "heredoc",
375+
"value": Array [
376+
EncapsedPart {
377+
"curly": false,
378+
"expression": String {
379+
"isDoubleQuote": false,
380+
"kind": "string",
381+
"raw": " a
382+
b
383+
c
384+
",
385+
"unicode": false,
386+
"value": " a
387+
b
388+
c
389+
",
390+
},
391+
"kind": "encapsedpart",
392+
},
393+
],
394+
},
395+
],
396+
"kind": "echo",
397+
"shortForm": false,
398+
},
399+
],
400+
"errors": Array [],
401+
"kind": "program",
402+
}
403+
`;
404+
317405
exports[`heredoc with double quotes 1`] = `
318406
Program {
319407
"children": Array [

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

-2
Original file line numberDiff line numberDiff line change
@@ -8105,7 +8105,6 @@ EOD;",
81058105
"offset": 0,
81068106
},
81078107
},
8108-
"quote": true,
81098108
"raw": "<<<'EOD'
81108109
Text
81118110
EOD",
@@ -8207,7 +8206,6 @@ EOD",
82078206
"offset": 7,
82088207
},
82098208
},
8210-
"quote": true,
82118209
"raw": "<<<'EOD'
82128210
Text
82138211
EOD",

test/snapshot/__snapshots__/nowdoc.test.js.snap

+54-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Program {
88
Nowdoc {
99
"kind": "nowdoc",
1010
"label": "TEST",
11-
"quote": true,
1211
"raw": "<<<'TEST'
1312
TEST",
1413
"value": "",
@@ -34,7 +33,6 @@ Program {
3433
Nowdoc {
3534
"kind": "nowdoc",
3635
"label": "EOD",
37-
"quote": true,
3836
"raw": "<<<'EOD'
3937
foobar!
4038
EOD
@@ -77,7 +75,6 @@ Program {
7775
"value": Nowdoc {
7876
"kind": "nowdoc",
7977
"label": "FOOBAR",
80-
"quote": true,
8178
"raw": "<<<'FOOBAR'
8279
Constant example
8380
FOOBAR",
@@ -101,7 +98,6 @@ FOOBAR",
10198
"value": Nowdoc {
10299
"kind": "nowdoc",
103100
"label": "FOOBAR",
104-
"quote": true,
105101
"raw": "<<<'FOOBAR'
106102
Property example
107103
FOOBAR",
@@ -143,7 +139,6 @@ Program {
143139
"defaultValue": Nowdoc {
144140
"kind": "nowdoc",
145141
"label": "LABEL",
146-
"quote": true,
147142
"raw": "<<<'LABEL'
148143
Nothing in here...
149144
LABEL",
@@ -184,7 +179,6 @@ Program {
184179
Nowdoc {
185180
"kind": "nowdoc",
186181
"label": "TEST",
187-
"quote": true,
188182
"raw": "<<<'TEST'
189183
190184
TEST",
@@ -208,7 +202,6 @@ Program {
208202
Nowdoc {
209203
"kind": "nowdoc",
210204
"label": "EOD",
211-
"quote": true,
212205
"raw": "<<<'EOD'
213206
Example of string
214207
spanning multiple lines
@@ -228,6 +221,60 @@ using heredoc syntax.",
228221
}
229222
`;
230223

224+
exports[`nowdoc space between <<< and label 1`] = `
225+
Program {
226+
"children": Array [
227+
Echo {
228+
"expressions": Array [
229+
Nowdoc {
230+
"kind": "nowdoc",
231+
"label": "TEST",
232+
"raw": "<<< 'TEST'
233+
a
234+
b
235+
c
236+
TEST",
237+
"value": " a
238+
b
239+
c",
240+
},
241+
],
242+
"kind": "echo",
243+
"shortForm": false,
244+
},
245+
],
246+
"errors": Array [],
247+
"kind": "program",
248+
}
249+
`;
250+
251+
exports[`nowdoc tab between <<< and label 1`] = `
252+
Program {
253+
"children": Array [
254+
Echo {
255+
"expressions": Array [
256+
Nowdoc {
257+
"kind": "nowdoc",
258+
"label": "TEST",
259+
"raw": "<<< 'TEST'
260+
a
261+
b
262+
c
263+
TEST",
264+
"value": " a
265+
b
266+
c",
267+
},
268+
],
269+
"kind": "echo",
270+
"shortForm": false,
271+
},
272+
],
273+
"errors": Array [],
274+
"kind": "program",
275+
}
276+
`;
277+
231278
exports[`nowdoc with space between <<< and label 1`] = `
232279
Program {
233280
"children": Array [
@@ -236,7 +283,6 @@ Program {
236283
Nowdoc {
237284
"kind": "nowdoc",
238285
"label": "EOD",
239-
"quote": false,
240286
"raw": "<<< 'EOD'
241287
Example of string
242288
spanning multiple lines
@@ -264,7 +310,6 @@ Program {
264310
Nowdoc {
265311
"kind": "nowdoc",
266312
"label": "EOT",
267-
"quote": true,
268313
"raw": "<<<'EOT'
269314
My name is \\"$name\\". I am printing some $foo->foo.
270315
Now, I am printing some {$foo->bar[1]}.

test/snapshot/__snapshots__/property.test.js.snap

-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,6 @@ Program {
758758
"value": Nowdoc {
759759
"kind": "nowdoc",
760760
"label": "EOD",
761-
"quote": true,
762761
"raw": "<<<'EOD'
763762
hello world
764763
EOD",

test/snapshot/__snapshots__/string.test.js.snap

-2
Original file line numberDiff line numberDiff line change
@@ -3125,7 +3125,6 @@ Program {
31253125
"right": Nowdoc {
31263126
"kind": "nowdoc",
31273127
"label": "EOF2",
3128-
"quote": true,
31293128
"raw": "<<<'EOF2'
31303129
FOO",
31313130
"value": "FOO",
@@ -3162,7 +3161,6 @@ Program {
31623161
"right": Nowdoc {
31633162
"kind": "nowdoc",
31643163
"label": "EOF",
3165-
"quote": true,
31663164
"raw": "<<<'EOF'
31673165
}
31683166
EOF",

test/snapshot/heredoc.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,30 @@ TEST;
103103
parser.parseEval(`
104104
echo <<<TEST
105105
106+
TEST;
107+
`)
108+
).toMatchSnapshot();
109+
});
110+
111+
it("space between <<< and label", function() {
112+
expect(
113+
parser.parseEval(`
114+
echo <<< TEST
115+
a
116+
b
117+
c
118+
TEST;
119+
`)
120+
).toMatchSnapshot();
121+
});
122+
123+
it("tab between <<< and label", function() {
124+
expect(
125+
parser.parseEval(`
126+
echo <<<\tTEST
127+
a
128+
b
129+
c
106130
TEST;
107131
`)
108132
).toMatchSnapshot();

test/snapshot/nowdoc.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ TEST;
9191
parser.parseEval(`
9292
echo <<<'TEST'
9393
94+
TEST;
95+
`)
96+
).toMatchSnapshot();
97+
});
98+
99+
it("space between <<< and label", function() {
100+
expect(
101+
parser.parseEval(`
102+
echo <<< 'TEST'
103+
a
104+
b
105+
c
106+
TEST;
107+
`)
108+
).toMatchSnapshot();
109+
});
110+
111+
it("tab between <<< and label", function() {
112+
expect(
113+
parser.parseEval(`
114+
echo <<<\t'TEST'
115+
a
116+
b
117+
c
94118
TEST;
95119
`)
96120
).toMatchSnapshot();

0 commit comments

Comments
 (0)