Skip to content

Commit

Permalink
fix: don't remove comments when comment is in the first line (#3365)
Browse files Browse the repository at this point in the history
Co-authored-by: Johnson Chu <johnsoncodehk@gmail.com>
  • Loading branch information
so1ve and johnsoncodehk committed Jul 13, 2023
1 parent ea76b72 commit 960b29c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/vue-language-core/src/parsers/scriptSetupRanges.ts
Expand Up @@ -44,7 +44,14 @@ export function parseScriptSetupRanges(
// fix https://github.com/vuejs/language-tools/issues/1223
&& !ts.isImportEqualsDeclaration(node)
) {
importSectionEndOffset = node.getStart(ast, true);
const commentRagnes = ts.getLeadingCommentRanges(ast.getFullText(), node.getFullStart());
if (commentRagnes?.length) {
const commentRange = commentRagnes.sort((a, b) => a.pos - b.pos)[0];
importSectionEndOffset = commentRange.pos;
}
else {
importSectionEndOffset = node.getStart(ast);
}
foundNonImportExportNode = true;
}
});
Expand Down
@@ -0,0 +1,11 @@
<script setup lang="ts">
import { ref } from 'vue';
// @ts-ignore
let a: number = '';
const msg = ref('Hello World!');
</script>

<template>
<h1>{{ msg }}</h1>
</template>
@@ -0,0 +1,4 @@
<script setup lang="ts">
// @ts-ignore
let a: number = '';
</script>

0 comments on commit 960b29c

Please sign in to comment.