Skip to content

Commit 4584faf

Browse files
committed
fix(component-meta): read ast from sfc.script
1 parent 317b0cc commit 4584faf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/component-meta/lib/base.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,11 @@ ${commandLine.vueOptions.target < 3 ? vue2TypeHelpersCode : typeHelpersCode}
336336
? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts) : {})
337337
: {};
338338
const tsDefaults = !vueFile ? readTsComponentDefaultProps(
339-
componentPath.slice(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
340-
snapshot.getText(0, snapshot.getLength()),
339+
ts.createSourceFile(
340+
'/tmp.' + componentPath.slice(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
341+
snapshot.getText(0, snapshot.getLength()),
342+
ts.ScriptTarget.Latest
343+
),
341344
exportName,
342345
printer,
343346
ts
@@ -785,7 +788,7 @@ function readVueComponentDefaultProps(
785788
const sfc = root._sfc;
786789

787790
if (sfc.script) {
788-
const scriptResult = readTsComponentDefaultProps(sfc.script.lang, sfc.script.content, 'default', printer, ts);
791+
const scriptResult = readTsComponentDefaultProps(sfc.script.ast, 'default', printer, ts);
789792
for (const [key, value] of Object.entries(scriptResult)) {
790793
result[key] = value;
791794
}
@@ -794,14 +797,11 @@ function readVueComponentDefaultProps(
794797
}
795798

796799
function readTsComponentDefaultProps(
797-
lang: string,
798-
tsFileText: string,
800+
ast: ts.SourceFile,
799801
exportName: string,
800802
printer: ts.Printer | undefined,
801803
ts: typeof import('typescript')
802804
) {
803-
804-
const ast = ts.createSourceFile('/tmp.' + lang, tsFileText, ts.ScriptTarget.Latest);
805805
const props = getPropsNode();
806806

807807
if (props) {

0 commit comments

Comments
 (0)