Skip to content

Commit

Permalink
fix: generic attr unexpectedly trimmed by formatting when includes "<"
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 1, 2023
1 parent 659331c commit 8b34cd0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vue-language-core/src/sourceFile.ts
Expand Up @@ -468,7 +468,7 @@ export class VueFile implements VirtualFile {

const newData: Sfc['template'] | null = block ? {
name: 'template',
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<'),
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<template'),
end: block.loc.end.offset + this.snapshot.getText(block.loc.end.offset, this.snapshot.getLength()).indexOf('>') + 1,
startTagEnd: block.loc.start.offset,
endTagStart: block.loc.end.offset,
Expand All @@ -488,7 +488,7 @@ export class VueFile implements VirtualFile {

const newData: Sfc['script'] | null = block ? {
name: 'script',
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<'),
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<script'),
end: block.loc.end.offset + this.snapshot.getText(block.loc.end.offset, this.snapshot.getLength()).indexOf('>') + 1,
startTagEnd: block.loc.start.offset,
endTagStart: block.loc.end.offset,
Expand All @@ -510,7 +510,7 @@ export class VueFile implements VirtualFile {

const newData: Sfc['scriptSetup'] | null = block ? {
name: 'scriptSetup',
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<'),
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<script'),
end: block.loc.end.offset + this.snapshot.getText(block.loc.end.offset, this.snapshot.getLength()).indexOf('>') + 1,
startTagEnd: block.loc.start.offset,
endTagStart: block.loc.end.offset,
Expand All @@ -534,7 +534,7 @@ export class VueFile implements VirtualFile {
const block = blocks[i];
const newData: Sfc['styles'][number] = {
name: 'style_' + i,
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<'),
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<style'),
end: block.loc.end.offset + this.snapshot.getText(block.loc.end.offset, this.snapshot.getLength()).indexOf('>') + 1,
startTagEnd: block.loc.start.offset,
endTagStart: block.loc.end.offset,
Expand Down
1 change: 1 addition & 0 deletions packages/vue-test-workspace/format/#3101/input.vue
@@ -0,0 +1 @@
<script lang="ts" setup generic="T extends Record<string, string>"></script>

This comment has been minimized.

Copy link
@rchl

rchl May 1, 2023

Collaborator

Maybe introduce some formatting issue in the input so that it also verifies that formatting does work at all?

1 change: 1 addition & 0 deletions packages/vue-test-workspace/format/#3101/output.vue
@@ -0,0 +1 @@
<script lang="ts" setup generic="T extends Record<string, string>"></script>

0 comments on commit 8b34cd0

Please sign in to comment.