From 91cfd649f81c86735e4b604f1d137065e928fc14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Fri, 17 Jul 2020 07:43:38 +0200 Subject: [PATCH 1/2] Fix expression code output in template strings --- src/Compiler.php | 13 ++++++++----- .../binding-with-template-string-3.twig | 5 +++++ .../binding-with-template-string-3.vue | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tests/fixtures/vue-bind/binding-with-template-string-3.twig create mode 100644 tests/fixtures/vue-bind/binding-with-template-string-3.vue diff --git a/src/Compiler.php b/src/Compiler.php index dc447f5..4f7bd1b 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -387,11 +387,14 @@ private function handleAttributeBinding(DOMElement $node) */ $templateStringContent = $matches['content']; - $templateStringContent = preg_replace( - '/\$\{([^}]+)\}/', - '{{ $1 }}', - $templateStringContent - ); + preg_match_all('/\$\{([^}]+)\}/', $templateStringContent, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $templateStringContent = str_replace( + $match[0], + '{{ ' . $this->builder->refactorCondition($match[1]) . ' }}', + $templateStringContent + ); + } $dynamicValues[] = $templateStringContent; } else { diff --git a/tests/fixtures/vue-bind/binding-with-template-string-3.twig b/tests/fixtures/vue-bind/binding-with-template-string-3.twig new file mode 100644 index 0000000..014c950 --- /dev/null +++ b/tests/fixtures/vue-bind/binding-with-template-string-3.twig @@ -0,0 +1,5 @@ +
+
+ Hello World +
+
diff --git a/tests/fixtures/vue-bind/binding-with-template-string-3.vue b/tests/fixtures/vue-bind/binding-with-template-string-3.vue new file mode 100644 index 0000000..a9eccd8 --- /dev/null +++ b/tests/fixtures/vue-bind/binding-with-template-string-3.vue @@ -0,0 +1,18 @@ + + + From 856c5899785a868f4efc4f6cdb68a625e995c33e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Fri, 17 Jul 2020 08:49:24 +0200 Subject: [PATCH 2/2] Fix #47 src attributes --- src/Compiler.php | 2 +- src/Models/Replacements.php | 1 + tests/fixtures/vue-bind/bindings-src.twig | 3 +++ tests/fixtures/vue-bind/bindings-src.vue | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/vue-bind/bindings-src.twig create mode 100644 tests/fixtures/vue-bind/bindings-src.vue diff --git a/src/Compiler.php b/src/Compiler.php index 4f7bd1b..f71e3e5 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -407,7 +407,7 @@ private function handleAttributeBinding(DOMElement $node) } $node->setAttribute( - $name, + $name === 'src' ? Replacements::getSanitizedConstant('SRC_ATTRIBUTE_NAME') : $name, $this->implodeAttributeValue($name, $dynamicValues, $staticValues) ); } diff --git a/src/Models/Replacements.php b/src/Models/Replacements.php index d927cb2..01f8a7b 100644 --- a/src/Models/Replacements.php +++ b/src/Models/Replacements.php @@ -12,6 +12,7 @@ abstract class Replacements extends BasicEnum public const SMALLER = '<'; public const AMPERSAND = '&'; public const PIPE = '|'; + public const SRC_ATTRIBUTE_NAME = 'src'; /** * Removes all instances of replacements from target diff --git a/tests/fixtures/vue-bind/bindings-src.twig b/tests/fixtures/vue-bind/bindings-src.twig new file mode 100644 index 0000000..e22acc7 --- /dev/null +++ b/tests/fixtures/vue-bind/bindings-src.twig @@ -0,0 +1,3 @@ +
+ +
diff --git a/tests/fixtures/vue-bind/bindings-src.vue b/tests/fixtures/vue-bind/bindings-src.vue new file mode 100644 index 0000000..72e5d33 --- /dev/null +++ b/tests/fixtures/vue-bind/bindings-src.vue @@ -0,0 +1,5 @@ +