@vue/language-core 2.2.6 → 2.2.10
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/codegen/globalTypes.js +1 -4
- package/lib/codegen/template/context.d.ts +1 -0
- package/lib/codegen/template/context.js +5 -0
- package/lib/codegen/template/elementEvents.d.ts +0 -1
- package/lib/codegen/template/elementEvents.js +14 -36
- package/lib/codegen/template/index.js +2 -3
- package/lib/plugins/vue-tsx.d.ts +1 -0
- 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
|
@@ -100,9 +100,6 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
100
100
|
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
101
101
|
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
102
102
|
>>;
|
|
103
|
-
type __VLS_OmitStringIndex<T> = {
|
|
104
|
-
[K in keyof T as string extends K ? never : K]: T[K];
|
|
105
|
-
};
|
|
106
103
|
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
107
104
|
|
|
108
105
|
function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
|
|
@@ -144,7 +141,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
144
141
|
: (_: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'} } };
|
|
145
142
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
|
146
143
|
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
|
|
147
|
-
function __VLS_asFunctionalSlot<S>(slot: S):
|
|
144
|
+
function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
|
|
148
145
|
function __VLS_tryAsConstant<const T>(t: T): T;
|
|
149
146
|
}
|
|
150
147
|
`;
|
|
@@ -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;
|
|
@@ -6,5 +6,4 @@ 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>;
|
|
10
9
|
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|
|
@@ -3,7 +3,6 @@ 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;
|
|
7
6
|
exports.isCompoundExpression = isCompoundExpression;
|
|
8
7
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
9
8
|
const shared_1 = require("@vue/shared");
|
|
@@ -17,8 +16,9 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
17
16
|
let propsVar;
|
|
18
17
|
for (const prop of node.props) {
|
|
19
18
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
20
|
-
&&
|
|
21
|
-
|
|
19
|
+
&& prop.name === 'on'
|
|
20
|
+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
21
|
+
&& prop.arg.isStatic) {
|
|
22
22
|
ctx.currentComponent.used = true;
|
|
23
23
|
if (!emitVar) {
|
|
24
24
|
emitVar = ctx.getInternalVariable();
|
|
@@ -28,31 +28,21 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
28
28
|
yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${utils_1.endOfLine}`;
|
|
29
29
|
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
30
30
|
}
|
|
31
|
-
let source = prop.arg
|
|
32
|
-
let start = prop.arg
|
|
33
|
-
let propPrefix = 'on
|
|
31
|
+
let source = prop.arg.loc.source;
|
|
32
|
+
let start = prop.arg.loc.start.offset;
|
|
33
|
+
let propPrefix = 'on';
|
|
34
34
|
let emitPrefix = '';
|
|
35
|
-
if (
|
|
36
|
-
propPrefix = 'onUpdate:';
|
|
37
|
-
emitPrefix = 'update:';
|
|
38
|
-
}
|
|
39
|
-
else if (source.startsWith('vue:')) {
|
|
35
|
+
if (source.startsWith('vue:')) {
|
|
40
36
|
source = source.slice('vue:'.length);
|
|
41
37
|
start = start + 'vue:'.length;
|
|
42
|
-
propPrefix = 'onVnode
|
|
38
|
+
propPrefix = 'onVnode';
|
|
43
39
|
emitPrefix = 'vnode-';
|
|
44
40
|
}
|
|
45
|
-
yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${eventsVar}, '${(0, shared_1.camelize)(propPrefix + source)}', '${emitPrefix
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
yield `'${(0, shared_1.camelize)(propPrefix + source)}': `;
|
|
53
|
-
yield* generateModelEventExpression(options, ctx, prop);
|
|
54
|
-
}
|
|
55
|
-
yield `})${utils_1.endOfLine}`;
|
|
41
|
+
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${eventsVar}, '${(0, shared_1.camelize)(propPrefix + '-' + source)}', '${emitPrefix}${source}', '${(0, shared_1.camelize)(emitPrefix + source)}'> = {${utils_1.newLine}`;
|
|
42
|
+
yield* generateEventArg(ctx, source, start, propPrefix);
|
|
43
|
+
yield `: `;
|
|
44
|
+
yield* generateEventExpression(options, ctx, prop);
|
|
45
|
+
yield `}${utils_1.endOfLine}`;
|
|
56
46
|
}
|
|
57
47
|
}
|
|
58
48
|
}
|
|
@@ -80,11 +70,9 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
80
70
|
if (_isCompoundExpression) {
|
|
81
71
|
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
82
72
|
ctx.addLocalVariable('$event');
|
|
73
|
+
yield* ctx.generateConditionGuards();
|
|
83
74
|
prefix = ``;
|
|
84
75
|
suffix = ``;
|
|
85
|
-
for (const blockCondition of ctx.blockConditions) {
|
|
86
|
-
prefix += `if (!${blockCondition}) return${utils_1.endOfLine}`;
|
|
87
|
-
}
|
|
88
76
|
}
|
|
89
77
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
|
|
90
78
|
if (_isCompoundExpression && isFirstMapping) {
|
|
@@ -115,16 +103,6 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
115
103
|
yield `() => {}`;
|
|
116
104
|
}
|
|
117
105
|
}
|
|
118
|
-
function* generateModelEventExpression(options, ctx, prop) {
|
|
119
|
-
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
120
|
-
yield `(...[$event]) => (`;
|
|
121
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset, prop.exp.loc);
|
|
122
|
-
yield ` = $event)`;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
yield `() => {}`;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
106
|
function isCompoundExpression(ts, ast) {
|
|
129
107
|
let result = true;
|
|
130
108
|
if (ast.statements.length === 0) {
|
|
@@ -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
|
}
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.10",
|
|
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": "0422c03ffa4958431c9cd3cd19ae51f726c30b07"
|
|
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
|