@vue/language-core 3.0.0-alpha.8 → 3.0.0-beta.1
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 +5 -0
- package/lib/codegen/codeFeatures.js +5 -0
- package/lib/codegen/script/component.js +1 -1
- package/lib/codegen/script/scriptSetup.js +37 -74
- package/lib/codegen/style/imports.d.ts +2 -0
- package/lib/codegen/style/imports.js +27 -0
- package/lib/codegen/style/modules.js +10 -2
- package/lib/codegen/style/scopedClasses.js +6 -2
- package/lib/codegen/template/context.d.ts +1 -0
- package/lib/codegen/template/interpolation.js +3 -1
- package/lib/parsers/scriptSetupRanges.d.ts +3 -3
- package/lib/parsers/scriptSetupRanges.js +32 -56
- package/lib/plugins/vue-tsx.d.ts +2 -2
- package/lib/types.d.ts +9 -3
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/ts.js +4 -3
- package/lib/virtualFile/computedSfc.js +5 -0
- package/package.json +4 -4
- package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
- package/lib/utils/vue2TemplateCompiler.js +0 -89
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.tsCodegen = void 0;
|
|
18
18
|
__exportStar(require("./lib/codegen/globalTypes"), exports);
|
|
19
19
|
__exportStar(require("./lib/codegen/template"), exports);
|
|
20
|
+
__exportStar(require("./lib/codegen/utils"), exports);
|
|
20
21
|
__exportStar(require("./lib/languagePlugin"), exports);
|
|
21
22
|
__exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
|
|
22
23
|
__exportStar(require("./lib/plugins"), exports);
|
|
@@ -78,6 +78,11 @@ declare const raw: {
|
|
|
78
78
|
};
|
|
79
79
|
verification: true;
|
|
80
80
|
};
|
|
81
|
+
withoutSemantic: {
|
|
82
|
+
verification: true;
|
|
83
|
+
navigation: true;
|
|
84
|
+
completion: true;
|
|
85
|
+
};
|
|
81
86
|
};
|
|
82
87
|
export declare const codeFeatures: { [K in keyof typeof raw]: VueCodeInformation; };
|
|
83
88
|
export {};
|
|
@@ -66,6 +66,11 @@ const raw = {
|
|
|
66
66
|
semantic: { shouldHighlight: () => false },
|
|
67
67
|
verification: true,
|
|
68
68
|
},
|
|
69
|
+
withoutSemantic: {
|
|
70
|
+
verification: true,
|
|
71
|
+
navigation: true,
|
|
72
|
+
completion: true,
|
|
73
|
+
},
|
|
69
74
|
};
|
|
70
75
|
exports.codeFeatures = raw;
|
|
71
76
|
//# sourceMappingURL=codeFeatures.js.map
|
|
@@ -60,7 +60,7 @@ function* generateComponentSetupReturns(scriptSetupRanges) {
|
|
|
60
60
|
}
|
|
61
61
|
function* generateEmitsOption(options, scriptSetupRanges) {
|
|
62
62
|
const codes = [];
|
|
63
|
-
if (scriptSetupRanges.
|
|
63
|
+
if (scriptSetupRanges.defineModel.length) {
|
|
64
64
|
codes.push({
|
|
65
65
|
optionExp: `{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`,
|
|
66
66
|
typeOptionType: `__VLS_ModelEmit`,
|
|
@@ -50,7 +50,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
50
50
|
if (scriptSetupRanges.defineEmits) {
|
|
51
51
|
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'}`);
|
|
52
52
|
}
|
|
53
|
-
if (scriptSetupRanges.
|
|
53
|
+
if (scriptSetupRanges.defineModel.length) {
|
|
54
54
|
emitTypes.push(`typeof __VLS_modelEmit`);
|
|
55
55
|
}
|
|
56
56
|
yield `return {} as {${utils_1.newLine}`
|
|
@@ -187,7 +187,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
187
187
|
const templateRefType = arg
|
|
188
188
|
? [
|
|
189
189
|
`__VLS_TemplateRefs[`,
|
|
190
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.
|
|
190
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic),
|
|
191
191
|
`]`
|
|
192
192
|
]
|
|
193
193
|
: [`unknown`];
|
|
@@ -235,7 +235,6 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
235
235
|
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, codeFeatures_1.codeFeatures.all);
|
|
236
236
|
yield* (0, index_1.generateScriptSectionPartiallyEnding)(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue');
|
|
237
237
|
yield* generateMacros(options, ctx);
|
|
238
|
-
yield* generateDefineProp(options);
|
|
239
238
|
if (scriptSetupRanges.defineProps?.typeArg && scriptSetupRanges.withDefaults?.arg) {
|
|
240
239
|
// fix https://github.com/vuejs/language-tools/issues/1187
|
|
241
240
|
yield `const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`;
|
|
@@ -276,22 +275,6 @@ function* generateMacros(options, ctx) {
|
|
|
276
275
|
yield `}: typeof import('${options.vueCompilerOptions.lib}')${utils_1.endOfLine}`;
|
|
277
276
|
}
|
|
278
277
|
}
|
|
279
|
-
function* generateDefineProp(options) {
|
|
280
|
-
const definePropProposalA = options.vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
|
281
|
-
const definePropProposalB = options.vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
|
|
282
|
-
if (definePropProposalA || definePropProposalB) {
|
|
283
|
-
yield `type __VLS_PropOptions<T> = Exclude<import('${options.vueCompilerOptions.lib}').Prop<T>, import('${options.vueCompilerOptions.lib}').PropType<T>>${utils_1.endOfLine}`;
|
|
284
|
-
if (definePropProposalA) {
|
|
285
|
-
yield `declare function defineProp<T>(name: string, options: ({ required: true } | { default: T }) & __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${utils_1.endOfLine}`;
|
|
286
|
-
yield `declare function defineProp<T>(name?: string, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${utils_1.endOfLine}`;
|
|
287
|
-
}
|
|
288
|
-
if (definePropProposalB) {
|
|
289
|
-
yield `declare function defineProp<T>(value: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${utils_1.endOfLine}`;
|
|
290
|
-
yield `declare function defineProp<T>(value: T | (() => T) | undefined, required: true, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${utils_1.endOfLine}`;
|
|
291
|
-
yield `declare function defineProp<T>(value?: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${utils_1.endOfLine}`;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
278
|
function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, defaultName, typeName) {
|
|
296
279
|
if (typeArg) {
|
|
297
280
|
yield [[
|
|
@@ -348,24 +331,15 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
348
331
|
yield `${ctx.localTypes.OmitKeepDiscriminatedUnion}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
|
|
349
332
|
yield utils_1.endOfLine;
|
|
350
333
|
}
|
|
351
|
-
if (scriptSetupRanges.
|
|
334
|
+
if (scriptSetupRanges.defineModel.length) {
|
|
352
335
|
yield `const __VLS_defaults = {${utils_1.newLine}`;
|
|
353
|
-
for (const
|
|
354
|
-
if (!
|
|
355
|
-
continue;
|
|
356
|
-
}
|
|
357
|
-
const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
|
358
|
-
if (defineProp.name || defineProp.isModel) {
|
|
359
|
-
yield `'${propName}'`;
|
|
360
|
-
}
|
|
361
|
-
else if (defineProp.localName) {
|
|
362
|
-
yield localName;
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
336
|
+
for (const defineModel of scriptSetupRanges.defineModel) {
|
|
337
|
+
if (!defineModel.defaultValue) {
|
|
365
338
|
continue;
|
|
366
339
|
}
|
|
367
|
-
|
|
368
|
-
yield
|
|
340
|
+
const [propName] = getPropAndLocalName(scriptSetup, defineModel);
|
|
341
|
+
yield `'${propName}': `;
|
|
342
|
+
yield getRangeText(scriptSetup, defineModel.defaultValue);
|
|
369
343
|
yield `,${utils_1.newLine}`;
|
|
370
344
|
}
|
|
371
345
|
yield `}${utils_1.endOfLine}`;
|
|
@@ -385,38 +359,30 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
385
359
|
ctx.generatedPropsType = true;
|
|
386
360
|
yield `__VLS_Props`;
|
|
387
361
|
}
|
|
388
|
-
if (scriptSetupRanges.
|
|
362
|
+
if (scriptSetupRanges.defineModel.length) {
|
|
389
363
|
if (ctx.generatedPropsType) {
|
|
390
364
|
yield ` & `;
|
|
391
365
|
}
|
|
392
366
|
ctx.generatedPropsType = true;
|
|
393
367
|
yield `{${utils_1.newLine}`;
|
|
394
|
-
for (const
|
|
395
|
-
const [propName, localName] = getPropAndLocalName(scriptSetup,
|
|
396
|
-
if (
|
|
397
|
-
yield scriptSetup.content.slice(
|
|
368
|
+
for (const defineModel of scriptSetupRanges.defineModel) {
|
|
369
|
+
const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
|
|
370
|
+
if (defineModel.comments) {
|
|
371
|
+
yield scriptSetup.content.slice(defineModel.comments.start, defineModel.comments.end);
|
|
398
372
|
yield utils_1.newLine;
|
|
399
373
|
}
|
|
400
|
-
if (
|
|
401
|
-
yield
|
|
402
|
-
}
|
|
403
|
-
else if (defineProp.name) {
|
|
404
|
-
yield* (0, camelized_1.generateCamelized)(getRangeText(scriptSetup, defineProp.name), scriptSetup.name, defineProp.name.start, codeFeatures_1.codeFeatures.navigation);
|
|
405
|
-
}
|
|
406
|
-
else if (defineProp.localName) {
|
|
407
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.localName.start, defineProp.localName.end, codeFeatures_1.codeFeatures.navigation);
|
|
374
|
+
if (defineModel.name) {
|
|
375
|
+
yield* (0, camelized_1.generateCamelized)(getRangeText(scriptSetup, defineModel.name), scriptSetup.name, defineModel.name.start, codeFeatures_1.codeFeatures.navigation);
|
|
408
376
|
}
|
|
409
377
|
else {
|
|
410
|
-
|
|
378
|
+
yield propName;
|
|
411
379
|
}
|
|
412
|
-
yield
|
|
413
|
-
|
|
414
|
-
: `?: `;
|
|
415
|
-
yield* generateDefinePropType(scriptSetup, propName, localName, defineProp);
|
|
380
|
+
yield defineModel.required ? `: ` : `?: `;
|
|
381
|
+
yield* generateDefineModelType(scriptSetup, propName, localName, defineModel);
|
|
416
382
|
yield `,${utils_1.newLine}`;
|
|
417
|
-
if (
|
|
418
|
-
const modifierName = `${
|
|
419
|
-
const modifierType = getRangeText(scriptSetup,
|
|
383
|
+
if (defineModel.modifierType) {
|
|
384
|
+
const modifierName = `${defineModel.name ? propName : 'model'}Modifiers`;
|
|
385
|
+
const modifierType = getRangeText(scriptSetup, defineModel.modifierType);
|
|
420
386
|
yield `'${modifierName}'?: Partial<Record<${modifierType}, true>>,${utils_1.newLine}`;
|
|
421
387
|
}
|
|
422
388
|
}
|
|
@@ -428,13 +394,12 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
428
394
|
yield utils_1.endOfLine;
|
|
429
395
|
}
|
|
430
396
|
function* generateModelEmit(scriptSetup, scriptSetupRanges) {
|
|
431
|
-
|
|
432
|
-
if (defineModels.length) {
|
|
397
|
+
if (scriptSetupRanges.defineModel.length) {
|
|
433
398
|
yield `type __VLS_ModelEmit = {${utils_1.newLine}`;
|
|
434
|
-
for (const defineModel of
|
|
399
|
+
for (const defineModel of scriptSetupRanges.defineModel) {
|
|
435
400
|
const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
|
|
436
401
|
yield `'update:${propName}': [value: `;
|
|
437
|
-
yield*
|
|
402
|
+
yield* generateDefineModelType(scriptSetup, propName, localName, defineModel);
|
|
438
403
|
if (!defineModel.required && !defineModel.defaultValue) {
|
|
439
404
|
yield ` | undefined`;
|
|
440
405
|
}
|
|
@@ -444,32 +409,30 @@ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
|
|
|
444
409
|
yield `const __VLS_modelEmit = defineEmits<__VLS_ModelEmit>()${utils_1.endOfLine}`;
|
|
445
410
|
}
|
|
446
411
|
}
|
|
447
|
-
function*
|
|
448
|
-
if (
|
|
449
|
-
// Infer from
|
|
450
|
-
yield getRangeText(scriptSetup,
|
|
412
|
+
function* generateDefineModelType(scriptSetup, propName, localName, defineModel) {
|
|
413
|
+
if (defineModel.type) {
|
|
414
|
+
// Infer from defineModel<T>
|
|
415
|
+
yield getRangeText(scriptSetup, defineModel.type);
|
|
451
416
|
}
|
|
452
|
-
else if (
|
|
417
|
+
else if (defineModel.runtimeType && localName) {
|
|
453
418
|
// Infer from actual prop declaration code
|
|
454
419
|
yield `typeof ${localName}['value']`;
|
|
455
420
|
}
|
|
456
|
-
else if (
|
|
457
|
-
// Infer from
|
|
421
|
+
else if (defineModel.defaultValue && propName) {
|
|
422
|
+
// Infer from defineModel({default: T})
|
|
458
423
|
yield `typeof __VLS_defaults['${propName}']`;
|
|
459
424
|
}
|
|
460
425
|
else {
|
|
461
426
|
yield `any`;
|
|
462
427
|
}
|
|
463
428
|
}
|
|
464
|
-
function getPropAndLocalName(scriptSetup,
|
|
465
|
-
const localName =
|
|
466
|
-
? getRangeText(scriptSetup,
|
|
429
|
+
function getPropAndLocalName(scriptSetup, defineModel) {
|
|
430
|
+
const localName = defineModel.localName
|
|
431
|
+
? getRangeText(scriptSetup, defineModel.localName)
|
|
467
432
|
: undefined;
|
|
468
|
-
const propName =
|
|
469
|
-
? (0, shared_1.camelize)(getRangeText(scriptSetup,
|
|
470
|
-
:
|
|
471
|
-
? 'modelValue'
|
|
472
|
-
: localName;
|
|
433
|
+
const propName = defineModel.name
|
|
434
|
+
? (0, shared_1.camelize)(getRangeText(scriptSetup, defineModel.name).slice(1, -1))
|
|
435
|
+
: 'modelValue';
|
|
473
436
|
return [propName, localName];
|
|
474
437
|
}
|
|
475
438
|
function getRangeText(scriptSetup, range) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateStyleImports = generateStyleImports;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
6
|
+
function* generateStyleImports(style) {
|
|
7
|
+
const features = {
|
|
8
|
+
navigation: true,
|
|
9
|
+
verification: true
|
|
10
|
+
};
|
|
11
|
+
if (typeof style.src === 'object') {
|
|
12
|
+
yield `${utils_1.newLine} & typeof import(`;
|
|
13
|
+
yield* (0, wrapWith_1.wrapWith)(style.src.offset, style.src.offset + style.src.text.length, 'main', features, `'`, [style.src.text, 'main', style.src.offset, utils_1.combineLastMapping], `'`);
|
|
14
|
+
yield `).default`;
|
|
15
|
+
}
|
|
16
|
+
for (const { text, offset } of style.imports) {
|
|
17
|
+
yield `${utils_1.newLine} & typeof import('`;
|
|
18
|
+
yield [
|
|
19
|
+
text,
|
|
20
|
+
style.name,
|
|
21
|
+
offset,
|
|
22
|
+
features
|
|
23
|
+
];
|
|
24
|
+
yield `').default`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=imports.js.map
|
|
@@ -4,6 +4,7 @@ exports.generateStyleModules = generateStyleModules;
|
|
|
4
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const classProperty_1 = require("./classProperty");
|
|
7
|
+
const imports_1 = require("./imports");
|
|
7
8
|
function* generateStyleModules(options) {
|
|
8
9
|
const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
|
|
9
10
|
if (!styles.length && !options.scriptSetupRanges?.useCssModule.length) {
|
|
@@ -20,10 +21,17 @@ function* generateStyleModules(options) {
|
|
|
20
21
|
text,
|
|
21
22
|
'main',
|
|
22
23
|
offset,
|
|
23
|
-
codeFeatures_1.codeFeatures.
|
|
24
|
+
codeFeatures_1.codeFeatures.navigation,
|
|
24
25
|
];
|
|
25
26
|
}
|
|
26
|
-
yield `:
|
|
27
|
+
yield `: `;
|
|
28
|
+
if (!options.vueCompilerOptions.strictCssModules) {
|
|
29
|
+
yield `Record<string, string> & `;
|
|
30
|
+
}
|
|
31
|
+
yield `__VLS_PrettifyGlobal<{}`;
|
|
32
|
+
if (options.vueCompilerOptions.resolveStyleImports) {
|
|
33
|
+
yield* (0, imports_1.generateStyleImports)(style);
|
|
34
|
+
}
|
|
27
35
|
for (const className of style.classNames) {
|
|
28
36
|
yield* (0, classProperty_1.generateClassProperty)(i, className.text, className.offset, 'string');
|
|
29
37
|
}
|
|
@@ -3,17 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateStyleScopedClasses = generateStyleScopedClasses;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const classProperty_1 = require("./classProperty");
|
|
6
|
+
const imports_1 = require("./imports");
|
|
6
7
|
function* generateStyleScopedClasses(options, ctx) {
|
|
7
|
-
const option = options.vueCompilerOptions.
|
|
8
|
+
const option = options.vueCompilerOptions.resolveStyleClassNames;
|
|
8
9
|
const styles = options.sfc.styles
|
|
9
10
|
.map((style, i) => [style, i])
|
|
10
|
-
.filter(([style]) => option ===
|
|
11
|
+
.filter(([style]) => option === true || (option === 'scoped' && style.scoped));
|
|
11
12
|
if (!styles.length) {
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
const firstClasses = new Set();
|
|
15
16
|
yield `type __VLS_StyleScopedClasses = {}`;
|
|
16
17
|
for (const [style, i] of styles) {
|
|
18
|
+
if (options.vueCompilerOptions.resolveStyleImports) {
|
|
19
|
+
yield* (0, imports_1.generateStyleImports)(style);
|
|
20
|
+
}
|
|
17
21
|
for (const className of style.classNames) {
|
|
18
22
|
if (firstClasses.has(className.text)) {
|
|
19
23
|
ctx.scopedClasses.push({
|
|
@@ -129,6 +129,7 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
129
129
|
withoutHighlightAndNavigation: VueCodeInformation;
|
|
130
130
|
withoutHighlightAndCompletion: VueCodeInformation;
|
|
131
131
|
withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
|
|
132
|
+
withoutSemantic: VueCodeInformation;
|
|
132
133
|
};
|
|
133
134
|
resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
|
|
134
135
|
inVFor: boolean;
|
|
@@ -114,7 +114,9 @@ function* generateVar(templateRefNames, ctx, code, offset, curVar) {
|
|
|
114
114
|
if (ctx.dollarVars.has(curVar.text)) {
|
|
115
115
|
yield [`__VLS_dollars.`, undefined];
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
else {
|
|
118
|
+
yield [`__VLS_ctx.`, undefined];
|
|
119
|
+
}
|
|
118
120
|
yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
119
121
|
}
|
|
120
122
|
}
|
|
@@ -6,7 +6,7 @@ type CallExpressionRange = {
|
|
|
6
6
|
arg?: TextRange;
|
|
7
7
|
typeArg?: TextRange;
|
|
8
8
|
};
|
|
9
|
-
type
|
|
9
|
+
type DefineModel = {
|
|
10
10
|
localName?: TextRange;
|
|
11
11
|
name?: TextRange;
|
|
12
12
|
type?: TextRange;
|
|
@@ -14,7 +14,6 @@ type DefineProp = {
|
|
|
14
14
|
runtimeType?: TextRange;
|
|
15
15
|
defaultValue?: TextRange;
|
|
16
16
|
required?: boolean;
|
|
17
|
-
isModel?: boolean;
|
|
18
17
|
comments?: TextRange;
|
|
19
18
|
argNode?: ts.Expression;
|
|
20
19
|
};
|
|
@@ -55,7 +54,7 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
55
54
|
isDefaultImport?: boolean;
|
|
56
55
|
isNamespace?: boolean;
|
|
57
56
|
}[];
|
|
58
|
-
|
|
57
|
+
defineModel: DefineModel[];
|
|
59
58
|
defineProps: DefineProps | undefined;
|
|
60
59
|
withDefaults: WithDefaults | undefined;
|
|
61
60
|
defineEmits: DefineEmits | undefined;
|
|
@@ -73,4 +72,5 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
|
|
|
73
72
|
isDefaultImport?: boolean;
|
|
74
73
|
isNamespace?: boolean;
|
|
75
74
|
}[];
|
|
75
|
+
export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, ast: ts.SourceFile): TextRange[];
|
|
76
76
|
export {};
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseScriptSetupRanges = parseScriptSetupRanges;
|
|
4
4
|
exports.parseBindingRanges = parseBindingRanges;
|
|
5
|
+
exports.findBindingVars = findBindingVars;
|
|
5
6
|
const utils_1 = require("../codegen/utils");
|
|
6
7
|
const shared_1 = require("../utils/shared");
|
|
7
8
|
const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
|
|
8
9
|
function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
9
|
-
const
|
|
10
|
+
const defineModel = [];
|
|
10
11
|
let defineProps;
|
|
11
12
|
let withDefaults;
|
|
12
13
|
let defineEmits;
|
|
@@ -17,8 +18,6 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
17
18
|
const useCssModule = [];
|
|
18
19
|
const useSlots = [];
|
|
19
20
|
const useTemplateRef = [];
|
|
20
|
-
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
|
21
|
-
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
|
|
22
21
|
const text = ast.text;
|
|
23
22
|
const leadingCommentRanges = ts.getLeadingCommentRanges(text, 0)?.reverse() ?? [];
|
|
24
23
|
const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckReg.test(text.slice(range.pos, range.end)))?.end ?? 0;
|
|
@@ -26,24 +25,27 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
26
25
|
let foundNonImportExportNode = false;
|
|
27
26
|
let importSectionEndOffset = 0;
|
|
28
27
|
ts.forEachChild(ast, node => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
&& !isTypeExport
|
|
34
|
-
&& !ts.isEmptyStatement(node)
|
|
28
|
+
if (foundNonImportExportNode
|
|
29
|
+
|| ts.isImportDeclaration(node)
|
|
30
|
+
|| ts.isExportDeclaration(node)
|
|
31
|
+
|| ts.isEmptyStatement(node)
|
|
35
32
|
// fix https://github.com/vuejs/language-tools/issues/1223
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
|| ts.isImportEqualsDeclaration(node)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if ((ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node))
|
|
37
|
+
&& node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const commentRanges = ts.getLeadingCommentRanges(text, node.pos);
|
|
41
|
+
if (commentRanges?.length) {
|
|
42
|
+
const commentRange = commentRanges.sort((a, b) => a.pos - b.pos)[0];
|
|
43
|
+
importSectionEndOffset = commentRange.pos;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
importSectionEndOffset = (0, shared_1.getStartEnd)(ts, node, ast).start;
|
|
46
47
|
}
|
|
48
|
+
foundNonImportExportNode = true;
|
|
47
49
|
});
|
|
48
50
|
ts.forEachChild(ast, node => visitNode(node, [ast]));
|
|
49
51
|
const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
|
|
@@ -55,7 +57,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
55
57
|
leadingCommentEndOffset,
|
|
56
58
|
importSectionEndOffset,
|
|
57
59
|
bindings,
|
|
58
|
-
|
|
60
|
+
defineModel,
|
|
59
61
|
defineProps,
|
|
60
62
|
withDefaults,
|
|
61
63
|
defineEmits,
|
|
@@ -72,8 +74,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
72
74
|
if (ts.isCallExpression(node)
|
|
73
75
|
&& ts.isIdentifier(node.expression)) {
|
|
74
76
|
const callText = _getNodeText(node.expression);
|
|
75
|
-
|
|
76
|
-
if (isDefineModel || callText === 'defineProp') {
|
|
77
|
+
if (vueCompilerOptions.macros.defineModel.includes(callText)) {
|
|
77
78
|
let localName;
|
|
78
79
|
let propName;
|
|
79
80
|
let options;
|
|
@@ -82,8 +83,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
82
83
|
let runtimeType;
|
|
83
84
|
let defaultValue;
|
|
84
85
|
let required = false;
|
|
85
|
-
if (ts.isVariableDeclaration(parent) &&
|
|
86
|
-
ts.isIdentifier(parent.name)) {
|
|
86
|
+
if (ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)) {
|
|
87
87
|
localName = _getStartEnd(parent.name);
|
|
88
88
|
}
|
|
89
89
|
if (node.typeArguments) {
|
|
@@ -94,39 +94,16 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
94
94
|
modifierType = _getStartEnd(node.typeArguments[1]);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
options = node.arguments[1];
|
|
101
|
-
}
|
|
102
|
-
else if (node.arguments.length >= 1) {
|
|
103
|
-
if (ts.isStringLiteralLike(node.arguments[0])) {
|
|
104
|
-
propName = node.arguments[0];
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
options = node.arguments[0];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
97
|
+
if (node.arguments.length >= 2) {
|
|
98
|
+
propName = node.arguments[0];
|
|
99
|
+
options = node.arguments[1];
|
|
110
100
|
}
|
|
111
|
-
else if (
|
|
112
|
-
if (node.arguments
|
|
113
|
-
options = node.arguments[1];
|
|
114
|
-
}
|
|
115
|
-
if (node.arguments.length >= 1) {
|
|
101
|
+
else if (node.arguments.length >= 1) {
|
|
102
|
+
if (ts.isStringLiteralLike(node.arguments[0])) {
|
|
116
103
|
propName = node.arguments[0];
|
|
117
104
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (node.arguments.length >= 3) {
|
|
121
|
-
options = node.arguments[2];
|
|
122
|
-
}
|
|
123
|
-
if (node.arguments.length >= 2) {
|
|
124
|
-
if (node.arguments[1].kind === ts.SyntaxKind.TrueKeyword) {
|
|
125
|
-
required = true;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (node.arguments.length >= 1) {
|
|
129
|
-
defaultValue = _getStartEnd(node.arguments[0]);
|
|
105
|
+
else {
|
|
106
|
+
options = node.arguments[0];
|
|
130
107
|
}
|
|
131
108
|
}
|
|
132
109
|
if (options && ts.isObjectLiteralExpression(options)) {
|
|
@@ -150,7 +127,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
150
127
|
if (propName && ts.isStringLiteralLike(propName)) {
|
|
151
128
|
name = _getStartEnd(propName);
|
|
152
129
|
}
|
|
153
|
-
|
|
130
|
+
defineModel.push({
|
|
154
131
|
localName,
|
|
155
132
|
name,
|
|
156
133
|
type,
|
|
@@ -158,7 +135,6 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
158
135
|
runtimeType,
|
|
159
136
|
defaultValue,
|
|
160
137
|
required,
|
|
161
|
-
isModel: isDefineModel,
|
|
162
138
|
comments: getClosestMultiLineCommentRange(ts, node, parents, ast),
|
|
163
139
|
argNode: options,
|
|
164
140
|
});
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
27
27
|
isDefaultImport?: boolean;
|
|
28
28
|
isNamespace?: boolean;
|
|
29
29
|
}[];
|
|
30
|
-
|
|
30
|
+
defineModel: {
|
|
31
31
|
localName?: import("../types").TextRange;
|
|
32
32
|
name?: import("../types").TextRange;
|
|
33
33
|
type?: import("../types").TextRange;
|
|
@@ -35,7 +35,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
35
35
|
runtimeType?: import("../types").TextRange;
|
|
36
36
|
defaultValue?: import("../types").TextRange;
|
|
37
37
|
required?: boolean;
|
|
38
|
-
isModel?: boolean;
|
|
39
38
|
comments?: import("../types").TextRange;
|
|
40
39
|
argNode?: import("typescript").Expression;
|
|
41
40
|
}[];
|
|
@@ -165,6 +164,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
165
164
|
withoutHighlightAndNavigation: import("../types").VueCodeInformation;
|
|
166
165
|
withoutHighlightAndCompletion: import("../types").VueCodeInformation;
|
|
167
166
|
withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
|
|
167
|
+
withoutSemantic: import("../types").VueCodeInformation;
|
|
168
168
|
};
|
|
169
169
|
resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
|
|
170
170
|
inVFor: boolean;
|
package/lib/types.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export interface VueCompilerOptions {
|
|
|
25
25
|
jsxSlots: boolean;
|
|
26
26
|
strictSlotChildren: boolean;
|
|
27
27
|
strictVModel: boolean;
|
|
28
|
+
strictCssModules: boolean;
|
|
28
29
|
checkUnknownProps: boolean;
|
|
29
30
|
checkUnknownEvents: boolean;
|
|
30
31
|
checkUnknownDirectives: boolean;
|
|
@@ -37,6 +38,8 @@ export interface VueCompilerOptions {
|
|
|
37
38
|
inferTemplateDollarSlots: boolean;
|
|
38
39
|
skipTemplateCodegen: boolean;
|
|
39
40
|
fallthroughAttributes: boolean;
|
|
41
|
+
resolveStyleImports: boolean;
|
|
42
|
+
resolveStyleClassNames: boolean | 'scoped';
|
|
40
43
|
fallthroughComponentNames: string[];
|
|
41
44
|
dataAttributes: string[];
|
|
42
45
|
htmlAttributes: string[];
|
|
@@ -57,8 +60,6 @@ export interface VueCompilerOptions {
|
|
|
57
60
|
useTemplateRef: string[];
|
|
58
61
|
};
|
|
59
62
|
plugins: VueLanguagePlugin[];
|
|
60
|
-
experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false;
|
|
61
|
-
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
|
|
62
63
|
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
|
|
63
64
|
__setupedGlobalTypes?: true | {
|
|
64
65
|
absolutePath: string;
|
|
@@ -133,8 +134,13 @@ export interface Sfc {
|
|
|
133
134
|
ast: ts.SourceFile;
|
|
134
135
|
} | undefined;
|
|
135
136
|
styles: readonly (SfcBlock & {
|
|
137
|
+
src: SfcBlockAttr | undefined;
|
|
138
|
+
module: SfcBlockAttr | undefined;
|
|
136
139
|
scoped: boolean;
|
|
137
|
-
|
|
140
|
+
imports: {
|
|
141
|
+
text: string;
|
|
142
|
+
offset: number;
|
|
143
|
+
}[];
|
|
138
144
|
cssVars: {
|
|
139
145
|
text: string;
|
|
140
146
|
offset: number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCssImports = parseCssImports;
|
|
4
|
+
const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
|
|
5
|
+
function* parseCssImports(css) {
|
|
6
|
+
const matches = css.matchAll(cssImportReg);
|
|
7
|
+
for (const match of matches) {
|
|
8
|
+
let text = match[0];
|
|
9
|
+
let offset = match.index;
|
|
10
|
+
if (text.startsWith('\'') || text.startsWith('"')) {
|
|
11
|
+
text = text.slice(1, -1);
|
|
12
|
+
offset += 1;
|
|
13
|
+
}
|
|
14
|
+
if (text) {
|
|
15
|
+
yield { text, offset };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=parseCssImports.js.map
|
package/lib/utils/ts.js
CHANGED
|
@@ -131,7 +131,7 @@ class CompilerOptionsResolver {
|
|
|
131
131
|
break;
|
|
132
132
|
case 'plugins':
|
|
133
133
|
this.plugins = (options.plugins ?? [])
|
|
134
|
-
.
|
|
134
|
+
.flatMap((pluginPath) => {
|
|
135
135
|
try {
|
|
136
136
|
const resolvedPath = resolvePath(pluginPath, rootDir);
|
|
137
137
|
if (resolvedPath) {
|
|
@@ -219,6 +219,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
219
219
|
jsxSlots: false,
|
|
220
220
|
strictSlotChildren: strictTemplates,
|
|
221
221
|
strictVModel: strictTemplates,
|
|
222
|
+
strictCssModules: false,
|
|
222
223
|
checkUnknownProps: strictTemplates,
|
|
223
224
|
checkUnknownEvents: strictTemplates,
|
|
224
225
|
checkUnknownDirectives: strictTemplates,
|
|
@@ -231,6 +232,8 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
231
232
|
inferTemplateDollarSlots: false,
|
|
232
233
|
skipTemplateCodegen: false,
|
|
233
234
|
fallthroughAttributes: false,
|
|
235
|
+
resolveStyleImports: false,
|
|
236
|
+
resolveStyleClassNames: 'scoped',
|
|
234
237
|
fallthroughComponentNames: [
|
|
235
238
|
'Transition',
|
|
236
239
|
'KeepAlive',
|
|
@@ -256,8 +259,6 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
256
259
|
useTemplateRef: ['useTemplateRef', 'templateRef'],
|
|
257
260
|
},
|
|
258
261
|
plugins: [],
|
|
259
|
-
experimentalDefinePropProposal: false,
|
|
260
|
-
experimentalResolveStyleCssClasses: 'scoped',
|
|
261
262
|
experimentalModelPropName: {
|
|
262
263
|
'': {
|
|
263
264
|
input: true
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.computedSfc = computedSfc;
|
|
4
4
|
const alien_signals_1 = require("alien-signals");
|
|
5
5
|
const parseCssClassNames_1 = require("../utils/parseCssClassNames");
|
|
6
|
+
const parseCssImports_1 = require("../utils/parseCssImports");
|
|
6
7
|
const parseCssVars_1 = require("../utils/parseCssVars");
|
|
7
8
|
const signals_1 = require("../utils/signals");
|
|
8
9
|
function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
@@ -86,13 +87,17 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
86
87
|
});
|
|
87
88
|
const styles = (0, signals_1.computedArray)((0, alien_signals_1.computed)(() => getParseResult()?.descriptor.styles ?? []), (getBlock, i) => {
|
|
88
89
|
const base = computedSfcBlock('style_' + i, 'css', getBlock);
|
|
90
|
+
const getSrc = computedAttrValue('__src', base, getBlock);
|
|
89
91
|
const getModule = computedAttrValue('__module', base, getBlock);
|
|
90
92
|
const getScoped = (0, alien_signals_1.computed)(() => !!getBlock().scoped);
|
|
93
|
+
const getImports = (0, signals_1.computedItems)(() => [...(0, parseCssImports_1.parseCssImports)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
91
94
|
const getCssVars = (0, signals_1.computedItems)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
92
95
|
const getClassNames = (0, signals_1.computedItems)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
93
96
|
return () => mergeObject(base, {
|
|
97
|
+
get src() { return getSrc(); },
|
|
94
98
|
get module() { return getModule(); },
|
|
95
99
|
get scoped() { return getScoped(); },
|
|
100
|
+
get imports() { return getImports(); },
|
|
96
101
|
get cssVars() { return getCssVars(); },
|
|
97
102
|
get classNames() { return getClassNames(); },
|
|
98
103
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"directory": "packages/language-core"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "
|
|
16
|
+
"@volar/language-core": "2.4.14",
|
|
17
17
|
"@vue/compiler-dom": "^3.5.0",
|
|
18
18
|
"@vue/shared": "^3.5.0",
|
|
19
19
|
"alien-signals": "^2.0.5",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^22.10.4",
|
|
26
26
|
"@types/path-browserify": "^1.0.1",
|
|
27
|
-
"@volar/typescript": "
|
|
27
|
+
"@volar/typescript": "2.4.14",
|
|
28
28
|
"@vue/compiler-sfc": "^3.5.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"optional": true
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "7a2ea48123679387d7095a81ac49cfc667aeeabb"
|
|
39
39
|
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compile = void 0;
|
|
4
|
-
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
-
const Vue2TemplateCompiler = require('@vue/compiler-vue2/build');
|
|
6
|
-
const compile = (template, options = {}) => {
|
|
7
|
-
if (typeof template !== 'string') {
|
|
8
|
-
throw new Error(`[@vue/language-core] compile() first argument must be string.`);
|
|
9
|
-
}
|
|
10
|
-
const onError = options.onError;
|
|
11
|
-
const onWarn = options.onWarn;
|
|
12
|
-
options.onError = error => {
|
|
13
|
-
if (error.code === 33 // :key binding allowed in v-for template child in vue 2
|
|
14
|
-
|| error.code === 29 // fix https://github.com/vuejs/language-tools/issues/1638
|
|
15
|
-
) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (onError) {
|
|
19
|
-
onError(error);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const vue2Result = Vue2TemplateCompiler.compile(template, { outputSourceRange: true });
|
|
26
|
-
for (const error of vue2Result.errors) {
|
|
27
|
-
onError?.({
|
|
28
|
-
code: 'vue-template-compiler',
|
|
29
|
-
name: '',
|
|
30
|
-
message: error.msg,
|
|
31
|
-
loc: {
|
|
32
|
-
source: '',
|
|
33
|
-
start: { column: -1, line: -1, offset: error.start },
|
|
34
|
-
end: { column: -1, line: -1, offset: error.end ?? error.start },
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
for (const error of vue2Result.tips) {
|
|
39
|
-
onWarn?.({
|
|
40
|
-
code: 'vue-template-compiler',
|
|
41
|
-
name: '',
|
|
42
|
-
message: error.msg,
|
|
43
|
-
loc: {
|
|
44
|
-
source: '',
|
|
45
|
-
start: { column: -1, line: -1, offset: error.start },
|
|
46
|
-
end: { column: -1, line: -1, offset: error.end ?? error.start },
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
return baseCompile(template, Object.assign({}, CompilerDOM.parserOptions, options, {
|
|
51
|
-
nodeTransforms: [
|
|
52
|
-
...CompilerDOM.DOMNodeTransforms,
|
|
53
|
-
...(options.nodeTransforms || [])
|
|
54
|
-
],
|
|
55
|
-
directiveTransforms: Object.assign({}, CompilerDOM.DOMDirectiveTransforms, options.directiveTransforms || {}),
|
|
56
|
-
}));
|
|
57
|
-
};
|
|
58
|
-
exports.compile = compile;
|
|
59
|
-
function baseCompile(template, options = {}) {
|
|
60
|
-
const onError = options.onError || (error => { throw error; });
|
|
61
|
-
const isModuleMode = options.mode === 'module';
|
|
62
|
-
const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
|
|
63
|
-
if (!prefixIdentifiers && options.cacheHandlers) {
|
|
64
|
-
onError(CompilerDOM.createCompilerError(49));
|
|
65
|
-
}
|
|
66
|
-
if (options.scopeId && !isModuleMode) {
|
|
67
|
-
onError(CompilerDOM.createCompilerError(50));
|
|
68
|
-
}
|
|
69
|
-
const ast = CompilerDOM.baseParse(template, options);
|
|
70
|
-
const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset(prefixIdentifiers);
|
|
71
|
-
// v-for > v-if in vue 2
|
|
72
|
-
const transformIf = nodeTransforms[1];
|
|
73
|
-
const transformFor = nodeTransforms[3];
|
|
74
|
-
nodeTransforms[1] = transformFor;
|
|
75
|
-
nodeTransforms[3] = transformIf;
|
|
76
|
-
CompilerDOM.transform(ast, Object.assign({}, options, {
|
|
77
|
-
prefixIdentifiers,
|
|
78
|
-
nodeTransforms: [
|
|
79
|
-
...nodeTransforms,
|
|
80
|
-
...(options.nodeTransforms || []) // user transforms
|
|
81
|
-
],
|
|
82
|
-
directiveTransforms: Object.assign({}, directiveTransforms, options.directiveTransforms || {} // user transforms
|
|
83
|
-
)
|
|
84
|
-
}));
|
|
85
|
-
return CompilerDOM.generate(ast, Object.assign({}, options, {
|
|
86
|
-
prefixIdentifiers
|
|
87
|
-
}));
|
|
88
|
-
}
|
|
89
|
-
//# sourceMappingURL=vue2TemplateCompiler.js.map
|