Skip to content

Commit

Permalink
fix: 🐛 script does not format when type is module
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Jul 23, 2023
1 parent 1d96a63 commit 044fcd2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
69 changes: 69 additions & 0 deletions __tests__/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4245,6 +4245,75 @@ describe('formatter', () => {
await util.doubleFormatCheck(content, expected);
});

test('script tag with module type', async () => {
const content = [
`@push('scripts')`,
` <script type="module">`,
` $("#table-kategori").DataTable({`,
` processing: true,`,
` serverSide: true,ajax: "{{ route('kategori.list') }}",`,
` columns: [{data: "DT_RowIndex",`,
` name: "DT_RowIndex",orderable: false,searchable: false`,
` },`,
` { data: "nama",name: "nama"`,
` },`,
` {`,
` data: "jumlah_barang",`,
` name: "jumlah_barang"`,
` },`,
` {`,
` data: "created_at",`,
` name: "created_at"`,
` },`,
` {`,
` data: "action",`,
` name: "action"`,
` },`,
` ],`,
` });`,
` </script>`,
`@endpush`,
].join('\n');

const expected = [
`@push('scripts')`,
` <script type="module">`,
` $("#table-kategori").DataTable({`,
` processing: true,`,
` serverSide: true,`,
` ajax: "{{ route('kategori.list') }}",`,
` columns: [{`,
` data: "DT_RowIndex",`,
` name: "DT_RowIndex",`,
` orderable: false,`,
` searchable: false`,
` },`,
` {`,
` data: "nama",`,
` name: "nama"`,
` },`,
` {`,
` data: "jumlah_barang",`,
` name: "jumlah_barang"`,
` },`,
` {`,
` data: "created_at",`,
` name: "created_at"`,
` },`,
` {`,
` data: "action",`,
` name: "action"`,
` },`,
` ],`,
` });`,
` </script>`,
`@endpush`,
``,
].join('\n');

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

test('escaped quote in raw php directive #669', async () => {
const content = [
` @php`,
Expand Down
2 changes: 1 addition & 1 deletion src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ export default class Formatter {
async preserveNonnativeScripts(content: string) {
return _.replace(
content,
/<script[^>]*?type=(["'])(?!text\/javascript)[^\1]*?\1[^>]*?>.*?<\/script>/gis,
/<script[^>]*?type=(["'])(?!(text\/javascript|module))[^\1]*?\1[^>]*?>.*?<\/script>/gis,
(match: string) => this.storeNonnativeScripts(match),
);
}
Expand Down

0 comments on commit 044fcd2

Please sign in to comment.