@vue/language-core 2.0.18 → 2.0.19
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/template/element.js +2 -2
- package/lib/codegen/template/elementEvents.js +1 -9
- package/lib/codegen/template/elementProps.d.ts +5 -1
- package/lib/codegen/template/elementProps.js +13 -12
- package/lib/codegen/template/index.d.ts +0 -1
- package/lib/codegen/template/index.js +1 -5
- package/lib/codegen/template/vFor.js +11 -4
- package/lib/codegen/template/vIf.js +7 -2
- package/package.json +2 -2
|
@@ -157,7 +157,7 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
|
|
|
157
157
|
componentCtxVar = var_defineComponentCtx;
|
|
158
158
|
currentComponent = node;
|
|
159
159
|
for (const failedExp of propsFailedExps) {
|
|
160
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, ctx.codeFeatures.all,
|
|
160
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.node.loc.source, failedExp.node.loc, failedExp.node.loc.start.offset, ctx.codeFeatures.all, failedExp.prefix, failedExp.suffix);
|
|
161
161
|
yield common_1.endOfLine;
|
|
162
162
|
}
|
|
163
163
|
yield* generateVScope(options, ctx, node, props);
|
|
@@ -195,7 +195,7 @@ function* generateElement(options, ctx, node, currentComponent, componentCtxVar)
|
|
|
195
195
|
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, true, propsFailedExps), `}`);
|
|
196
196
|
yield `)${common_1.endOfLine}`;
|
|
197
197
|
for (const failedExp of propsFailedExps) {
|
|
198
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, ctx.codeFeatures.all,
|
|
198
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.node.loc.source, failedExp.node.loc, failedExp.node.loc.start.offset, ctx.codeFeatures.all, failedExp.prefix, failedExp.suffix);
|
|
199
199
|
yield common_1.endOfLine;
|
|
200
200
|
}
|
|
201
201
|
yield* generateVScope(options, ctx, node, node.props);
|
|
@@ -51,14 +51,6 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
|
|
|
51
51
|
yield* generateEventExpression(options, ctx, prop);
|
|
52
52
|
yield `}${common_1.endOfLine}`;
|
|
53
53
|
}
|
|
54
|
-
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
55
|
-
&& prop.name === 'on'
|
|
56
|
-
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
57
|
-
// for vue 2 nameless event
|
|
58
|
-
// https://github.com/johnsoncodehk/vue-tsc/issues/67
|
|
59
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '$event => {(', ')}');
|
|
60
|
-
yield common_1.endOfLine;
|
|
61
|
-
}
|
|
62
54
|
}
|
|
63
55
|
return usedComponentEventsVar;
|
|
64
56
|
}
|
|
@@ -104,7 +96,7 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
104
96
|
const ast = (0, common_1.createTsAst)(options.ts, prop.exp, prop.exp.content);
|
|
105
97
|
const _isCompoundExpression = isCompoundExpression(options.ts, ast);
|
|
106
98
|
if (_isCompoundExpression) {
|
|
107
|
-
yield
|
|
99
|
+
yield `(...[$event]) => {${common_1.newLine}`;
|
|
108
100
|
ctx.addLocalVariable('$event');
|
|
109
101
|
prefix = '';
|
|
110
102
|
suffix = '';
|
|
@@ -2,4 +2,8 @@ import * as CompilerDOM from '@vue/compiler-dom';
|
|
|
2
2
|
import type { Code } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
|
-
export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], enableCodeFeatures: boolean, propsFailedExps?:
|
|
5
|
+
export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], enableCodeFeatures: boolean, propsFailedExps?: {
|
|
6
|
+
node: CompilerDOM.SimpleExpressionNode;
|
|
7
|
+
prefix: string;
|
|
8
|
+
suffix: string;
|
|
9
|
+
}[]): Generator<Code>;
|
|
@@ -31,22 +31,23 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
31
31
|
yield `...{ '${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any }, `;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
else
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
else if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
35
|
+
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
36
|
+
&& prop.arg.loc.source.startsWith('[')
|
|
37
|
+
&& prop.arg.loc.source.endsWith(']')) {
|
|
38
|
+
propsFailedExps?.push({ node: prop.arg, prefix: '(', suffix: ')' });
|
|
39
|
+
propsFailedExps?.push({ node: prop.exp, prefix: '() => {', suffix: '}' });
|
|
40
|
+
}
|
|
41
|
+
else if (!prop.arg
|
|
42
|
+
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
43
|
+
propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
for (const prop of props) {
|
|
47
48
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
48
|
-
&& (prop.name === 'bind'
|
|
49
|
-
|
|
49
|
+
&& ((prop.name === 'bind' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)
|
|
50
|
+
|| prop.name === 'model')
|
|
50
51
|
&& (!prop.exp || prop.exp.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)) {
|
|
51
52
|
let propName;
|
|
52
53
|
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
@@ -60,7 +61,7 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
60
61
|
if (propName === undefined
|
|
61
62
|
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
|
|
62
63
|
if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
63
|
-
propsFailedExps?.push(prop.exp);
|
|
64
|
+
propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
|
|
64
65
|
}
|
|
65
66
|
continue;
|
|
66
67
|
}
|
|
@@ -15,4 +15,3 @@ export interface TemplateCodegenOptions {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function generateTemplate(options: TemplateCodegenOptions): Generator<Code, TemplateCodegenContext>;
|
|
17
17
|
export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
|
|
18
|
-
export declare function isFragment(node: CompilerDOM.IfNode | CompilerDOM.ForNode): boolean | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.forEachElementNode = exports.generateTemplate = void 0;
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
5
|
const common_1 = require("../common");
|
|
6
6
|
const context_1 = require("./context");
|
|
@@ -138,8 +138,4 @@ function* forEachElementNode(node) {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
exports.forEachElementNode = forEachElementNode;
|
|
141
|
-
function isFragment(node) {
|
|
142
|
-
return node.codegenNode && 'consequent' in node.codegenNode && 'tag' in node.codegenNode.consequent && node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
|
|
143
|
-
}
|
|
144
|
-
exports.isFragment = isFragment;
|
|
145
141
|
//# sourceMappingURL=index.js.map
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseVForNode = exports.generateVFor = void 0;
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
5
|
const common_1 = require("../common");
|
|
6
|
-
const index_1 = require("./index");
|
|
7
6
|
const interpolation_1 = require("./interpolation");
|
|
8
7
|
const templateChild_1 = require("./templateChild");
|
|
9
8
|
function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
|
@@ -34,17 +33,25 @@ function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
34
33
|
for (const varName of forBlockVars) {
|
|
35
34
|
ctx.addLocalVariable(varName);
|
|
36
35
|
}
|
|
36
|
+
let isFragment = true;
|
|
37
37
|
for (const argument of node.codegenNode?.children.arguments ?? []) {
|
|
38
38
|
if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
|
|
39
39
|
&& argument.returns.type === CompilerDOM.NodeTypes.VNODE_CALL
|
|
40
40
|
&& argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
|
|
41
|
+
if (argument.returns.tag !== CompilerDOM.FRAGMENT) {
|
|
42
|
+
isFragment = false;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
41
45
|
for (const prop of argument.returns.props.properties) {
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
47
|
+
&& !prop.value.isStatic) {
|
|
48
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.value.content, prop.value.loc, prop.value.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
49
|
+
yield common_1.endOfLine;
|
|
50
|
+
}
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
|
-
if (
|
|
54
|
+
if (isFragment) {
|
|
48
55
|
yield* ctx.resetDirectiveComments('end of v-for start');
|
|
49
56
|
}
|
|
50
57
|
let prev;
|
|
@@ -4,7 +4,6 @@ exports.generateVIf = void 0;
|
|
|
4
4
|
const language_core_1 = require("@volar/language-core");
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const common_1 = require("../common");
|
|
7
|
-
const index_1 = require("./index");
|
|
8
7
|
const interpolation_1 = require("./interpolation");
|
|
9
8
|
const templateChild_1 = require("./templateChild");
|
|
10
9
|
function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
|
|
@@ -33,7 +32,7 @@ function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
33
32
|
yield ` `;
|
|
34
33
|
}
|
|
35
34
|
yield `{${common_1.newLine}`;
|
|
36
|
-
if (
|
|
35
|
+
if (isFragment(node)) {
|
|
37
36
|
yield* ctx.resetDirectiveComments('end of v-if start');
|
|
38
37
|
}
|
|
39
38
|
let prev;
|
|
@@ -50,4 +49,10 @@ function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
50
49
|
ctx.blockConditions.length = originalBlockConditionsLength;
|
|
51
50
|
}
|
|
52
51
|
exports.generateVIf = generateVIf;
|
|
52
|
+
function isFragment(node) {
|
|
53
|
+
return node.codegenNode
|
|
54
|
+
&& 'consequent' in node.codegenNode
|
|
55
|
+
&& 'tag' in node.codegenNode.consequent
|
|
56
|
+
&& node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
|
|
57
|
+
}
|
|
53
58
|
//# sourceMappingURL=vIf.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"optional": true
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a9fae154ad1efc4359866cfd10251d53e4b0faed"
|
|
38
38
|
}
|