Skip to content

Commit

Permalink
fix(component-meta): read ast from sfc.script
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Feb 11, 2025
1 parent 317b0cc commit 4584faf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/component-meta/lib/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,11 @@ ${commandLine.vueOptions.target < 3 ? vue2TypeHelpersCode : typeHelpersCode}
? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts) : {})
: {};
const tsDefaults = !vueFile ? readTsComponentDefaultProps(
componentPath.slice(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
snapshot.getText(0, snapshot.getLength()),
ts.createSourceFile(
'/tmp.' + componentPath.slice(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
snapshot.getText(0, snapshot.getLength()),
ts.ScriptTarget.Latest
),
exportName,
printer,
ts
Expand Down Expand Up @@ -785,7 +788,7 @@ function readVueComponentDefaultProps(
const sfc = root._sfc;

if (sfc.script) {
const scriptResult = readTsComponentDefaultProps(sfc.script.lang, sfc.script.content, 'default', printer, ts);
const scriptResult = readTsComponentDefaultProps(sfc.script.ast, 'default', printer, ts);
for (const [key, value] of Object.entries(scriptResult)) {
result[key] = value;
}
Expand All @@ -794,14 +797,11 @@ function readVueComponentDefaultProps(
}

function readTsComponentDefaultProps(
lang: string,
tsFileText: string,
ast: ts.SourceFile,
exportName: string,
printer: ts.Printer | undefined,
ts: typeof import('typescript')
) {

const ast = ts.createSourceFile('/tmp.' + lang, tsFileText, ts.ScriptTarget.Latest);
const props = getPropsNode();

if (props) {
Expand Down

0 comments on commit 4584faf

Please sign in to comment.