Skip to content

Commit cd22a28

Browse files
authored
Fix: fix script-indent to prevent removing <script> tag (fixes #367) (#374)
1 parent 7c4a1d2 commit cd22a28

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: lib/utils/indent-common.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,16 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
631631
*/
632632
function validateCore (token, expectedIndent, optionalExpectedIndent) {
633633
const line = token.loc.start.line
634-
const actualIndent = token.loc.start.column
635634
const indentText = getIndentText(token)
635+
636+
// If there is no line terminator after the `<script>` start tag,
637+
// `indentText` contains non-whitespace characters.
638+
// In that case, do nothing in order to prevent removing the `<script>` tag.
639+
if (indentText.trim() !== '') {
640+
return
641+
}
642+
643+
const actualIndent = token.loc.start.column
636644
const unit = (options.indentChar === '\t' ? 'tab' : 'space')
637645

638646
for (let i = 0; i < indentText.length; ++i) {

Diff for: tests/fixtures/script-indent/no-linebreak-script.vue

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!--{}-->
2+
<script>var a
3+
</script>

0 commit comments

Comments
 (0)