Skip to content

Commit 32c3f28

Browse files
committed
fix(language-core): correct codegen when src path does not match the generated length
1 parent cfdc74f commit 32c3f28

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

packages/language-core/lib/codegen/script/src.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Code, SfcBlockAttr } from '../../types';
22
import { codeFeatures } from '../codeFeatures';
3-
import { endOfLine, generateSfcBlockAttrValue } from '../utils';
3+
import { combineLastMapping, endOfLine } from '../utils';
4+
import { wrapWith } from '../utils/wrapWith';
45

56
export function* generateSrc(src: SfcBlockAttr): Generator<Code> {
67
if (src === true) {
@@ -23,10 +24,19 @@ export function* generateSrc(src: SfcBlockAttr): Generator<Code> {
2324
}
2425

2526
yield `export * from `;
26-
yield* generateSfcBlockAttrValue(src, text, {
27-
...codeFeatures.all,
28-
...text === src.text ? codeFeatures.navigation : codeFeatures.navigationWithoutRename,
29-
});
27+
yield* wrapWith(
28+
src.offset,
29+
src.offset + src.text.length,
30+
'main',
31+
{
32+
...codeFeatures.all,
33+
...text !== src.text ? codeFeatures.navigationWithoutRename : {},
34+
},
35+
`'`,
36+
[text.slice(0, src.text.length), 'main', src.offset, combineLastMapping],
37+
text.slice(src.text.length),
38+
`'`
39+
);
3040
yield endOfLine;
3141
yield `export { default } from '${text}'${endOfLine}`;
3242
}

packages/language-core/lib/codegen/utils/index.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as CompilerDOM from '@vue/compiler-dom';
22
import type * as ts from 'typescript';
3-
import type { Code, SfcBlock, SfcBlockAttr, VueCodeInformation } from '../../types';
3+
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
44
import { getNodeText } from '../../utils/shared';
55

66
export const newLine = `\n`;
@@ -82,23 +82,3 @@ export function generateSfcBlockSection(block: SfcBlock, start: number, end: num
8282
features,
8383
];
8484
}
85-
86-
export function* generateSfcBlockAttrValue(
87-
src: SfcBlockAttr & object,
88-
text: string,
89-
features: VueCodeInformation
90-
): Generator<Code> {
91-
const { offset, quotes } = src;
92-
if (!quotes) {
93-
yield [``, 'main', offset, { verification: true }];
94-
}
95-
yield [
96-
`'${text}'`,
97-
'main',
98-
quotes ? offset - 1 : offset,
99-
features
100-
];
101-
if (!quotes) {
102-
yield [``, 'main', offset + text.length, { __combineOffset: 2 }];
103-
}
104-
}

0 commit comments

Comments
 (0)