@vue/language-core 3.0.5 → 3.0.7-alpha.0
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 -1
- package/index.js +1 -1
- package/lib/codegen/codeFeatures.d.ts +0 -5
- package/lib/codegen/codeFeatures.js +0 -3
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +10 -14
- package/lib/codegen/script/componentSelf.js +19 -23
- package/lib/codegen/script/index.d.ts +20 -3
- package/lib/codegen/script/index.js +10 -16
- package/lib/codegen/script/scriptSetup.js +1 -1
- package/lib/codegen/script/template.d.ts +0 -1
- package/lib/codegen/script/template.js +6 -43
- package/lib/codegen/template/element.js +4 -18
- package/lib/codegen/template/elementDirectives.js +3 -1
- package/lib/codegen/template/index.d.ts +63 -3
- package/lib/codegen/template/index.js +21 -21
- package/lib/codegen/template/interpolation.js +19 -5
- package/lib/codegen/template/slotOutlet.js +2 -2
- package/lib/codegen/template/styleScopedClasses.js +6 -10
- package/lib/codegen/template/vSlot.js +15 -25
- package/lib/{utils/ts.d.ts → compilerOptions.d.ts} +8 -8
- package/lib/compilerOptions.js +294 -0
- package/lib/plugins/file-html.js +1 -1
- package/lib/plugins/file-md.js +1 -1
- package/lib/plugins/file-vue.js +1 -1
- package/lib/plugins/vue-root-tags.js +1 -1
- package/lib/plugins/vue-script-js.js +1 -1
- package/lib/plugins/vue-sfc-customblocks.js +1 -1
- package/lib/plugins/vue-sfc-scripts.js +1 -1
- package/lib/plugins/vue-sfc-styles.js +5 -5
- package/lib/plugins/vue-sfc-template.js +1 -1
- package/lib/plugins/vue-template-html.js +1 -1
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +1 -1
- package/lib/plugins/vue-tsx.d.ts +5 -5
- package/lib/plugins/vue-tsx.js +7 -26
- package/lib/plugins.js +2 -0
- package/lib/types.d.ts +3 -2
- package/lib/types.js +1 -1
- package/lib/utils/shared.d.ts +3 -1
- package/lib/utils/shared.js +13 -0
- package/lib/utils/ts.js +43 -66
- package/lib/virtualFile/computedSfc.js +13 -8
- package/package.json +4 -4
- package/lib/codegen/tenp.d.ts +0 -1
- package/lib/codegen/tenp.js +0 -3
- package/lib/parsers/utils.d.ts +0 -12
- package/lib/parsers/utils.js +0 -95
- package/lib/plugins/file-css.d.ts +0 -3
- package/lib/plugins/file-css.js +0 -57
- package/lib/utils/parseCssClassNames.d.ts +0 -4
- package/lib/utils/parseCssClassNames.js +0 -17
- package/lib/utils/parseCssImports.d.ts +0 -4
- package/lib/utils/parseCssImports.js +0 -19
- package/lib/utils/parseCssVars.d.ts +0 -6
- package/lib/utils/parseCssVars.js +0 -26
|
@@ -62,24 +62,24 @@ function collectStyleScopedClassReferences(options, ctx, node) {
|
|
|
62
62
|
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
63
63
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
64
64
|
&& prop.arg.content === 'class') {
|
|
65
|
-
const content = '
|
|
66
|
-
const startOffset = prop.exp.loc.start.offset -
|
|
65
|
+
const content = '(' + prop.exp.content + ')';
|
|
66
|
+
const startOffset = prop.exp.loc.start.offset - 1;
|
|
67
67
|
const { ts } = options;
|
|
68
68
|
const ast = ts.createSourceFile('', content, 99);
|
|
69
69
|
const literals = [];
|
|
70
70
|
ts.forEachChild(ast, node => {
|
|
71
71
|
if (!ts.isExpressionStatement(node)
|
|
72
|
-
|| !
|
|
72
|
+
|| !ts.isParenthesizedExpression(node.expression)) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
|
-
const expression = node.expression
|
|
75
|
+
const { expression } = node.expression;
|
|
76
76
|
if (ts.isStringLiteralLike(expression)) {
|
|
77
77
|
literals.push(expression);
|
|
78
78
|
}
|
|
79
|
-
if (ts.isArrayLiteralExpression(expression)) {
|
|
79
|
+
else if (ts.isArrayLiteralExpression(expression)) {
|
|
80
80
|
walkArrayLiteral(expression);
|
|
81
81
|
}
|
|
82
|
-
if (ts.isObjectLiteralExpression(expression)) {
|
|
82
|
+
else if (ts.isObjectLiteralExpression(expression)) {
|
|
83
83
|
walkObjectLiteral(expression);
|
|
84
84
|
}
|
|
85
85
|
});
|
|
@@ -160,8 +160,4 @@ function collectClasses(content, startOffset = 0) {
|
|
|
160
160
|
}
|
|
161
161
|
return classes;
|
|
162
162
|
}
|
|
163
|
-
// isTemplateExpression is missing in tsc
|
|
164
|
-
function isTemplateExpression(node) {
|
|
165
|
-
return node.kind === 228;
|
|
166
|
-
}
|
|
167
163
|
//# sourceMappingURL=styleScopedClasses.js.map
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateVSlot = generateVSlot;
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const muggle_string_1 = require("muggle-string");
|
|
5
6
|
const collectBindings_1 = require("../../utils/collectBindings");
|
|
6
|
-
const shared_1 = require("../../utils/shared");
|
|
7
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
10
10
|
const elementChildren_1 = require("./elementChildren");
|
|
11
|
+
const interpolation_1 = require("./interpolation");
|
|
11
12
|
const objectProperty_1 = require("./objectProperty");
|
|
12
13
|
function* generateVSlot(options, ctx, node, slotDir) {
|
|
13
14
|
if (!ctx.currentComponent) {
|
|
@@ -38,7 +39,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
38
39
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
39
40
|
const slotAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `(${slotDir.exp.content}) => {}`);
|
|
40
41
|
slotBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, slotAst, slotAst));
|
|
41
|
-
yield* generateSlotParameters(options, slotAst, slotDir.exp, slotVar);
|
|
42
|
+
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
|
|
42
43
|
}
|
|
43
44
|
for (const varName of slotBlockVars) {
|
|
44
45
|
ctx.addLocalVariable(varName);
|
|
@@ -69,7 +70,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
69
70
|
yield `}${utils_1.newLine}`;
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
|
-
function* generateSlotParameters(options, ast, exp, slotVar) {
|
|
73
|
+
function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
73
74
|
const { ts } = options;
|
|
74
75
|
const statement = ast.statements[0];
|
|
75
76
|
if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
|
|
@@ -77,42 +78,31 @@ function* generateSlotParameters(options, ast, exp, slotVar) {
|
|
|
77
78
|
}
|
|
78
79
|
const { expression } = statement;
|
|
79
80
|
const startOffset = exp.loc.start.offset - 1;
|
|
80
|
-
const modifies = [];
|
|
81
81
|
const types = [];
|
|
82
|
+
const interpolation = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, ast.text, startOffset)];
|
|
83
|
+
(0, muggle_string_1.replaceSourceRange)(interpolation, 'template', startOffset, startOffset + `(`.length);
|
|
84
|
+
(0, muggle_string_1.replaceSourceRange)(interpolation, 'template', startOffset + ast.text.length - `) => {}`.length, startOffset + ast.text.length);
|
|
82
85
|
for (const { name, type } of expression.parameters) {
|
|
83
86
|
if (type) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
types.push([
|
|
88
|
+
ast.text.slice(name.end, type.end),
|
|
89
|
+
'template',
|
|
90
|
+
startOffset + name.end,
|
|
91
|
+
codeFeatures_1.codeFeatures.all,
|
|
88
92
|
]);
|
|
89
|
-
|
|
93
|
+
(0, muggle_string_1.replaceSourceRange)(interpolation, 'template', startOffset + name.end, startOffset + type.end);
|
|
90
94
|
}
|
|
91
95
|
else {
|
|
92
96
|
types.push(null);
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
yield `const [`;
|
|
96
|
-
|
|
97
|
-
for (const [codes, start, end] of modifies) {
|
|
98
|
-
yield chunk(nextStart, start);
|
|
99
|
-
yield* codes;
|
|
100
|
-
nextStart = end;
|
|
101
|
-
}
|
|
102
|
-
yield chunk(nextStart, expression.equalsGreaterThanToken.pos - 1);
|
|
100
|
+
yield* interpolation;
|
|
103
101
|
yield `] = __VLS_getSlotParameters(${slotVar}!`;
|
|
104
102
|
if (types.some(t => t)) {
|
|
105
103
|
yield `, `;
|
|
106
|
-
yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_
|
|
104
|
+
yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_`, type, `, `] : `_, `), `) => [] as any`);
|
|
107
105
|
}
|
|
108
106
|
yield `)${utils_1.endOfLine}`;
|
|
109
|
-
function chunk(start, end) {
|
|
110
|
-
return [
|
|
111
|
-
ast.text.slice(start, end),
|
|
112
|
-
'template',
|
|
113
|
-
startOffset + start,
|
|
114
|
-
codeFeatures_1.codeFeatures.all,
|
|
115
|
-
];
|
|
116
|
-
}
|
|
117
107
|
}
|
|
118
108
|
//# sourceMappingURL=vSlot.js.map
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from '
|
|
3
|
-
|
|
2
|
+
import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from './types';
|
|
3
|
+
interface ParseConfigHost extends Omit<ts.ParseConfigHost, 'readDirectory'> {
|
|
4
|
+
}
|
|
5
|
+
export interface ParsedCommandLine extends Omit<ts.ParsedCommandLine, 'fileNames'> {
|
|
4
6
|
vueOptions: VueCompilerOptions;
|
|
5
|
-
}
|
|
6
|
-
export declare function createParsedCommandLineByJson(ts: typeof import('typescript'),
|
|
7
|
-
|
|
8
|
-
}, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
|
|
9
|
-
export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string): ParsedCommandLine;
|
|
7
|
+
}
|
|
8
|
+
export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), host: ParseConfigHost, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
|
|
9
|
+
export declare function createParsedCommandLine(ts: typeof import('typescript'), host: ParseConfigHost, configFileName: string): ParsedCommandLine;
|
|
10
10
|
export declare class CompilerOptionsResolver {
|
|
11
11
|
fileExists?: ((path: string) => boolean) | undefined;
|
|
12
|
-
configRoots: Set<string>;
|
|
13
12
|
options: Omit<RawVueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>;
|
|
14
13
|
target: number | undefined;
|
|
15
14
|
globalTypesPath: string | undefined;
|
|
@@ -21,3 +20,4 @@ export declare class CompilerOptionsResolver {
|
|
|
21
20
|
}
|
|
22
21
|
export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
|
|
23
22
|
export declare function writeGlobalTypes(vueOptions: VueCompilerOptions, writeFile: (fileName: string, data: string) => void): void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompilerOptionsResolver = void 0;
|
|
4
|
+
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
|
|
5
|
+
exports.createParsedCommandLine = createParsedCommandLine;
|
|
6
|
+
exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
|
|
7
|
+
exports.writeGlobalTypes = writeGlobalTypes;
|
|
8
|
+
const shared_1 = require("@vue/shared");
|
|
9
|
+
const path_browserify_1 = require("path-browserify");
|
|
10
|
+
const globalTypes_1 = require("./codegen/globalTypes");
|
|
11
|
+
const shared_2 = require("./utils/shared");
|
|
12
|
+
function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName) {
|
|
13
|
+
const extendedPaths = new Set();
|
|
14
|
+
const proxyHost = {
|
|
15
|
+
...host,
|
|
16
|
+
readFile(fileName) {
|
|
17
|
+
if (!fileName.endsWith('/package.json')) {
|
|
18
|
+
extendedPaths.add(fileName);
|
|
19
|
+
}
|
|
20
|
+
return host.readFile(fileName);
|
|
21
|
+
},
|
|
22
|
+
readDirectory() {
|
|
23
|
+
return [];
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const parsed = ts.parseJsonConfigFileContent(json, proxyHost, rootDir, {}, configFileName);
|
|
27
|
+
const resolver = new CompilerOptionsResolver(host.fileExists);
|
|
28
|
+
for (const extendPath of [...extendedPaths].reverse()) {
|
|
29
|
+
try {
|
|
30
|
+
const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
|
|
31
|
+
const obj = ts.convertToObject(configFile, []);
|
|
32
|
+
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
33
|
+
resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
|
|
34
|
+
}
|
|
35
|
+
catch { }
|
|
36
|
+
}
|
|
37
|
+
// ensure the rootDir is added to the config roots
|
|
38
|
+
resolver.addConfig({}, rootDir);
|
|
39
|
+
return {
|
|
40
|
+
...parsed,
|
|
41
|
+
vueOptions: resolver.build(),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function createParsedCommandLine(ts, host, configFileName) {
|
|
45
|
+
try {
|
|
46
|
+
const extendedPaths = new Set();
|
|
47
|
+
const proxyHost = {
|
|
48
|
+
...host,
|
|
49
|
+
readFile(fileName) {
|
|
50
|
+
if (!fileName.endsWith('/package.json')) {
|
|
51
|
+
extendedPaths.add(fileName);
|
|
52
|
+
}
|
|
53
|
+
return host.readFile(fileName);
|
|
54
|
+
},
|
|
55
|
+
readDirectory() {
|
|
56
|
+
return [];
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const config = ts.readJsonConfigFile(configFileName, proxyHost.readFile);
|
|
60
|
+
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, path_browserify_1.posix.dirname(configFileName), {}, configFileName);
|
|
61
|
+
const resolver = new CompilerOptionsResolver(host.fileExists);
|
|
62
|
+
for (const extendPath of [...extendedPaths].reverse()) {
|
|
63
|
+
try {
|
|
64
|
+
const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
|
|
65
|
+
const obj = ts.convertToObject(configFile, []);
|
|
66
|
+
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
67
|
+
resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
|
|
68
|
+
}
|
|
69
|
+
catch { }
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
...parsed,
|
|
73
|
+
vueOptions: resolver.build(),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch { }
|
|
77
|
+
return {
|
|
78
|
+
options: {},
|
|
79
|
+
errors: [],
|
|
80
|
+
vueOptions: getDefaultCompilerOptions(),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
class CompilerOptionsResolver {
|
|
84
|
+
constructor(fileExists) {
|
|
85
|
+
this.fileExists = fileExists;
|
|
86
|
+
this.options = {};
|
|
87
|
+
this.plugins = [];
|
|
88
|
+
}
|
|
89
|
+
addConfig(options, rootDir) {
|
|
90
|
+
for (const key in options) {
|
|
91
|
+
switch (key) {
|
|
92
|
+
case 'target':
|
|
93
|
+
if (options[key] === 'auto') {
|
|
94
|
+
this.target = findVueVersion(rootDir);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.target = options[key];
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case 'globalTypesPath':
|
|
101
|
+
if (options[key] !== undefined) {
|
|
102
|
+
this.globalTypesPath = path_browserify_1.posix.join(rootDir, options[key]);
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
case 'plugins':
|
|
106
|
+
this.plugins = (options.plugins ?? [])
|
|
107
|
+
.flatMap((pluginPath) => {
|
|
108
|
+
try {
|
|
109
|
+
const resolvedPath = resolvePath(pluginPath, rootDir);
|
|
110
|
+
if (resolvedPath) {
|
|
111
|
+
const plugin = require(resolvedPath);
|
|
112
|
+
plugin.__moduleName = pluginPath;
|
|
113
|
+
return plugin;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.warn('[Vue] Load plugin failed:', pluginPath);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.warn('[Vue] Resolve plugin path failed:', pluginPath, error);
|
|
121
|
+
}
|
|
122
|
+
return [];
|
|
123
|
+
});
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
// @ts-expect-error
|
|
127
|
+
this.options[key] = options[key];
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (options.target === undefined) {
|
|
132
|
+
this.target ??= findVueVersion(rootDir);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
build(defaults) {
|
|
136
|
+
defaults ??= getDefaultCompilerOptions(this.target, this.options.lib, this.options.strictTemplates);
|
|
137
|
+
const resolvedOptions = {
|
|
138
|
+
...defaults,
|
|
139
|
+
...this.options,
|
|
140
|
+
plugins: this.plugins,
|
|
141
|
+
macros: {
|
|
142
|
+
...defaults.macros,
|
|
143
|
+
...this.options.macros,
|
|
144
|
+
},
|
|
145
|
+
composables: {
|
|
146
|
+
...defaults.composables,
|
|
147
|
+
...this.options.composables,
|
|
148
|
+
},
|
|
149
|
+
fallthroughComponentNames: [
|
|
150
|
+
...defaults.fallthroughComponentNames,
|
|
151
|
+
...this.options.fallthroughComponentNames ?? [],
|
|
152
|
+
].map(shared_2.hyphenateTag),
|
|
153
|
+
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
|
|
154
|
+
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
|
|
155
|
+
experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
|
|
156
|
+
};
|
|
157
|
+
if (resolvedOptions.globalTypesPath === shared_1.NOOP) {
|
|
158
|
+
if (this.fileExists && this.globalTypesPath === undefined) {
|
|
159
|
+
const fileDirToGlobalTypesPath = new Map();
|
|
160
|
+
resolvedOptions.globalTypesPath = fileName => {
|
|
161
|
+
const fileDir = path_browserify_1.posix.dirname(fileName);
|
|
162
|
+
if (fileDirToGlobalTypesPath.has(fileDir)) {
|
|
163
|
+
return fileDirToGlobalTypesPath.get(fileDir);
|
|
164
|
+
}
|
|
165
|
+
const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
|
|
166
|
+
const result = root
|
|
167
|
+
? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
|
|
168
|
+
: undefined;
|
|
169
|
+
fileDirToGlobalTypesPath.set(fileDir, result);
|
|
170
|
+
return result;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
resolvedOptions.globalTypesPath = () => this.globalTypesPath;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return resolvedOptions;
|
|
178
|
+
}
|
|
179
|
+
findNodeModulesRoot(dir, lib) {
|
|
180
|
+
while (!this.fileExists(path_browserify_1.posix.join(dir, 'node_modules', lib, 'package.json'))) {
|
|
181
|
+
const parentDir = path_browserify_1.posix.dirname(dir);
|
|
182
|
+
if (dir === parentDir) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
dir = parentDir;
|
|
186
|
+
}
|
|
187
|
+
return dir;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.CompilerOptionsResolver = CompilerOptionsResolver;
|
|
191
|
+
function findVueVersion(rootDir) {
|
|
192
|
+
const resolvedPath = resolvePath('vue/package.json', rootDir);
|
|
193
|
+
if (resolvedPath) {
|
|
194
|
+
const vuePackageJson = require(resolvedPath);
|
|
195
|
+
const versionNumbers = vuePackageJson.version.split('.');
|
|
196
|
+
return Number(versionNumbers[0] + '.' + versionNumbers[1]);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// console.warn('Load vue/package.json failed from', folder);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function resolvePath(scriptPath, root) {
|
|
203
|
+
try {
|
|
204
|
+
if (require?.resolve) {
|
|
205
|
+
return require.resolve(scriptPath, { paths: [root] });
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
// console.warn('failed to resolve path:', scriptPath, 'require.resolve is not supported in web');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
// console.warn(error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = false) {
|
|
216
|
+
return {
|
|
217
|
+
target,
|
|
218
|
+
lib,
|
|
219
|
+
globalTypesPath: shared_1.NOOP,
|
|
220
|
+
extensions: ['.vue'],
|
|
221
|
+
vitePressExtensions: [],
|
|
222
|
+
petiteVueExtensions: [],
|
|
223
|
+
jsxSlots: false,
|
|
224
|
+
strictVModel: strictTemplates,
|
|
225
|
+
strictCssModules: false,
|
|
226
|
+
checkUnknownProps: strictTemplates,
|
|
227
|
+
checkUnknownEvents: strictTemplates,
|
|
228
|
+
checkUnknownDirectives: strictTemplates,
|
|
229
|
+
checkUnknownComponents: strictTemplates,
|
|
230
|
+
inferComponentDollarEl: false,
|
|
231
|
+
inferComponentDollarRefs: false,
|
|
232
|
+
inferTemplateDollarAttrs: false,
|
|
233
|
+
inferTemplateDollarEl: false,
|
|
234
|
+
inferTemplateDollarRefs: false,
|
|
235
|
+
inferTemplateDollarSlots: false,
|
|
236
|
+
skipTemplateCodegen: false,
|
|
237
|
+
fallthroughAttributes: false,
|
|
238
|
+
resolveStyleImports: false,
|
|
239
|
+
resolveStyleClassNames: 'scoped',
|
|
240
|
+
fallthroughComponentNames: [
|
|
241
|
+
'Transition',
|
|
242
|
+
'KeepAlive',
|
|
243
|
+
'Teleport',
|
|
244
|
+
'Suspense',
|
|
245
|
+
],
|
|
246
|
+
dataAttributes: [],
|
|
247
|
+
htmlAttributes: ['aria-*'],
|
|
248
|
+
optionsWrapper: target >= 2.7
|
|
249
|
+
? [`(await import('${lib}')).defineComponent(`, `)`]
|
|
250
|
+
: [`(await import('${lib}')).default.extend(`, `)`],
|
|
251
|
+
macros: {
|
|
252
|
+
defineProps: ['defineProps'],
|
|
253
|
+
defineSlots: ['defineSlots'],
|
|
254
|
+
defineEmits: ['defineEmits'],
|
|
255
|
+
defineExpose: ['defineExpose'],
|
|
256
|
+
defineModel: ['defineModel'],
|
|
257
|
+
defineOptions: ['defineOptions'],
|
|
258
|
+
withDefaults: ['withDefaults'],
|
|
259
|
+
},
|
|
260
|
+
composables: {
|
|
261
|
+
useAttrs: ['useAttrs'],
|
|
262
|
+
useCssModule: ['useCssModule'],
|
|
263
|
+
useSlots: ['useSlots'],
|
|
264
|
+
useTemplateRef: ['useTemplateRef', 'templateRef'],
|
|
265
|
+
},
|
|
266
|
+
plugins: [],
|
|
267
|
+
experimentalModelPropName: {
|
|
268
|
+
'': {
|
|
269
|
+
input: true,
|
|
270
|
+
},
|
|
271
|
+
value: {
|
|
272
|
+
input: { type: 'text' },
|
|
273
|
+
textarea: true,
|
|
274
|
+
select: true,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function writeGlobalTypes(vueOptions, writeFile) {
|
|
280
|
+
const originalFn = vueOptions.globalTypesPath;
|
|
281
|
+
if (!originalFn) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const writed = new Set();
|
|
285
|
+
vueOptions.globalTypesPath = (fileName) => {
|
|
286
|
+
const result = originalFn(fileName);
|
|
287
|
+
if (result && !writed.has(result)) {
|
|
288
|
+
writed.add(result);
|
|
289
|
+
writeFile(result, (0, globalTypes_1.generateGlobalTypes)(vueOptions));
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=compilerOptions.js.map
|
package/lib/plugins/file-html.js
CHANGED
|
@@ -4,7 +4,7 @@ const sfcBlockReg = /<(script|style)\b([\s\S]*?)>([\s\S]*?)<\/\1>/g;
|
|
|
4
4
|
const langReg = /\blang\s*=\s*(['"]?)(\S*)\b\1/;
|
|
5
5
|
const plugin = ({ vueCompilerOptions }) => {
|
|
6
6
|
return {
|
|
7
|
-
version: 2.
|
|
7
|
+
version: 2.2,
|
|
8
8
|
getLanguageId(fileName) {
|
|
9
9
|
if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
|
|
10
10
|
return 'html';
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -15,7 +15,7 @@ const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
|
|
|
15
15
|
const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
|
16
16
|
const plugin = ({ vueCompilerOptions }) => {
|
|
17
17
|
return {
|
|
18
|
-
version: 2.
|
|
18
|
+
version: 2.2,
|
|
19
19
|
getLanguageId(fileName) {
|
|
20
20
|
if (vueCompilerOptions.vitePressExtensions.some(ext => fileName.endsWith(ext))) {
|
|
21
21
|
return 'markdown';
|
package/lib/plugins/file-vue.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const parseSfc_1 = require("../utils/parseSfc");
|
|
4
4
|
const plugin = ({ vueCompilerOptions }) => {
|
|
5
5
|
return {
|
|
6
|
-
version: 2.
|
|
6
|
+
version: 2.2,
|
|
7
7
|
getLanguageId(fileName) {
|
|
8
8
|
if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
|
|
9
9
|
return 'vue';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const plugin = ({ modules }) => {
|
|
4
4
|
return {
|
|
5
|
-
version: 2.
|
|
5
|
+
version: 2.2,
|
|
6
6
|
compileSFCScript(lang, script) {
|
|
7
7
|
if (lang === 'js' || lang === 'ts' || lang === 'jsx' || lang === 'tsx') {
|
|
8
8
|
const ts = modules.typescript;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const shared_1 = require("./shared");
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
|
-
version: 2.
|
|
6
|
+
version: 2.2,
|
|
7
7
|
getEmbeddedCodes(_fileName, sfc) {
|
|
8
8
|
return sfc.customBlocks.map((customBlock, i) => ({
|
|
9
9
|
id: 'custom_block_' + i,
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const shared_1 = require("./shared");
|
|
4
4
|
const plugin = () => {
|
|
5
5
|
return {
|
|
6
|
-
version: 2.
|
|
6
|
+
version: 2.2,
|
|
7
7
|
getEmbeddedCodes(_fileName, sfc) {
|
|
8
8
|
const result = [];
|
|
9
9
|
for (let i = 0; i < sfc.styles.length; i++) {
|
|
@@ -13,7 +13,7 @@ const plugin = () => {
|
|
|
13
13
|
id: 'style_' + i,
|
|
14
14
|
lang: style.lang,
|
|
15
15
|
});
|
|
16
|
-
if (style.
|
|
16
|
+
if (style.bindings.length) {
|
|
17
17
|
result.push({
|
|
18
18
|
id: 'style_' + i + '_inline_ts',
|
|
19
19
|
lang: 'ts',
|
|
@@ -29,11 +29,11 @@ const plugin = () => {
|
|
|
29
29
|
const style = sfc.styles[index];
|
|
30
30
|
if (embeddedFile.id.endsWith('_inline_ts')) {
|
|
31
31
|
embeddedFile.parentCodeId = 'style_' + index;
|
|
32
|
-
for (const
|
|
32
|
+
for (const binding of style.bindings) {
|
|
33
33
|
embeddedFile.content.push('(', [
|
|
34
|
-
|
|
34
|
+
binding.text,
|
|
35
35
|
style.name,
|
|
36
|
-
|
|
36
|
+
binding.offset,
|
|
37
37
|
shared_1.allCodeFeatures,
|
|
38
38
|
], ');\n');
|
|
39
39
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const shouldAddSuffix = /(?<=<[^>/]+)$/;
|
|
4
4
|
const plugin = ({ modules }) => {
|
|
5
5
|
return {
|
|
6
|
-
version: 2.
|
|
6
|
+
version: 2.2,
|
|
7
7
|
compileSFCTemplate(lang, template, options) {
|
|
8
8
|
if (lang === 'html' || lang === 'md') {
|
|
9
9
|
const compiler = modules['@vue/compiler-dom'];
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Sfc, VueLanguagePlugin } from '../types';
|
|
2
2
|
export declare const tsCodegen: WeakMap<Sfc, {
|
|
3
3
|
getLang: () => string;
|
|
4
4
|
getScriptRanges: () => {
|
|
@@ -118,7 +118,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
118
118
|
} | undefined;
|
|
119
119
|
getSetupSlotsAssignName: () => string | undefined;
|
|
120
120
|
getGeneratedScript: () => {
|
|
121
|
-
codes: Code[];
|
|
121
|
+
codes: import("../types").Code[];
|
|
122
122
|
generatedTemplate: boolean;
|
|
123
123
|
generatedPropsType: boolean;
|
|
124
124
|
bypassDefineComponent: boolean;
|
|
@@ -137,7 +137,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
137
137
|
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
138
138
|
};
|
|
139
139
|
getGeneratedTemplate: () => {
|
|
140
|
-
codes: Code[];
|
|
140
|
+
codes: import("../types").Code[];
|
|
141
141
|
currentInfo: {
|
|
142
142
|
ignoreError?: boolean;
|
|
143
143
|
expectError?: {
|
|
@@ -194,9 +194,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
194
194
|
getHoistVariable(originalVar: string): string;
|
|
195
195
|
generateHoistVariables(): Generator<string, void, unknown>;
|
|
196
196
|
generateConditionGuards(): Generator<string, void, unknown>;
|
|
197
|
-
generateAutoImportCompletion(): Generator<Code>;
|
|
197
|
+
generateAutoImportCompletion(): Generator<import("../types").Code>;
|
|
198
198
|
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
199
|
-
exit(): Generator<Code>;
|
|
199
|
+
exit(): Generator<import("../types").Code>;
|
|
200
200
|
} | undefined;
|
|
201
201
|
}>;
|
|
202
202
|
declare const plugin: VueLanguagePlugin;
|