From 83d8b91c7fe1f5fd18bc9e17601aea7f4c222aea Mon Sep 17 00:00:00 2001 From: Toshiyuki Goto Date: Fri, 31 Jan 2020 08:58:08 +0900 Subject: [PATCH] Fix InlineHtml in control structures Fixes #309 --- src/Parser.php | 2 +- .../parser/InlineHtmlInControlStructures.php | 1 + .../InlineHtmlInControlStructures.php.diag | 1 + .../InlineHtmlInControlStructures.php.tree | 122 ++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 tests/cases/parser/InlineHtmlInControlStructures.php create mode 100644 tests/cases/parser/InlineHtmlInControlStructures.php.diag create mode 100644 tests/cases/parser/InlineHtmlInControlStructures.php.tree diff --git a/src/Parser.php b/src/Parser.php index a78f5aa2..f35dccf2 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -200,7 +200,7 @@ private function parseList($parentNode, int $listParseContext) { $nodeArray[] = $element; if ($element instanceof Node) { $element->parent = $parentNode; - if ($element instanceof InlineHtml && $element->echoStatement && $listParseContext === ParseContext::SourceElements) { + if ($element instanceof InlineHtml && $element->echoStatement) { $nodeArray[] = $element->echoStatement; $element->echoStatement->parent = $parentNode; $element->echoStatement = null; diff --git a/tests/cases/parser/InlineHtmlInControlStructures.php b/tests/cases/parser/InlineHtmlInControlStructures.php new file mode 100644 index 00000000..5187df27 --- /dev/null +++ b/tests/cases/parser/InlineHtmlInControlStructures.php @@ -0,0 +1 @@ + diff --git a/tests/cases/parser/InlineHtmlInControlStructures.php.diag b/tests/cases/parser/InlineHtmlInControlStructures.php.diag new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/tests/cases/parser/InlineHtmlInControlStructures.php.diag @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/cases/parser/InlineHtmlInControlStructures.php.tree b/tests/cases/parser/InlineHtmlInControlStructures.php.tree new file mode 100644 index 00000000..0d102096 --- /dev/null +++ b/tests/cases/parser/InlineHtmlInControlStructures.php.tree @@ -0,0 +1,122 @@ +{ + "SourceFileNode": { + "statementList": [ + { + "InlineHtml": { + "scriptSectionEndTag": null, + "text": null, + "scriptSectionStartTag": { + "kind": "ScriptSectionStartTag", + "textLength": 6 + } + } + }, + { + "IfStatementNode": { + "ifKeyword": { + "kind": "IfKeyword", + "textLength": 2 + }, + "openParen": { + "kind": "OpenParenToken", + "textLength": 1 + }, + "expression": { + "ReservedWord": { + "children": { + "kind": "TrueReservedWord", + "textLength": 4 + } + } + }, + "closeParen": { + "kind": "CloseParenToken", + "textLength": 1 + }, + "colon": { + "kind": "ColonToken", + "textLength": 1 + }, + "statements": [ + { + "InlineHtml": { + "scriptSectionEndTag": { + "kind": "ScriptSectionEndTag", + "textLength": 2 + }, + "text": null, + "scriptSectionStartTag": { + "kind": "ScriptSectionStartWithEchoTag", + "textLength": 3 + } + } + }, + { + "ExpressionStatement": { + "expression": { + "EchoExpression": { + "echoKeyword": null, + "expressions": { + "ExpressionList": { + "children": [ + { + "StringLiteral": { + "startQuote": null, + "children": { + "kind": "StringLiteralToken", + "textLength": 3 + }, + "endQuote": null + } + } + ] + } + } + } + }, + "semicolon": null + } + }, + { + "InlineHtml": { + "scriptSectionEndTag": { + "kind": "ScriptSectionEndTag", + "textLength": 2 + }, + "text": null, + "scriptSectionStartTag": { + "kind": "ScriptSectionStartTag", + "textLength": 6 + } + } + } + ], + "elseIfClauses": [], + "elseClause": null, + "endifKeyword": { + "kind": "EndIfKeyword", + "textLength": 5 + }, + "semicolon": { + "kind": "SemicolonToken", + "textLength": 1 + } + } + }, + { + "InlineHtml": { + "scriptSectionEndTag": { + "kind": "ScriptSectionEndTag", + "textLength": 3 + }, + "text": null, + "scriptSectionStartTag": null + } + } + ], + "endOfFileToken": { + "kind": "EndOfFileToken", + "textLength": 0 + } + } +} \ No newline at end of file