From a10780ca0da545ab715b3bf054c9d5df9dc90d0d Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 29 Aug 2017 23:14:27 +0200 Subject: [PATCH] Handle Nop statement after brace-style namespace Fixes #412. --- CHANGELOG.md | 4 +++- lib/PhpParser/ParserAbstract.php | 1 + .../stmt/namespace/commentAfterNamespace.test | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/code/parser/stmt/namespace/commentAfterNamespace.test diff --git a/CHANGELOG.md b/CHANGELOG.md index 9870a95..649efd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ Version 3.1.1-dev ----------------- -Nothing yet. +### Fixed + +* Fixed syntax error on comment after brace-style namespace declaration. (#412) Version 3.1.0 (2017-07-28) -------------------------- diff --git a/lib/PhpParser/ParserAbstract.php b/lib/PhpParser/ParserAbstract.php index afc525d..e0f6e25 100644 --- a/lib/PhpParser/ParserAbstract.php +++ b/lib/PhpParser/ParserAbstract.php @@ -445,6 +445,7 @@ abstract class ParserAbstract implements Parser if ($stmt instanceof Node\Stmt\Namespace_) { $afterFirstNamespace = true; } elseif (!$stmt instanceof Node\Stmt\HaltCompiler + && !$stmt instanceof Node\Stmt\Nop && $afterFirstNamespace && !$hasErrored) { $this->emitError(new Error( 'No code may exist outside of namespace {}', $stmt->getAttributes())); diff --git a/test/code/parser/stmt/namespace/commentAfterNamespace.test b/test/code/parser/stmt/namespace/commentAfterNamespace.test new file mode 100644 index 0000000..3f379b7 --- /dev/null +++ b/test/code/parser/stmt/namespace/commentAfterNamespace.test @@ -0,0 +1,22 @@ +Trailing comment after braced namespace declaration +----- +