From 2010b5dd9f70941f03cdc695e9f420150cad0724 Mon Sep 17 00:00:00 2001 From: Shuhei Hayashibara Date: Sun, 5 Nov 2023 11:10:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20incorrect=20format=20when?= =?UTF-8?q?=20inline=20directive=20and=20endif=20exists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs: https://github.com/shufo/prettier-plugin-blade/issues/199. It occurs when inlined directive like `@php` followed by `@if` ~ `@endif` directive --- .../snapshots/inline_php_directive.snapshot | 18 ++++++++++++++++++ src/formatter.ts | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 __tests__/fixtures/snapshots/inline_php_directive.snapshot diff --git a/__tests__/fixtures/snapshots/inline_php_directive.snapshot b/__tests__/fixtures/snapshots/inline_php_directive.snapshot new file mode 100644 index 00000000..5663d335 --- /dev/null +++ b/__tests__/fixtures/snapshots/inline_php_directive.snapshot @@ -0,0 +1,18 @@ +------------------------------------options---------------------------------------- +{} +------------------------------------content---------------------------------------- +
+ + @if ($counter) + {{-- --}} + @endif + +
+------------------------------------expected---------------------------------------- +
+ + @if ($counter) + {{-- --}} + @endif + +
diff --git a/src/formatter.ts b/src/formatter.ts index 8438dcee..f08ab923 100644 --- a/src/formatter.ts +++ b/src/formatter.ts @@ -194,8 +194,8 @@ export default class Formatter { .then((target) => this.preserveRawBladeBrace(target)) .then((target) => this.preserveConditions(target)) .then((target) => this.preservePropsBlock(target)) - .then((target) => this.preserveInlineDirective(target)) .then((target) => this.preserveInlinePhpDirective(target)) + .then((target) => this.preserveInlineDirective(target)) .then((target) => this.preserveBladeDirectivesInScripts(target)) .then((target) => this.preserveBladeDirectivesInStyles(target)) .then((target) => this.preserveCustomDirective(target)) @@ -231,8 +231,8 @@ export default class Formatter { .then((target) => this.restoreCustomDirective(target)) .then((target) => this.restoreBladeDirectivesInStyles(target)) .then((target) => this.restoreBladeDirectivesInScripts(target)) - .then((target) => this.restoreInlinePhpDirective(target)) .then((target) => this.restoreInlineDirective(target)) + .then((target) => this.restoreInlinePhpDirective(target)) .then((target) => this.restoreConditions(target)) .then((target) => this.restoreRawBladeBrace(target)) .then((target) => this.restoreBladeBrace(target))