@vue/language-core 2.2.8 → 3.0.0-alpha.0
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 +1 -2
- package/index.js +1 -1
- package/lib/codegen/globalTypes.js +1 -5
- package/lib/codegen/script/index.d.ts +0 -1
- package/lib/codegen/script/index.js +0 -3
- package/lib/codegen/script/src.js +1 -20
- package/lib/codegen/script/template.js +4 -1
- package/lib/codegen/template/context.d.ts +2 -1
- package/lib/codegen/template/context.js +5 -3
- package/lib/codegen/template/element.js +14 -33
- package/lib/codegen/template/elementDirectives.js +0 -8
- package/lib/codegen/template/elementEvents.d.ts +1 -0
- package/lib/codegen/template/elementEvents.js +39 -16
- package/lib/codegen/template/elementProps.js +3 -7
- package/lib/codegen/template/index.d.ts +0 -1
- package/lib/codegen/template/index.js +2 -3
- package/lib/codegen/template/interpolation.js +4 -4
- package/lib/codegen/template/styleScopedClasses.js +2 -2
- package/lib/codegen/utils/index.js +2 -2
- package/lib/parsers/scriptRanges.js +7 -3
- package/lib/parsers/scriptSetupRanges.d.ts +0 -3
- package/lib/parsers/scriptSetupRanges.js +10 -22
- package/lib/plugins/vue-tsx.d.ts +1 -0
- package/lib/plugins/vue-tsx.js +0 -4
- package/lib/types.d.ts +1 -1
- package/lib/utils/shared.d.ts +5 -1
- package/lib/utils/shared.js +16 -4
- package/lib/utils/ts.d.ts +0 -4
- package/lib/utils/ts.js +1 -10
- package/package.json +2 -2
- package/lib/codegen/script/styleModulesType.d.ts +0 -4
- package/lib/codegen/script/styleModulesType.js +0 -34
- package/lib/codegen/utils/objectProperty.d.ts +0 -3
- package/lib/codegen/utils/objectProperty.js +0 -41
package/index.d.ts
CHANGED
|
@@ -5,9 +5,8 @@ export * from './lib/parsers/scriptSetupRanges';
|
|
|
5
5
|
export * from './lib/plugins';
|
|
6
6
|
export * from './lib/types';
|
|
7
7
|
export * from './lib/utils/parseSfc';
|
|
8
|
+
export * from './lib/utils/shared';
|
|
8
9
|
export * from './lib/utils/ts';
|
|
9
10
|
export * from './lib/virtualFile/vueFile';
|
|
10
11
|
export { tsCodegen } from './lib/plugins/vue-tsx';
|
|
11
|
-
export * from './lib/utils/shared';
|
|
12
12
|
export * from '@volar/language-core';
|
|
13
|
-
export type * as CompilerDOM from '@vue/compiler-dom';
|
package/index.js
CHANGED
|
@@ -22,10 +22,10 @@ __exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
|
|
|
22
22
|
__exportStar(require("./lib/plugins"), exports);
|
|
23
23
|
__exportStar(require("./lib/types"), exports);
|
|
24
24
|
__exportStar(require("./lib/utils/parseSfc"), exports);
|
|
25
|
+
__exportStar(require("./lib/utils/shared"), exports);
|
|
25
26
|
__exportStar(require("./lib/utils/ts"), exports);
|
|
26
27
|
__exportStar(require("./lib/virtualFile/vueFile"), exports);
|
|
27
28
|
var vue_tsx_1 = require("./lib/plugins/vue-tsx");
|
|
28
29
|
Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
|
|
29
|
-
__exportStar(require("./lib/utils/shared"), exports);
|
|
30
30
|
__exportStar(require("@volar/language-core"), exports);
|
|
31
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -24,7 +24,6 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
24
24
|
}
|
|
25
25
|
text += `
|
|
26
26
|
; declare global {
|
|
27
|
-
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
|
|
28
27
|
const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
|
|
29
28
|
const __VLS_unref: typeof import('${lib}').unref;
|
|
30
29
|
const __VLS_placeholder: any;
|
|
@@ -100,9 +99,6 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
100
99
|
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
101
100
|
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
102
101
|
>>;
|
|
103
|
-
type __VLS_OmitStringIndex<T> = {
|
|
104
|
-
[K in keyof T as string extends K ? never : K]: T[K];
|
|
105
|
-
};
|
|
106
102
|
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
107
103
|
|
|
108
104
|
function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
|
|
@@ -144,7 +140,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
144
140
|
: (_: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'} } };
|
|
145
141
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
|
146
142
|
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
|
|
147
|
-
function __VLS_asFunctionalSlot<S>(slot: S):
|
|
143
|
+
function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
|
|
148
144
|
function __VLS_tryAsConstant<const T>(t: T): T;
|
|
149
145
|
}
|
|
150
146
|
`;
|
|
@@ -105,9 +105,6 @@ function* generateScript(options) {
|
|
|
105
105
|
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
106
106
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
107
107
|
}
|
|
108
|
-
if (options.edited) {
|
|
109
|
-
yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${utils_1.endOfLine}`;
|
|
110
|
-
}
|
|
111
108
|
yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
|
|
112
109
|
if (options.appendGlobalTypes) {
|
|
113
110
|
yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
|
|
@@ -23,26 +23,7 @@ function* generateSrc(src) {
|
|
|
23
23
|
yield `export * from `;
|
|
24
24
|
yield* (0, utils_1.generateSfcBlockAttrValue)(src, text, {
|
|
25
25
|
...codeFeatures_1.codeFeatures.all,
|
|
26
|
-
|
|
27
|
-
? true
|
|
28
|
-
: {
|
|
29
|
-
shouldRename: () => false,
|
|
30
|
-
resolveRenameEditText(newName) {
|
|
31
|
-
if (newName.endsWith('.jsx') || newName.endsWith('.js')) {
|
|
32
|
-
newName = newName.split('.').slice(0, -1).join('.');
|
|
33
|
-
}
|
|
34
|
-
if (src?.text.endsWith('.d.ts')) {
|
|
35
|
-
newName = newName + '.d.ts';
|
|
36
|
-
}
|
|
37
|
-
else if (src?.text.endsWith('.ts')) {
|
|
38
|
-
newName = newName + '.ts';
|
|
39
|
-
}
|
|
40
|
-
else if (src?.text.endsWith('.tsx')) {
|
|
41
|
-
newName = newName + '.tsx';
|
|
42
|
-
}
|
|
43
|
-
return newName;
|
|
44
|
-
},
|
|
45
|
-
},
|
|
26
|
+
...text === src.text ? codeFeatures_1.codeFeatures.navigation : codeFeatures_1.codeFeatures.navigationWithoutRename,
|
|
46
27
|
});
|
|
47
28
|
yield utils_1.endOfLine;
|
|
48
29
|
yield `export { default } from '${text}'${utils_1.endOfLine}`;
|
|
@@ -15,9 +15,9 @@ function* generateTemplate(options, ctx) {
|
|
|
15
15
|
ctx.generatedTemplate = true;
|
|
16
16
|
const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)({
|
|
17
17
|
scriptSetupBindingNames: new Set(),
|
|
18
|
-
edited: options.edited,
|
|
19
18
|
});
|
|
20
19
|
yield* generateTemplateCtx(options);
|
|
20
|
+
yield* generateTemplateElements();
|
|
21
21
|
yield* generateTemplateComponents(options);
|
|
22
22
|
yield* generateTemplateDirectives(options);
|
|
23
23
|
yield* generateTemplateBody(options, templateCodegenCtx);
|
|
@@ -47,6 +47,9 @@ function* generateTemplateCtx(options) {
|
|
|
47
47
|
yield `}${utils_1.endOfLine}`;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
function* generateTemplateElements() {
|
|
51
|
+
yield `let __VLS_elements!: __VLS_IntrinsicElements${utils_1.endOfLine}`;
|
|
52
|
+
}
|
|
50
53
|
function* generateTemplateComponents(options) {
|
|
51
54
|
const types = [];
|
|
52
55
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
|
|
@@ -100,7 +100,7 @@ export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenCont
|
|
|
100
100
|
* an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
|
|
101
101
|
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
|
102
102
|
*/
|
|
103
|
-
export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames'
|
|
103
|
+
export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames'>): {
|
|
104
104
|
codeFeatures: {
|
|
105
105
|
all: VueCodeInformation;
|
|
106
106
|
none: VueCodeInformation;
|
|
@@ -164,6 +164,7 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
164
164
|
getInternalVariable: () => string;
|
|
165
165
|
getHoistVariable: (originalVar: string) => string;
|
|
166
166
|
generateHoistVariables: () => Generator<string, void, unknown>;
|
|
167
|
+
generateConditionGuards: () => Generator<string, void, unknown>;
|
|
167
168
|
ignoreError: () => Generator<Code>;
|
|
168
169
|
expectError: (prevNode: CompilerDOM.CommentNode) => Generator<Code>;
|
|
169
170
|
resetDirectiveComments: (endStr: string) => Generator<Code>;
|
|
@@ -210,6 +210,11 @@ function createTemplateCodegenContext(options) {
|
|
|
210
210
|
yield utils_1.endOfLine;
|
|
211
211
|
}
|
|
212
212
|
},
|
|
213
|
+
generateConditionGuards: function* () {
|
|
214
|
+
for (const condition of blockConditions) {
|
|
215
|
+
yield `if (!${condition}) return${utils_1.endOfLine}`;
|
|
216
|
+
}
|
|
217
|
+
},
|
|
213
218
|
ignoreError: function* () {
|
|
214
219
|
if (!ignoredError) {
|
|
215
220
|
ignoredError = true;
|
|
@@ -246,9 +251,6 @@ function createTemplateCodegenContext(options) {
|
|
|
246
251
|
}
|
|
247
252
|
},
|
|
248
253
|
generateAutoImportCompletion: function* () {
|
|
249
|
-
if (!options.edited) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
254
|
const all = [...accessExternalVariables.entries()];
|
|
253
255
|
if (!all.some(([_, offsets]) => offsets.size)) {
|
|
254
256
|
return;
|
|
@@ -5,6 +5,7 @@ exports.generateElement = generateElement;
|
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
7
|
const shared_2 = require("../../utils/shared");
|
|
8
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
8
9
|
const inlayHints_1 = require("../inlayHints");
|
|
9
10
|
const utils_1 = require("../utils");
|
|
10
11
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -82,13 +83,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
82
83
|
}
|
|
83
84
|
else {
|
|
84
85
|
const shouldCapitalize = matchImportName[0].toUpperCase() === matchImportName[0];
|
|
85
|
-
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset,
|
|
86
|
-
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
87
|
-
navigation: {
|
|
88
|
-
resolveRenameNewName: camelizeComponentName,
|
|
89
|
-
resolveRenameEditText: getTagRenameApply(node.tag),
|
|
90
|
-
},
|
|
91
|
-
});
|
|
86
|
+
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
92
87
|
}
|
|
93
88
|
yield `, `;
|
|
94
89
|
}
|
|
@@ -125,29 +120,21 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
125
120
|
yield `/** @type {[`;
|
|
126
121
|
for (const tagOffset of tagOffsets) {
|
|
127
122
|
for (const shouldCapitalize of (node.tag[0] === node.tag[0].toUpperCase() ? [false] : [true, false])) {
|
|
128
|
-
const expectName = shouldCapitalize ? (0, shared_1.capitalize)(camelizedTag) : camelizedTag;
|
|
129
123
|
yield `typeof __VLS_components.`;
|
|
130
|
-
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset,
|
|
131
|
-
navigation: {
|
|
132
|
-
resolveRenameNewName: node.tag !== expectName ? camelizeComponentName : undefined,
|
|
133
|
-
resolveRenameEditText: getTagRenameApply(node.tag),
|
|
134
|
-
},
|
|
135
|
-
});
|
|
124
|
+
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, codeFeatures_1.codeFeatures.navigation);
|
|
136
125
|
yield `, `;
|
|
137
126
|
}
|
|
138
127
|
}
|
|
139
128
|
yield `]} */${utils_1.endOfLine}`;
|
|
140
129
|
// auto import support
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
yield `${utils_1.endOfLine}`;
|
|
150
|
-
}
|
|
130
|
+
yield `// @ts-ignore${utils_1.newLine}`; // #2304
|
|
131
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), 'template', tagOffsets[0], {
|
|
132
|
+
completion: {
|
|
133
|
+
isAdditional: true,
|
|
134
|
+
onlyImport: true,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
yield `${utils_1.endOfLine}`;
|
|
151
138
|
}
|
|
152
139
|
}
|
|
153
140
|
else {
|
|
@@ -220,10 +207,10 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
220
207
|
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
221
208
|
: undefined;
|
|
222
209
|
const failedPropExps = [];
|
|
223
|
-
yield `__VLS_asFunctionalElement(
|
|
210
|
+
yield `__VLS_asFunctionalElement(__VLS_elements`;
|
|
224
211
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
225
212
|
if (endTagOffset !== undefined) {
|
|
226
|
-
yield `,
|
|
213
|
+
yield `, __VLS_elements`;
|
|
227
214
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
228
215
|
}
|
|
229
216
|
yield `)(`;
|
|
@@ -246,7 +233,7 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
246
233
|
ctx.singleRootElTypes.push(`__VLS_NativeElements['${node.tag}']`);
|
|
247
234
|
}
|
|
248
235
|
if (hasVBindAttrs(options, ctx, node)) {
|
|
249
|
-
ctx.inheritedAttrVars.add(`
|
|
236
|
+
ctx.inheritedAttrVars.add(`__VLS_elements.${node.tag}`);
|
|
250
237
|
}
|
|
251
238
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
252
239
|
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
@@ -319,10 +306,4 @@ function hasVBindAttrs(options, ctx, node) {
|
|
|
319
306
|
&& prop.name === 'bind'
|
|
320
307
|
&& prop.exp?.loc.source === '$attrs'));
|
|
321
308
|
}
|
|
322
|
-
function camelizeComponentName(newName) {
|
|
323
|
-
return (0, shared_1.camelize)('-' + newName);
|
|
324
|
-
}
|
|
325
|
-
function getTagRenameApply(oldName) {
|
|
326
|
-
return oldName === (0, shared_2.hyphenateTag)(oldName) ? shared_2.hyphenateTag : undefined;
|
|
327
|
-
}
|
|
328
309
|
//# sourceMappingURL=element.js.map
|
|
@@ -4,7 +4,6 @@ exports.generateElementDirectives = generateElementDirectives;
|
|
|
4
4
|
exports.generateModifiers = generateModifiers;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
|
-
const shared_2 = require("../../utils/shared");
|
|
8
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
9
8
|
const utils_1 = require("../utils");
|
|
10
9
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -44,10 +43,6 @@ function* generateIdentifier(options, ctx, prop) {
|
|
|
44
43
|
// fix https://github.com/vuejs/language-tools/issues/1905
|
|
45
44
|
...codeFeatures_1.codeFeatures.additionalCompletion,
|
|
46
45
|
verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
|
|
47
|
-
navigation: {
|
|
48
|
-
resolveRenameNewName: shared_1.camelize,
|
|
49
|
-
resolveRenameEditText: getPropRenameApply(prop.name),
|
|
50
|
-
},
|
|
51
46
|
})));
|
|
52
47
|
}
|
|
53
48
|
function* generateArg(options, ctx, prop) {
|
|
@@ -90,7 +85,4 @@ function* generateValue(options, ctx, prop) {
|
|
|
90
85
|
yield `: `;
|
|
91
86
|
yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp, ctx.codeFeatures.all);
|
|
92
87
|
}
|
|
93
|
-
function getPropRenameApply(oldName) {
|
|
94
|
-
return oldName === (0, shared_2.hyphenateAttr)(oldName) ? shared_2.hyphenateAttr : undefined;
|
|
95
|
-
}
|
|
96
88
|
//# sourceMappingURL=elementDirectives.js.map
|
|
@@ -6,4 +6,5 @@ import type { TemplateCodegenOptions } from './index';
|
|
|
6
6
|
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
|
|
7
7
|
export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string): Generator<Code>;
|
|
8
8
|
export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
9
|
+
export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
9
10
|
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateElementEvents = generateElementEvents;
|
|
4
4
|
exports.generateEventArg = generateEventArg;
|
|
5
5
|
exports.generateEventExpression = generateEventExpression;
|
|
6
|
+
exports.generateModelEventExpression = generateModelEventExpression;
|
|
6
7
|
exports.isCompoundExpression = isCompoundExpression;
|
|
7
8
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
9
|
const shared_1 = require("@vue/shared");
|
|
@@ -16,9 +17,11 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
16
17
|
let propsVar;
|
|
17
18
|
for (const prop of node.props) {
|
|
18
19
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
19
|
-
&& prop.name === 'on'
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
&& (prop.name === 'on'
|
|
21
|
+
&& (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)
|
|
22
|
+
|| options.vueCompilerOptions.strictVModel
|
|
23
|
+
&& prop.name === 'model'
|
|
24
|
+
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
|
22
25
|
ctx.currentComponent.used = true;
|
|
23
26
|
if (!emitVar) {
|
|
24
27
|
emitVar = ctx.getInternalVariable();
|
|
@@ -28,21 +31,31 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
28
31
|
yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${utils_1.endOfLine}`;
|
|
29
32
|
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
30
33
|
}
|
|
31
|
-
let source = prop.arg
|
|
32
|
-
let start = prop.arg
|
|
33
|
-
let propPrefix = 'on';
|
|
34
|
+
let source = prop.arg?.loc.source ?? 'model-value';
|
|
35
|
+
let start = prop.arg?.loc.start.offset;
|
|
36
|
+
let propPrefix = 'on-';
|
|
34
37
|
let emitPrefix = '';
|
|
35
|
-
if (
|
|
38
|
+
if (prop.name === 'model') {
|
|
39
|
+
propPrefix = 'onUpdate:';
|
|
40
|
+
emitPrefix = 'update:';
|
|
41
|
+
}
|
|
42
|
+
else if (source.startsWith('vue:')) {
|
|
36
43
|
source = source.slice('vue:'.length);
|
|
37
44
|
start = start + 'vue:'.length;
|
|
38
|
-
propPrefix = 'onVnode';
|
|
45
|
+
propPrefix = 'onVnode-';
|
|
39
46
|
emitPrefix = 'vnode-';
|
|
40
47
|
}
|
|
41
|
-
yield `
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${eventsVar}, '${(0, shared_1.camelize)(propPrefix + source)}', '${emitPrefix + source}', '${(0, shared_1.camelize)(emitPrefix + source)}'> => ({${utils_1.newLine}`;
|
|
49
|
+
if (prop.name === 'on') {
|
|
50
|
+
yield* generateEventArg(ctx, source, start, propPrefix.slice(0, -1));
|
|
51
|
+
yield `: `;
|
|
52
|
+
yield* generateEventExpression(options, ctx, prop);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
yield `'${(0, shared_1.camelize)(propPrefix + source)}': `;
|
|
56
|
+
yield* generateModelEventExpression(options, ctx, prop);
|
|
57
|
+
}
|
|
58
|
+
yield `})${utils_1.endOfLine}`;
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
61
|
}
|
|
@@ -70,11 +83,9 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
70
83
|
if (_isCompoundExpression) {
|
|
71
84
|
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
72
85
|
ctx.addLocalVariable('$event');
|
|
86
|
+
yield* ctx.generateConditionGuards();
|
|
73
87
|
prefix = ``;
|
|
74
88
|
suffix = ``;
|
|
75
|
-
for (const blockCondition of ctx.blockConditions) {
|
|
76
|
-
prefix += `if (!${blockCondition}) return${utils_1.endOfLine}`;
|
|
77
|
-
}
|
|
78
89
|
}
|
|
79
90
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
|
|
80
91
|
if (_isCompoundExpression && isFirstMapping) {
|
|
@@ -105,6 +116,18 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
105
116
|
yield `() => {}`;
|
|
106
117
|
}
|
|
107
118
|
}
|
|
119
|
+
function* generateModelEventExpression(options, ctx, prop) {
|
|
120
|
+
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
121
|
+
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
122
|
+
yield* ctx.generateConditionGuards();
|
|
123
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset, prop.exp.loc);
|
|
124
|
+
yield ` = $event${utils_1.endOfLine}`;
|
|
125
|
+
yield `}`;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
yield `() => {}`;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
108
131
|
function isCompoundExpression(ts, ast) {
|
|
109
132
|
let result = true;
|
|
110
133
|
if (ast.statements.length === 0) {
|
|
@@ -77,7 +77,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
77
77
|
}
|
|
78
78
|
const shouldSpread = propName === 'style' || propName === 'class';
|
|
79
79
|
const shouldCamelize = isComponent && getShouldCamelize(options, prop, propName);
|
|
80
|
-
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck
|
|
80
|
+
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);
|
|
81
81
|
if (shouldSpread) {
|
|
82
82
|
yield `...{ `;
|
|
83
83
|
}
|
|
@@ -120,7 +120,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
120
120
|
}
|
|
121
121
|
const shouldSpread = prop.name === 'style' || prop.name === 'class';
|
|
122
122
|
const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
|
|
123
|
-
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck
|
|
123
|
+
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);
|
|
124
124
|
if (shouldSpread) {
|
|
125
125
|
yield `...{ `;
|
|
126
126
|
}
|
|
@@ -223,13 +223,9 @@ function getShouldCamelize(options, prop, propName) {
|
|
|
223
223
|
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
|
224
224
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
|
|
225
225
|
}
|
|
226
|
-
function getPropsCodeInfo(ctx, strictPropsCheck
|
|
226
|
+
function getPropsCodeInfo(ctx, strictPropsCheck) {
|
|
227
227
|
return ctx.resolveCodeFeatures({
|
|
228
228
|
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
229
|
-
navigation: {
|
|
230
|
-
resolveRenameNewName: shared_1.camelize,
|
|
231
|
-
resolveRenameEditText: shouldCamelize ? shared_2.hyphenateAttr : undefined,
|
|
232
|
-
},
|
|
233
229
|
verification: strictPropsCheck || {
|
|
234
230
|
shouldReport(_source, code) {
|
|
235
231
|
// https://typescript.tv/errors/#ts2353
|
|
@@ -7,7 +7,6 @@ export interface TemplateCodegenOptions {
|
|
|
7
7
|
compilerOptions: ts.CompilerOptions;
|
|
8
8
|
vueCompilerOptions: VueCompilerOptions;
|
|
9
9
|
template: NonNullable<Sfc['template']>;
|
|
10
|
-
edited: boolean;
|
|
11
10
|
scriptSetupBindingNames: Set<string>;
|
|
12
11
|
scriptSetupImportComponentNames: Set<string>;
|
|
13
12
|
destructuredPropNames: Set<string>;
|
|
@@ -52,8 +52,7 @@ function* generateTemplate(options) {
|
|
|
52
52
|
}
|
|
53
53
|
function* generateSlots(options, ctx) {
|
|
54
54
|
if (!options.hasDefineSlots) {
|
|
55
|
-
|
|
56
|
-
yield `type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${name}>`;
|
|
55
|
+
yield `type __VLS_Slots = {}`;
|
|
57
56
|
for (const { expVar, propsVar } of ctx.dynamicSlots) {
|
|
58
57
|
yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
|
|
59
58
|
}
|
|
@@ -67,7 +66,7 @@ function* generateSlots(options, ctx) {
|
|
|
67
66
|
}
|
|
68
67
|
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
69
68
|
}
|
|
70
|
-
yield
|
|
69
|
+
yield `${utils_1.endOfLine}`;
|
|
71
70
|
}
|
|
72
71
|
return `__VLS_Slots`;
|
|
73
72
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateInterpolation = generateInterpolation;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
|
-
const
|
|
5
|
+
const shared_2 = require("../../utils/shared");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
function* generateInterpolation(options, ctx, source, data, _code, start, astHolder = {}, prefix = '', suffix = '') {
|
|
8
8
|
const code = prefix + _code + suffix;
|
|
@@ -49,7 +49,7 @@ function* generateInterpolation(options, ctx, source, data, _code, start, astHol
|
|
|
49
49
|
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, code, offset, ast) {
|
|
50
50
|
let ctxVars = [];
|
|
51
51
|
const varCb = (id, isShorthand) => {
|
|
52
|
-
const text = (0,
|
|
52
|
+
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
53
53
|
if (ctx.hasLocalVariable(text)
|
|
54
54
|
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
55
55
|
|| (0, shared_1.isGloballyAllowed)(text)
|
|
@@ -61,13 +61,13 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
61
61
|
ctxVars.push({
|
|
62
62
|
text,
|
|
63
63
|
isShorthand: isShorthand,
|
|
64
|
-
offset: (0,
|
|
64
|
+
offset: (0, shared_2.getStartEnd)(ts, id, ast).start,
|
|
65
65
|
});
|
|
66
66
|
if (destructuredPropNames?.has(text)) {
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
if (offset !== undefined) {
|
|
70
|
-
ctx.accessExternalVariable(text, offset + (0,
|
|
70
|
+
ctx.accessExternalVariable(text, offset + (0, shared_2.getStartEnd)(ts, id, ast).start);
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
73
|
ctx.accessExternalVariable(text);
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateStyleScopedClassReferences = generateStyleScopedClassReferences;
|
|
4
4
|
exports.collectStyleScopedClassReferences = collectStyleScopedClassReferences;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
-
const
|
|
6
|
+
const shared_1 = require("../../utils/shared");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const escaped_1 = require("../utils/escaped");
|
|
9
9
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
@@ -126,7 +126,7 @@ function collectStyleScopedClassReferences(options, ctx, node) {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
function walkIdentifier(node) {
|
|
129
|
-
const text = (0,
|
|
129
|
+
const text = (0, shared_1.getNodeText)(ts, node, ast);
|
|
130
130
|
ctx.scopedClasses.push({
|
|
131
131
|
source: 'template',
|
|
132
132
|
className: text,
|
|
@@ -7,7 +7,7 @@ exports.normalizeAttributeValue = normalizeAttributeValue;
|
|
|
7
7
|
exports.createTsAst = createTsAst;
|
|
8
8
|
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
9
9
|
exports.generateSfcBlockAttrValue = generateSfcBlockAttrValue;
|
|
10
|
-
const
|
|
10
|
+
const shared_1 = require("../../utils/shared");
|
|
11
11
|
exports.newLine = `\n`;
|
|
12
12
|
exports.endOfLine = `;${exports.newLine}`;
|
|
13
13
|
exports.combineLastMapping = { __combineOffset: 1 };
|
|
@@ -15,7 +15,7 @@ exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
|
15
15
|
function collectVars(ts, node, ast, results = []) {
|
|
16
16
|
const identifiers = collectIdentifiers(ts, node, []);
|
|
17
17
|
for (const { id } of identifiers) {
|
|
18
|
-
results.push((0,
|
|
18
|
+
results.push((0, shared_1.getNodeText)(ts, id, ast));
|
|
19
19
|
}
|
|
20
20
|
return results;
|
|
21
21
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseScriptRanges = parseScriptRanges;
|
|
4
|
+
const shared_1 = require("../utils/shared");
|
|
4
5
|
const scriptSetupRanges_1 = require("./scriptSetupRanges");
|
|
5
6
|
function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
6
7
|
let exportDefault;
|
|
@@ -29,7 +30,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
29
30
|
let inheritAttrsOption;
|
|
30
31
|
ts.forEachChild(obj, node => {
|
|
31
32
|
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
|
32
|
-
const name = (
|
|
33
|
+
const name = _getNodeText(node.name);
|
|
33
34
|
if (name === 'components' && ts.isObjectLiteralExpression(node.initializer)) {
|
|
34
35
|
componentsOptionNode = node.initializer;
|
|
35
36
|
}
|
|
@@ -40,7 +41,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
40
41
|
nameOptionNode = node.initializer;
|
|
41
42
|
}
|
|
42
43
|
else if (name === 'inheritAttrs') {
|
|
43
|
-
inheritAttrsOption = (
|
|
44
|
+
inheritAttrsOption = _getNodeText(node.initializer);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
});
|
|
@@ -69,7 +70,10 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
69
70
|
bindings,
|
|
70
71
|
};
|
|
71
72
|
function _getStartEnd(node) {
|
|
72
|
-
return (0,
|
|
73
|
+
return (0, shared_1.getStartEnd)(ts, node, ast);
|
|
74
|
+
}
|
|
75
|
+
function _getNodeText(node) {
|
|
76
|
+
return (0, shared_1.getNodeText)(ts, node, ast);
|
|
73
77
|
}
|
|
74
78
|
// isAsExpression is missing in tsc
|
|
75
79
|
function isAsExpression(node) {
|
|
@@ -73,7 +73,4 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
|
|
|
73
73
|
isDefaultImport?: boolean;
|
|
74
74
|
isNamespace?: boolean;
|
|
75
75
|
}[];
|
|
76
|
-
export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, ast: ts.SourceFile): TextRange[];
|
|
77
|
-
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
78
|
-
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
|
79
76
|
export {};
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseScriptSetupRanges = parseScriptSetupRanges;
|
|
4
4
|
exports.parseBindingRanges = parseBindingRanges;
|
|
5
|
-
exports.findBindingVars = findBindingVars;
|
|
6
|
-
exports.getStartEnd = getStartEnd;
|
|
7
|
-
exports.getNodeText = getNodeText;
|
|
8
5
|
const utils_1 = require("../codegen/utils");
|
|
6
|
+
const shared_1 = require("../utils/shared");
|
|
9
7
|
const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
|
|
10
8
|
function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
11
9
|
const defineProp = [];
|
|
@@ -42,7 +40,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
42
40
|
importSectionEndOffset = commentRange.pos;
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
|
-
importSectionEndOffset = getStartEnd(ts, node, ast).start;
|
|
43
|
+
importSectionEndOffset = (0, shared_1.getStartEnd)(ts, node, ast).start;
|
|
46
44
|
}
|
|
47
45
|
foundNonImportExportNode = true;
|
|
48
46
|
}
|
|
@@ -282,10 +280,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
282
280
|
};
|
|
283
281
|
}
|
|
284
282
|
function _getStartEnd(node) {
|
|
285
|
-
return getStartEnd(ts, node, ast);
|
|
283
|
+
return (0, shared_1.getStartEnd)(ts, node, ast);
|
|
286
284
|
}
|
|
287
285
|
function _getNodeText(node) {
|
|
288
|
-
return getNodeText(ts, node, ast);
|
|
286
|
+
return (0, shared_1.getNodeText)(ts, node, ast);
|
|
289
287
|
}
|
|
290
288
|
}
|
|
291
289
|
function parseBindingRanges(ts, ast) {
|
|
@@ -353,10 +351,10 @@ function parseBindingRanges(ts, ast) {
|
|
|
353
351
|
});
|
|
354
352
|
return bindings;
|
|
355
353
|
function _getStartEnd(node) {
|
|
356
|
-
return getStartEnd(ts, node, ast);
|
|
354
|
+
return (0, shared_1.getStartEnd)(ts, node, ast);
|
|
357
355
|
}
|
|
358
356
|
function _getNodeText(node) {
|
|
359
|
-
return getNodeText(ts, node, ast);
|
|
357
|
+
return (0, shared_1.getNodeText)(ts, node, ast);
|
|
360
358
|
}
|
|
361
359
|
function _findBindingVars(left) {
|
|
362
360
|
return findBindingVars(ts, left, ast);
|
|
@@ -368,7 +366,7 @@ function findBindingVars(ts, left, ast) {
|
|
|
368
366
|
return vars;
|
|
369
367
|
function worker(node) {
|
|
370
368
|
if (ts.isIdentifier(node)) {
|
|
371
|
-
vars.push(getStartEnd(ts, node, ast));
|
|
369
|
+
vars.push((0, shared_1.getStartEnd)(ts, node, ast));
|
|
372
370
|
}
|
|
373
371
|
// { ? } = ...
|
|
374
372
|
// [ ? ] = ...
|
|
@@ -385,7 +383,7 @@ function findBindingVars(ts, left, ast) {
|
|
|
385
383
|
}
|
|
386
384
|
// { foo } = ...
|
|
387
385
|
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
388
|
-
vars.push(getStartEnd(ts, node.name, ast));
|
|
386
|
+
vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
|
|
389
387
|
}
|
|
390
388
|
// { ...? } = ...
|
|
391
389
|
// [ ...? ] = ...
|
|
@@ -394,23 +392,13 @@ function findBindingVars(ts, left, ast) {
|
|
|
394
392
|
}
|
|
395
393
|
}
|
|
396
394
|
}
|
|
397
|
-
function getStartEnd(ts, node, ast) {
|
|
398
|
-
return {
|
|
399
|
-
start: ts.getTokenPosOfNode(node, ast),
|
|
400
|
-
end: node.end,
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
function getNodeText(ts, node, ast) {
|
|
404
|
-
const { start, end } = getStartEnd(ts, node, ast);
|
|
405
|
-
return ast.text.slice(start, end);
|
|
406
|
-
}
|
|
407
395
|
function getStatementRange(ts, parents, node, ast) {
|
|
408
396
|
let statementRange;
|
|
409
397
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
410
398
|
if (ts.isStatement(parents[i])) {
|
|
411
399
|
const statement = parents[i];
|
|
412
400
|
ts.forEachChild(statement, child => {
|
|
413
|
-
const range = getStartEnd(ts, child, ast);
|
|
401
|
+
const range = (0, shared_1.getStartEnd)(ts, child, ast);
|
|
414
402
|
statementRange ??= range;
|
|
415
403
|
statementRange.end = range.end;
|
|
416
404
|
});
|
|
@@ -418,7 +406,7 @@ function getStatementRange(ts, parents, node, ast) {
|
|
|
418
406
|
}
|
|
419
407
|
}
|
|
420
408
|
if (!statementRange) {
|
|
421
|
-
statementRange = getStartEnd(ts, node, ast);
|
|
409
|
+
statementRange = (0, shared_1.getStartEnd)(ts, node, ast);
|
|
422
410
|
}
|
|
423
411
|
return statementRange;
|
|
424
412
|
}
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -201,6 +201,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
201
201
|
getInternalVariable: () => string;
|
|
202
202
|
getHoistVariable: (originalVar: string) => string;
|
|
203
203
|
generateHoistVariables: () => Generator<string, void, unknown>;
|
|
204
|
+
generateConditionGuards: () => Generator<string, void, unknown>;
|
|
204
205
|
ignoreError: () => Generator<Code>;
|
|
205
206
|
expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
|
|
206
207
|
resetDirectiveComments: (endStr: string) => Generator<Code>;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -12,7 +12,6 @@ const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
|
|
|
12
12
|
const signals_1 = require("../utils/signals");
|
|
13
13
|
const ts_1 = require("../utils/ts");
|
|
14
14
|
exports.tsCodegen = new WeakMap();
|
|
15
|
-
const fileEditTimes = new Map();
|
|
16
15
|
const plugin = ctx => {
|
|
17
16
|
let appendedGlobalTypes = false;
|
|
18
17
|
return {
|
|
@@ -144,7 +143,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
144
143
|
compilerOptions: ctx.compilerOptions,
|
|
145
144
|
vueCompilerOptions: getResolvedOptions(),
|
|
146
145
|
template: sfc.template,
|
|
147
|
-
edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
148
146
|
scriptSetupBindingNames: getSetupBindingNames(),
|
|
149
147
|
scriptSetupImportComponentNames: getSetupImportComponentNames(),
|
|
150
148
|
destructuredPropNames: getSetupDestructuredPropNames(),
|
|
@@ -173,7 +171,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
173
171
|
compilerOptions: ctx.compilerOptions,
|
|
174
172
|
vueCompilerOptions: getResolvedOptions(),
|
|
175
173
|
sfc: sfc,
|
|
176
|
-
edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
177
174
|
fileName,
|
|
178
175
|
lang: getLang(),
|
|
179
176
|
scriptRanges: getScriptRanges(),
|
|
@@ -183,7 +180,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
183
180
|
templateRefNames: getSetupTemplateRefNames(),
|
|
184
181
|
appendGlobalTypes,
|
|
185
182
|
});
|
|
186
|
-
fileEditTimes.set(fileName, (fileEditTimes.get(fileName) ?? 0) + 1);
|
|
187
183
|
let current = codegen.next();
|
|
188
184
|
while (!current.done) {
|
|
189
185
|
const code = current.value;
|
package/lib/types.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface VueCompilerOptions {
|
|
|
23
23
|
vitePressExtensions: string[];
|
|
24
24
|
petiteVueExtensions: string[];
|
|
25
25
|
jsxSlots: boolean;
|
|
26
|
+
strictVModel: boolean;
|
|
26
27
|
checkUnknownProps: boolean;
|
|
27
28
|
checkUnknownEvents: boolean;
|
|
28
29
|
checkUnknownDirectives: boolean;
|
|
@@ -61,7 +62,6 @@ export interface VueCompilerOptions {
|
|
|
61
62
|
__setupedGlobalTypes?: true | {
|
|
62
63
|
absolutePath: string;
|
|
63
64
|
};
|
|
64
|
-
__test?: boolean;
|
|
65
65
|
}
|
|
66
66
|
export declare const validVersions: readonly [2, 2.1];
|
|
67
67
|
export type VueLanguagePluginReturn = {
|
package/lib/utils/shared.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { TextRange } from '../types';
|
|
2
3
|
export { hyphenate as hyphenateTag } from '@vue/shared';
|
|
3
4
|
export declare function hyphenateAttr(str: string): string;
|
|
5
|
+
export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
|
|
6
|
+
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
7
|
+
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
package/lib/utils/shared.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hyphenateTag = void 0;
|
|
4
|
-
exports.getSlotsPropertyName = getSlotsPropertyName;
|
|
5
4
|
exports.hyphenateAttr = hyphenateAttr;
|
|
5
|
+
exports.getSlotsPropertyName = getSlotsPropertyName;
|
|
6
|
+
exports.getStartEnd = getStartEnd;
|
|
7
|
+
exports.getNodeText = getNodeText;
|
|
6
8
|
const shared_1 = require("@vue/shared");
|
|
7
|
-
function getSlotsPropertyName(vueVersion) {
|
|
8
|
-
return vueVersion < 3 ? '$scopedSlots' : '$slots';
|
|
9
|
-
}
|
|
10
9
|
var shared_2 = require("@vue/shared");
|
|
11
10
|
Object.defineProperty(exports, "hyphenateTag", { enumerable: true, get: function () { return shared_2.hyphenate; } });
|
|
12
11
|
function hyphenateAttr(str) {
|
|
@@ -17,4 +16,17 @@ function hyphenateAttr(str) {
|
|
|
17
16
|
}
|
|
18
17
|
return hyphencase;
|
|
19
18
|
}
|
|
19
|
+
function getSlotsPropertyName(vueVersion) {
|
|
20
|
+
return vueVersion < 3 ? '$scopedSlots' : '$slots';
|
|
21
|
+
}
|
|
22
|
+
function getStartEnd(ts, node, ast) {
|
|
23
|
+
return {
|
|
24
|
+
start: ts.getTokenPosOfNode(node, ast),
|
|
25
|
+
end: node.end,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function getNodeText(ts, node, ast) {
|
|
29
|
+
const { start, end } = getStartEnd(ts, node, ast);
|
|
30
|
+
return ast.text.slice(start, end);
|
|
31
|
+
}
|
|
20
32
|
//# sourceMappingURL=shared.js.map
|
package/lib/utils/ts.d.ts
CHANGED
|
@@ -16,10 +16,6 @@ export declare class CompilerOptionsResolver {
|
|
|
16
16
|
build(defaults?: VueCompilerOptions): VueCompilerOptions;
|
|
17
17
|
}
|
|
18
18
|
export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated use `getDefaultCompilerOptions` instead
|
|
21
|
-
*/
|
|
22
|
-
export declare function resolveVueCompilerOptions(options: Partial<VueCompilerOptions>): VueCompilerOptions;
|
|
23
19
|
export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
|
|
24
20
|
fileExists(path: string): boolean;
|
|
25
21
|
writeFile?(path: string, data: string): void;
|
package/lib/utils/ts.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.CompilerOptionsResolver = void 0;
|
|
|
4
4
|
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
|
|
5
5
|
exports.createParsedCommandLine = createParsedCommandLine;
|
|
6
6
|
exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
|
|
7
|
-
exports.resolveVueCompilerOptions = resolveVueCompilerOptions;
|
|
8
7
|
exports.setupGlobalTypes = setupGlobalTypes;
|
|
9
8
|
const shared_1 = require("@vue/shared");
|
|
10
9
|
const path_browserify_1 = require("path-browserify");
|
|
@@ -218,6 +217,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
218
217
|
vitePressExtensions: [],
|
|
219
218
|
petiteVueExtensions: [],
|
|
220
219
|
jsxSlots: false,
|
|
220
|
+
strictVModel: strictTemplates,
|
|
221
221
|
checkUnknownProps: strictTemplates,
|
|
222
222
|
checkUnknownEvents: strictTemplates,
|
|
223
223
|
checkUnknownDirectives: strictTemplates,
|
|
@@ -271,15 +271,6 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
271
271
|
},
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
|
-
/**
|
|
275
|
-
* @deprecated use `getDefaultCompilerOptions` instead
|
|
276
|
-
*/
|
|
277
|
-
function resolveVueCompilerOptions(options) {
|
|
278
|
-
return {
|
|
279
|
-
...getDefaultCompilerOptions(options.target, options.lib),
|
|
280
|
-
...options,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
274
|
function setupGlobalTypes(rootDir, vueOptions, host) {
|
|
284
275
|
if (!host.writeFile) {
|
|
285
276
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"optional": true
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "4b49cbe09097e482def4603b90f6c3b93bb2e913"
|
|
41
41
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Code } from '../../types';
|
|
2
|
-
import type { ScriptCodegenContext } from './context';
|
|
3
|
-
import { ScriptCodegenOptions } from './index';
|
|
4
|
-
export declare function generateStyleModulesType(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateStyleModulesType = generateStyleModulesType;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const index_1 = require("./index");
|
|
6
|
-
const template_1 = require("./template");
|
|
7
|
-
function* generateStyleModulesType(options, ctx) {
|
|
8
|
-
const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
|
|
9
|
-
if (!styles.length && !options.scriptSetupRanges?.useCssModule.length) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
yield `type __VLS_StyleModules = {${utils_1.newLine}`;
|
|
13
|
-
for (const [style, i] of styles) {
|
|
14
|
-
const { name, offset } = style.module;
|
|
15
|
-
if (offset) {
|
|
16
|
-
yield [
|
|
17
|
-
name,
|
|
18
|
-
'main',
|
|
19
|
-
offset + 1,
|
|
20
|
-
index_1.codeFeatures.all
|
|
21
|
-
];
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
yield name;
|
|
25
|
-
}
|
|
26
|
-
yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
|
|
27
|
-
for (const className of style.classNames) {
|
|
28
|
-
yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
|
|
29
|
-
}
|
|
30
|
-
yield `>${utils_1.endOfLine}`;
|
|
31
|
-
}
|
|
32
|
-
yield `}${utils_1.endOfLine}`;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=styleModulesType.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
-
export declare function getObjectProperty(code: string): string;
|
|
3
|
-
export declare function generateObjectProperty(code: string, source: string, offset: number, features: VueCodeInformation, hasQuotes?: boolean, shouldCamelize?: boolean): Generator<Code>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getObjectProperty = getObjectProperty;
|
|
4
|
-
exports.generateObjectProperty = generateObjectProperty;
|
|
5
|
-
const shared_1 = require("@vue/shared");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
const camelized_1 = require("../utils/camelized");
|
|
8
|
-
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
9
|
-
function getObjectProperty(code) {
|
|
10
|
-
if (utils_1.identifierRegex.test(code)) {
|
|
11
|
-
return code;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return `'${code}'`;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function* generateObjectProperty(code, source, offset, features, hasQuotes = false, shouldCamelize = false) {
|
|
18
|
-
const start = offset;
|
|
19
|
-
const end = offset + code.length;
|
|
20
|
-
if (hasQuotes) {
|
|
21
|
-
code = code.slice(1, -1);
|
|
22
|
-
offset++;
|
|
23
|
-
}
|
|
24
|
-
if (shouldCamelize) {
|
|
25
|
-
if (utils_1.identifierRegex.test((0, shared_1.camelize)(code))) {
|
|
26
|
-
yield* (0, camelized_1.generateCamelized)(code, source, offset, features);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
yield* (0, utils_1.wrapWith)(start, end, source, features, `'`, ...(0, camelized_1.generateCamelized)(code, source, offset, features), `'`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
if (utils_1.identifierRegex.test(code)) {
|
|
34
|
-
yield [code, source, offset, features];
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(code, source, offset, features);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=objectProperty.js.map
|