@vue/language-core 3.0.0-beta.4 → 3.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/codegen/globalTypes.js +5 -2
- package/lib/codegen/localTypes.js +2 -1
- package/lib/codegen/script/index.js +14 -1
- package/lib/codegen/script/scriptSetup.js +5 -3
- package/lib/codegen/template/element.js +4 -2
- package/lib/codegen/template/elementProps.js +6 -2
- package/lib/codegen/template/index.js +4 -2
- package/lib/languagePlugin.js +7 -1
- package/lib/parsers/scriptRanges.d.ts +1 -0
- package/lib/parsers/scriptRanges.js +7 -0
- package/lib/plugins/vue-tsx.d.ts +1 -0
- package/lib/types.d.ts +1 -1
- package/lib/utils/shared.d.ts +1 -0
- package/lib/utils/shared.js +4 -0
- package/lib/utils/ts.js +3 -1
- package/lib/utils/vue2TemplateCompiler.d.ts +2 -0
- package/lib/utils/vue2TemplateCompiler.js +90 -0
- package/package.json +3 -2
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGlobalTypesFileName = getGlobalTypesFileName;
|
|
4
4
|
exports.generateGlobalTypes = generateGlobalTypes;
|
|
5
|
+
const shared_1 = require("../utils/shared");
|
|
5
6
|
function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
|
|
6
7
|
return [
|
|
7
8
|
lib,
|
|
@@ -61,7 +62,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
61
62
|
type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
|
|
62
63
|
__ctx?: {
|
|
63
64
|
attrs?: any,
|
|
64
|
-
slots?: T extends { $
|
|
65
|
+
slots?: T extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : Record<string, any>,
|
|
65
66
|
emit?: T extends { $emit: infer Emit } ? Emit : {},
|
|
66
67
|
props?: ${fnPropsType},
|
|
67
68
|
expose?: (exposed: T) => void,
|
|
@@ -151,7 +152,9 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
151
152
|
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
152
153
|
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
153
154
|
T extends new (...args: any) => any ? __VLS_FunctionalComponent<K>
|
|
154
|
-
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T
|
|
155
|
+
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>${target === 2.7
|
|
156
|
+
? `: T extends import('${lib}').AsyncComponent ? (props: {}, ctx?: any) => any`
|
|
157
|
+
: ``}
|
|
155
158
|
: T extends (...args: any) => any ? T
|
|
156
159
|
: __VLS_FunctionalComponent<{}>;
|
|
157
160
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLocalTypesGenerator = getLocalTypesGenerator;
|
|
4
|
+
const shared_1 = require("../utils/shared");
|
|
4
5
|
const utils_1 = require("./utils");
|
|
5
6
|
function getLocalTypesGenerator(vueCompilerOptions) {
|
|
6
7
|
const used = new Set();
|
|
@@ -20,7 +21,7 @@ type __VLS_WithDefaults<P, D> = {
|
|
|
20
21
|
const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
|
|
21
22
|
type __VLS_WithSlots<T, S> = T & {
|
|
22
23
|
new(): {
|
|
23
|
-
$
|
|
24
|
+
${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;
|
|
24
25
|
${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
|
|
25
26
|
}
|
|
26
27
|
};
|
|
@@ -36,7 +36,7 @@ function* generateScript(options) {
|
|
|
36
36
|
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
37
37
|
}
|
|
38
38
|
if (options.sfc.script && options.scriptRanges) {
|
|
39
|
-
const { exportDefault } = options.scriptRanges;
|
|
39
|
+
const { exportDefault, classBlockEnd } = options.scriptRanges;
|
|
40
40
|
const isExportRawObject = exportDefault
|
|
41
41
|
&& options.sfc.script.content[exportDefault.expression.start] === '{';
|
|
42
42
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
@@ -77,6 +77,19 @@ function* generateScript(options) {
|
|
|
77
77
|
yield options.vueCompilerOptions.optionsWrapper[1];
|
|
78
78
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
79
79
|
}
|
|
80
|
+
else if (classBlockEnd !== undefined) {
|
|
81
|
+
if (options.vueCompilerOptions.skipTemplateCodegen) {
|
|
82
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, codeFeatures_1.codeFeatures.all);
|
|
86
|
+
yield `__VLS_template = () => {${utils_1.newLine}`;
|
|
87
|
+
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
88
|
+
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
89
|
+
yield `}${utils_1.endOfLine}`;
|
|
90
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
80
93
|
else {
|
|
81
94
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
82
95
|
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
|
|
@@ -341,9 +341,11 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
341
341
|
yield `})${utils_1.endOfLine}`;
|
|
342
342
|
yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
|
|
343
343
|
? `import('${options.vueCompilerOptions.lib}').PublicProps`
|
|
344
|
-
:
|
|
345
|
-
|
|
346
|
-
|
|
344
|
+
: options.vueCompilerOptions.target >= 3
|
|
345
|
+
? `import('${options.vueCompilerOptions.lib}').VNodeProps`
|
|
346
|
+
+ ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
|
|
347
|
+
+ ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`
|
|
348
|
+
: `globalThis.JSX.IntrinsicAttributes`}`;
|
|
347
349
|
yield utils_1.endOfLine;
|
|
348
350
|
yield `type __VLS_OwnProps = `;
|
|
349
351
|
yield `${ctx.localTypes.OmitKeepDiscriminatedUnion}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
|
|
@@ -101,7 +101,9 @@ function* generateComponent(options, ctx, node) {
|
|
|
101
101
|
else if (!isComponentTag) {
|
|
102
102
|
yield `const ${componentOriginalVar} = ({} as __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `;
|
|
103
103
|
if (options.selfComponentName && possibleOriginalNames.includes(options.selfComponentName)) {
|
|
104
|
-
yield `typeof __VLS_self & (new () => {
|
|
104
|
+
yield `typeof __VLS_self & (new () => { `
|
|
105
|
+
+ (0, shared_2.getSlotsPropertyName)(options.vueCompilerOptions.target)
|
|
106
|
+
+ `: __VLS_Slots }), `;
|
|
105
107
|
}
|
|
106
108
|
else {
|
|
107
109
|
yield `void, `;
|
|
@@ -180,7 +182,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
180
182
|
}
|
|
181
183
|
if (hasVBindAttrs(options, ctx, node)) {
|
|
182
184
|
const attrsVar = ctx.getInternalVariable();
|
|
183
|
-
yield `
|
|
185
|
+
yield `var ${attrsVar}!: Parameters<typeof ${componentFunctionalVar}>[0]${utils_1.endOfLine}`;
|
|
184
186
|
ctx.inheritedAttrVars.add(attrsVar);
|
|
185
187
|
}
|
|
186
188
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
@@ -111,7 +111,11 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
114
|
-
if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
|
|
114
|
+
if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
|
|
115
|
+
// Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
|
|
116
|
+
|| (options.vueCompilerOptions.target < 3
|
|
117
|
+
&& prop.name === 'persisted'
|
|
118
|
+
&& node.tag.toLowerCase() === 'transition')) {
|
|
115
119
|
continue;
|
|
116
120
|
}
|
|
117
121
|
const shouldSpread = prop.name === 'style' || prop.name === 'class';
|
|
@@ -268,6 +272,6 @@ function getModelPropName(node, vueCompilerOptions) {
|
|
|
268
272
|
}
|
|
269
273
|
}
|
|
270
274
|
}
|
|
271
|
-
return 'modelValue';
|
|
275
|
+
return vueCompilerOptions.target < 3 ? 'value' : 'modelValue';
|
|
272
276
|
}
|
|
273
277
|
//# sourceMappingURL=elementProps.js.map
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateTemplate = generateTemplate;
|
|
4
4
|
exports.forEachElementNode = forEachElementNode;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
+
const shared_1 = require("../../utils/shared");
|
|
6
7
|
const utils_1 = require("../utils");
|
|
7
8
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
8
9
|
const context_1 = require("./context");
|
|
@@ -17,8 +18,9 @@ function* generateTemplate(options) {
|
|
|
17
18
|
if (options.propsAssignName) {
|
|
18
19
|
ctx.addLocalVariable(options.propsAssignName);
|
|
19
20
|
}
|
|
21
|
+
const slotsPropertyName = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
|
|
20
22
|
if (options.vueCompilerOptions.inferTemplateDollarSlots) {
|
|
21
|
-
ctx.dollarVars.add(
|
|
23
|
+
ctx.dollarVars.add(slotsPropertyName);
|
|
22
24
|
}
|
|
23
25
|
if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
|
|
24
26
|
ctx.dollarVars.add('$attrs');
|
|
@@ -35,7 +37,7 @@ function* generateTemplate(options) {
|
|
|
35
37
|
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
|
|
36
38
|
yield* ctx.generateHoistVariables();
|
|
37
39
|
const speicalTypes = [
|
|
38
|
-
[
|
|
40
|
+
[slotsPropertyName, yield* generateSlots(options, ctx)],
|
|
39
41
|
['$attrs', yield* generateInheritedAttrs(options, ctx)],
|
|
40
42
|
['$refs', yield* generateTemplateRefs(options, ctx)],
|
|
41
43
|
['$el', yield* generateRootEl(ctx)],
|
package/lib/languagePlugin.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.getAllExtensions = getAllExtensions;
|
|
|
6
6
|
const language_core_1 = require("@volar/language-core");
|
|
7
7
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
8
|
const plugins_1 = require("./plugins");
|
|
9
|
+
const CompilerVue2 = require("./utils/vue2TemplateCompiler");
|
|
9
10
|
const vueFile_1 = require("./virtualFile/vueFile");
|
|
10
11
|
const fileRegistries = [];
|
|
11
12
|
function getVueFileRegistry(key, plugins) {
|
|
@@ -37,7 +38,12 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
|
|
|
37
38
|
function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
|
|
38
39
|
const pluginContext = {
|
|
39
40
|
modules: {
|
|
40
|
-
'@vue/compiler-dom':
|
|
41
|
+
'@vue/compiler-dom': vueCompilerOptions.target < 3
|
|
42
|
+
? {
|
|
43
|
+
...CompilerDOM,
|
|
44
|
+
compile: CompilerVue2.compile,
|
|
45
|
+
}
|
|
46
|
+
: CompilerDOM,
|
|
41
47
|
typescript: ts,
|
|
42
48
|
},
|
|
43
49
|
compilerOptions,
|
|
@@ -13,6 +13,7 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
|
|
|
13
13
|
nameOption: TextRange | undefined;
|
|
14
14
|
inheritAttrsOption: string | undefined;
|
|
15
15
|
}) | undefined;
|
|
16
|
+
classBlockEnd: number | undefined;
|
|
16
17
|
bindings: {
|
|
17
18
|
range: TextRange;
|
|
18
19
|
moduleName?: string;
|
|
@@ -5,6 +5,7 @@ const shared_1 = require("../utils/shared");
|
|
|
5
5
|
const scriptSetupRanges_1 = require("./scriptSetupRanges");
|
|
6
6
|
function parseScriptRanges(ts, ast, hasScriptSetup) {
|
|
7
7
|
let exportDefault;
|
|
8
|
+
let classBlockEnd;
|
|
8
9
|
const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
|
|
9
10
|
ts.forEachChild(ast, raw => {
|
|
10
11
|
if (ts.isExportAssignment(raw)) {
|
|
@@ -57,9 +58,15 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
|
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
if (ts.isClassDeclaration(raw)
|
|
62
|
+
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
|
|
63
|
+
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)) {
|
|
64
|
+
classBlockEnd = raw.end - 1;
|
|
65
|
+
}
|
|
60
66
|
});
|
|
61
67
|
return {
|
|
62
68
|
exportDefault,
|
|
69
|
+
classBlockEnd,
|
|
63
70
|
bindings,
|
|
64
71
|
};
|
|
65
72
|
function _getStartEnd(node) {
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
11
11
|
nameOption: import("../types").TextRange | undefined;
|
|
12
12
|
inheritAttrsOption: string | undefined;
|
|
13
13
|
}) | undefined;
|
|
14
|
+
classBlockEnd: number | undefined;
|
|
14
15
|
bindings: {
|
|
15
16
|
range: import("../types").TextRange;
|
|
16
17
|
moduleName?: string;
|
package/lib/types.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type { SFCParseResult } from '@vue/compiler-sfc';
|
|
|
8
8
|
export { VueEmbeddedCode };
|
|
9
9
|
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
|
|
10
10
|
strictTemplates?: boolean;
|
|
11
|
-
target?: 'auto' | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
|
|
11
|
+
target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
|
|
12
12
|
plugins?: string[];
|
|
13
13
|
};
|
|
14
14
|
export interface VueCodeInformation extends CodeInformation {
|
package/lib/utils/shared.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import type * as ts from 'typescript';
|
|
|
2
2
|
import type { TextRange } from '../types';
|
|
3
3
|
export { hyphenate as hyphenateTag } from '@vue/shared';
|
|
4
4
|
export declare function hyphenateAttr(str: string): string;
|
|
5
|
+
export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
|
|
5
6
|
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
6
7
|
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
package/lib/utils/shared.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hyphenateTag = void 0;
|
|
4
4
|
exports.hyphenateAttr = hyphenateAttr;
|
|
5
|
+
exports.getSlotsPropertyName = getSlotsPropertyName;
|
|
5
6
|
exports.getStartEnd = getStartEnd;
|
|
6
7
|
exports.getNodeText = getNodeText;
|
|
7
8
|
const shared_1 = require("@vue/shared");
|
|
@@ -15,6 +16,9 @@ function hyphenateAttr(str) {
|
|
|
15
16
|
}
|
|
16
17
|
return hyphencase;
|
|
17
18
|
}
|
|
19
|
+
function getSlotsPropertyName(vueVersion) {
|
|
20
|
+
return vueVersion < 3 ? '$scopedSlots' : '$slots';
|
|
21
|
+
}
|
|
18
22
|
function getStartEnd(ts, node, ast) {
|
|
19
23
|
return {
|
|
20
24
|
start: ts.getTokenPosOfNode(node, ast),
|
package/lib/utils/ts.js
CHANGED
|
@@ -242,7 +242,9 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
242
242
|
],
|
|
243
243
|
dataAttributes: [],
|
|
244
244
|
htmlAttributes: ['aria-*'],
|
|
245
|
-
optionsWrapper:
|
|
245
|
+
optionsWrapper: target >= 2.7
|
|
246
|
+
? [`(await import('${lib}')).defineComponent(`, `)`]
|
|
247
|
+
: [`(await import('${lib}')).default.extend(`, `)`],
|
|
246
248
|
macros: {
|
|
247
249
|
defineProps: ['defineProps'],
|
|
248
250
|
defineSlots: ['defineSlots'],
|
|
@@ -0,0 +1,90 @@
|
|
|
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 => {
|
|
61
|
+
throw error;
|
|
62
|
+
});
|
|
63
|
+
const isModuleMode = options.mode === 'module';
|
|
64
|
+
const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
|
|
65
|
+
if (!prefixIdentifiers && options.cacheHandlers) {
|
|
66
|
+
onError(CompilerDOM.createCompilerError(49));
|
|
67
|
+
}
|
|
68
|
+
if (options.scopeId && !isModuleMode) {
|
|
69
|
+
onError(CompilerDOM.createCompilerError(50));
|
|
70
|
+
}
|
|
71
|
+
const ast = CompilerDOM.baseParse(template, options);
|
|
72
|
+
const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset(prefixIdentifiers);
|
|
73
|
+
// v-for > v-if in vue 2
|
|
74
|
+
const transformIf = nodeTransforms[1];
|
|
75
|
+
const transformFor = nodeTransforms[3];
|
|
76
|
+
nodeTransforms[1] = transformFor;
|
|
77
|
+
nodeTransforms[3] = transformIf;
|
|
78
|
+
CompilerDOM.transform(ast, Object.assign({}, options, {
|
|
79
|
+
prefixIdentifiers,
|
|
80
|
+
nodeTransforms: [
|
|
81
|
+
...nodeTransforms,
|
|
82
|
+
...(options.nodeTransforms || []), // user transforms
|
|
83
|
+
],
|
|
84
|
+
directiveTransforms: Object.assign({}, directiveTransforms, options.directiveTransforms || {}),
|
|
85
|
+
}));
|
|
86
|
+
return CompilerDOM.generate(ast, Object.assign({}, options, {
|
|
87
|
+
prefixIdentifiers,
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=vue2TemplateCompiler.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@volar/language-core": "2.4.15",
|
|
17
17
|
"@vue/compiler-dom": "^3.5.0",
|
|
18
|
+
"@vue/compiler-vue2": "^2.7.16",
|
|
18
19
|
"@vue/shared": "^3.5.0",
|
|
19
20
|
"alien-signals": "^2.0.5",
|
|
20
21
|
"minimatch": "^10.0.1",
|
|
@@ -35,5 +36,5 @@
|
|
|
35
36
|
"optional": true
|
|
36
37
|
}
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "3a4648914c60c90444d939cf762a016a4318ca09"
|
|
39
40
|
}
|