Skip to content

Commit

Permalink
fix: 🐛 unexpected result when wrap attributes min attrs option
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Jul 23, 2023
1 parent 900196d commit a7480c4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
59 changes: 59 additions & 0 deletions __tests__/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5140,4 +5140,63 @@ describe('formatter', () => {
wrapAttributes: 'force-expand-multiline',
});
});

test('script tag with wrapAttributesMinAttrs option', async () => {
const content = [
`@push('scripts')`,
` <script>`,
` $("#table-kategori").DataTable({});`,
` </script>`,
`@endpush`,
].join('\n');

const expected = [
`@push('scripts')`,
` <script>`,
` $("#table-kategori").DataTable({});`,
` </script>`,
`@endpush`,
``,
].join('\n');

await util.doubleFormatCheck(content, expected, {
wrapAttributesMinAttrs: 0,
wrapAttributes: 'force-expand-multiline',
});
});

test('nonnative script tag with wrapAttributesMinAttrs option', async () => {
const content = [
`@push('scripts')`,
` <script type="template">`,
` <div></div>`,
` </script>`,
`@endpush`,
].join('\n');

const expected = [
`@push('scripts')`,
` <script type="template">`,
` <div></div>`,
` </script>`,
`@endpush`,
``,
].join('\n');

await util.doubleFormatCheck(content, expected, {
wrapAttributesMinAttrs: 0,
wrapAttributes: 'force-expand-multiline',
});
});

test('content sensitive html tag with wrapAttributesMinAttrs option', async () => {
const content = [`<textarea>`, `foo`, `</textarea>`, `<pre>`, `bar`, `</pre>`].join('\n');

const expected = [`<textarea>`, `foo`, `</textarea>`, `<pre>`, `bar`, `</pre>`, ``].join('\n');

await util.doubleFormatCheck(content, expected, {
wrapAttributesMinAttrs: 0,
wrapAttributes: 'force-expand-multiline',
});
});
});
6 changes: 3 additions & 3 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,15 +1147,15 @@ export default class Formatter {
}

getNonnativeScriptPlaceholder(replace: string) {
return _.replace('<blade ___non_native_scripts_#___ />', '#', replace);
return _.replace('<blade___non_native_scripts_#___ />', '#', replace);
}

getScriptPlaceholder(replace: any) {
return _.replace('<blade ___scripts_#___ />', '#', replace);
return _.replace('<blade___scripts_#___ />', '#', replace);
}

getHtmlTagPlaceholder(replace: string) {
return _.replace('<blade ___html_tags_#___ />', '#', replace);
return _.replace('<blade___html_tags_#___ />', '#', replace);
}

getInlineCustomDirectivePlaceholder(replace: string) {
Expand Down
3 changes: 3 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ const escapeTags = [
'/\\* blade_comment_start \\*/',
'/\\* blade_comment_end \\*/',
'/\\*\\*\\*script_placeholder\\*\\*\\*/',
'blade___non_native_scripts_',
'blade___scripts_',
'blade___html_tags_',
'beautifyTag',
'@customdirective',
'@elsecustomdirective',
Expand Down

0 comments on commit a7480c4

Please sign in to comment.