diff --git a/src/Leevel/View/Compiler.php b/src/Leevel/View/Compiler.php index f13e26672..8646b6572 100644 --- a/src/Leevel/View/Compiler.php +++ b/src/Leevel/View/Compiler.php @@ -52,63 +52,6 @@ class Compiler */ protected array $nodeMap = []; - /** - * js 风格支持的特殊别名映射. - */ - protected array $jsMap = []; - - /** - * js 风格标签. - */ - protected array $jsTag = [ - // required 属性不能为空,single 单标签 - 'if' => [ - 'attr' => [ - 'condition1', - ], - 'single' => false, - 'required' => [ - 'condition1', - ], - ], - 'elseif' => [ - 'attr' => [ - 'condition1', - ], - 'single' => true, - 'required' => [ - 'condition1', - ], - ], - 'else' => [ - 'attr' => [], - 'single' => true, - 'required' => [], - ], - 'let' => [ - 'attr' => [ - 'condition1', - ], - 'single' => true, - 'required' => [ - 'condition1', - ], - ], - 'for' => [ - 'attr' => [ - 'condition1', - 'condition2', - 'condition3', - ], - 'single' => false, - 'required' => [ - 'condition1', - 'condition2', - 'condition3', - ], - ], - ]; - /** * Node 标签. */ @@ -250,22 +193,12 @@ public function getCompilers(): array ], true)) { $type = strtolower(substr($method, -4)); $tag = substr($method, 0, -4); - if ('code' === $type) { $name = $this->codeMap[$tag] ?? $tag; } elseif ('node' === $type) { $name = $this->nodeMap[$tag] ?? $tag; - } else { - $type = strtolower(substr($method, -2)); - $tag = substr($method, 0, -2); - $name = $this->jsMap[$tag] ?? $tag; } - - $compilers[] = [ - $type, - $name, - $tag, - ]; + $compilers[] = [$type, $name, $tag]; } } @@ -280,14 +213,6 @@ public function getNodeTagHelp(): array return $this->nodeTag; } - /** - * js.tag. - */ - public function getJsTagHelp(): array - { - return $this->jsTag; - } - /** * 全局编译器(保护标签). */ @@ -487,108 +412,6 @@ public function endtagCodeCompiler(array &$theme): void $theme['content'] = $this->encodeContent($theme['content']); } - /** - * 变量及表达式. - */ - public function jsvarCompiler(array &$theme): void - { - $theme['content'] = $this->withPhpTag( - 'echo '.$this->parseJcontent($theme['content']).';' - ); - } - - /** - * let 编译器. - */ - public function letJsCompiler(array &$theme): void - { - $this->checkNode($theme, true); - $attr = $this->getNodeAttribute($theme); - $name = array_shift($attr); - $equal = array_shift($attr); - if ('=' !== $equal) { - array_unshift($attr, $equal); - } - - if (!$attr) { - $value = 'null'; - } else { - $value = $this->parseExpression(implode(' ', $attr)); - if ('' === $value) { - $value = 'null'; - } - } - - $theme['content'] = $this->withPhpTag("\${$name} = ".$value.';'); - } - - /** - * if 编译器. - */ - public function ifJsCompiler(array &$theme): void - { - $this->checkNode($theme, true); - $attr = $this->getNodeAttribute($theme); - $attr = $this->parseExpression(implode(' ', $attr)); - $theme['content'] = $this->withPhpTag("if ({$attr}):"); - $theme['content'] .= $this->getNodeBody($theme); - $theme['content'] .= $this->withPhpTag('endif;'); - } - - /** - * elseif 编译器. - */ - public function elseifJsCompiler(array &$theme): void - { - $this->checkNode($theme, true); - $attr = $this->getNodeAttribute($theme); - $attr = $this->parseExpression(implode(' ', $attr)); - $theme['content'] = $this->withPhpTag("elseif ({$attr}):"); - $theme['content'] .= $this->getNodeBody($theme); - } - - /** - * else. - */ - public function elseJsCompiler(array &$theme): void - { - $theme['content'] = $this->withPhpTag('else:'); - } - - /** - * for 循环. - * - * @throws \InvalidArgumentException - */ - public function forJsCompiler(array &$theme): void - { - $this->checkNode($theme, true); - $attr = $this->getNodeAttribute($theme); - $attr = array_values($attr); - if (!in_array('in', $attr, true)) { - $e = 'For tag need “in“ separate.'; - - throw new InvalidArgumentException($e); - } - - $key = 'key'; - $value = array_shift($attr); - if (false !== strpos($value, ',')) { - list($key, $value) = explode(',', $value); - } - - $next = array_shift($attr); - if ('in' !== $next) { - $key = $value; - $value = $next; - array_shift($attr); - } - $attr = $this->parseExpression(implode(' ', $attr)); - $theme['content'] = $this->withPhpTag("foreach ({$attr} as \${$key} => \${$value}):"); - $theme['content'] .= $this->getNodeBody($theme); - $theme['content'] .= $this->withPhpTag('endforeach;'); - } - /** * assign. */ @@ -860,25 +683,15 @@ public function attributeNodeCompiler(array &$theme): void { $source = trim($theme['content']); $source = $this->escapeRegexCharacter($source); - - if (true === $theme['is_js']) { - $tag = $this->jsTag; - } else { - $tag = $this->nodeTag; - } - + $tag = $this->nodeTag; $allowedAttr = $tag[$theme['parent_name']]['attr']; // 正则匹配 $regexp = []; - if (!$theme['is_js']) { - // xxx="yyy" 或 "yyy" 格式 - $regexp[] = '/(([^=\\s]+)=)?"([^"]+)"/'; - - // xxx='yyy' 或 'yyy' 格式 - $regexp[] = "/(([^=\\s]+)=)?'([^\\']+)'/"; - } - + // xxx="yyy" 或 "yyy" 格式 + $regexp[] = '/(([^=\\s]+)=)?"([^"]+)"/'; + // xxx='yyy' 或 'yyy' 格式 + $regexp[] = "/(([^=\\s]+)=)?'([^\\']+)'/"; // xxx=yyy 或 yyy 格式 $regexp[] = '/(([^=\\s]+)=)?([^\\s]+)/'; $nameIdx = 2; @@ -888,10 +701,11 @@ public function attributeNodeCompiler(array &$theme): void if (preg_match_all($item, $source, $res)) { foreach ($res[0] as $idx => $attribute) { $source = str_replace($attribute, '', $source); - $name = $res[$nameIdx][$idx]; - if (empty($name)) { + if (empty($res[$nameIdx][$idx])) { $defaultIdx++; $name = 'condition'.$defaultIdx; + } else { + $name = $res[$nameIdx][$idx]; } $value = $res[$valueIdx][$idx]; $value = $this->escapeRegexCharacter($value, false); @@ -933,128 +747,6 @@ protected function parseContentIf(string $content, ?string $type = null): string return $type."if ({$result})"; } - /** - * 解析 JS 变量内容. - */ - protected function parseJcontent(string $content): string - { - $var = explode('|', $content); - $content = (string) array_shift($var); - $content = $this->parseExpression($content); - if (count($var) > 0) { - return $this->parseJsFunction($content, $var); - } - - return $content; - } - - /** - * 解析表达式语法. - */ - protected function parseExpression(string $content): string - { - $content = trim($content); - $logic = [ - '+', - '-', - '.', - '(', - ')', - '/', - '%', - '*', - '?', - ':', - '<', - '>', - '=', - '|', - '&', - '~', - '!', - ]; - - $result = []; - - // 单逻辑 - $findLogic = false; - - for ($i = 0; $i < strlen($content); $i++) { - $temp = $content[$i]; - if (0 === $i && $this->isVarExpression($temp)) { - $result[] = '$'; - } - - if (in_array($temp, $logic, true)) { - // . 语法作为对象连接符 - if ('.' === $temp && - isset($content[$i + 1]) && - $this->isVarExpression($content[$i + 1]) && - !in_array($content[$i + 1], [' ', '$'], true)) { - $result[] = '->'; - $findLogic = false; - } - - // -> 语法原生对象连接符 - elseif ('>' === $temp && - $i > 0 && - '-' === $content[$i - 1] && - isset($content[$i + 1]) && - !in_array($content[$i + 1], [' ', '$'], true)) { - $result[] = '>'; - $findLogic = false; - } else { - $findLogic = true; - $result[] = $temp; - } - - continue; - } - - if (true === $findLogic && ' ' !== $temp) { - if ($this->isVarExpression($temp)) { - $result[] = '$'; - } - $findLogic = false; - } - - $result[] = $temp; - } - - $content = implode('', $result); - - // 还原函数去掉开头的美元符号 - $content = preg_replace_callback( - '/(\$+?[a-z0-9\\_]+?\\s*?)\\(.+?\\)/', - function ($match) { - return substr($match[0], 1); - }, - $content - ); - - return (string) $content; - } - - /** - * 是否为字符串表达式字符. - */ - protected function isVarExpression(string $char): bool - { - return !in_array($char, [ - '"', - '\'', - '(', - ], true) && !is_numeric($char); - } - - /** - * 解析 JS 风格函数. - */ - protected function parseJsFunction(string $name, array $var): string - { - return $this->parseVarFunction($name, $var, true); - } - /** * 解析变量内容. */ @@ -1105,7 +797,7 @@ protected function parseContent(string $content, bool $isFunc = true): string /** * 解析函数. */ - protected function parseVarFunction(string $name, array $var, bool $isJavascript = false): string + protected function parseVarFunction(string $name, array $var): string { $len = count($var); @@ -1117,7 +809,7 @@ protected function parseVarFunction(string $name, array $var, bool $isJavascript } $args[0] = trim($args[0]); - if (false === $isJavascript && isset($args[1])) { + if (isset($args[1])) { $args[1] = str_replace('->', ':', $args[1]); } @@ -1187,9 +879,10 @@ protected function encodeContent(string $content, string $type = ''): string * * @throws \InvalidArgumentException */ - protected function checkNode(array $theme, bool $jsNode = false): bool + protected function checkNode(array $theme): bool { $attribute = $theme['children'][0]; + // 验证标签的属性值 if (true !== $attribute['is_attribute']) { $e = 'Tag attribute type validation failed.'; @@ -1198,7 +891,7 @@ protected function checkNode(array $theme, bool $jsNode = false): bool } // 验证必要属性 - $tag = true === $jsNode ? $this->jsTag : $this->nodeTag; + $tag = $this->nodeTag; if (!isset($tag[$theme['name']])) { $e = sprintf('The tag %s is undefined.', $theme['name']); diff --git a/src/Leevel/View/Parser.php b/src/Leevel/View/Parser.php index df4e05349..8537a1e11 100644 --- a/src/Leevel/View/Parser.php +++ b/src/Leevel/View/Parser.php @@ -40,11 +40,6 @@ class Parser */ protected Stack $nodeStack; - /** - * js 风格 和 node 共用分析器. - */ - protected bool $jsNode = false; - /** * 编译器. */ @@ -66,16 +61,16 @@ class Parser ], // js 风格代码 - 'js' => [ - 'left' => '{%', - 'right' => '%}', - ], + // 'js' => [ + // 'left' => '{%', + // 'right' => '%}', + // ], // js 风格变量代码 - 'jsvar' => [ - 'left' => '{{', - 'right' => '}}', - ], + // 'jsvar' => [ + // 'left' => '{{', + // 'right' => '}}', + // ], // 代码 'code' => [ @@ -333,21 +328,11 @@ protected function codeParse(string &$compiled): void } } - /** - * js 风格分析器 与 node 公用分析器. - */ - protected function jsParse(string &$compiled): void - { - $this->jsNode = true; - $this->normalizeNodeParse($compiled); - } - /** * node 分析器. */ protected function nodeParse(string &$compiled): void { - $this->jsNode = false; $this->normalizeNodeParse($compiled); } @@ -424,7 +409,7 @@ protected function findNodeTag(string &$compiled): void $this->nodeStack = new Stack(['array']); // 判断是那种编译器 - $nodeType = true === $this->jsNode ? 'js' : 'node'; + $nodeType = 'node'; // 所有一级节点名 $names = []; @@ -435,9 +420,9 @@ protected function findNodeTag(string &$compiled): void $tag = $this->getTag($nodeType); $regex = "/{$tag['left']}\\s*(\\/?)(({$names})(:[^\\s". - (true === $this->jsNode ? '' : '\\>'). + ('\\>'). '\\}]+)?)(\\s[^'. - (true === $this->jsNode ? '' : '>'). + ('>'). "\\}]*?)?\\/?{$tag['right']}/isx"; // 标签名称位置 @@ -452,16 +437,11 @@ protected function findNodeTag(string &$compiled): void // 标签属性位置 $tagAttributeIndex = 5; - if (true === $this->jsNode) { - $compiler = $this->compilers['js']; - } else { - $compiler = $this->compilers['node']; - } + $compiler = $this->compilers['node']; // 依次创建标签对象 if (preg_match_all($regex, $compiled, $res)) { $startPos = 0; - foreach ($res[0] as $index => &$tagSource) { $nodeName = $res[$nodeNameIndex][$index]; $nodeTopName = $res[$nodeTopNameIndex][$index]; @@ -500,13 +480,8 @@ protected function findNodeTag(string &$compiled): void */ protected function packNode(string &$compiled): void { - if (true === $this->jsNode) { - $nodeTag = $this->compiler->getJsTagHelp(); - $compiler = 'Js'; - } else { - $nodeTag = $this->compiler->getNodeTagHelp(); - $compiler = 'Node'; - } + $nodeTag = $this->compiler->getNodeTagHelp(); + $compiler = 'Node'; // 尾标签栈 $tailStack = new Stack(['array']); @@ -598,7 +573,6 @@ protected function packNode(string &$compiled): void 'attribute_list' => [], 'is_attribute' => true, 'parent_name' => $themeNode['name'], - 'is_js' => $this->jsNode, ]; $themeAttr['position'] = $this->getPosition($compiled, $tag['source'], 0); @@ -627,7 +601,7 @@ protected function registerParser(string $tag): void } /** - * 注册编译器 code 和 node 编译器注册. + * 注册编译器. */ protected function registerCompiler(string $type, string $name, string $tag): void { @@ -640,7 +614,6 @@ protected function registerCompiler(string $type, string $name, string $tag): vo protected function compileThemeTree(): string { $cache = ''; - foreach ($this->themeTree as $theme) { $this->compileTheme($theme); $cache .= $theme['content']; diff --git a/tests/View/Compiler/CompilerAssignTest.php b/tests/View/Compiler/CompilerAssignTest.php index 0bfb1028d..23f8575f6 100644 --- a/tests/View/Compiler/CompilerAssignTest.php +++ b/tests/View/Compiler/CompilerAssignTest.php @@ -144,94 +144,4 @@ public function testNode4(): void $this->assertSame($compiled, $parser->doCompile($source, null, true)); } - - /** - * @api( - * zh-CN:title="JS 风格版本", - * zh-CN:description="", - * zh-CN:note="", - * ) - */ - public function testLet(): void - { - $parser = $this->createParser(); - - $source = <<<'eot' - {% let foo = 'foo' %} - {% let hello = hello . 'foo' %} - eot; - - $compiled = <<<'eot' - - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - - /** - * @api( - * zh-CN:title="JS 风格版本.初始化值", - * zh-CN:description="", - * zh-CN:note="", - * ) - */ - public function testLet2(): void - { - $parser = $this->createParser(); - - $source = <<<'eot' - {% let foo 'foo' %} - eot; - - $compiled = <<<'eot' - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - - /** - * @api( - * zh-CN:title="JS 风格版本.初始化为 Null 值", - * zh-CN:description="", - * zh-CN:note="", - * ) - */ - public function testLet3(): void - { - $parser = $this->createParser(); - - $source = <<<'eot' - {% let foo %} - eot; - - $compiled = <<<'eot' - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - - /** - * @api( - * zh-CN:title="JS 风格版本.初始化为 Null 值带上等于符", - * zh-CN:description="", - * zh-CN:note="", - * ) - */ - public function testLet4(): void - { - $parser = $this->createParser(); - - $source = <<<'eot' - {% let foo = %} - eot; - - $compiled = <<<'eot' - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } } diff --git a/tests/View/Compiler/CompilerForTest.php b/tests/View/Compiler/CompilerForTest.php index 62296c5cf..f5f45d929 100644 --- a/tests/View/Compiler/CompilerForTest.php +++ b/tests/View/Compiler/CompilerForTest.php @@ -110,118 +110,6 @@ public function testForNode2(): void $this->assertSame($compiled, $parser->doCompile($source, null, true)); } - /** - * @api( - * zh-CN:title="JS 风格版: 例 1", - * zh-CN:description="最终生成一个 foreach 结果,简单的循环。", - * zh-CN:note="", - * ) - */ - public function testForJsStyle(): void - { - $parser = $this->createParser(); - - $source = <<<'eot' - {% for item in navigation %} -
  • {{ item.caption }}
  • - {% /for %} - eot; - - $compiled = <<<'eot' - $item): ?> -
  • caption; ?>
  • - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - - /** - * @api( - * zh-CN:title="JS 风格版: 例 2", - * zh-CN:description="可以使用逗号分割建和值,逗号连接不能有空格。", - * zh-CN:note="", - * ) - */ - public function testForJsStyle2(): void - { - $parser = $this->createParser(); - - $source = <<<'eot' - {% for mykey,item in navigation %} -
  • {{ item.caption }}
  • - {% /for %} - eot; - - $compiled = <<<'eot' - $item): ?> -
  • caption; ?>
  • - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - - /** - * @api( - * zh-CN:title="JS 风格版: 例 3", - * zh-CN:description="可以使用空格分割建和值。", - * zh-CN:note="", - * ) - */ - public function testForJsStyle3(): void - { - $parser = $this->createParser(); - - $source = <<<'eot' - {% for mykey item in navigation %} -
  • {{ item.caption }}
  • - {% /for %} - eot; - - $compiled = <<<'eot' - $item): ?> -
  • caption; ?>
  • - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - - public function testForJsStyleException(): void - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage( - 'The node for lacks the required property: condition3.' - ); - - $parser = $this->createParser(); - - $source = <<<'eot' - {% for item navigation %} - {% /for %} - eot; - - $parser->doCompile($source, null, true); - } - - public function testForJsStyleException2(): void - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage( - 'For tag need “in“ separate.' - ); - - $parser = $this->createParser(); - - $source = <<<'eot' - {% for key item navigation %} - {% /for %} - eot; - - $parser->doCompile($source, null, true); - } - public function testForType(): void { $parser = $this->createParser(); diff --git a/tests/View/Compiler/CompilerIfTest.php b/tests/View/Compiler/CompilerIfTest.php index 496423b58..3db4d70b7 100644 --- a/tests/View/Compiler/CompilerIfTest.php +++ b/tests/View/Compiler/CompilerIfTest.php @@ -185,38 +185,4 @@ public function testNodeStyleSupportExpression(): void $this->assertSame($compiled, $parser->doCompile($source, null, true)); } - - /** - * @api( - * zh-CN:title="JS 语法流程控制", - * zh-CN:description="", - * zh-CN:note="", - * ) - */ - public function testJsStyle(): void - { - $parser = $this->createParser(); - - $source = <<<'eot' - {% if length(users) > 0 %} - a - {% elseif foo.bar > 0 %} - b - {% else %} - c - {% /if %} - eot; - - $compiled = <<<'eot' - 0): ?> - a - bar > 0): ?> - b - - c - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } } diff --git a/tests/View/Compiler/CompilerVarTest.php b/tests/View/Compiler/CompilerVarTest.php index 4611a73bf..715c60e24 100644 --- a/tests/View/Compiler/CompilerVarTest.php +++ b/tests/View/Compiler/CompilerVarTest.php @@ -56,29 +56,6 @@ public function testBaseUse(): void $this->assertSame($compiled, $parser->doCompile($source, null, true)); } - /** - * @api( - * zh-CN:title="JS 风格变量", - * zh-CN:description="", - * zh-CN:note="注意:“{{“ 与内容之间可以有空格,也可以没有,结果一样。", - * ) - */ - public function testJsStyle(): void - { - $parser = $this->createParser(); - - // JS 风格变量 - $source = <<<'eot' - {{ value }} - eot; - - $compiled = <<<'eot' - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - /** * @api( * zh-CN:title="输出一个数组", @@ -102,29 +79,6 @@ public function testArraySupport(): void $this->assertSame($compiled, $parser->doCompile($source, null, true)); } - /** - * @api( - * zh-CN:title="JS 风格输出一个数组", - * zh-CN:description="", - * zh-CN:note="", - * ) - */ - public function testJsStyleArraySupport(): void - { - $parser = $this->createParser(); - - // JS 风格数组支持 - $source = <<<'eot' - {{ value['test'] }} - eot; - - $compiled = <<<'eot' - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - /** * @api( * zh-CN:title="输出一个对象", @@ -148,38 +102,6 @@ public function testObject(): void $this->assertSame($compiled, $parser->doCompile($source, null, true)); } - /** - * @api( - * zh-CN:title="JS 风格输出一个对象", - * zh-CN:description="其中 `.` 是一个非常特殊的语法,如果中间没有空格将被解析为对象连接符,否则就是字符串连接符。", - * zh-CN:note="`.` 周围有空格表示变量", - * ) - */ - public function testJsStyleObject(): void - { - $parser = $this->createParser(); - - // JS 风格输出一个对象 - // . 周围有空格表示变量 - $source = <<<'eot' -
  • {{ item.caption }}
  • - eot; - - $source = <<<'eot' - {{ a.b }} - {{ a . b }} - {{ a->b }} - eot; - - $compiled = <<<'eot' - b; ?> - - b; ?> - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - /** * @api( * zh-CN:title="无限级支持", @@ -328,85 +250,6 @@ public function testOperator3(): void $this->assertSame($compiled, $parser->doCompile($source, null, true)); } - /** - * @api( - * zh-CN:title="JS 风格运算符.加减法运算", - * zh-CN:description="JS 风格的运算符也遵循这一个规则,需要注意的 `.` 语法有一定特殊性,周围 `是否有空格` 会影响到解析为 `->` 作为对象或者 `.` 作为连接符。", - * zh-CN:note="", - * ) - */ - public function testJsOperator(): void - { - $parser = $this->createParser(); - - // 变量之间的加减法运算 - $source = <<<'eot' - {{ value+value2 }} - {{ value-value2 }} - eot; - - $compiled = <<<'eot' - - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - - /** - * @api( - * zh-CN:title="JS 风格运算符.乘除余数", - * zh-CN:description="", - * zh-CN:note="", - * ) - */ - public function testJsOperator2(): void - { - $parser = $this->createParser(); - - // 变量之间的乘除余数 - $source = <<<'eot' - {{ value + 9 +10 }} - {{ value * value2 * 10 }} - {{ value / value2 }} - {{ value3+list['key'] }} - {{ value3%list['key'] }} - eot; - - $compiled = <<<'eot' - - - - - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - - /** - * @api( - * zh-CN:title="JS 风格运算符.连接字符", - * zh-CN:description="", - * zh-CN:note="", - * ) - */ - public function testJsOperator3(): void - { - $parser = $this->createParser(); - - // 变量之间的连接字符 - $source = <<<'eot' - {{ value3.'start - '. value. value2.'end' }} - eot; - - $compiled = <<<'eot' - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } - /** * @api( * zh-CN:title="函数支持", @@ -646,62 +489,4 @@ public function testFunction8(): void $this->assertSame($compiled, $parser->doCompile($source, null, true)); } - - /** - * @api( - * zh-CN:title="JS 风格函数支持", - * zh-CN:description="JS 风格函数和上面的函数支持得差不多。", - * zh-CN:note="", - * ) - */ - public function testJsFunction(): void - { - $parser = $this->createParser(); - - // 例 1 - $source = <<<'eot' - {{ var|escape }} - {{ var|e }} - eot; - - $compiled = <<<'eot' - - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - - // 例 2 - $source = <<<'eot' - {{ list|join=',' }} - eot; - - $compiled = <<<'eot' - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - - // 例 3 - $source = <<<'eot' - {{ data|convert_encoding='iso-2022-jp', 'UTF-8') }} - eot; - - $compiled = <<<'eot' - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - - // 例 4 - $source = <<<'eot' - {{ data|convert_encoding='iso-2022-jp', **, 'UTF-8') }} - eot; - - $compiled = <<<'eot' - - eot; - - $this->assertSame($compiled, $parser->doCompile($source, null, true)); - } }