vue-component-meta 2.2.0 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/base.js +39 -29
- package/package.json +6 -6
package/lib/base.js
CHANGED
|
@@ -99,8 +99,8 @@ function baseCreate(ts, getCommandLine, checkerOptions, rootPath, globalComponen
|
|
|
99
99
|
const directoryExists = languageServiceHost.directoryExists?.bind(languageServiceHost);
|
|
100
100
|
const fileExists = languageServiceHost.fileExists.bind(languageServiceHost);
|
|
101
101
|
const getScriptSnapshot = languageServiceHost.getScriptSnapshot.bind(languageServiceHost);
|
|
102
|
-
const globalTypesName =
|
|
103
|
-
const globalTypesContents = `// @ts-nocheck\nexport {};\n` + vue.generateGlobalTypes(commandLine.vueOptions
|
|
102
|
+
const globalTypesName = vue.getGlobalTypesFileName(commandLine.vueOptions);
|
|
103
|
+
const globalTypesContents = `// @ts-nocheck\nexport {};\n` + vue.generateGlobalTypes(commandLine.vueOptions);
|
|
104
104
|
const globalTypesSnapshot = {
|
|
105
105
|
getText: (start, end) => globalTypesContents.slice(start, end),
|
|
106
106
|
getLength: () => globalTypesContents.length,
|
|
@@ -261,13 +261,14 @@ ${commandLine.vueOptions.target < 3 ? vue2_1.code : vue_component_type_helpers_1
|
|
|
261
261
|
}
|
|
262
262
|
// fill defaults
|
|
263
263
|
const printer = ts.createPrinter(checkerOptions.printer);
|
|
264
|
-
const
|
|
265
|
-
const
|
|
264
|
+
const sourceScript = language.scripts.get(componentPath);
|
|
265
|
+
const { snapshot } = sourceScript;
|
|
266
|
+
const vueFile = sourceScript.generated?.root;
|
|
266
267
|
const vueDefaults = vueFile && exportName === 'default'
|
|
267
|
-
? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts
|
|
268
|
+
? (vueFile instanceof vue.VueVirtualCode ? readVueComponentDefaultProps(vueFile, printer, ts) : {})
|
|
268
269
|
: {};
|
|
269
|
-
const tsDefaults = !vueFile ? readTsComponentDefaultProps(componentPath.slice(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
|
|
270
|
-
snapshot.getText(0, snapshot.getLength()), exportName, printer, ts) : {};
|
|
270
|
+
const tsDefaults = !vueFile ? readTsComponentDefaultProps(ts.createSourceFile('/tmp.' + componentPath.slice(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
|
|
271
|
+
snapshot.getText(0, snapshot.getLength()), ts.ScriptTarget.Latest), exportName, printer, ts) : {};
|
|
271
272
|
for (const [propName, defaultExp] of Object.entries({
|
|
272
273
|
...vueDefaults,
|
|
273
274
|
...tsDefaults,
|
|
@@ -528,9 +529,9 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
528
529
|
}
|
|
529
530
|
function getDeclaration(declaration) {
|
|
530
531
|
const fileName = declaration.getSourceFile().fileName;
|
|
531
|
-
const
|
|
532
|
-
if (
|
|
533
|
-
const script =
|
|
532
|
+
const sourceScript = language.scripts.get(fileName);
|
|
533
|
+
if (sourceScript?.generated) {
|
|
534
|
+
const script = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
|
|
534
535
|
if (script) {
|
|
535
536
|
for (const [sourceScript, map] of language.maps.forEach(script.code)) {
|
|
536
537
|
for (const [start] of map.toSourceLocation(declaration.getStart())) {
|
|
@@ -558,18 +559,21 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
558
559
|
resolveSchema,
|
|
559
560
|
};
|
|
560
561
|
}
|
|
561
|
-
function readVueComponentDefaultProps(
|
|
562
|
+
function readVueComponentDefaultProps(root, printer, ts) {
|
|
562
563
|
let result = {};
|
|
564
|
+
const { sfc } = root;
|
|
563
565
|
scriptSetupWorker();
|
|
564
566
|
scriptWorker();
|
|
565
567
|
return result;
|
|
566
568
|
function scriptSetupWorker() {
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
569
|
+
const ast = sfc.scriptSetup?.ast;
|
|
570
|
+
if (!ast) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const codegen = vue.tsCodegen.get(sfc);
|
|
574
|
+
const scriptSetupRanges = codegen?.getScriptSetupRanges();
|
|
575
|
+
if (scriptSetupRanges?.withDefaults?.argNode) {
|
|
576
|
+
const obj = findObjectLiteralExpression(scriptSetupRanges.withDefaults.argNode);
|
|
573
577
|
if (obj) {
|
|
574
578
|
for (const prop of obj.properties) {
|
|
575
579
|
if (ts.isPropertyAssignment(prop)) {
|
|
@@ -583,10 +587,8 @@ function readVueComponentDefaultProps(vueSourceFile, printer, ts, vueCompilerOpt
|
|
|
583
587
|
}
|
|
584
588
|
}
|
|
585
589
|
}
|
|
586
|
-
else if (
|
|
587
|
-
const
|
|
588
|
-
const ast = ts.createSourceFile('/tmp.' + descriptor.scriptSetup.lang, '(' + defaultsText + ')', ts.ScriptTarget.Latest);
|
|
589
|
-
const obj = findObjectLiteralExpression(ast);
|
|
590
|
+
else if (scriptSetupRanges?.defineProps?.argNode) {
|
|
591
|
+
const obj = findObjectLiteralExpression(scriptSetupRanges.defineProps.argNode);
|
|
590
592
|
if (obj) {
|
|
591
593
|
result = {
|
|
592
594
|
...result,
|
|
@@ -594,6 +596,14 @@ function readVueComponentDefaultProps(vueSourceFile, printer, ts, vueCompilerOpt
|
|
|
594
596
|
};
|
|
595
597
|
}
|
|
596
598
|
}
|
|
599
|
+
else if (scriptSetupRanges?.defineProps?.destructured) {
|
|
600
|
+
for (const [prop, initializer] of scriptSetupRanges.defineProps.destructured) {
|
|
601
|
+
if (initializer) {
|
|
602
|
+
const expText = printer?.printNode(ts.EmitHint.Expression, initializer, ast) ?? initializer.getText(ast);
|
|
603
|
+
result[prop] = { default: expText };
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
597
607
|
function findObjectLiteralExpression(node) {
|
|
598
608
|
if (ts.isObjectLiteralExpression(node)) {
|
|
599
609
|
return node;
|
|
@@ -608,17 +618,17 @@ function readVueComponentDefaultProps(vueSourceFile, printer, ts, vueCompilerOpt
|
|
|
608
618
|
}
|
|
609
619
|
}
|
|
610
620
|
function scriptWorker() {
|
|
611
|
-
const
|
|
612
|
-
if (
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
621
|
+
const ast = sfc.script?.ast;
|
|
622
|
+
if (!ast) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
const scriptResult = readTsComponentDefaultProps(ast, 'default', printer, ts);
|
|
626
|
+
for (const [key, value] of Object.entries(scriptResult)) {
|
|
627
|
+
result[key] = value;
|
|
617
628
|
}
|
|
618
629
|
}
|
|
619
630
|
}
|
|
620
|
-
function readTsComponentDefaultProps(
|
|
621
|
-
const ast = ts.createSourceFile('/tmp.' + lang, tsFileText, ts.ScriptTarget.Latest);
|
|
631
|
+
function readTsComponentDefaultProps(ast, exportName, printer, ts) {
|
|
622
632
|
const props = getPropsNode();
|
|
623
633
|
if (props) {
|
|
624
634
|
return resolvePropsOption(ast, props, printer, ts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-component-meta",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@volar/typescript": "~2.4.11",
|
|
17
|
-
"@vue/language-core": "2.2.
|
|
17
|
+
"@vue/language-core": "2.2.4",
|
|
18
18
|
"path-browserify": "^1.0.1",
|
|
19
|
-
"vue-component-type-helpers": "2.2.
|
|
19
|
+
"vue-component-type-helpers": "2.2.4"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"typescript": "*"
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/node": "
|
|
31
|
-
"@types/path-browserify": "
|
|
30
|
+
"@types/node": "^22.10.4",
|
|
31
|
+
"@types/path-browserify": "^1.0.1"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "c28986596935cb43979c9d437c25f292bdb36cef"
|
|
34
34
|
}
|