Skip to content

Commit

Permalink
Merge pull request #979 from shufo/fix/js-directive-support
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo authored Feb 3, 2025
2 parents 42259e8 + 08b67c6 commit ca81caa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions __tests__/formatter/js.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, test } from "vitest";
import * as util from "../support/util";

describe("formatter js test", () => {
test("basic @js directive usage", async () => {
const content = [`<div x-data="@js($data, JSON_FORCE_OBJECT)"></div>`].join(
"\n",
);

const expected = [
`<div x-data="@js($data, JSON_FORCE_OBJECT)"></div>`,
"",
].join("\n");

await util.doubleFormatCheck(content, expected);
});

test("@js directive in script tag", async () => {
const content = [
"<script>",
" @foreach ($files as $file)",
" addUpload(",
" @js($file->id),",
" @js($file->name),",
" @js($file->hash),",
" $('#article_inline_uploads')",
" );",
" @endforeach",
"</script>",
].join("\n");

const expected = [
"<script>",
" @foreach ($files as $file)",
" addUpload(",
" @js($file->id),",
" @js($file->name),",
" @js($file->hash),",
" $('#article_inline_uploads')",
" );",
" @endforeach",
"</script>",
"",
].join("\n");

await util.doubleFormatCheck(content, expected);
});
});
1 change: 1 addition & 0 deletions src/indent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const inlinePhpDirectives = [
export const inlineFunctionTokens = [
"@set",
"@json",
"@js",
"@selected",
"@checked",
"@disabled",
Expand Down

0 comments on commit ca81caa

Please sign in to comment.