Skip to content

Commit c5977d1

Browse files
authored
fix: valid_after_heredoc_73 missing the concatenation operator (#1156)
Sprinkled in some tests too.
1 parent a296eab commit c5977d1

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

src/lexer/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const valid_after_heredoc_73 = valid_after_heredoc.concat([
1616
"/",
1717
"=",
1818
"!",
19+
".",
1920
]);
2021

2122
module.exports = {

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

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,104 @@ c",
2727
}
2828
`;
2929

30+
exports[`nowdoc Flexible nowdoc syntax: concatenation right after nowdoc 1`] = `
31+
Program {
32+
"children": [
33+
Echo {
34+
"expressions": [
35+
Bin {
36+
"kind": "bin",
37+
"left": Encapsed {
38+
"kind": "encapsed",
39+
"label": "END",
40+
"raw": "<<<END
41+
42+
END",
43+
"type": "heredoc",
44+
"value": [
45+
EncapsedPart {
46+
"curly": false,
47+
"expression": String {
48+
"isDoubleQuote": false,
49+
"kind": "string",
50+
"raw": "
51+
",
52+
"unicode": false,
53+
"value": "",
54+
},
55+
"kind": "encapsedpart",
56+
"syntax": null,
57+
},
58+
],
59+
},
60+
"right": String {
61+
"isDoubleQuote": true,
62+
"kind": "string",
63+
"raw": """",
64+
"unicode": false,
65+
"value": "",
66+
},
67+
"type": ".",
68+
},
69+
],
70+
"kind": "echo",
71+
"shortForm": false,
72+
},
73+
],
74+
"errors": [],
75+
"kind": "program",
76+
}
77+
`;
78+
79+
exports[`nowdoc Flexible nowdoc syntax: equals right after nowdoc 1`] = `
80+
Program {
81+
"children": [
82+
Echo {
83+
"expressions": [
84+
Bin {
85+
"kind": "bin",
86+
"left": Encapsed {
87+
"kind": "encapsed",
88+
"label": "END",
89+
"raw": "<<<END
90+
91+
END",
92+
"type": "heredoc",
93+
"value": [
94+
EncapsedPart {
95+
"curly": false,
96+
"expression": String {
97+
"isDoubleQuote": false,
98+
"kind": "string",
99+
"raw": "
100+
",
101+
"unicode": false,
102+
"value": "",
103+
},
104+
"kind": "encapsedpart",
105+
"syntax": null,
106+
},
107+
],
108+
},
109+
"right": String {
110+
"isDoubleQuote": true,
111+
"kind": "string",
112+
"raw": """",
113+
"unicode": false,
114+
"value": "",
115+
},
116+
"type": "==",
117+
},
118+
],
119+
"kind": "echo",
120+
"shortForm": false,
121+
},
122+
],
123+
"errors": [],
124+
"kind": "program",
125+
}
126+
`;
127+
30128
exports[`nowdoc Flexible nowdoc syntax: with variables 1`] = `
31129
Program {
32130
"children": [

test/snapshot/nowdoc.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,38 @@ TEST;
120120
).toMatchSnapshot();
121121
});
122122

123+
it("Flexible nowdoc syntax: errors in PHP 7.2", function () {
124+
expect(() =>
125+
parser.parseEval(
126+
`
127+
echo <<<END
128+
129+
END."";`,
130+
{ parser: { version: "7.2" } },
131+
),
132+
).toThrow();
133+
});
134+
135+
it("Flexible nowdoc syntax: concatenation right after nowdoc", function () {
136+
expect(
137+
parser.parseEval(`
138+
echo <<<END
139+
140+
END."";
141+
`),
142+
).toMatchSnapshot();
143+
});
144+
145+
it("Flexible nowdoc syntax: equals right after nowdoc", function () {
146+
expect(
147+
parser.parseEval(`
148+
echo <<<END
149+
150+
END=="";
151+
`),
152+
).toMatchSnapshot();
153+
});
154+
123155
it("Flexible nowdoc syntax: 4 spaces of indentation", function () {
124156
expect(
125157
parser.parseEval(`

0 commit comments

Comments
 (0)