From 31da25c5a426b09126b8562e0fc21fb30686e56c Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 15 Nov 2021 10:02:20 -0500 Subject: [PATCH] [8.x] Introduce `@js()` directive (#39522) * [8.x] Introduce `@js()` directive * Update CompilesJs.php * Update to match new name Co-authored-by: Taylor Otwell --- .../View/Compilers/BladeCompiler.php | 1 + .../View/Compilers/Concerns/CompilesJs.php | 22 ++++++++++++++ ...portJsStringTest.php => SupportJsTest.php} | 2 +- tests/View/Blade/BladeJsTest.php | 30 +++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/Illuminate/View/Compilers/Concerns/CompilesJs.php rename tests/Support/{SupportJsStringTest.php => SupportJsTest.php} (98%) create mode 100644 tests/View/Blade/BladeJsTest.php diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index b805126ee69f..54751435215b 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -20,6 +20,7 @@ class BladeCompiler extends Compiler implements CompilerInterface Concerns\CompilesIncludes, Concerns\CompilesInjections, Concerns\CompilesJson, + Concerns\CompilesJs, Concerns\CompilesLayouts, Concerns\CompilesLoops, Concerns\CompilesRawPhp, diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesJs.php b/src/Illuminate/View/Compilers/Concerns/CompilesJs.php new file mode 100644 index 000000000000..3104057dfc52 --- /dev/null +++ b/src/Illuminate/View/Compilers/Concerns/CompilesJs.php @@ -0,0 +1,22 @@ +toHtml() ?>", + Js::class, $this->stripParentheses($expression) + ); + } +} diff --git a/tests/Support/SupportJsStringTest.php b/tests/Support/SupportJsTest.php similarity index 98% rename from tests/Support/SupportJsStringTest.php rename to tests/Support/SupportJsTest.php index dfce3c458b62..3b19e9721662 100644 --- a/tests/Support/SupportJsStringTest.php +++ b/tests/Support/SupportJsTest.php @@ -8,7 +8,7 @@ use JsonSerializable; use PHPUnit\Framework\TestCase; -class SupportJsStringTest extends TestCase +class SupportJsTest extends TestCase { public function testScalars() { diff --git a/tests/View/Blade/BladeJsTest.php b/tests/View/Blade/BladeJsTest.php new file mode 100644 index 000000000000..be63c8f19e3b --- /dev/null +++ b/tests/View/Blade/BladeJsTest.php @@ -0,0 +1,30 @@ +'; + $expected = '
'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + + public function testJsonFlagsCanBeSet() + { + $string = '
'; + $expected = '
'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + + public function testEncodingDepthCanBeSet() + { + $string = '
'; + $expected = '
'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } +}