@vue/language-core 1.7.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/LICENSE +21 -0
- package/out/generators/script.d.ts +14 -0
- package/out/generators/script.js +881 -0
- package/out/generators/template.d.ts +16 -0
- package/out/generators/template.js +1389 -0
- package/out/index.d.ts +12 -0
- package/out/index.js +30 -0
- package/out/languageModule.d.ts +5 -0
- package/out/languageModule.js +91 -0
- package/out/parsers/scriptRanges.d.ts +15 -0
- package/out/parsers/scriptRanges.js +58 -0
- package/out/parsers/scriptSetupRanges.d.ts +32 -0
- package/out/parsers/scriptSetupRanges.js +295 -0
- package/out/plugins/file-html.d.ts +3 -0
- package/out/plugins/file-html.js +80 -0
- package/out/plugins/file-md.d.ts +3 -0
- package/out/plugins/file-md.js +62 -0
- package/out/plugins/file-vue.d.ts +3 -0
- package/out/plugins/file-vue.js +39 -0
- package/out/plugins/vue-sfc-customblocks.d.ts +3 -0
- package/out/plugins/vue-sfc-customblocks.js +31 -0
- package/out/plugins/vue-sfc-scripts.d.ts +3 -0
- package/out/plugins/vue-sfc-scripts.js +39 -0
- package/out/plugins/vue-sfc-styles.d.ts +3 -0
- package/out/plugins/vue-sfc-styles.js +31 -0
- package/out/plugins/vue-sfc-template.d.ts +3 -0
- package/out/plugins/vue-sfc-template.js +27 -0
- package/out/plugins/vue-template-html.d.ts +3 -0
- package/out/plugins/vue-template-html.js +165 -0
- package/out/plugins/vue-tsx.d.ts +14 -0
- package/out/plugins/vue-tsx.js +158 -0
- package/out/plugins.d.ts +23 -0
- package/out/plugins.js +52 -0
- package/out/sourceFile.d.ts +71 -0
- package/out/sourceFile.js +528 -0
- package/out/types.d.ts +100 -0
- package/out/types.js +3 -0
- package/out/utils/directorySharedTypes.d.ts +6 -0
- package/out/utils/directorySharedTypes.js +169 -0
- package/out/utils/parseCssClassNames.d.ts +4 -0
- package/out/utils/parseCssClassNames.js +19 -0
- package/out/utils/parseCssVars.d.ts +5 -0
- package/out/utils/parseCssVars.js +26 -0
- package/out/utils/parseSfc.d.ts +2 -0
- package/out/utils/parseSfc.js +135 -0
- package/out/utils/shared.d.ts +1 -0
- package/out/utils/shared.js +8 -0
- package/out/utils/transform.d.ts +8 -0
- package/out/utils/transform.js +182 -0
- package/out/utils/ts.d.ts +8 -0
- package/out/utils/ts.js +196 -0
- package/out/utils/vue2TemplateCompiler.d.ts +3 -0
- package/out/utils/vue2TemplateCompiler.js +101 -0
- package/package.json +29 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.colletVars = exports.walkInterpolationFragment = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
function walkInterpolationFragment(ts, code, ast, cb, localVars, identifiers, vueOptions) {
|
|
6
|
+
let ctxVars = [];
|
|
7
|
+
const varCb = (id, isShorthand) => {
|
|
8
|
+
if (!!localVars[id.text] ||
|
|
9
|
+
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
10
|
+
(0, shared_1.isGloballyWhitelisted)(id.text) ||
|
|
11
|
+
id.text === 'require' ||
|
|
12
|
+
id.text.startsWith('__VLS_')) {
|
|
13
|
+
// localVarOffsets.push(localVar.getStart(ast));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
ctxVars.push({
|
|
17
|
+
text: id.text,
|
|
18
|
+
isShorthand: isShorthand,
|
|
19
|
+
offset: id.getStart(ast),
|
|
20
|
+
});
|
|
21
|
+
identifiers.add(id.text);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
ast.forEachChild(node => walkIdentifiers(ts, node, varCb, localVars));
|
|
25
|
+
ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
|
|
26
|
+
if (ctxVars.length) {
|
|
27
|
+
if (ctxVars[0].isShorthand) {
|
|
28
|
+
cb(code.substring(0, ctxVars[0].offset + ctxVars[0].text.length), 0);
|
|
29
|
+
cb(': ', undefined);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
cb(code.substring(0, ctxVars[0].offset), 0);
|
|
33
|
+
}
|
|
34
|
+
for (let i = 0; i < ctxVars.length - 1; i++) {
|
|
35
|
+
// fix https://github.com/vuejs/language-tools/issues/1205
|
|
36
|
+
// fix https://github.com/vuejs/language-tools/issues/1264
|
|
37
|
+
cb('', ctxVars[i + 1].offset, true);
|
|
38
|
+
if (vueOptions.experimentalUseElementAccessInTemplate) {
|
|
39
|
+
const varStart = ctxVars[i].offset;
|
|
40
|
+
const varEnd = ctxVars[i].offset + ctxVars[i].text.length;
|
|
41
|
+
cb('__VLS_ctx[', undefined);
|
|
42
|
+
cb('', varStart, true);
|
|
43
|
+
cb("'", undefined);
|
|
44
|
+
cb(code.substring(varStart, varEnd), varStart);
|
|
45
|
+
cb("'", undefined);
|
|
46
|
+
cb('', varEnd, true);
|
|
47
|
+
cb(']', undefined);
|
|
48
|
+
if (ctxVars[i + 1].isShorthand) {
|
|
49
|
+
cb(code.substring(varEnd, ctxVars[i + 1].offset + ctxVars[i + 1].text.length), varEnd);
|
|
50
|
+
cb(': ', undefined);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
cb(code.substring(varEnd, ctxVars[i + 1].offset), varEnd);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
cb('__VLS_ctx.', undefined);
|
|
58
|
+
if (ctxVars[i + 1].isShorthand) {
|
|
59
|
+
cb(code.substring(ctxVars[i].offset, ctxVars[i + 1].offset + ctxVars[i + 1].text.length), ctxVars[i].offset);
|
|
60
|
+
cb(': ', undefined);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
cb(code.substring(ctxVars[i].offset, ctxVars[i + 1].offset), ctxVars[i].offset);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (vueOptions.experimentalUseElementAccessInTemplate) {
|
|
68
|
+
const varStart = ctxVars[ctxVars.length - 1].offset;
|
|
69
|
+
const varEnd = ctxVars[ctxVars.length - 1].offset + ctxVars[ctxVars.length - 1].text.length;
|
|
70
|
+
cb('__VLS_ctx[', undefined);
|
|
71
|
+
cb('', varStart, true);
|
|
72
|
+
cb("'", undefined);
|
|
73
|
+
cb(code.substring(varStart, varEnd), varStart);
|
|
74
|
+
cb("'", undefined);
|
|
75
|
+
cb('', varEnd, true);
|
|
76
|
+
cb(']', undefined);
|
|
77
|
+
cb(code.substring(varEnd), varEnd);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
cb('', ctxVars[ctxVars.length - 1].offset, true);
|
|
81
|
+
cb('__VLS_ctx.', undefined);
|
|
82
|
+
cb(code.substring(ctxVars[ctxVars.length - 1].offset), ctxVars[ctxVars.length - 1].offset);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
cb(code, 0);
|
|
87
|
+
}
|
|
88
|
+
return ctxVars;
|
|
89
|
+
}
|
|
90
|
+
exports.walkInterpolationFragment = walkInterpolationFragment;
|
|
91
|
+
function walkIdentifiers(ts, node, cb, localVars) {
|
|
92
|
+
const blockVars = [];
|
|
93
|
+
if (ts.isIdentifier(node)) {
|
|
94
|
+
cb(node, false);
|
|
95
|
+
}
|
|
96
|
+
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
97
|
+
cb(node.name, true);
|
|
98
|
+
}
|
|
99
|
+
else if (ts.isPropertyAccessExpression(node)) {
|
|
100
|
+
walkIdentifiers(ts, node.expression, cb, localVars);
|
|
101
|
+
}
|
|
102
|
+
else if (ts.isVariableDeclaration(node)) {
|
|
103
|
+
colletVars(ts, node.name, blockVars);
|
|
104
|
+
for (const varName of blockVars)
|
|
105
|
+
localVars[varName] = (localVars[varName] ?? 0) + 1;
|
|
106
|
+
if (node.initializer)
|
|
107
|
+
walkIdentifiers(ts, node.initializer, cb, localVars);
|
|
108
|
+
}
|
|
109
|
+
else if (ts.isArrowFunction(node)) {
|
|
110
|
+
const functionArgs = [];
|
|
111
|
+
for (const param of node.parameters) {
|
|
112
|
+
colletVars(ts, param.name, functionArgs);
|
|
113
|
+
if (param.type) {
|
|
114
|
+
walkIdentifiers(ts, param.type, cb, localVars);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const varName of functionArgs)
|
|
118
|
+
localVars[varName] = (localVars[varName] ?? 0) + 1;
|
|
119
|
+
walkIdentifiers(ts, node.body, cb, localVars);
|
|
120
|
+
for (const varName of functionArgs)
|
|
121
|
+
localVars[varName]--;
|
|
122
|
+
}
|
|
123
|
+
else if (ts.isObjectLiteralExpression(node)) {
|
|
124
|
+
for (const prop of node.properties) {
|
|
125
|
+
if (ts.isPropertyAssignment(prop)) {
|
|
126
|
+
// fix https://github.com/vuejs/language-tools/issues/1176
|
|
127
|
+
if (ts.isComputedPropertyName(prop.name)) {
|
|
128
|
+
walkIdentifiers(ts, prop.name.expression, cb, localVars);
|
|
129
|
+
}
|
|
130
|
+
walkIdentifiers(ts, prop.initializer, cb, localVars);
|
|
131
|
+
}
|
|
132
|
+
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
133
|
+
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
134
|
+
walkIdentifiers(ts, prop, cb, localVars);
|
|
135
|
+
}
|
|
136
|
+
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
137
|
+
else if (ts.isSpreadAssignment(prop)) {
|
|
138
|
+
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
|
139
|
+
walkIdentifiers(ts, prop.expression, cb, localVars);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (ts.isTypeReferenceNode(node)) {
|
|
144
|
+
// fix https://github.com/vuejs/language-tools/issues/1422
|
|
145
|
+
node.forEachChild(node => walkIdentifiersInTypeReference(ts, node, cb));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
node.forEachChild(node => walkIdentifiers(ts, node, cb, localVars));
|
|
149
|
+
}
|
|
150
|
+
for (const varName of blockVars)
|
|
151
|
+
localVars[varName]--;
|
|
152
|
+
}
|
|
153
|
+
function walkIdentifiersInTypeReference(ts, node, cb) {
|
|
154
|
+
if (ts.isTypeQueryNode(node) && ts.isIdentifier(node.exprName)) {
|
|
155
|
+
cb(node.exprName, false);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
node.forEachChild(node => walkIdentifiersInTypeReference(ts, node, cb));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function colletVars(ts, node, result) {
|
|
162
|
+
if (ts.isIdentifier(node)) {
|
|
163
|
+
result.push(node.text);
|
|
164
|
+
}
|
|
165
|
+
else if (ts.isObjectBindingPattern(node)) {
|
|
166
|
+
for (const el of node.elements) {
|
|
167
|
+
colletVars(ts, el.name, result);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (ts.isArrayBindingPattern(node)) {
|
|
171
|
+
for (const el of node.elements) {
|
|
172
|
+
if (ts.isBindingElement(el)) {
|
|
173
|
+
colletVars(ts, el.name, result);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
node.forEachChild(node => colletVars(ts, node, result));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.colletVars = colletVars;
|
|
182
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type { VueCompilerOptions } from '../types';
|
|
3
|
+
export type ParsedCommandLine = ts.ParsedCommandLine & {
|
|
4
|
+
vueOptions: VueCompilerOptions;
|
|
5
|
+
};
|
|
6
|
+
export declare function createParsedCommandLineByJson(ts: typeof import('typescript/lib/tsserverlibrary'), parseConfigHost: ts.ParseConfigHost, rootDir: string, json: any): ParsedCommandLine;
|
|
7
|
+
export declare function createParsedCommandLine(ts: typeof import('typescript/lib/tsserverlibrary'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string): ParsedCommandLine;
|
|
8
|
+
export declare function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions>): VueCompilerOptions;
|
package/out/utils/ts.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveVueCompilerOptions = exports.createParsedCommandLine = exports.createParsedCommandLineByJson = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json) {
|
|
6
|
+
const tsConfigPath = path.join(rootDir, 'jsconfig.json');
|
|
7
|
+
const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
|
|
8
|
+
ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, tsConfigPath);
|
|
9
|
+
let vueOptions = {};
|
|
10
|
+
for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
|
|
11
|
+
try {
|
|
12
|
+
vueOptions = {
|
|
13
|
+
...vueOptions,
|
|
14
|
+
...getPartialVueCompilerOptions(ts, ts.readJsonConfigFile(extendPath, proxyHost.host.readFile)),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
catch (err) { }
|
|
18
|
+
}
|
|
19
|
+
const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
|
|
20
|
+
const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, resolvedVueOptions.extensions.map(extension => ({ extension, isMixedContent: true, scriptKind: ts.ScriptKind.Deferred })));
|
|
21
|
+
// fix https://github.com/vuejs/language-tools/issues/1786
|
|
22
|
+
// https://github.com/microsoft/TypeScript/issues/30457
|
|
23
|
+
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
24
|
+
parsed.options.outDir = undefined;
|
|
25
|
+
return {
|
|
26
|
+
...parsed,
|
|
27
|
+
vueOptions: resolvedVueOptions,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
|
|
31
|
+
function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
|
|
32
|
+
try {
|
|
33
|
+
const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
|
|
34
|
+
const config = ts.readJsonConfigFile(tsConfigPath, proxyHost.host.readFile);
|
|
35
|
+
ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath);
|
|
36
|
+
let vueOptions = {};
|
|
37
|
+
for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
|
|
38
|
+
try {
|
|
39
|
+
vueOptions = {
|
|
40
|
+
...vueOptions,
|
|
41
|
+
...getPartialVueCompilerOptions(ts, ts.readJsonConfigFile(extendPath, proxyHost.host.readFile)),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (err) { }
|
|
45
|
+
}
|
|
46
|
+
const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
|
|
47
|
+
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, resolvedVueOptions.extensions.map(extension => ({ extension, isMixedContent: true, scriptKind: ts.ScriptKind.Deferred })));
|
|
48
|
+
// fix https://github.com/vuejs/language-tools/issues/1786
|
|
49
|
+
// https://github.com/microsoft/TypeScript/issues/30457
|
|
50
|
+
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
51
|
+
parsed.options.outDir = undefined;
|
|
52
|
+
return {
|
|
53
|
+
...parsed,
|
|
54
|
+
vueOptions: resolvedVueOptions,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
console.warn('Failed to resolve tsconfig path:', tsConfigPath, err);
|
|
59
|
+
return {
|
|
60
|
+
fileNames: [],
|
|
61
|
+
options: {},
|
|
62
|
+
vueOptions: resolveVueCompilerOptions({}),
|
|
63
|
+
errors: [],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.createParsedCommandLine = createParsedCommandLine;
|
|
68
|
+
function proxyParseConfigHostForExtendConfigPaths(parseConfigHost) {
|
|
69
|
+
const extendConfigPaths = [];
|
|
70
|
+
const host = new Proxy(parseConfigHost, {
|
|
71
|
+
get(target, key) {
|
|
72
|
+
if (key === 'readFile') {
|
|
73
|
+
return (fileName) => {
|
|
74
|
+
if (!fileName.endsWith('/package.json') && !extendConfigPaths.includes(fileName)) {
|
|
75
|
+
extendConfigPaths.push(fileName);
|
|
76
|
+
}
|
|
77
|
+
return target.readFile(fileName);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return target[key];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
host,
|
|
85
|
+
extendConfigPaths,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
|
|
89
|
+
const folder = path.dirname(tsConfigSourceFile.fileName);
|
|
90
|
+
const obj = ts.convertToObject(tsConfigSourceFile, []);
|
|
91
|
+
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
92
|
+
const result = {
|
|
93
|
+
...rawOptions,
|
|
94
|
+
};
|
|
95
|
+
const target = rawOptions.target ?? 'auto';
|
|
96
|
+
if (target === 'auto') {
|
|
97
|
+
const resolvedPath = resolvePath('vue/package.json');
|
|
98
|
+
if (resolvedPath) {
|
|
99
|
+
const vuePackageJson = require(resolvedPath);
|
|
100
|
+
const versionNumbers = vuePackageJson.version.split('.');
|
|
101
|
+
result.target = Number(versionNumbers[0] + '.' + versionNumbers[1]);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// console.warn('Load vue/package.json failed from', folder);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
result.target = target;
|
|
109
|
+
}
|
|
110
|
+
if (rawOptions.plugins) {
|
|
111
|
+
const plugins = rawOptions.plugins
|
|
112
|
+
.map((pluginPath) => {
|
|
113
|
+
try {
|
|
114
|
+
const resolvedPath = resolvePath(pluginPath);
|
|
115
|
+
if (resolvedPath) {
|
|
116
|
+
return require(resolvedPath);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.warn('Load plugin failed', pluginPath, error);
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.filter((plugin) => !!plugin);
|
|
124
|
+
result.plugins = plugins;
|
|
125
|
+
}
|
|
126
|
+
if (rawOptions.hooks) {
|
|
127
|
+
result.hooks = rawOptions.hooks
|
|
128
|
+
.map(resolvePath)
|
|
129
|
+
.filter((hook) => !!hook);
|
|
130
|
+
}
|
|
131
|
+
if (rawOptions.experimentalAdditionalLanguageModules) {
|
|
132
|
+
result.experimentalAdditionalLanguageModules = rawOptions.experimentalAdditionalLanguageModules
|
|
133
|
+
.map(resolvePath)
|
|
134
|
+
.filter((module) => !!module);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
function resolvePath(scriptPath) {
|
|
138
|
+
try {
|
|
139
|
+
if (require?.resolve) {
|
|
140
|
+
return require.resolve(scriptPath, { paths: [folder] });
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
// console.warn('failed to resolve path:', scriptPath, 'require.resolve is not supported in web');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
// console.warn(error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function resolveVueCompilerOptions(vueOptions) {
|
|
152
|
+
const target = vueOptions.target ?? 3.3;
|
|
153
|
+
const lib = vueOptions.lib || (target < 2.7 ? '@vue/runtime-dom' : 'vue');
|
|
154
|
+
return {
|
|
155
|
+
...vueOptions,
|
|
156
|
+
target,
|
|
157
|
+
extensions: vueOptions.extensions ?? ['.vue'],
|
|
158
|
+
lib,
|
|
159
|
+
jsxSlots: vueOptions.jsxSlots ?? false,
|
|
160
|
+
strictTemplates: vueOptions.strictTemplates ?? false,
|
|
161
|
+
skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false,
|
|
162
|
+
dataAttributes: vueOptions.dataAttributes ?? [],
|
|
163
|
+
htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'],
|
|
164
|
+
optionsWrapper: vueOptions.optionsWrapper ?? (target >= 2.7
|
|
165
|
+
? [`(await import('${lib}')).defineComponent(`, `)`]
|
|
166
|
+
: [`(await import('vue')).default.extend(`, `)`]),
|
|
167
|
+
macros: vueOptions.macros ?? {
|
|
168
|
+
defineProps: ['defineProps'],
|
|
169
|
+
defineSlots: ['defineSlots'],
|
|
170
|
+
defineEmits: ['defineEmits'],
|
|
171
|
+
defineExpose: ['defineExpose'],
|
|
172
|
+
withDefaults: ['withDefaults'],
|
|
173
|
+
},
|
|
174
|
+
plugins: vueOptions.plugins ?? [],
|
|
175
|
+
hooks: vueOptions.hooks ?? [],
|
|
176
|
+
// experimental
|
|
177
|
+
experimentalDefinePropProposal: vueOptions.experimentalDefinePropProposal ?? false,
|
|
178
|
+
experimentalAdditionalLanguageModules: vueOptions.experimentalAdditionalLanguageModules ?? [],
|
|
179
|
+
experimentalResolveStyleCssClasses: vueOptions.experimentalResolveStyleCssClasses ?? 'scoped',
|
|
180
|
+
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
|
|
181
|
+
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
|
|
182
|
+
experimentalModelPropName: vueOptions.experimentalModelPropName ?? {
|
|
183
|
+
'': {
|
|
184
|
+
input: true
|
|
185
|
+
},
|
|
186
|
+
value: {
|
|
187
|
+
input: { type: 'text' },
|
|
188
|
+
textarea: true,
|
|
189
|
+
select: true
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
experimentalUseElementAccessInTemplate: vueOptions.experimentalUseElementAccessInTemplate ?? false,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
exports.resolveVueCompilerOptions = resolveVueCompilerOptions;
|
|
196
|
+
//# sourceMappingURL=ts.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.compile = void 0;
|
|
18
|
+
const CompilerDom = require("@vue/compiler-dom");
|
|
19
|
+
const Vue2TemplateCompiler = require('vue-template-compiler/build');
|
|
20
|
+
__exportStar(require("@vue/compiler-dom"), exports);
|
|
21
|
+
function compile(template, options = {}) {
|
|
22
|
+
const onError = options.onError;
|
|
23
|
+
const onWarn = options.onWarn;
|
|
24
|
+
options.onError = (error) => {
|
|
25
|
+
if (error.code === 33 /* CompilerDom.ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */ // :key binding allowed in v-for template child in vue 2
|
|
26
|
+
|| error.code === 29 /* CompilerDom.ErrorCodes.X_V_IF_SAME_KEY */ // fix https://github.com/vuejs/language-tools/issues/1638
|
|
27
|
+
) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (onError) {
|
|
31
|
+
onError(error);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const vue2Result = Vue2TemplateCompiler.compile(template, { outputSourceRange: true });
|
|
38
|
+
for (const error of vue2Result.errors) {
|
|
39
|
+
onError?.({
|
|
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
|
+
for (const error of vue2Result.tips) {
|
|
51
|
+
onWarn?.({
|
|
52
|
+
code: 'vue-template-compiler',
|
|
53
|
+
name: '',
|
|
54
|
+
message: error.msg,
|
|
55
|
+
loc: {
|
|
56
|
+
source: '',
|
|
57
|
+
start: { column: -1, line: -1, offset: error.start },
|
|
58
|
+
end: { column: -1, line: -1, offset: error.end ?? error.start },
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return baseCompile(template, Object.assign({}, CompilerDom.parserOptions, options, {
|
|
63
|
+
nodeTransforms: [
|
|
64
|
+
...CompilerDom.DOMNodeTransforms,
|
|
65
|
+
...(options.nodeTransforms || [])
|
|
66
|
+
],
|
|
67
|
+
directiveTransforms: Object.assign({}, CompilerDom.DOMDirectiveTransforms, options.directiveTransforms || {}),
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
exports.compile = compile;
|
|
71
|
+
function baseCompile(template, options = {}) {
|
|
72
|
+
const onError = options.onError || ((error) => { throw error; });
|
|
73
|
+
const isModuleMode = options.mode === 'module';
|
|
74
|
+
const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
|
|
75
|
+
if (!prefixIdentifiers && options.cacheHandlers) {
|
|
76
|
+
onError(CompilerDom.createCompilerError(49 /* CompilerDom.ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
77
|
+
}
|
|
78
|
+
if (options.scopeId && !isModuleMode) {
|
|
79
|
+
onError(CompilerDom.createCompilerError(50 /* CompilerDom.ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */));
|
|
80
|
+
}
|
|
81
|
+
const ast = CompilerDom.baseParse(template, options);
|
|
82
|
+
const [nodeTransforms, directiveTransforms] = CompilerDom.getBaseTransformPreset(prefixIdentifiers);
|
|
83
|
+
// v-for > v-if in vue 2
|
|
84
|
+
const transformIf = nodeTransforms[1];
|
|
85
|
+
const transformFor = nodeTransforms[3];
|
|
86
|
+
nodeTransforms[1] = transformFor;
|
|
87
|
+
nodeTransforms[3] = transformIf;
|
|
88
|
+
CompilerDom.transform(ast, Object.assign({}, options, {
|
|
89
|
+
prefixIdentifiers,
|
|
90
|
+
nodeTransforms: [
|
|
91
|
+
...nodeTransforms,
|
|
92
|
+
...(options.nodeTransforms || []) // user transforms
|
|
93
|
+
],
|
|
94
|
+
directiveTransforms: Object.assign({}, directiveTransforms, options.directiveTransforms || {} // user transforms
|
|
95
|
+
)
|
|
96
|
+
}));
|
|
97
|
+
return CompilerDom.generate(ast, Object.assign({}, options, {
|
|
98
|
+
prefixIdentifiers
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=vue2TemplateCompiler.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vue/language-core",
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"main": "out/index.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"out/**/*.js",
|
|
8
|
+
"out/**/*.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/vuejs/language-tools.git",
|
|
13
|
+
"directory": "packages/vue-language-core"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@volar/language-core": "1.5.4",
|
|
17
|
+
"@volar/source-map": "1.5.4",
|
|
18
|
+
"@vue/compiler-dom": "^3.3.0-beta.3",
|
|
19
|
+
"@vue/compiler-sfc": "^3.3.0-beta.3",
|
|
20
|
+
"@vue/reactivity": "^3.3.0-beta.3",
|
|
21
|
+
"@vue/shared": "^3.3.0-beta.3",
|
|
22
|
+
"minimatch": "^9.0.0",
|
|
23
|
+
"muggle-string": "^0.2.2",
|
|
24
|
+
"vue-template-compiler": "^2.7.14"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/minimatch": "^5.1.2"
|
|
28
|
+
}
|
|
29
|
+
}
|