@vue/language-core 2.2.0 → 2.2.2
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/index.d.ts +0 -1
- package/index.js +1 -2
- package/lib/codeFeatures.d.ts +1 -0
- package/lib/codeFeatures.js +3 -0
- package/lib/codegen/codeFeatures.d.ts +83 -0
- package/lib/codegen/codeFeatures.js +71 -0
- package/lib/codegen/common.d.ts +12 -0
- package/lib/codegen/common.js +79 -0
- package/lib/codegen/globalTypes.d.ts +3 -1
- package/lib/codegen/globalTypes.js +30 -14
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +4 -4
- package/lib/codegen/script/binding.d.ts +4 -0
- package/lib/codegen/script/binding.js +41 -0
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +7 -7
- package/lib/codegen/script/componentSelf.d.ts +1 -1
- package/lib/codegen/script/componentSelf.js +2 -2
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/index.d.ts +1 -8
- package/lib/codegen/script/index.js +15 -39
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +46 -58
- package/lib/codegen/script/src.js +2 -2
- package/lib/codegen/script/styleModulesType.d.ts +1 -1
- package/lib/codegen/script/styleModulesType.js +2 -2
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +11 -32
- package/lib/codegen/template/camelized.d.ts +2 -0
- package/lib/codegen/template/camelized.js +31 -0
- package/lib/codegen/template/context.d.ts +17 -13
- package/lib/codegen/template/context.js +35 -89
- package/lib/codegen/template/element.js +32 -252
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +3 -4
- package/lib/codegen/template/elementDirectives.js +18 -11
- package/lib/codegen/template/elementProps.d.ts +2 -1
- package/lib/codegen/template/elementProps.js +22 -26
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +39 -33
- package/lib/codegen/template/interpolation.js +13 -9
- package/lib/codegen/template/slotOutlet.js +39 -17
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
- package/lib/codegen/template/styleScopedClasses.js +141 -0
- package/lib/codegen/template/templateChild.js +9 -2
- package/lib/codegen/template/vSlot.d.ts +5 -0
- package/lib/codegen/template/vSlot.js +80 -0
- package/lib/codegen/utils/index.d.ts +11 -1
- package/lib/codegen/utils/index.js +15 -4
- package/lib/codegen/utils/src.d.ts +2 -0
- package/lib/codegen/utils/src.js +19 -0
- package/lib/parsers/scriptSetupRanges.d.ts +5 -3
- package/lib/parsers/scriptSetupRanges.js +8 -11
- package/lib/parsers/vueCompilerOptions.d.ts +2 -2
- package/lib/plugins/vue-style-class-names.d.ts +5 -0
- package/lib/plugins/vue-style-class-names.js +32 -0
- package/lib/plugins/vue-style-reference-link.d.ts +1 -0
- package/lib/plugins/vue-style-reference-link.js +3 -0
- package/lib/plugins/vue-style-reference-links.d.ts +3 -0
- package/lib/plugins/vue-style-reference-links.js +26 -0
- package/lib/plugins/vue-template-inline-ts.js +53 -12
- package/lib/plugins/vue-tsx.d.ts +35 -28
- package/lib/plugins/vue-tsx.js +75 -55
- package/lib/plugins/vue-vine.d.ts +3 -0
- package/lib/plugins/vue-vine.js +35 -0
- package/lib/types.d.ts +6 -2
- package/lib/utils/findDestructuredProps.d.ts +1 -0
- package/lib/utils/findDestructuredProps.js +3 -0
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/parseSfc.js +4 -3
- package/lib/utils/signals.d.ts +2 -0
- package/lib/utils/signals.js +54 -0
- package/lib/utils/ts.d.ts +14 -2
- package/lib/utils/ts.js +117 -88
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -1
- package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
- package/lib/virtualFile/computedSfc.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +79 -82
- package/lib/virtualFile/computedVueSfc.d.ts +1 -2
- package/lib/virtualFile/computedVueSfc.js +7 -7
- package/lib/virtualFile/vueFile.d.ts +5 -5
- package/lib/virtualFile/vueFile.js +6 -6
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export * from './lib/types';
|
|
|
7
7
|
export * from './lib/utils/parseSfc';
|
|
8
8
|
export * from './lib/utils/ts';
|
|
9
9
|
export * from './lib/virtualFile/vueFile';
|
|
10
|
-
export * as scriptRanges from './lib/parsers/scriptRanges';
|
|
11
10
|
export { tsCodegen } from './lib/plugins/vue-tsx';
|
|
12
11
|
export * from './lib/utils/shared';
|
|
13
12
|
export * from '@volar/language-core';
|
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.tsCodegen =
|
|
17
|
+
exports.tsCodegen = void 0;
|
|
18
18
|
__exportStar(require("./lib/codegen/globalTypes"), exports);
|
|
19
19
|
__exportStar(require("./lib/codegen/template"), exports);
|
|
20
20
|
__exportStar(require("./lib/languagePlugin"), exports);
|
|
@@ -24,7 +24,6 @@ __exportStar(require("./lib/types"), exports);
|
|
|
24
24
|
__exportStar(require("./lib/utils/parseSfc"), exports);
|
|
25
25
|
__exportStar(require("./lib/utils/ts"), exports);
|
|
26
26
|
__exportStar(require("./lib/virtualFile/vueFile"), exports);
|
|
27
|
-
exports.scriptRanges = require("./lib/parsers/scriptRanges");
|
|
28
27
|
var vue_tsx_1 = require("./lib/plugins/vue-tsx");
|
|
29
28
|
Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
|
|
30
29
|
__exportStar(require("./lib/utils/shared"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { VueCodeInformation } from '../types';
|
|
2
|
+
declare const raw: {
|
|
3
|
+
all: {
|
|
4
|
+
verification: true;
|
|
5
|
+
completion: true;
|
|
6
|
+
semantic: true;
|
|
7
|
+
navigation: true;
|
|
8
|
+
};
|
|
9
|
+
none: {};
|
|
10
|
+
verification: {
|
|
11
|
+
verification: true;
|
|
12
|
+
};
|
|
13
|
+
completion: {
|
|
14
|
+
completion: true;
|
|
15
|
+
};
|
|
16
|
+
additionalCompletion: {
|
|
17
|
+
completion: {
|
|
18
|
+
isAdditional: true;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
withoutCompletion: {
|
|
22
|
+
verification: true;
|
|
23
|
+
semantic: true;
|
|
24
|
+
navigation: true;
|
|
25
|
+
};
|
|
26
|
+
navigation: {
|
|
27
|
+
navigation: true;
|
|
28
|
+
};
|
|
29
|
+
navigationWithoutRename: {
|
|
30
|
+
navigation: {
|
|
31
|
+
shouldRename: () => false;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
navigationAndCompletion: {
|
|
35
|
+
navigation: true;
|
|
36
|
+
completion: true;
|
|
37
|
+
};
|
|
38
|
+
navigationAndAdditionalCompletion: {
|
|
39
|
+
navigation: true;
|
|
40
|
+
completion: {
|
|
41
|
+
isAdditional: true;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
navigationAndVerification: {
|
|
45
|
+
navigation: true;
|
|
46
|
+
verification: true;
|
|
47
|
+
};
|
|
48
|
+
withoutNavigation: {
|
|
49
|
+
verification: true;
|
|
50
|
+
completion: true;
|
|
51
|
+
semantic: true;
|
|
52
|
+
};
|
|
53
|
+
withoutHighlight: {
|
|
54
|
+
semantic: {
|
|
55
|
+
shouldHighlight: () => false;
|
|
56
|
+
};
|
|
57
|
+
verification: true;
|
|
58
|
+
navigation: true;
|
|
59
|
+
completion: true;
|
|
60
|
+
};
|
|
61
|
+
withoutHighlightAndNavigation: {
|
|
62
|
+
semantic: {
|
|
63
|
+
shouldHighlight: () => false;
|
|
64
|
+
};
|
|
65
|
+
verification: true;
|
|
66
|
+
completion: true;
|
|
67
|
+
};
|
|
68
|
+
withoutHighlightAndCompletion: {
|
|
69
|
+
semantic: {
|
|
70
|
+
shouldHighlight: () => false;
|
|
71
|
+
};
|
|
72
|
+
verification: true;
|
|
73
|
+
navigation: true;
|
|
74
|
+
};
|
|
75
|
+
withoutHighlightAndCompletionAndNavigation: {
|
|
76
|
+
semantic: {
|
|
77
|
+
shouldHighlight: () => false;
|
|
78
|
+
};
|
|
79
|
+
verification: true;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
export declare const codeFeatures: { [K in keyof typeof raw]: VueCodeInformation; };
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codeFeatures = void 0;
|
|
4
|
+
const raw = {
|
|
5
|
+
all: {
|
|
6
|
+
verification: true,
|
|
7
|
+
completion: true,
|
|
8
|
+
semantic: true,
|
|
9
|
+
navigation: true,
|
|
10
|
+
},
|
|
11
|
+
none: {},
|
|
12
|
+
verification: {
|
|
13
|
+
verification: true,
|
|
14
|
+
},
|
|
15
|
+
completion: {
|
|
16
|
+
completion: true,
|
|
17
|
+
},
|
|
18
|
+
additionalCompletion: {
|
|
19
|
+
completion: { isAdditional: true },
|
|
20
|
+
},
|
|
21
|
+
withoutCompletion: {
|
|
22
|
+
verification: true,
|
|
23
|
+
semantic: true,
|
|
24
|
+
navigation: true,
|
|
25
|
+
},
|
|
26
|
+
navigation: {
|
|
27
|
+
navigation: true,
|
|
28
|
+
},
|
|
29
|
+
navigationWithoutRename: {
|
|
30
|
+
navigation: { shouldRename: () => false },
|
|
31
|
+
},
|
|
32
|
+
navigationAndCompletion: {
|
|
33
|
+
navigation: true,
|
|
34
|
+
completion: true,
|
|
35
|
+
},
|
|
36
|
+
navigationAndAdditionalCompletion: {
|
|
37
|
+
navigation: true,
|
|
38
|
+
completion: { isAdditional: true },
|
|
39
|
+
},
|
|
40
|
+
navigationAndVerification: {
|
|
41
|
+
navigation: true,
|
|
42
|
+
verification: true,
|
|
43
|
+
},
|
|
44
|
+
withoutNavigation: {
|
|
45
|
+
verification: true,
|
|
46
|
+
completion: true,
|
|
47
|
+
semantic: true,
|
|
48
|
+
},
|
|
49
|
+
withoutHighlight: {
|
|
50
|
+
semantic: { shouldHighlight: () => false },
|
|
51
|
+
verification: true,
|
|
52
|
+
navigation: true,
|
|
53
|
+
completion: true,
|
|
54
|
+
},
|
|
55
|
+
withoutHighlightAndNavigation: {
|
|
56
|
+
semantic: { shouldHighlight: () => false },
|
|
57
|
+
verification: true,
|
|
58
|
+
completion: true,
|
|
59
|
+
},
|
|
60
|
+
withoutHighlightAndCompletion: {
|
|
61
|
+
semantic: { shouldHighlight: () => false },
|
|
62
|
+
verification: true,
|
|
63
|
+
navigation: true,
|
|
64
|
+
},
|
|
65
|
+
withoutHighlightAndCompletionAndNavigation: {
|
|
66
|
+
semantic: { shouldHighlight: () => false },
|
|
67
|
+
verification: true,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
exports.codeFeatures = raw;
|
|
71
|
+
//# sourceMappingURL=codeFeatures.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { Code, SfcBlock, VueCodeInformation } from '../types';
|
|
3
|
+
export declare const newLine = "\n";
|
|
4
|
+
export declare const endOfLine = ";\n";
|
|
5
|
+
export declare const combineLastMapping: VueCodeInformation;
|
|
6
|
+
export declare const variableNameRegex: RegExp;
|
|
7
|
+
export declare function conditionWrapWith(condition: boolean, startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
|
|
8
|
+
export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
|
|
9
|
+
export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]): string[];
|
|
10
|
+
export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: [id: ts.Identifier, isRest: boolean][], isRest?: boolean): [id: ts.Identifier, isRest: boolean][];
|
|
11
|
+
export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
|
|
12
|
+
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.variableNameRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
|
|
4
|
+
exports.conditionWrapWith = conditionWrapWith;
|
|
5
|
+
exports.wrapWith = wrapWith;
|
|
6
|
+
exports.collectVars = collectVars;
|
|
7
|
+
exports.collectIdentifiers = collectIdentifiers;
|
|
8
|
+
exports.createTsAst = createTsAst;
|
|
9
|
+
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
10
|
+
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
11
|
+
exports.newLine = '\n';
|
|
12
|
+
exports.endOfLine = `;${exports.newLine}`;
|
|
13
|
+
exports.combineLastMapping = { __combineLastMapping: true };
|
|
14
|
+
exports.variableNameRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
15
|
+
function* conditionWrapWith(condition, startOffset, endOffset, features, ...wrapCodes) {
|
|
16
|
+
if (condition) {
|
|
17
|
+
yield* wrapWith(startOffset, endOffset, features, ...wrapCodes);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
for (const wrapCode of wrapCodes) {
|
|
21
|
+
yield wrapCode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
|
|
26
|
+
yield ['', 'template', startOffset, features];
|
|
27
|
+
let offset = 1;
|
|
28
|
+
for (const wrapCode of wrapCodes) {
|
|
29
|
+
if (typeof wrapCode !== 'string') {
|
|
30
|
+
offset++;
|
|
31
|
+
}
|
|
32
|
+
yield wrapCode;
|
|
33
|
+
}
|
|
34
|
+
yield ['', 'template', endOffset, { __combineOffsetMapping: offset }];
|
|
35
|
+
}
|
|
36
|
+
function collectVars(ts, node, ast, results = []) {
|
|
37
|
+
const identifiers = collectIdentifiers(ts, node, []);
|
|
38
|
+
for (const [id] of identifiers) {
|
|
39
|
+
results.push((0, scriptSetupRanges_1.getNodeText)(ts, id, ast));
|
|
40
|
+
}
|
|
41
|
+
return results;
|
|
42
|
+
}
|
|
43
|
+
function collectIdentifiers(ts, node, results = [], isRest = false) {
|
|
44
|
+
if (ts.isIdentifier(node)) {
|
|
45
|
+
results.push([node, isRest]);
|
|
46
|
+
}
|
|
47
|
+
else if (ts.isObjectBindingPattern(node)) {
|
|
48
|
+
for (const el of node.elements) {
|
|
49
|
+
collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (ts.isArrayBindingPattern(node)) {
|
|
53
|
+
for (const el of node.elements) {
|
|
54
|
+
if (ts.isBindingElement(el)) {
|
|
55
|
+
collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
ts.forEachChild(node, node => collectIdentifiers(ts, node, results, false));
|
|
61
|
+
}
|
|
62
|
+
return results;
|
|
63
|
+
}
|
|
64
|
+
function createTsAst(ts, astHolder, text) {
|
|
65
|
+
if (astHolder.__volar_ast_text !== text) {
|
|
66
|
+
astHolder.__volar_ast_text = text;
|
|
67
|
+
astHolder.__volar_ast = ts.createSourceFile('/a.ts', text, 99);
|
|
68
|
+
}
|
|
69
|
+
return astHolder.__volar_ast;
|
|
70
|
+
}
|
|
71
|
+
function generateSfcBlockSection(block, start, end, features) {
|
|
72
|
+
return [
|
|
73
|
+
block.content.substring(start, end),
|
|
74
|
+
block.name,
|
|
75
|
+
start,
|
|
76
|
+
features,
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { VueCompilerOptions } from '../types';
|
|
2
|
+
export declare function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
|
|
3
|
+
export declare function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGlobalTypesFileName = getGlobalTypesFileName;
|
|
3
4
|
exports.generateGlobalTypes = generateGlobalTypes;
|
|
4
5
|
const shared_1 = require("../utils/shared");
|
|
5
|
-
function
|
|
6
|
-
|
|
6
|
+
function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
|
|
7
|
+
return [
|
|
8
|
+
lib,
|
|
9
|
+
target,
|
|
10
|
+
checkUnknownProps,
|
|
11
|
+
checkUnknownEvents,
|
|
12
|
+
checkUnknownComponents,
|
|
13
|
+
].map(v => {
|
|
14
|
+
if (typeof v === 'boolean') {
|
|
15
|
+
return v ? 1 : 0;
|
|
16
|
+
}
|
|
17
|
+
return v;
|
|
18
|
+
}).join('_') + '.d.ts';
|
|
19
|
+
}
|
|
20
|
+
function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
|
|
21
|
+
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
|
|
7
22
|
let text = ``;
|
|
8
23
|
if (target < 3.5) {
|
|
9
24
|
text += `
|
|
@@ -37,14 +52,15 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
37
52
|
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
|
38
53
|
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
39
54
|
type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
|
|
40
|
-
type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
|
|
55
|
+
type __VLS_WithComponent<N0 extends string, LocalComponents, Self, N1 extends string, N2 extends string, N3 extends string> =
|
|
41
56
|
N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
|
|
42
57
|
N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
|
|
43
58
|
N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
|
|
59
|
+
Self extends object ? { [K in N0]: Self } :
|
|
44
60
|
N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
|
|
45
61
|
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
|
|
46
62
|
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
|
|
47
|
-
${
|
|
63
|
+
${checkUnknownComponents ? '{}' : '{ [K in N0]: unknown }'};
|
|
48
64
|
type __VLS_FunctionalComponentProps<T, K> =
|
|
49
65
|
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
|
|
50
66
|
: T extends (props: infer P, ...args: any) => any ? P :
|
|
@@ -64,7 +80,7 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
64
80
|
: __VLS_IsFunction<Events, CamelizedEvent> extends true
|
|
65
81
|
? { [K in onEvent]?: Events[CamelizedEvent] }
|
|
66
82
|
: Props
|
|
67
|
-
)${
|
|
83
|
+
)${checkUnknownEvents ? '' : ' & Record<string, unknown>'};
|
|
68
84
|
// fix https://github.com/vuejs/language-tools/issues/926
|
|
69
85
|
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
|
|
70
86
|
type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
|
|
@@ -93,25 +109,25 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
93
109
|
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
94
110
|
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
95
111
|
>>;
|
|
112
|
+
type __VLS_OmitStringIndex<T> = {
|
|
113
|
+
[K in keyof T as string extends K ? never : K]: T[K];
|
|
114
|
+
};
|
|
96
115
|
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
97
116
|
|
|
98
|
-
function __VLS_getVForSourceType(source: number): [number, number
|
|
99
|
-
function __VLS_getVForSourceType(source: string): [string, number
|
|
117
|
+
function __VLS_getVForSourceType(source: number): [number, number][];
|
|
118
|
+
function __VLS_getVForSourceType(source: string): [string, number][];
|
|
100
119
|
function __VLS_getVForSourceType<T extends any[]>(source: T): [
|
|
101
120
|
item: T[number],
|
|
102
|
-
key: number,
|
|
103
121
|
index: number,
|
|
104
122
|
][];
|
|
105
123
|
function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
106
124
|
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
|
|
107
|
-
|
|
108
|
-
index: undefined,
|
|
125
|
+
index: number,
|
|
109
126
|
][];
|
|
110
127
|
// #3845
|
|
111
128
|
function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
112
129
|
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
|
|
113
|
-
|
|
114
|
-
index: undefined,
|
|
130
|
+
index: number,
|
|
115
131
|
][];
|
|
116
132
|
function __VLS_getVForSourceType<T>(source: T): [
|
|
117
133
|
item: T[keyof T],
|
|
@@ -138,8 +154,8 @@ function generateGlobalTypes(lib, target, strictTemplates) {
|
|
|
138
154
|
} & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
|
|
139
155
|
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
|
|
140
156
|
: T extends (...args: any) => any ? T
|
|
141
|
-
: (_: {}${
|
|
142
|
-
function
|
|
157
|
+
: (_: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'} } };
|
|
158
|
+
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (_: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
|
|
143
159
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
|
144
160
|
function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
|
|
145
161
|
function __VLS_tryAsConstant<const T>(t: T): T;
|
|
@@ -6,7 +6,7 @@ export declare function getLocalTypesGenerator(compilerOptions: ts.CompilerOptio
|
|
|
6
6
|
readonly PrettifyLocal: string;
|
|
7
7
|
readonly OmitKeepDiscriminatedUnion: string;
|
|
8
8
|
readonly WithDefaults: string;
|
|
9
|
-
readonly
|
|
9
|
+
readonly WithSlots: string;
|
|
10
10
|
readonly PropsChildren: string;
|
|
11
11
|
readonly TypePropsToOption: string;
|
|
12
12
|
readonly OmitIndexSignature: string;
|
|
@@ -18,8 +18,8 @@ type __VLS_WithDefaults<P, D> = {
|
|
|
18
18
|
};
|
|
19
19
|
`.trimStart());
|
|
20
20
|
const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${utils_1.endOfLine}`);
|
|
21
|
-
const
|
|
22
|
-
type
|
|
21
|
+
const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
|
|
22
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
23
23
|
new(): {
|
|
24
24
|
${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;
|
|
25
25
|
${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
|
|
@@ -62,7 +62,7 @@ type __VLS_TypePropsToOption<T> = {
|
|
|
62
62
|
[PrettifyLocal.name]: PrettifyLocal,
|
|
63
63
|
[OmitKeepDiscriminatedUnion.name]: OmitKeepDiscriminatedUnion,
|
|
64
64
|
[WithDefaults.name]: WithDefaults,
|
|
65
|
-
[
|
|
65
|
+
[WithSlots.name]: WithSlots,
|
|
66
66
|
[PropsChildren.name]: PropsChildren,
|
|
67
67
|
[TypePropsToOption.name]: TypePropsToOption,
|
|
68
68
|
[OmitIndexSignature.name]: OmitIndexSignature,
|
|
@@ -76,7 +76,7 @@ type __VLS_TypePropsToOption<T> = {
|
|
|
76
76
|
get PrettifyLocal() { return PrettifyLocal.name; },
|
|
77
77
|
get OmitKeepDiscriminatedUnion() { return OmitKeepDiscriminatedUnion.name; },
|
|
78
78
|
get WithDefaults() { return WithDefaults.name; },
|
|
79
|
-
get
|
|
79
|
+
get WithSlots() { return WithSlots.name; },
|
|
80
80
|
get PropsChildren() { return PropsChildren.name; },
|
|
81
81
|
get TypePropsToOption() { return TypePropsToOption.name; },
|
|
82
82
|
get OmitIndexSignature() { return OmitIndexSignature.name; },
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { TemplateCodegenContext } from '../template/context';
|
|
2
|
+
import type { ScriptCodegenContext } from './context';
|
|
3
|
+
import type { ScriptCodegenOptions } from './index';
|
|
4
|
+
export declare function generateBindings(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<import("../../types").Code, void, any>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateBindings = generateBindings;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const component_1 = require("./component");
|
|
6
|
+
const template_1 = require("./template");
|
|
7
|
+
function* generateBindings(options, ctx, templateCodegenCtx) {
|
|
8
|
+
if (!options.sfc.scriptSetup || !options.scriptSetupRanges) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
yield `const __VLS_bindings = {`;
|
|
12
|
+
if (ctx.bypassDefineComponent) {
|
|
13
|
+
yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
|
|
14
|
+
}
|
|
15
|
+
const templateUsageVars = (0, template_1.getTemplateUsageVars)(options, ctx);
|
|
16
|
+
for (const [content, bindings] of [
|
|
17
|
+
[options.sfc.scriptSetup.content, options.scriptSetupRanges.bindings],
|
|
18
|
+
options.sfc.script && options.scriptRanges
|
|
19
|
+
? [options.sfc.script.content, options.scriptRanges.bindings]
|
|
20
|
+
: ['', []],
|
|
21
|
+
]) {
|
|
22
|
+
for (const { range } of bindings) {
|
|
23
|
+
const varName = content.slice(range.start, range.end);
|
|
24
|
+
if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const templateOffset = options.getGeneratedLength();
|
|
28
|
+
yield `${varName}: ${varName} as typeof `;
|
|
29
|
+
const scriptOffset = options.getGeneratedLength();
|
|
30
|
+
yield `${varName},${utils_1.newLine}`;
|
|
31
|
+
options.linkedCodeMappings.push({
|
|
32
|
+
sourceOffsets: [scriptOffset],
|
|
33
|
+
generatedOffsets: [templateOffset],
|
|
34
|
+
lengths: [varName.length],
|
|
35
|
+
data: undefined,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
yield `}${utils_1.endOfLine}`;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=binding.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
2
2
|
import type { Code, Sfc } from '../../types';
|
|
3
3
|
import type { ScriptCodegenContext } from './context';
|
|
4
|
-
import { ScriptCodegenOptions } from './index';
|
|
4
|
+
import type { ScriptCodegenOptions } from './index';
|
|
5
5
|
export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
6
6
|
export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
7
7
|
export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
@@ -4,12 +4,12 @@ exports.generateComponent = generateComponent;
|
|
|
4
4
|
exports.generateComponentSetupReturns = generateComponentSetupReturns;
|
|
5
5
|
exports.generateEmitsOption = generateEmitsOption;
|
|
6
6
|
exports.generatePropsOption = generatePropsOption;
|
|
7
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
7
8
|
const utils_1 = require("../utils");
|
|
8
|
-
const index_1 = require("./index");
|
|
9
9
|
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
10
10
|
if (options.sfc.script && options.scriptRanges?.exportDefault && options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
|
|
11
11
|
// use defineComponent() from user space code if it exist
|
|
12
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start,
|
|
12
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, codeFeatures_1.codeFeatures.all);
|
|
13
13
|
yield `{${utils_1.newLine}`;
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
@@ -34,13 +34,13 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
34
34
|
}
|
|
35
35
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
|
|
36
36
|
const { args } = options.scriptRanges.exportDefault;
|
|
37
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1,
|
|
37
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
|
|
38
38
|
}
|
|
39
39
|
if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.templateRefs.size) {
|
|
40
|
-
yield `__typeRefs: {} as
|
|
40
|
+
yield `__typeRefs: {} as __VLS_TemplateRefs,${utils_1.newLine}`;
|
|
41
41
|
}
|
|
42
42
|
if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.singleRootElType) {
|
|
43
|
-
yield `__typeEl: {} as
|
|
43
|
+
yield `__typeEl: {} as __VLS_RootEl,${utils_1.newLine}`;
|
|
44
44
|
}
|
|
45
45
|
yield `})`;
|
|
46
46
|
}
|
|
@@ -122,12 +122,12 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
122
122
|
if (scriptSetupRanges.defineProps?.arg) {
|
|
123
123
|
const { arg } = scriptSetupRanges.defineProps;
|
|
124
124
|
codes.push({
|
|
125
|
-
optionExp: (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end,
|
|
125
|
+
optionExp: (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation),
|
|
126
126
|
typeOptionExp: undefined,
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
|
|
130
|
-
let attrsType = `
|
|
130
|
+
let attrsType = `Partial<__VLS_InheritedAttrs>`;
|
|
131
131
|
if (hasEmitsOption) {
|
|
132
132
|
attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
|
|
133
133
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Code } from '../../types';
|
|
2
2
|
import type { TemplateCodegenContext } from '../template/context';
|
|
3
3
|
import type { ScriptCodegenContext } from './context';
|
|
4
|
-
import {
|
|
4
|
+
import type { ScriptCodegenOptions } from './index';
|
|
5
5
|
export declare function generateComponentSelf(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<Code>;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateComponentSelf = generateComponentSelf;
|
|
4
4
|
const path = require("path-browserify");
|
|
5
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const component_1 = require("./component");
|
|
7
|
-
const index_1 = require("./index");
|
|
8
8
|
const template_1 = require("./template");
|
|
9
9
|
function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
10
10
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
@@ -50,7 +50,7 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
50
50
|
}
|
|
51
51
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
|
|
52
52
|
const { args } = options.scriptRanges.exportDefault;
|
|
53
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1,
|
|
53
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
|
|
54
54
|
}
|
|
55
55
|
yield `})${utils_1.endOfLine}`; // defineComponent {
|
|
56
56
|
}
|
|
@@ -19,7 +19,7 @@ export declare function createScriptCodegenContext(options: ScriptCodegenOptions
|
|
|
19
19
|
readonly PrettifyLocal: string;
|
|
20
20
|
readonly OmitKeepDiscriminatedUnion: string;
|
|
21
21
|
readonly WithDefaults: string;
|
|
22
|
-
readonly
|
|
22
|
+
readonly WithSlots: string;
|
|
23
23
|
readonly PropsChildren: string;
|
|
24
24
|
readonly TypePropsToOption: string;
|
|
25
25
|
readonly OmitIndexSignature: string;
|
|
@@ -2,16 +2,9 @@ import type { Mapping } from '@volar/language-core';
|
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
4
4
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
5
|
-
import type { Code, Sfc,
|
|
5
|
+
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
6
6
|
import type { TemplateCodegenContext } from '../template/context';
|
|
7
7
|
import { ScriptCodegenContext } from './context';
|
|
8
|
-
export declare const codeFeatures: {
|
|
9
|
-
all: VueCodeInformation;
|
|
10
|
-
none: VueCodeInformation;
|
|
11
|
-
verification: VueCodeInformation;
|
|
12
|
-
navigation: VueCodeInformation;
|
|
13
|
-
navigationWithoutRename: VueCodeInformation;
|
|
14
|
-
};
|
|
15
8
|
export interface ScriptCodegenOptions {
|
|
16
9
|
ts: typeof ts;
|
|
17
10
|
compilerOptions: ts.CompilerOptions;
|