@vue/language-core 3.3.5 → 3.3.6
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 -0
- package/index.js +1 -0
- package/lib/codegen/codeFeatures.d.ts +24 -84
- package/lib/codegen/codeFeatures.js +46 -4
- package/lib/codegen/names.d.ts +3 -4
- package/lib/codegen/names.js +3 -4
- package/lib/codegen/script/index.js +5 -5
- package/lib/codegen/script/scriptSetup.js +4 -4
- package/lib/codegen/style/common.js +7 -11
- package/lib/codegen/style/index.d.ts +55 -27
- package/lib/codegen/style/index.js +3 -3
- package/lib/codegen/template/context.d.ts +55 -124
- package/lib/codegen/template/context.js +187 -269
- package/lib/codegen/template/element.js +16 -15
- package/lib/codegen/template/elementDirectives.js +11 -11
- package/lib/codegen/template/elementEvents.js +45 -44
- package/lib/codegen/template/elementProps.js +12 -12
- package/lib/codegen/template/index.d.ts +55 -27
- package/lib/codegen/template/index.js +7 -7
- package/lib/codegen/template/interpolation.js +28 -28
- package/lib/codegen/template/objectProperty.js +5 -5
- package/lib/codegen/template/propertyAccess.js +1 -1
- package/lib/codegen/template/slotOutlet.js +8 -10
- package/lib/codegen/template/styleScopedClasses.js +4 -4
- package/lib/codegen/template/vFor.js +3 -3
- package/lib/codegen/template/vIf.js +4 -4
- package/lib/codegen/template/vSlot.js +9 -9
- package/lib/codegen/utils/boundary.d.ts +7 -2
- package/lib/codegen/utils/boundary.js +15 -9
- package/lib/codegen/utils/camelized.js +5 -13
- package/lib/codegen/utils/escaped.js +4 -9
- package/lib/codegen/utils/index.d.ts +1 -1
- package/lib/codegen/utils/index.js +3 -3
- package/lib/codegen/utils/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +1 -1
- package/lib/codegen/utils/unicode.js +4 -4
- package/lib/languagePlugin.js +2 -1
- package/lib/parsers/scriptRanges.d.ts +2 -2
- package/lib/parsers/scriptRanges.js +3 -10
- package/lib/parsers/scriptSetupRanges.d.ts +2 -2
- package/lib/parsers/scriptSetupRanges.js +3 -10
- package/lib/parsers/utils.d.ts +1 -0
- package/lib/parsers/utils.js +10 -0
- package/lib/parsers/vueCompilerOptions.js +2 -2
- package/lib/plugins/file-html.js +4 -4
- package/lib/plugins/file-md.js +15 -15
- package/lib/plugins/file-vue.js +2 -2
- package/lib/plugins/vue-root-tags.js +3 -3
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -4
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-style-css.js +86 -33
- package/lib/plugins/vue-template-html.js +3 -3
- package/lib/plugins/vue-template-inline-css.js +2 -7
- package/lib/plugins/vue-template-inline-ts.js +4 -5
- package/lib/plugins/vue-tsx.d.ts +61 -31
- package/lib/plugins/vue-tsx.js +26 -23
- package/lib/plugins.d.ts +0 -1
- package/lib/plugins.js +0 -15
- package/lib/utils/forEachTemplateNode.js +36 -43
- package/lib/virtualCode/index.js +2 -2
- package/package.json +2 -2
- package/types/template-helpers.d.ts +14 -24
- package/lib/plugins/shared.d.ts +0 -2
- package/lib/plugins/shared.js +0 -12
|
@@ -40,9 +40,10 @@ exports.generateModelEventExpression = generateModelEventExpression;
|
|
|
40
40
|
exports.isCompoundExpression = isCompoundExpression;
|
|
41
41
|
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
42
42
|
const shared_1 = require("@vue/shared");
|
|
43
|
+
const utils_1 = require("../../parsers/utils");
|
|
43
44
|
const codeFeatures_1 = require("../codeFeatures");
|
|
44
45
|
const names_1 = require("../names");
|
|
45
|
-
const
|
|
46
|
+
const utils_2 = require("../utils");
|
|
46
47
|
const boundary_1 = require("../utils/boundary");
|
|
47
48
|
const camelized_1 = require("../utils/camelized");
|
|
48
49
|
const interpolation_1 = require("./interpolation");
|
|
@@ -94,14 +95,14 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtx
|
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
96
97
|
const emitsVar = ctx.getInternalVariable();
|
|
97
|
-
yield `let ${emitsVar}!: ${names_1.names.ResolveEmits}<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${
|
|
98
|
+
yield `let ${emitsVar}!: ${names_1.names.ResolveEmits}<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${utils_2.endOfLine}`;
|
|
98
99
|
for (const { propPrefix, emitPrefix, propName, emitName, items } of Object.values(definitions)) {
|
|
99
|
-
yield `const ${ctx.getInternalVariable()}: ${names_1.names.ResolveEvent}<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${(0, shared_1.camelize)(emitName)}'> = {${
|
|
100
|
+
yield `const ${ctx.getInternalVariable()}: ${names_1.names.ResolveEvent}<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${(0, shared_1.camelize)(emitName)}'> = {${utils_2.newLine}`;
|
|
100
101
|
for (const { prop, source, offset } of items) {
|
|
101
102
|
if (prop.name === 'on') {
|
|
102
103
|
yield `/** @type {typeof ${emitsVar}.`;
|
|
103
104
|
yield* generateEventArg(options, source, offset, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
|
|
104
|
-
yield `} */${
|
|
105
|
+
yield `} */${utils_2.newLine}`;
|
|
105
106
|
}
|
|
106
107
|
if (prop.name === 'on') {
|
|
107
108
|
yield* generateEventArg(options, source, offset, propPrefix.slice(0, -1));
|
|
@@ -112,9 +113,9 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtx
|
|
|
112
113
|
yield `'${propName}': `;
|
|
113
114
|
yield* generateModelEventExpression(options, ctx, prop);
|
|
114
115
|
}
|
|
115
|
-
yield `,${
|
|
116
|
+
yield `,${utils_2.newLine}`;
|
|
116
117
|
}
|
|
117
|
-
yield `}${
|
|
118
|
+
yield `}${utils_2.endOfLine}`;
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
function* generateEventArg(options, name, start, directive = 'on', features) {
|
|
@@ -128,33 +129,36 @@ function* generateEventArg(options, name, start, directive = 'on', features) {
|
|
|
128
129
|
if (directive.length) {
|
|
129
130
|
name = (0, shared_1.capitalize)(name);
|
|
130
131
|
}
|
|
131
|
-
if (
|
|
132
|
-
const
|
|
132
|
+
if (utils_2.identifierRE.test((0, shared_1.camelize)(name))) {
|
|
133
|
+
const boundary = yield* boundary_1.Boundary.start('template', start, features);
|
|
133
134
|
yield directive;
|
|
134
|
-
yield* (0, camelized_1.generateCamelized)(name, 'template', start,
|
|
135
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, boundary.features);
|
|
135
136
|
}
|
|
136
137
|
else {
|
|
137
|
-
const
|
|
138
|
+
const boundary = yield* boundary_1.Boundary.start('template', start, features);
|
|
138
139
|
yield `'`;
|
|
139
140
|
yield directive;
|
|
140
|
-
yield* (0, camelized_1.generateCamelized)(name, 'template', start,
|
|
141
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, boundary.features);
|
|
141
142
|
yield `'`;
|
|
142
|
-
yield
|
|
143
|
+
yield boundary.end(start + name.length);
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
function* generateEventExpression(options, ctx, prop) {
|
|
146
147
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
147
|
-
const ast = (0,
|
|
148
|
+
const ast = (0, utils_2.getTypeScriptAST)(options.typescript, options.template, prop.exp.content);
|
|
148
149
|
const isCompound = isCompoundExpression(options.typescript, ast);
|
|
149
150
|
const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
|
|
150
151
|
if (isCompound) {
|
|
151
|
-
yield `(...[$event]) => {${
|
|
152
|
-
const
|
|
153
|
-
|
|
152
|
+
yield `(...[$event]) => {${utils_2.newLine}`;
|
|
153
|
+
const scope = ctx.scope();
|
|
154
|
+
scope.declare('$event');
|
|
154
155
|
yield* ctx.generateConditionGuards();
|
|
156
|
+
if (isSingleExpression(options.typescript, ast)) {
|
|
157
|
+
yield `return `;
|
|
158
|
+
}
|
|
155
159
|
yield* interpolation;
|
|
156
|
-
yield
|
|
157
|
-
yield*
|
|
160
|
+
yield utils_2.endOfLine;
|
|
161
|
+
yield* scope.end();
|
|
158
162
|
yield `}`;
|
|
159
163
|
ctx.inlayHints.push({
|
|
160
164
|
blockName: 'template',
|
|
@@ -179,10 +183,10 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
179
183
|
}
|
|
180
184
|
function* generateModelEventExpression(options, ctx, prop) {
|
|
181
185
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
182
|
-
yield `(...[$event]) => {${
|
|
186
|
+
yield `(...[$event]) => {${utils_2.newLine}`;
|
|
183
187
|
yield* ctx.generateConditionGuards();
|
|
184
188
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
|
|
185
|
-
yield ` = $event${
|
|
189
|
+
yield ` = $event${utils_2.endOfLine}`;
|
|
186
190
|
yield `}`;
|
|
187
191
|
}
|
|
188
192
|
else {
|
|
@@ -190,35 +194,32 @@ function* generateModelEventExpression(options, ctx, prop) {
|
|
|
190
194
|
}
|
|
191
195
|
}
|
|
192
196
|
function isCompoundExpression(ts, ast) {
|
|
193
|
-
let result = true;
|
|
194
197
|
if (ast.statements.length === 0) {
|
|
195
|
-
|
|
198
|
+
return false;
|
|
196
199
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
else if (ts.isFunctionDeclaration(child_1)) {
|
|
210
|
-
result = false;
|
|
200
|
+
if (ast.statements.length === 1 && ast.text[ast.endOfFileToken.pos - 1] !== ';') {
|
|
201
|
+
const statement = ast.statements[0];
|
|
202
|
+
if (ts.isExpressionStatement(statement)) {
|
|
203
|
+
const node = (0, utils_1.getUnwrappedExpression)(ts, statement.expression);
|
|
204
|
+
if (ts.isArrowFunction(node)
|
|
205
|
+
|| ts.isIdentifier(node)
|
|
206
|
+
|| ts.isElementAccessExpression(node)
|
|
207
|
+
|| ts.isPropertyAccessExpression(node)) {
|
|
208
|
+
return false;
|
|
211
209
|
}
|
|
212
|
-
}
|
|
210
|
+
}
|
|
211
|
+
else if (ts.isFunctionDeclaration(statement)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
213
214
|
}
|
|
214
|
-
return
|
|
215
|
+
return true;
|
|
215
216
|
}
|
|
216
|
-
function
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
function isSingleExpression(ts, ast) {
|
|
218
|
+
if (ast.statements.length === 1 && ast.text[ast.endOfFileToken.pos - 1] !== ';') {
|
|
219
|
+
const statement = ast.statements[0];
|
|
220
|
+
if (ts.isExpressionStatement(statement)) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
222
223
|
}
|
|
223
224
|
return false;
|
|
224
225
|
}
|
|
@@ -114,21 +114,21 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
114
114
|
if (shouldSpread) {
|
|
115
115
|
yield `...{ `;
|
|
116
116
|
}
|
|
117
|
-
const
|
|
117
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
118
118
|
if (prop.arg) {
|
|
119
119
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize);
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
|
-
const
|
|
122
|
+
const boundary2 = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
123
123
|
yield propName;
|
|
124
|
-
yield
|
|
124
|
+
yield boundary2.end(prop.loc.start.offset + 'v-model'.length);
|
|
125
125
|
}
|
|
126
126
|
yield `: `;
|
|
127
127
|
const argLoc = prop.arg?.loc ?? prop.loc;
|
|
128
|
-
const
|
|
128
|
+
const boundary3 = yield* boundary_1.Boundary.start('template', argLoc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
129
129
|
yield* generatePropExp(options, ctx, prop, prop.exp);
|
|
130
|
-
yield
|
|
131
|
-
yield
|
|
130
|
+
yield boundary3.end(argLoc.end.offset);
|
|
131
|
+
yield boundary.end(prop.loc.end.offset);
|
|
132
132
|
if (shouldSpread) {
|
|
133
133
|
yield ` }`;
|
|
134
134
|
}
|
|
@@ -153,7 +153,7 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
153
153
|
if (shouldSpread) {
|
|
154
154
|
yield `...{ `;
|
|
155
155
|
}
|
|
156
|
-
const
|
|
156
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
157
157
|
const prefix = options.template.content.slice(prop.loc.start.offset, prop.loc.start.offset + 1);
|
|
158
158
|
if (prefix === '.' || prefix === '#') {
|
|
159
159
|
// Pug shorthand syntax
|
|
@@ -174,7 +174,7 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
174
174
|
else {
|
|
175
175
|
yield `true`;
|
|
176
176
|
}
|
|
177
|
-
yield
|
|
177
|
+
yield boundary.end(prop.loc.end.offset);
|
|
178
178
|
if (shouldSpread) {
|
|
179
179
|
yield ` }`;
|
|
180
180
|
}
|
|
@@ -187,10 +187,10 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
187
187
|
failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
188
188
|
}
|
|
189
189
|
else {
|
|
190
|
-
const
|
|
190
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
191
191
|
yield `...`;
|
|
192
192
|
yield* generatePropExp(options, ctx, prop, prop.exp);
|
|
193
|
-
yield
|
|
193
|
+
yield boundary.end(prop.exp.loc.end.offset);
|
|
194
194
|
yield `,${utils_1.newLine}`;
|
|
195
195
|
}
|
|
196
196
|
}
|
|
@@ -205,7 +205,7 @@ function* generatePropExp(options, ctx, prop, exp) {
|
|
|
205
205
|
}
|
|
206
206
|
else {
|
|
207
207
|
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
208
|
-
if (utils_1.
|
|
208
|
+
if (utils_1.identifierRE.test(propVariableName)) {
|
|
209
209
|
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, {
|
|
210
210
|
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
211
211
|
__shorthandExpression: 'html',
|
|
@@ -218,7 +218,7 @@ function* generatePropExp(options, ctx, prop, exp) {
|
|
|
218
218
|
yield `.value`;
|
|
219
219
|
}
|
|
220
220
|
else {
|
|
221
|
-
ctx.
|
|
221
|
+
ctx.accessVariable('template', propVariableName, exp.loc.start.offset);
|
|
222
222
|
yield names_1.names.ctx;
|
|
223
223
|
yield `.`;
|
|
224
224
|
yield* codes;
|
|
@@ -14,8 +14,7 @@ export interface TemplateCodegenOptions {
|
|
|
14
14
|
}
|
|
15
15
|
export { generate as generateTemplate };
|
|
16
16
|
declare function generate(options: TemplateCodegenOptions): {
|
|
17
|
-
|
|
18
|
-
currentInfo: {
|
|
17
|
+
getCommentInfo: () => {
|
|
19
18
|
ignoreError?: boolean;
|
|
20
19
|
expectError?: {
|
|
21
20
|
token: number;
|
|
@@ -26,41 +25,70 @@ declare function generate(options: TemplateCodegenOptions): {
|
|
|
26
25
|
offset: number;
|
|
27
26
|
};
|
|
28
27
|
};
|
|
28
|
+
enter: (node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode) => boolean;
|
|
29
|
+
exit: () => Generator<Code>;
|
|
29
30
|
resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
|
|
30
|
-
|
|
31
|
+
getInternalVariable: () => string;
|
|
32
|
+
scopes: {
|
|
33
|
+
add(value: string): /*elided*/ any;
|
|
34
|
+
declare(...variables: string[]): void;
|
|
35
|
+
end(): Generator<Code, any, any>;
|
|
36
|
+
clear(): void;
|
|
37
|
+
delete(value: string): boolean;
|
|
38
|
+
forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
|
|
39
|
+
has(value: string): boolean;
|
|
40
|
+
readonly size: number;
|
|
41
|
+
[Symbol.iterator](): SetIterator<string>;
|
|
42
|
+
entries(): SetIterator<[string, string]>;
|
|
43
|
+
keys(): SetIterator<string>;
|
|
44
|
+
values(): SetIterator<string>;
|
|
45
|
+
readonly [Symbol.toStringTag]: string;
|
|
46
|
+
}[];
|
|
47
|
+
scope: () => {
|
|
48
|
+
add(value: string): any;
|
|
49
|
+
declare(...variables: string[]): void;
|
|
50
|
+
end(): Generator<Code, any, any>;
|
|
51
|
+
clear(): void;
|
|
52
|
+
delete(value: string): boolean;
|
|
53
|
+
forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
|
|
54
|
+
has(value: string): boolean;
|
|
55
|
+
readonly size: number;
|
|
56
|
+
[Symbol.iterator](): SetIterator<string>;
|
|
57
|
+
entries(): SetIterator<[string, string]>;
|
|
58
|
+
keys(): SetIterator<string>;
|
|
59
|
+
values(): SetIterator<string>;
|
|
60
|
+
readonly [Symbol.toStringTag]: string;
|
|
61
|
+
};
|
|
62
|
+
contextAccesses: Map<string, Map<string, Set<number>>>;
|
|
63
|
+
accessVariable: (source: string, name: string, offset?: number) => void;
|
|
64
|
+
generateAutoImport: () => Generator<Code>;
|
|
65
|
+
conditions: string[];
|
|
66
|
+
generateConditionGuards: () => Generator<string, void, unknown>;
|
|
67
|
+
hoistVars: Map<string, string>;
|
|
68
|
+
getHoistVariable: (originalVar: string) => string;
|
|
69
|
+
generateHoistVariables: () => Generator<string, void, unknown>;
|
|
70
|
+
templateRefs: Map<string, {
|
|
71
|
+
typeExp: string;
|
|
72
|
+
offset: number;
|
|
73
|
+
}[]>;
|
|
74
|
+
addTemplateRef: (name: string, typeExp: string, offset: number) => void;
|
|
75
|
+
components: (() => string)[];
|
|
76
|
+
dollarVars: Set<string>;
|
|
77
|
+
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
78
|
+
generatedTypes: Set<string>;
|
|
79
|
+
inheritedAttrVars: Set<string>;
|
|
80
|
+
singleRootElTypes: Set<string>;
|
|
81
|
+
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
31
82
|
slots: {
|
|
32
83
|
name: string;
|
|
33
84
|
offset?: number;
|
|
34
85
|
tagRange: [number, number];
|
|
35
|
-
nodeLoc: any;
|
|
36
86
|
propsVar: string;
|
|
37
87
|
}[];
|
|
38
88
|
dynamicSlots: {
|
|
39
89
|
expVar: string;
|
|
40
90
|
propsVar: string;
|
|
41
91
|
}[];
|
|
42
|
-
|
|
43
|
-
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
|
44
|
-
blockConditions: string[];
|
|
45
|
-
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
46
|
-
inheritedAttrVars: Set<string>;
|
|
47
|
-
templateRefs: Map<string, {
|
|
48
|
-
typeExp: string;
|
|
49
|
-
offset: number;
|
|
50
|
-
}[]>;
|
|
51
|
-
singleRootElTypes: Set<string>;
|
|
52
|
-
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
53
|
-
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
54
|
-
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
55
|
-
scopes: Set<string>[];
|
|
56
|
-
components: (() => string)[];
|
|
57
|
-
declare(...varNames: string[]): void;
|
|
58
|
-
startScope(): () => Generator<Code, any, any>;
|
|
59
|
-
getInternalVariable(): string;
|
|
60
|
-
getHoistVariable(originalVar: string): string;
|
|
61
|
-
generateHoistVariables(): Generator<string, void, unknown>;
|
|
62
|
-
generateConditionGuards(): Generator<string, void, unknown>;
|
|
63
|
-
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
64
|
-
exit(): Generator<Code>;
|
|
92
|
+
inVFor: boolean;
|
|
65
93
|
codes: Code[];
|
|
66
94
|
};
|
|
@@ -21,14 +21,14 @@ function generate(options) {
|
|
|
21
21
|
return { ...ctx, codes };
|
|
22
22
|
}
|
|
23
23
|
function* generateWorker(options, ctx) {
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const scope = ctx.scope();
|
|
25
|
+
scope.declare(...options.setupConsts);
|
|
26
26
|
const { slotsAssignName, propsAssignName, vueCompilerOptions, template, } = options;
|
|
27
27
|
if (slotsAssignName) {
|
|
28
|
-
|
|
28
|
+
scope.declare(slotsAssignName);
|
|
29
29
|
}
|
|
30
30
|
if (propsAssignName) {
|
|
31
|
-
|
|
31
|
+
scope.declare(propsAssignName);
|
|
32
32
|
}
|
|
33
33
|
if (vueCompilerOptions.inferTemplateDollarSlots) {
|
|
34
34
|
ctx.dollarVars.add('$slots');
|
|
@@ -73,7 +73,7 @@ function* generateWorker(options, ctx) {
|
|
|
73
73
|
}
|
|
74
74
|
yield `} & { [K in keyof import('${vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
|
|
75
75
|
}
|
|
76
|
-
yield*
|
|
76
|
+
yield* scope.end();
|
|
77
77
|
}
|
|
78
78
|
function* generateSlotsType(options, ctx) {
|
|
79
79
|
if (options.hasDefineSlots) {
|
|
@@ -94,9 +94,9 @@ function* generateSlotsType(options, ctx) {
|
|
|
94
94
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, codeFeatures_1.codeFeatures.navigation);
|
|
95
95
|
}
|
|
96
96
|
else {
|
|
97
|
-
const
|
|
97
|
+
const boundary = yield* boundary_1.Boundary.start('template', slot.tagRange[0], codeFeatures_1.codeFeatures.navigation);
|
|
98
98
|
yield `default`;
|
|
99
|
-
yield
|
|
99
|
+
yield boundary.end(slot.tagRange[1]);
|
|
100
100
|
}
|
|
101
101
|
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
102
102
|
}
|
|
@@ -45,12 +45,12 @@ function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, cod
|
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
// #1205, #1264
|
|
48
|
-
const
|
|
48
|
+
const boundary = yield* boundary_1.Boundary.start(block.name, start + offset, codeFeatures_1.codeFeatures.verification);
|
|
49
49
|
if (ctx.dollarVars.has(name)) {
|
|
50
50
|
yield names_1.names.dollars;
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
ctx.
|
|
53
|
+
ctx.accessVariable(block.name, name, start + offset);
|
|
54
54
|
yield names_1.names.ctx;
|
|
55
55
|
}
|
|
56
56
|
yield `.`;
|
|
@@ -62,7 +62,7 @@ function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, cod
|
|
|
62
62
|
? { ...data, __shorthandExpression: 'js' }
|
|
63
63
|
: data,
|
|
64
64
|
];
|
|
65
|
-
yield
|
|
65
|
+
yield boundary.end(start + offset + name.length);
|
|
66
66
|
}
|
|
67
67
|
prevEnd = offset + name.length;
|
|
68
68
|
}
|
|
@@ -79,22 +79,22 @@ function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, cod
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
function* forEachIdentifiers(ts, ctx, block, code, prefix, suffix) {
|
|
82
|
-
if (utils_1.
|
|
82
|
+
if (utils_1.identifierRE.test(code) && !shouldIdentifierSkipped(ctx, code)) {
|
|
83
83
|
yield [code, 0, false];
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
const
|
|
86
|
+
const scope = ctx.scope();
|
|
87
87
|
const ast = (0, utils_1.getTypeScriptAST)(ts, block, prefix + code + suffix);
|
|
88
|
-
for (const [id, isShorthand] of forEachDeclarations(ts, ast, ast, ctx)) {
|
|
88
|
+
for (const [id, isShorthand] of forEachDeclarations(ts, ast, ast, ctx, scope)) {
|
|
89
89
|
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
90
90
|
if (shouldIdentifierSkipped(ctx, text)) {
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
93
|
yield [text, (0, shared_2.getStartEnd)(ts, id, ast).start - prefix.length, isShorthand];
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
scope.end();
|
|
96
96
|
}
|
|
97
|
-
function* forEachDeclarations(ts, node, ast, ctx) {
|
|
97
|
+
function* forEachDeclarations(ts, node, ast, ctx, scope) {
|
|
98
98
|
if (ts.isIdentifier(node)) {
|
|
99
99
|
yield [node, false];
|
|
100
100
|
}
|
|
@@ -102,16 +102,16 @@ function* forEachDeclarations(ts, node, ast, ctx) {
|
|
|
102
102
|
yield [node.name, true];
|
|
103
103
|
}
|
|
104
104
|
else if (ts.isPropertyAccessExpression(node)) {
|
|
105
|
-
yield* forEachDeclarations(ts, node.expression, ast, ctx);
|
|
105
|
+
yield* forEachDeclarations(ts, node.expression, ast, ctx, scope);
|
|
106
106
|
}
|
|
107
107
|
else if (ts.isVariableDeclaration(node)) {
|
|
108
|
-
|
|
109
|
-
yield* forEachDeclarationsInBinding(ts, node, ast, ctx);
|
|
108
|
+
scope.declare(...(0, collectBindings_1.collectBindingNames)(ts, node.name, ast));
|
|
109
|
+
yield* forEachDeclarationsInBinding(ts, node, ast, ctx, scope);
|
|
110
110
|
}
|
|
111
111
|
else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
|
|
112
112
|
for (const element of node.elements) {
|
|
113
113
|
if (ts.isBindingElement(element)) {
|
|
114
|
-
yield* forEachDeclarationsInBinding(ts, element, ast, ctx);
|
|
114
|
+
yield* forEachDeclarationsInBinding(ts, element, ast, ctx, scope);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -123,18 +123,18 @@ function* forEachDeclarations(ts, node, ast, ctx) {
|
|
|
123
123
|
if (ts.isPropertyAssignment(prop)) {
|
|
124
124
|
// fix https://github.com/vuejs/language-tools/issues/1176
|
|
125
125
|
if (ts.isComputedPropertyName(prop.name)) {
|
|
126
|
-
yield* forEachDeclarations(ts, prop.name.expression, ast, ctx);
|
|
126
|
+
yield* forEachDeclarations(ts, prop.name.expression, ast, ctx, scope);
|
|
127
127
|
}
|
|
128
|
-
yield* forEachDeclarations(ts, prop.initializer, ast, ctx);
|
|
128
|
+
yield* forEachDeclarations(ts, prop.initializer, ast, ctx, scope);
|
|
129
129
|
}
|
|
130
130
|
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
131
131
|
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
132
|
-
yield* forEachDeclarations(ts, prop, ast, ctx);
|
|
132
|
+
yield* forEachDeclarations(ts, prop, ast, ctx, scope);
|
|
133
133
|
}
|
|
134
134
|
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
135
135
|
else if (ts.isSpreadAssignment(prop)) {
|
|
136
136
|
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
|
137
|
-
yield* forEachDeclarations(ts, prop.expression, ast, ctx);
|
|
137
|
+
yield* forEachDeclarations(ts, prop.expression, ast, ctx, scope);
|
|
138
138
|
}
|
|
139
139
|
// fix https://github.com/vuejs/language-tools/issues/4604
|
|
140
140
|
else if (ts.isFunctionLike(prop) && prop.body) {
|
|
@@ -147,39 +147,39 @@ function* forEachDeclarations(ts, node, ast, ctx) {
|
|
|
147
147
|
yield* forEachDeclarationsInTypeNode(ts, node);
|
|
148
148
|
}
|
|
149
149
|
else if (ts.isBlock(node)) {
|
|
150
|
-
const
|
|
150
|
+
const scope = ctx.scope();
|
|
151
151
|
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
|
152
|
-
yield* forEachDeclarations(ts, child, ast, ctx);
|
|
152
|
+
yield* forEachDeclarations(ts, child, ast, ctx, scope);
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
scope.end();
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
157
|
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
|
158
|
-
yield* forEachDeclarations(ts, child, ast, ctx);
|
|
158
|
+
yield* forEachDeclarations(ts, child, ast, ctx, scope);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
function* forEachDeclarationsInBinding(ts, node, ast, ctx) {
|
|
162
|
+
function* forEachDeclarationsInBinding(ts, node, ast, ctx, scope) {
|
|
163
163
|
if ('type' in node && node.type) {
|
|
164
164
|
yield* forEachDeclarationsInTypeNode(ts, node.type);
|
|
165
165
|
}
|
|
166
166
|
if (!ts.isIdentifier(node.name)) {
|
|
167
|
-
yield* forEachDeclarations(ts, node.name, ast, ctx);
|
|
167
|
+
yield* forEachDeclarations(ts, node.name, ast, ctx, scope);
|
|
168
168
|
}
|
|
169
169
|
if (node.initializer) {
|
|
170
|
-
yield* forEachDeclarations(ts, node.initializer, ast, ctx);
|
|
170
|
+
yield* forEachDeclarations(ts, node.initializer, ast, ctx, scope);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
function* forEachDeclarationsInFunction(ts, node, ast, ctx) {
|
|
174
|
-
const
|
|
174
|
+
const scope = ctx.scope();
|
|
175
175
|
for (const param of node.parameters) {
|
|
176
|
-
|
|
177
|
-
yield* forEachDeclarationsInBinding(ts, param, ast, ctx);
|
|
176
|
+
scope.declare(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
|
|
177
|
+
yield* forEachDeclarationsInBinding(ts, param, ast, ctx, scope);
|
|
178
178
|
}
|
|
179
179
|
if (node.body) {
|
|
180
|
-
yield* forEachDeclarations(ts, node.body, ast, ctx);
|
|
180
|
+
yield* forEachDeclarations(ts, node.body, ast, ctx, scope);
|
|
181
181
|
}
|
|
182
|
-
|
|
182
|
+
scope.end();
|
|
183
183
|
}
|
|
184
184
|
function* forEachDeclarationsInTypeNode(ts, node) {
|
|
185
185
|
if (ts.isTypeQueryNode(node)) {
|
|
@@ -18,19 +18,19 @@ function* generateObjectProperty(options, ctx, code, offset, features, shouldCam
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
else if (shouldCamelize) {
|
|
21
|
-
if (utils_1.
|
|
21
|
+
if (utils_1.identifierRE.test((0, shared_1.camelize)(code))) {
|
|
22
22
|
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, features);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
const
|
|
25
|
+
const boundary = yield* boundary_1.Boundary.start('template', offset, features);
|
|
26
26
|
yield `'`;
|
|
27
|
-
yield* (0, camelized_1.generateCamelized)(code, 'template', offset,
|
|
27
|
+
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, boundary.features);
|
|
28
28
|
yield `'`;
|
|
29
|
-
yield
|
|
29
|
+
yield boundary.end(offset + code.length);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
if (utils_1.
|
|
33
|
+
if (utils_1.identifierRE.test(code)) {
|
|
34
34
|
yield [code, 'template', offset, features];
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
@@ -8,7 +8,7 @@ function* generatePropertyAccess(options, ctx, code, offset, features) {
|
|
|
8
8
|
if (code.startsWith('[') && code.endsWith(']')) {
|
|
9
9
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, features, code, offset);
|
|
10
10
|
}
|
|
11
|
-
else if (utils_1.
|
|
11
|
+
else if (utils_1.identifierRE.test(code)) {
|
|
12
12
|
yield `.`;
|
|
13
13
|
yield [code, 'template', offset, features];
|
|
14
14
|
}
|
|
@@ -77,26 +77,26 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
77
77
|
else {
|
|
78
78
|
codes = [`['default']`];
|
|
79
79
|
}
|
|
80
|
-
const
|
|
80
|
+
const boundary = yield* boundary_1.Boundary.start('template', nameProp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
81
81
|
yield options.slotsAssignName ?? names_1.names.slots;
|
|
82
82
|
yield* codes;
|
|
83
|
-
yield
|
|
83
|
+
yield boundary.end(nameProp.loc.end.offset);
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
const
|
|
86
|
+
const boundary = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
87
87
|
yield `${options.slotsAssignName ?? names_1.names.slots}[`;
|
|
88
|
-
const
|
|
88
|
+
const boundary2 = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
89
89
|
yield `'default'`;
|
|
90
|
-
yield
|
|
90
|
+
yield boundary2.end(startTagEndOffset);
|
|
91
91
|
yield `]`;
|
|
92
|
-
yield
|
|
92
|
+
yield boundary.end(startTagEndOffset);
|
|
93
93
|
}
|
|
94
94
|
yield `)(`;
|
|
95
|
-
const
|
|
95
|
+
const boundary = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
96
96
|
yield `{${utils_1.newLine}`;
|
|
97
97
|
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
|
|
98
98
|
yield `}`;
|
|
99
|
-
yield
|
|
99
|
+
yield boundary.end(startTagEndOffset);
|
|
100
100
|
yield `)${utils_1.endOfLine}`;
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
@@ -109,7 +109,6 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
109
109
|
name: nameProp.value.content,
|
|
110
110
|
offset: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
|
|
111
111
|
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
112
|
-
nodeLoc: node.loc,
|
|
113
112
|
propsVar: ctx.getHoistVariable(propsVar),
|
|
114
113
|
});
|
|
115
114
|
}
|
|
@@ -134,7 +133,6 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
134
133
|
ctx.slots.push({
|
|
135
134
|
name: 'default',
|
|
136
135
|
tagRange: [startTagOffset, startTagEndOffset],
|
|
137
|
-
nodeLoc: node.loc,
|
|
138
136
|
propsVar: ctx.getHoistVariable(propsVar),
|
|
139
137
|
});
|
|
140
138
|
}
|
|
@@ -7,7 +7,7 @@ const names_1 = require("../names");
|
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const boundary_1 = require("../utils/boundary");
|
|
9
9
|
const escaped_1 = require("../utils/escaped");
|
|
10
|
-
const
|
|
10
|
+
const classNameEscapeRE = /([\\'])/;
|
|
11
11
|
// For language-service/lib/plugins/vue-scoped-class-links.ts usage
|
|
12
12
|
exports.references = new WeakMap();
|
|
13
13
|
function* generateStyleScopedClassReference(block, className, offset, fullStart = offset) {
|
|
@@ -27,11 +27,11 @@ function* generateStyleScopedClassReference(block, className, offset, fullStart
|
|
|
27
27
|
cache[1].push([className, offset]);
|
|
28
28
|
}
|
|
29
29
|
yield `/** @type {${names_1.names.StyleScopedClasses}[`;
|
|
30
|
-
const
|
|
30
|
+
const boundary = yield* boundary_1.Boundary.start(block.name, fullStart, codeFeatures_1.codeFeatures.navigationAndCompletion);
|
|
31
31
|
yield `'`;
|
|
32
|
-
yield* (0, escaped_1.generateEscaped)(className, block.name, offset,
|
|
32
|
+
yield* (0, escaped_1.generateEscaped)(className, block.name, offset, boundary.features, classNameEscapeRE);
|
|
33
33
|
yield `'`;
|
|
34
|
-
yield
|
|
34
|
+
yield boundary.end(offset + className.length);
|
|
35
35
|
yield `]} */${utils_1.endOfLine}`;
|
|
36
36
|
}
|
|
37
37
|
//# sourceMappingURL=styleScopedClasses.js.map
|