Skip to content

fix: valid_after_heredoc_73 missing the concatenation operator #1156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lexer/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const valid_after_heredoc_73 = valid_after_heredoc.concat([
"/",
"=",
"!",
".",
]);

module.exports = {
Expand Down
98 changes: 98 additions & 0 deletions test/snapshot/__snapshots__/nowdoc.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,104 @@ c",
}
`;

exports[`nowdoc Flexible nowdoc syntax: concatenation right after nowdoc 1`] = `
Program {
"children": [
Echo {
"expressions": [
Bin {
"kind": "bin",
"left": Encapsed {
"kind": "encapsed",
"label": "END",
"raw": "<<<END

END",
"type": "heredoc",
"value": [
EncapsedPart {
"curly": false,
"expression": String {
"isDoubleQuote": false,
"kind": "string",
"raw": "
",
"unicode": false,
"value": "",
},
"kind": "encapsedpart",
"syntax": null,
},
],
},
"right": String {
"isDoubleQuote": true,
"kind": "string",
"raw": """",
"unicode": false,
"value": "",
},
"type": ".",
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": [],
"kind": "program",
}
`;

exports[`nowdoc Flexible nowdoc syntax: equals right after nowdoc 1`] = `
Program {
"children": [
Echo {
"expressions": [
Bin {
"kind": "bin",
"left": Encapsed {
"kind": "encapsed",
"label": "END",
"raw": "<<<END

END",
"type": "heredoc",
"value": [
EncapsedPart {
"curly": false,
"expression": String {
"isDoubleQuote": false,
"kind": "string",
"raw": "
",
"unicode": false,
"value": "",
},
"kind": "encapsedpart",
"syntax": null,
},
],
},
"right": String {
"isDoubleQuote": true,
"kind": "string",
"raw": """",
"unicode": false,
"value": "",
},
"type": "==",
},
],
"kind": "echo",
"shortForm": false,
},
],
"errors": [],
"kind": "program",
}
`;

exports[`nowdoc Flexible nowdoc syntax: with variables 1`] = `
Program {
"children": [
Expand Down
32 changes: 32 additions & 0 deletions test/snapshot/nowdoc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,38 @@ TEST;
).toMatchSnapshot();
});

it("Flexible nowdoc syntax: errors in PHP 7.2", function () {
expect(() =>
parser.parseEval(
`
echo <<<END

END."";`,
{ parser: { version: "7.2" } },
),
).toThrow();
});

it("Flexible nowdoc syntax: concatenation right after nowdoc", function () {
expect(
parser.parseEval(`
echo <<<END

END."";
`),
).toMatchSnapshot();
});

it("Flexible nowdoc syntax: equals right after nowdoc", function () {
expect(
parser.parseEval(`
echo <<<END

END=="";
`),
).toMatchSnapshot();
});

it("Flexible nowdoc syntax: 4 spaces of indentation", function () {
expect(
parser.parseEval(`
Expand Down
Loading