@vue/language-core 3.2.7 → 3.2.9
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 +2 -1
- package/index.js +3 -23
- package/lib/codegen/names.d.ts +73 -26
- package/lib/codegen/names.js +75 -27
- package/lib/codegen/script/component.js +19 -58
- package/lib/codegen/script/index.js +12 -12
- package/lib/codegen/script/scriptSetup.js +48 -81
- package/lib/codegen/script/template.js +29 -63
- package/lib/codegen/style/modules.js +4 -37
- package/lib/codegen/style/scopedClasses.js +2 -1
- package/lib/codegen/template/element.d.ts +1 -0
- package/lib/codegen/template/element.js +45 -25
- package/lib/codegen/template/elementDirectives.js +4 -4
- package/lib/codegen/template/elementEvents.js +3 -2
- package/lib/codegen/template/elementProps.js +9 -9
- package/lib/codegen/template/index.js +16 -49
- package/lib/codegen/template/interpolation.js +3 -36
- package/lib/codegen/template/objectProperty.js +2 -1
- package/lib/codegen/template/slotOutlet.js +5 -5
- package/lib/codegen/template/styleScopedClasses.js +3 -2
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +14 -23
- package/lib/codegen/template/vFor.js +3 -20
- package/lib/codegen/template/vIf.js +1 -5
- package/lib/codegen/template/vSlot.js +2 -1
- package/lib/languagePlugin.js +2 -0
- package/lib/plugins/file-md.js +26 -30
- package/lib/plugins/vue-template-html.js +37 -12
- package/lib/plugins/vue-template-inline-ts.js +0 -4
- package/lib/plugins/vue-tsx.js +5 -22
- package/lib/template/compile.d.ts +2 -0
- package/lib/template/compile.js +31 -0
- package/lib/template/transforms/transformElement.d.ts +2 -0
- package/lib/template/transforms/transformElement.js +95 -0
- package/lib/template/transforms/transformText.d.ts +2 -0
- package/lib/template/transforms/transformText.js +35 -0
- package/lib/template/transforms/vFor.d.ts +1 -0
- package/lib/template/transforms/vFor.js +42 -0
- package/lib/template/transforms/vIf.d.ts +1 -0
- package/lib/template/transforms/vIf.js +92 -0
- package/lib/template/utils.d.ts +3 -0
- package/lib/template/utils.js +37 -0
- package/lib/types.d.ts +1 -0
- package/lib/utils/forEachTemplateNode.js +0 -3
- package/lib/virtualCode/ir.js +0 -39
- package/package.json +12 -6
- package/lib/virtualCode/normalize.d.ts +0 -2
- package/lib/virtualCode/normalize.js +0 -205
package/lib/types.d.ts
CHANGED
|
@@ -101,6 +101,7 @@ export type VueLanguagePlugin<T extends Record<string, any> = {}> = (ctx: {
|
|
|
101
101
|
modules: {
|
|
102
102
|
typescript: typeof ts;
|
|
103
103
|
'@vue/compiler-dom': typeof CompilerDOM;
|
|
104
|
+
'@vue/language-core': typeof import('../index');
|
|
104
105
|
};
|
|
105
106
|
compilerOptions: ts.CompilerOptions;
|
|
106
107
|
vueCompilerOptions: VueCompilerOptions;
|
|
@@ -72,9 +72,6 @@ function* forEachInterpolationNode(node) {
|
|
|
72
72
|
yield* forEachInterpolationNode(child);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
76
|
-
yield* forEachInterpolationNode(node.content);
|
|
77
|
-
}
|
|
78
75
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
79
76
|
for (const child of node.children) {
|
|
80
77
|
if (typeof child === 'object') {
|
package/lib/virtualCode/ir.js
CHANGED
|
@@ -1,43 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.useIR = useIR;
|
|
37
|
-
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
38
4
|
const alien_signals_1 = require("alien-signals");
|
|
39
5
|
const signals_1 = require("../utils/signals");
|
|
40
|
-
const normalize_1 = require("./normalize");
|
|
41
6
|
function useIR(ts, plugins, fileName, getSnapshot, getParseSfcResult) {
|
|
42
7
|
const getUntrackedSnapshot = () => {
|
|
43
8
|
const pausedSub = (0, alien_signals_1.setActiveSub)(undefined);
|
|
@@ -229,13 +194,10 @@ function useIR(ts, plugins, fileName, getSnapshot, getParseSfcResult) {
|
|
|
229
194
|
}
|
|
230
195
|
const errors = [];
|
|
231
196
|
const warnings = [];
|
|
232
|
-
const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset();
|
|
233
197
|
let options = {
|
|
234
198
|
onError: err => errors.push(err),
|
|
235
199
|
onWarn: err => warnings.push(err),
|
|
236
200
|
expressionPlugins: ['typescript'],
|
|
237
|
-
nodeTransforms,
|
|
238
|
-
directiveTransforms,
|
|
239
201
|
};
|
|
240
202
|
for (const plugin of plugins) {
|
|
241
203
|
if (plugin.resolveTemplateCompilerOptions) {
|
|
@@ -246,7 +208,6 @@ function useIR(ts, plugins, fileName, getSnapshot, getParseSfcResult) {
|
|
|
246
208
|
try {
|
|
247
209
|
const result = plugin.compileSFCTemplate?.(base.lang, base.content, options);
|
|
248
210
|
if (result) {
|
|
249
|
-
(0, normalize_1.normalizeTemplateAST)(result.ast);
|
|
250
211
|
return {
|
|
251
212
|
snapshot: getUntrackedSnapshot(),
|
|
252
213
|
template: base.content,
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"index.d.ts",
|
|
7
|
+
"index.js",
|
|
8
|
+
"lib/**/*.d.ts",
|
|
9
|
+
"lib/**/*.js",
|
|
10
|
+
"types"
|
|
8
11
|
],
|
|
9
12
|
"sideEffects": false,
|
|
10
13
|
"repository": {
|
|
@@ -12,21 +15,24 @@
|
|
|
12
15
|
"url": "https://github.com/vuejs/language-tools.git",
|
|
13
16
|
"directory": "packages/language-core"
|
|
14
17
|
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"generate-names": "node scripts/generate-names.js"
|
|
20
|
+
},
|
|
15
21
|
"dependencies": {
|
|
16
22
|
"@volar/language-core": "2.4.28",
|
|
17
23
|
"@vue/compiler-dom": "^3.5.0",
|
|
18
24
|
"@vue/shared": "^3.5.0",
|
|
19
|
-
"alien-signals": "^3.
|
|
25
|
+
"alien-signals": "^3.2.0",
|
|
20
26
|
"muggle-string": "^0.4.1",
|
|
21
27
|
"path-browserify": "^1.0.1",
|
|
22
28
|
"picomatch": "^4.0.4"
|
|
23
29
|
},
|
|
24
30
|
"devDependencies": {
|
|
25
|
-
"@types/node": "^
|
|
31
|
+
"@types/node": "^24.1.0",
|
|
26
32
|
"@types/path-browserify": "^1.0.3",
|
|
27
33
|
"@types/picomatch": "^4.0.3",
|
|
28
34
|
"@volar/typescript": "2.4.28",
|
|
29
35
|
"@vue/compiler-sfc": "^3.5.0"
|
|
30
36
|
},
|
|
31
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9c1fd47ffe25e86394232dfc76453a5f76cb4fe0"
|
|
32
38
|
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.normalizeTemplateAST = normalizeTemplateAST;
|
|
37
|
-
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
38
|
-
const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
|
|
39
|
-
// See https://github.com/vuejs/core/issues/3498
|
|
40
|
-
function normalizeTemplateAST(root) {
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
const transformContext = {
|
|
43
|
-
onError: () => { },
|
|
44
|
-
helperString: str => str.toString(),
|
|
45
|
-
replaceNode: () => { },
|
|
46
|
-
cacheHandlers: false,
|
|
47
|
-
prefixIdentifiers: false,
|
|
48
|
-
scopes: {
|
|
49
|
-
vFor: 0,
|
|
50
|
-
vOnce: 0,
|
|
51
|
-
vPre: 0,
|
|
52
|
-
vSlot: 0,
|
|
53
|
-
},
|
|
54
|
-
expressionPlugins: ['typescript'],
|
|
55
|
-
};
|
|
56
|
-
for (const { children, codegenNode, props } of (0, forEachTemplateNode_1.forEachElementNode)(root)) {
|
|
57
|
-
for (let i = 0; i < children.length; i++) {
|
|
58
|
-
const child = children[i];
|
|
59
|
-
if (child.type !== CompilerDOM.NodeTypes.ELEMENT) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
const forNode = getVForNode(child, transformContext);
|
|
63
|
-
if (forNode) {
|
|
64
|
-
children[i] = forNode;
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
const ifNode = getVIfNode(child, transformContext);
|
|
68
|
-
if (ifNode) {
|
|
69
|
-
const normalized = normalizeIfBranch(ifNode, children, i);
|
|
70
|
-
children.splice(i, normalized.end - i + 1, normalized.node);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// #4539
|
|
75
|
-
if (codegenNode
|
|
76
|
-
&& 'props' in codegenNode
|
|
77
|
-
&& codegenNode.props
|
|
78
|
-
&& 'properties' in codegenNode.props) {
|
|
79
|
-
for (const p of codegenNode.props.properties) {
|
|
80
|
-
if (p.key.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
81
|
-
&& p.key.content === 'key'
|
|
82
|
-
&& !p.key.isHandlerKey
|
|
83
|
-
&& !p.key.loc.source
|
|
84
|
-
&& p.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
85
|
-
&& p.value.constType === CompilerDOM.ConstantTypes.NOT_CONSTANT) {
|
|
86
|
-
const contentBeforeValue = root.loc.source.slice(0, p.value.loc.start.offset);
|
|
87
|
-
const argOffset = contentBeforeValue.lastIndexOf('key');
|
|
88
|
-
props.push({
|
|
89
|
-
type: CompilerDOM.NodeTypes.DIRECTIVE,
|
|
90
|
-
name: 'bind',
|
|
91
|
-
exp: p.value,
|
|
92
|
-
loc: p.loc,
|
|
93
|
-
arg: {
|
|
94
|
-
...p.key,
|
|
95
|
-
loc: {
|
|
96
|
-
start: { line: -1, column: -1, offset: argOffset },
|
|
97
|
-
end: { line: -1, column: -1, offset: argOffset + 'key'.length },
|
|
98
|
-
source: 'key',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
modifiers: [],
|
|
102
|
-
});
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function normalizeIfBranch(ifNode, children, start) {
|
|
110
|
-
let end = start;
|
|
111
|
-
let comments = [];
|
|
112
|
-
for (let i = start + 1; i < children.length; i++) {
|
|
113
|
-
const sibling = children[i];
|
|
114
|
-
if (sibling.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
115
|
-
comments.push(sibling);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (sibling.type === CompilerDOM.NodeTypes.TEXT && !sibling.content.trim()) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
const elseBranch = getVElseDirective(sibling);
|
|
122
|
-
if (elseBranch) {
|
|
123
|
-
const branchNode = {
|
|
124
|
-
...elseBranch.element,
|
|
125
|
-
props: elseBranch.element.props.filter(prop => prop !== elseBranch.directive),
|
|
126
|
-
};
|
|
127
|
-
const branch = createIfBranch(branchNode, elseBranch.directive);
|
|
128
|
-
if (comments.length) {
|
|
129
|
-
branch.children = [...comments, ...branch.children];
|
|
130
|
-
}
|
|
131
|
-
ifNode.branches.push(branch);
|
|
132
|
-
comments = [];
|
|
133
|
-
end = i;
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
return { node: ifNode, end };
|
|
139
|
-
}
|
|
140
|
-
// source: https://github.com/vuejs/core/blob/25ebe3a42cd80ac0256355c2740a0258cdd7419d/packages/compiler-core/src/transforms/vIf.ts#L207
|
|
141
|
-
function createIfBranch(node, dir) {
|
|
142
|
-
const isTemplateIf = node.tagType === CompilerDOM.ElementTypes.TEMPLATE;
|
|
143
|
-
return {
|
|
144
|
-
type: CompilerDOM.NodeTypes.IF_BRANCH,
|
|
145
|
-
loc: node.loc,
|
|
146
|
-
condition: dir.name === 'else' ? undefined : dir.exp,
|
|
147
|
-
children: isTemplateIf && !CompilerDOM.findDir(node, 'for') && !CompilerDOM.findDir(node, 'slot')
|
|
148
|
-
? node.children
|
|
149
|
-
: [node],
|
|
150
|
-
userKey: CompilerDOM.findProp(node, 'key'),
|
|
151
|
-
isTemplateIf,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function getVElseDirective(node) {
|
|
155
|
-
if (node.type !== CompilerDOM.NodeTypes.ELEMENT) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const directive = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
159
|
-
&& (prop.name === 'else-if' || prop.name === 'else'));
|
|
160
|
-
if (directive) {
|
|
161
|
-
return {
|
|
162
|
-
element: node,
|
|
163
|
-
directive,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function getVForNode(node, transformContext) {
|
|
168
|
-
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
169
|
-
&& prop.name === 'for');
|
|
170
|
-
if (forDirective) {
|
|
171
|
-
let forNode;
|
|
172
|
-
CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
|
|
173
|
-
forNode = { ..._forNode };
|
|
174
|
-
return undefined;
|
|
175
|
-
});
|
|
176
|
-
if (forNode) {
|
|
177
|
-
forNode.children = [{
|
|
178
|
-
...node,
|
|
179
|
-
props: node.props.filter(prop => prop !== forDirective),
|
|
180
|
-
}];
|
|
181
|
-
return forNode;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
function getVIfNode(node, transformContext) {
|
|
186
|
-
const ifDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
187
|
-
&& prop.name === 'if');
|
|
188
|
-
if (ifDirective) {
|
|
189
|
-
let ifNode;
|
|
190
|
-
CompilerDOM.processIf(node, ifDirective, transformContext, _ifNode => {
|
|
191
|
-
ifNode = { ..._ifNode };
|
|
192
|
-
return undefined;
|
|
193
|
-
});
|
|
194
|
-
if (ifNode) {
|
|
195
|
-
for (const branch of ifNode.branches) {
|
|
196
|
-
branch.children = [{
|
|
197
|
-
...node,
|
|
198
|
-
props: node.props.filter(prop => prop !== ifDirective),
|
|
199
|
-
}];
|
|
200
|
-
}
|
|
201
|
-
return ifNode;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=normalize.js.map
|