@vue/language-core 2.0.0 → 2.0.2
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 +13 -0
- package/index.js +31 -0
- package/lib/generators/script.d.ts +13 -0
- package/lib/generators/script.js +1060 -0
- package/lib/generators/template.d.ts +9 -0
- package/lib/generators/template.js +1567 -0
- package/lib/generators/utils.d.ts +6 -0
- package/lib/generators/utils.js +58 -0
- package/lib/languageModule.d.ts +5 -0
- package/lib/languageModule.js +114 -0
- package/lib/parsers/scriptRanges.d.ts +15 -0
- package/lib/parsers/scriptRanges.js +63 -0
- package/lib/parsers/scriptSetupRanges.d.ts +57 -0
- package/lib/parsers/scriptSetupRanges.js +298 -0
- package/lib/plugins/file-html.d.ts +3 -0
- package/lib/plugins/file-html.js +81 -0
- package/lib/plugins/file-md.d.ts +3 -0
- package/lib/plugins/file-md.js +71 -0
- package/lib/plugins/file-vue.d.ts +3 -0
- package/lib/plugins/file-vue.js +47 -0
- package/lib/plugins/vue-sfc-customblocks.d.ts +3 -0
- package/lib/plugins/vue-sfc-customblocks.js +28 -0
- package/lib/plugins/vue-sfc-scripts.d.ts +3 -0
- package/lib/plugins/vue-sfc-scripts.js +36 -0
- package/lib/plugins/vue-sfc-styles.d.ts +3 -0
- package/lib/plugins/vue-sfc-styles.js +28 -0
- package/lib/plugins/vue-sfc-template.d.ts +3 -0
- package/lib/plugins/vue-sfc-template.js +29 -0
- package/lib/plugins/vue-template-html.d.ts +3 -0
- package/lib/plugins/vue-template-html.js +169 -0
- package/lib/plugins/vue-tsx.d.ts +80 -0
- package/lib/plugins/vue-tsx.js +212 -0
- package/lib/plugins.d.ts +37 -0
- package/lib/plugins.js +64 -0
- package/lib/types.d.ts +142 -0
- package/lib/types.js +5 -0
- package/lib/utils/parseCssClassNames.d.ts +4 -0
- package/lib/utils/parseCssClassNames.js +19 -0
- package/lib/utils/parseCssVars.d.ts +5 -0
- package/lib/utils/parseCssVars.js +28 -0
- package/lib/utils/parseSfc.d.ts +2 -0
- package/lib/utils/parseSfc.js +121 -0
- package/lib/utils/shared.d.ts +3 -0
- package/lib/utils/shared.js +20 -0
- package/lib/utils/transform.d.ts +8 -0
- package/lib/utils/transform.js +195 -0
- package/lib/utils/ts.d.ts +8 -0
- package/lib/utils/ts.js +225 -0
- package/lib/utils/vue2TemplateCompiler.d.ts +2 -0
- package/lib/utils/vue2TemplateCompiler.js +89 -0
- package/lib/virtualFile/computedFiles.d.ts +3 -0
- package/lib/virtualFile/computedFiles.js +217 -0
- package/lib/virtualFile/computedMappings.d.ts +4 -0
- package/lib/virtualFile/computedMappings.js +36 -0
- package/lib/virtualFile/computedSfc.d.ts +4 -0
- package/lib/virtualFile/computedSfc.js +197 -0
- package/lib/virtualFile/computedVueSfc.d.ts +4 -0
- package/lib/virtualFile/computedVueSfc.js +41 -0
- package/lib/virtualFile/embeddedFile.d.ts +12 -0
- package/lib/virtualFile/embeddedFile.js +15 -0
- package/lib/virtualFile/vueFile.d.ts +25 -0
- package/lib/virtualFile/vueFile.js +43 -0
- package/package.json +4 -4
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { VueCompilerOptions } from '../types';
|
|
3
|
+
export declare function eachInterpolationSegment(ts: typeof import('typescript'), code: string, ast: ts.SourceFile, localVars: Map<string, number>, identifiers: Set<string>, vueOptions: VueCompilerOptions, ctxVars?: {
|
|
4
|
+
text: string;
|
|
5
|
+
isShorthand: boolean;
|
|
6
|
+
offset: number;
|
|
7
|
+
}[]): Generator<[fragment: string, offset: number | undefined, isJustForErrorMapping?: boolean]>;
|
|
8
|
+
export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, result: string[]): void;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectVars = exports.eachInterpolationSegment = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
6
|
+
function* eachInterpolationSegment(ts, code, ast, localVars, identifiers, vueOptions, ctxVars = []) {
|
|
7
|
+
const varCb = (id, isShorthand) => {
|
|
8
|
+
const text = (0, scriptSetupRanges_1.getNodeText)(ts, id, ast);
|
|
9
|
+
if (localVars.get(text) ||
|
|
10
|
+
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
11
|
+
(0, shared_1.isGloballyWhitelisted)(text) ||
|
|
12
|
+
text === 'require' ||
|
|
13
|
+
text.startsWith('__VLS_')) {
|
|
14
|
+
// localVarOffsets.push(localVar.getStart(ast));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
ctxVars.push({
|
|
18
|
+
text,
|
|
19
|
+
isShorthand: isShorthand,
|
|
20
|
+
offset: (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start,
|
|
21
|
+
});
|
|
22
|
+
identifiers.add(text);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, localVars));
|
|
26
|
+
ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
|
|
27
|
+
if (ctxVars.length) {
|
|
28
|
+
if (ctxVars[0].isShorthand) {
|
|
29
|
+
yield [code.substring(0, ctxVars[0].offset + ctxVars[0].text.length), 0];
|
|
30
|
+
yield [': ', undefined];
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
yield [code.substring(0, ctxVars[0].offset), 0];
|
|
34
|
+
}
|
|
35
|
+
for (let i = 0; i < ctxVars.length - 1; i++) {
|
|
36
|
+
// fix https://github.com/vuejs/language-tools/issues/1205
|
|
37
|
+
// fix https://github.com/vuejs/language-tools/issues/1264
|
|
38
|
+
yield ['', ctxVars[i + 1].offset, true];
|
|
39
|
+
if (vueOptions.experimentalUseElementAccessInTemplate) {
|
|
40
|
+
const varStart = ctxVars[i].offset;
|
|
41
|
+
const varEnd = ctxVars[i].offset + ctxVars[i].text.length;
|
|
42
|
+
yield ['__VLS_ctx[', undefined];
|
|
43
|
+
yield ['', varStart, true];
|
|
44
|
+
yield ["'", undefined];
|
|
45
|
+
yield [code.substring(varStart, varEnd), varStart];
|
|
46
|
+
yield ["'", undefined];
|
|
47
|
+
yield ['', varEnd, true];
|
|
48
|
+
yield [']', undefined];
|
|
49
|
+
if (ctxVars[i + 1].isShorthand) {
|
|
50
|
+
yield [code.substring(varEnd, ctxVars[i + 1].offset + ctxVars[i + 1].text.length), varEnd];
|
|
51
|
+
yield [': ', undefined];
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
yield [code.substring(varEnd, ctxVars[i + 1].offset), varEnd];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
yield ['__VLS_ctx.', undefined];
|
|
59
|
+
if (ctxVars[i + 1].isShorthand) {
|
|
60
|
+
yield [code.substring(ctxVars[i].offset, ctxVars[i + 1].offset + ctxVars[i + 1].text.length), ctxVars[i].offset];
|
|
61
|
+
yield [': ', undefined];
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
yield [code.substring(ctxVars[i].offset, ctxVars[i + 1].offset), ctxVars[i].offset];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (vueOptions.experimentalUseElementAccessInTemplate) {
|
|
69
|
+
const varStart = ctxVars[ctxVars.length - 1].offset;
|
|
70
|
+
const varEnd = ctxVars[ctxVars.length - 1].offset + ctxVars[ctxVars.length - 1].text.length;
|
|
71
|
+
yield ['__VLS_ctx[', undefined];
|
|
72
|
+
yield ['', varStart, true];
|
|
73
|
+
yield ["'", undefined];
|
|
74
|
+
yield [code.substring(varStart, varEnd), varStart];
|
|
75
|
+
yield ["'", undefined];
|
|
76
|
+
yield ['', varEnd, true];
|
|
77
|
+
yield [']', undefined];
|
|
78
|
+
yield [code.substring(varEnd), varEnd];
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
yield ['', ctxVars[ctxVars.length - 1].offset, true];
|
|
82
|
+
yield ['__VLS_ctx.', undefined];
|
|
83
|
+
yield [code.substring(ctxVars[ctxVars.length - 1].offset), ctxVars[ctxVars.length - 1].offset];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
yield [code, 0];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.eachInterpolationSegment = eachInterpolationSegment;
|
|
91
|
+
function walkIdentifiers(ts, node, ast, cb, localVars, blockVars = [], isRoot = true) {
|
|
92
|
+
if (ts.isIdentifier(node)) {
|
|
93
|
+
cb(node, false);
|
|
94
|
+
}
|
|
95
|
+
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
96
|
+
cb(node.name, true);
|
|
97
|
+
}
|
|
98
|
+
else if (ts.isPropertyAccessExpression(node)) {
|
|
99
|
+
walkIdentifiers(ts, node.expression, ast, cb, localVars, blockVars, false);
|
|
100
|
+
}
|
|
101
|
+
else if (ts.isVariableDeclaration(node)) {
|
|
102
|
+
collectVars(ts, node.name, ast, blockVars);
|
|
103
|
+
for (const varName of blockVars) {
|
|
104
|
+
localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
|
|
105
|
+
}
|
|
106
|
+
if (node.initializer)
|
|
107
|
+
walkIdentifiers(ts, node.initializer, ast, cb, localVars, blockVars, false);
|
|
108
|
+
}
|
|
109
|
+
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
110
|
+
const functionArgs = [];
|
|
111
|
+
for (const param of node.parameters) {
|
|
112
|
+
collectVars(ts, param.name, ast, functionArgs);
|
|
113
|
+
if (param.type) {
|
|
114
|
+
walkIdentifiers(ts, param.type, ast, cb, localVars, blockVars, false);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const varName of functionArgs)
|
|
118
|
+
localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
|
|
119
|
+
walkIdentifiers(ts, node.body, ast, cb, localVars, blockVars, false);
|
|
120
|
+
for (const varName of functionArgs)
|
|
121
|
+
localVars.set(varName, localVars.get(varName) - 1);
|
|
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, ast, cb, localVars, blockVars, false);
|
|
129
|
+
}
|
|
130
|
+
walkIdentifiers(ts, prop.initializer, ast, cb, localVars, blockVars, false);
|
|
131
|
+
}
|
|
132
|
+
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
133
|
+
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
134
|
+
walkIdentifiers(ts, prop, ast, cb, localVars, blockVars, false);
|
|
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, ast, cb, localVars, blockVars, false);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (ts.isTypeReferenceNode(node)) {
|
|
144
|
+
// fix https://github.com/vuejs/language-tools/issues/1422
|
|
145
|
+
ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const _blockVars = blockVars;
|
|
149
|
+
if (ts.isBlock(node)) {
|
|
150
|
+
blockVars = [];
|
|
151
|
+
}
|
|
152
|
+
ts.forEachChild(node, node => walkIdentifiers(ts, node, ast, cb, localVars, blockVars, false));
|
|
153
|
+
if (ts.isBlock(node)) {
|
|
154
|
+
for (const varName of blockVars) {
|
|
155
|
+
localVars.set(varName, localVars.get(varName) - 1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
blockVars = _blockVars;
|
|
159
|
+
}
|
|
160
|
+
if (isRoot) {
|
|
161
|
+
for (const varName of blockVars) {
|
|
162
|
+
localVars.set(varName, localVars.get(varName) - 1);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function walkIdentifiersInTypeReference(ts, node, cb) {
|
|
167
|
+
if (ts.isTypeQueryNode(node) && ts.isIdentifier(node.exprName)) {
|
|
168
|
+
cb(node.exprName, false);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function collectVars(ts, node, ast, result) {
|
|
175
|
+
if (ts.isIdentifier(node)) {
|
|
176
|
+
result.push((0, scriptSetupRanges_1.getNodeText)(ts, node, ast));
|
|
177
|
+
}
|
|
178
|
+
else if (ts.isObjectBindingPattern(node)) {
|
|
179
|
+
for (const el of node.elements) {
|
|
180
|
+
collectVars(ts, el.name, ast, result);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else if (ts.isArrayBindingPattern(node)) {
|
|
184
|
+
for (const el of node.elements) {
|
|
185
|
+
if (ts.isBindingElement(el)) {
|
|
186
|
+
collectVars(ts, el.name, ast, result);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
ts.forEachChild(node, node => collectVars(ts, node, ast, result));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.collectVars = collectVars;
|
|
195
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { VueCompilerOptions } from '../types';
|
|
3
|
+
export type ParsedCommandLine = ts.ParsedCommandLine & {
|
|
4
|
+
vueOptions: Partial<VueCompilerOptions>;
|
|
5
|
+
};
|
|
6
|
+
export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
|
|
7
|
+
export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string): ParsedCommandLine;
|
|
8
|
+
export declare function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions>): VueCompilerOptions;
|
package/lib/utils/ts.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveVueCompilerOptions = exports.createParsedCommandLine = exports.createParsedCommandLineByJson = void 0;
|
|
4
|
+
const path = require("path-browserify");
|
|
5
|
+
function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json') {
|
|
6
|
+
const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
|
|
7
|
+
ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
|
|
8
|
+
let vueOptions = {};
|
|
9
|
+
for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
|
|
10
|
+
try {
|
|
11
|
+
vueOptions = {
|
|
12
|
+
...vueOptions,
|
|
13
|
+
...getPartialVueCompilerOptions(ts, ts.readJsonConfigFile(extendPath, proxyHost.host.readFile)),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
catch (err) { }
|
|
17
|
+
}
|
|
18
|
+
const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, (vueOptions.extensions ?? ['.vue']).map(extension => ({
|
|
19
|
+
extension: extension.slice(1),
|
|
20
|
+
isMixedContent: true,
|
|
21
|
+
scriptKind: ts.ScriptKind.Deferred,
|
|
22
|
+
})));
|
|
23
|
+
// fix https://github.com/vuejs/language-tools/issues/1786
|
|
24
|
+
// https://github.com/microsoft/TypeScript/issues/30457
|
|
25
|
+
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
26
|
+
parsed.options.outDir = undefined;
|
|
27
|
+
return {
|
|
28
|
+
...parsed,
|
|
29
|
+
vueOptions,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
|
|
33
|
+
function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
|
|
34
|
+
try {
|
|
35
|
+
const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
|
|
36
|
+
const config = ts.readJsonConfigFile(tsConfigPath, proxyHost.host.readFile);
|
|
37
|
+
ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath);
|
|
38
|
+
let vueOptions = {};
|
|
39
|
+
for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
|
|
40
|
+
try {
|
|
41
|
+
vueOptions = {
|
|
42
|
+
...vueOptions,
|
|
43
|
+
...getPartialVueCompilerOptions(ts, ts.readJsonConfigFile(extendPath, proxyHost.host.readFile)),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (err) { }
|
|
47
|
+
}
|
|
48
|
+
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, (vueOptions.extensions ?? ['.vue']).map(extension => ({
|
|
49
|
+
extension: extension.slice(1),
|
|
50
|
+
isMixedContent: true,
|
|
51
|
+
scriptKind: ts.ScriptKind.Deferred,
|
|
52
|
+
})));
|
|
53
|
+
// fix https://github.com/vuejs/language-tools/issues/1786
|
|
54
|
+
// https://github.com/microsoft/TypeScript/issues/30457
|
|
55
|
+
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
56
|
+
parsed.options.outDir = undefined;
|
|
57
|
+
return {
|
|
58
|
+
...parsed,
|
|
59
|
+
vueOptions,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
// console.warn('Failed to resolve tsconfig path:', tsConfigPath, err);
|
|
64
|
+
return {
|
|
65
|
+
fileNames: [],
|
|
66
|
+
options: {},
|
|
67
|
+
vueOptions: resolveVueCompilerOptions({}),
|
|
68
|
+
errors: [],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.createParsedCommandLine = createParsedCommandLine;
|
|
73
|
+
function proxyParseConfigHostForExtendConfigPaths(parseConfigHost) {
|
|
74
|
+
const extendConfigPaths = [];
|
|
75
|
+
const host = new Proxy(parseConfigHost, {
|
|
76
|
+
get(target, key) {
|
|
77
|
+
if (key === 'readFile') {
|
|
78
|
+
return (fileName) => {
|
|
79
|
+
if (!fileName.endsWith('/package.json') && !extendConfigPaths.includes(fileName)) {
|
|
80
|
+
extendConfigPaths.push(fileName);
|
|
81
|
+
}
|
|
82
|
+
return target.readFile(fileName);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return target[key];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
host,
|
|
90
|
+
extendConfigPaths,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
|
|
94
|
+
const folder = path.dirname(tsConfigSourceFile.fileName);
|
|
95
|
+
const obj = ts.convertToObject(tsConfigSourceFile, []);
|
|
96
|
+
const rawOptions = obj?.vueCompilerOptions ?? {};
|
|
97
|
+
const result = {
|
|
98
|
+
...rawOptions,
|
|
99
|
+
};
|
|
100
|
+
const target = rawOptions.target ?? 'auto';
|
|
101
|
+
if (target === 'auto') {
|
|
102
|
+
const resolvedPath = resolvePath('vue/package.json');
|
|
103
|
+
if (resolvedPath) {
|
|
104
|
+
const vuePackageJson = require(resolvedPath);
|
|
105
|
+
const versionNumbers = vuePackageJson.version.split('.');
|
|
106
|
+
result.target = Number(versionNumbers[0] + '.' + versionNumbers[1]);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// console.warn('Load vue/package.json failed from', folder);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
result.target = target;
|
|
114
|
+
}
|
|
115
|
+
if (rawOptions.plugins) {
|
|
116
|
+
const plugins = rawOptions.plugins
|
|
117
|
+
.map((pluginPath) => {
|
|
118
|
+
try {
|
|
119
|
+
const resolvedPath = resolvePath(pluginPath);
|
|
120
|
+
if (resolvedPath) {
|
|
121
|
+
return require(resolvedPath);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
console.warn('Load plugin failed:', pluginPath);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.warn('Load plugin failed:', pluginPath, error);
|
|
129
|
+
}
|
|
130
|
+
return [];
|
|
131
|
+
})
|
|
132
|
+
.flat(Infinity);
|
|
133
|
+
result.plugins = plugins;
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
function resolvePath(scriptPath) {
|
|
137
|
+
try {
|
|
138
|
+
if (require?.resolve) {
|
|
139
|
+
return require.resolve(scriptPath, { paths: [folder] });
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// console.warn('failed to resolve path:', scriptPath, 'require.resolve is not supported in web');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
// console.warn(error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element
|
|
151
|
+
const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
|
|
152
|
+
'header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
|
|
153
|
+
'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
|
|
154
|
+
'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
|
|
155
|
+
'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
|
|
156
|
+
'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
|
|
157
|
+
'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
|
|
158
|
+
'option,output,progress,select,textarea,details,dialog,menu,' +
|
|
159
|
+
'summary,template,blockquote,iframe,tfoot';
|
|
160
|
+
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element
|
|
161
|
+
const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
|
|
162
|
+
'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
|
|
163
|
+
'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
|
|
164
|
+
'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
|
|
165
|
+
'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
|
|
166
|
+
'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
|
|
167
|
+
'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
|
|
168
|
+
'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
|
|
169
|
+
'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
|
|
170
|
+
'text,textPath,title,tspan,unknown,use,view';
|
|
171
|
+
function resolveVueCompilerOptions(vueOptions) {
|
|
172
|
+
const target = vueOptions.target ?? 3.3;
|
|
173
|
+
const lib = vueOptions.lib || (target < 2.7 ? '@vue/runtime-dom' : 'vue');
|
|
174
|
+
return {
|
|
175
|
+
...vueOptions,
|
|
176
|
+
target,
|
|
177
|
+
extensions: vueOptions.extensions ?? ['.vue'],
|
|
178
|
+
lib,
|
|
179
|
+
jsxSlots: vueOptions.jsxSlots ?? false,
|
|
180
|
+
strictTemplates: vueOptions.strictTemplates ?? false,
|
|
181
|
+
skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false,
|
|
182
|
+
nativeTags: vueOptions.nativeTags ?? [...new Set([
|
|
183
|
+
...HTML_TAGS.split(','),
|
|
184
|
+
...SVG_TAGS.split(','),
|
|
185
|
+
// fix https://github.com/johnsoncodehk/volar/issues/1340
|
|
186
|
+
'hgroup',
|
|
187
|
+
'slot',
|
|
188
|
+
'component',
|
|
189
|
+
])],
|
|
190
|
+
dataAttributes: vueOptions.dataAttributes ?? [],
|
|
191
|
+
htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'],
|
|
192
|
+
optionsWrapper: vueOptions.optionsWrapper ?? (target >= 2.7
|
|
193
|
+
? [`(await import('${lib}')).defineComponent(`, `)`]
|
|
194
|
+
: [`(await import('vue')).default.extend(`, `)`]),
|
|
195
|
+
macros: {
|
|
196
|
+
defineProps: ['defineProps'],
|
|
197
|
+
defineSlots: ['defineSlots'],
|
|
198
|
+
defineEmits: ['defineEmits'],
|
|
199
|
+
defineExpose: ['defineExpose'],
|
|
200
|
+
defineModel: ['defineModel'],
|
|
201
|
+
defineOptions: ['defineOptions'],
|
|
202
|
+
withDefaults: ['withDefaults'],
|
|
203
|
+
...vueOptions.macros,
|
|
204
|
+
},
|
|
205
|
+
plugins: vueOptions.plugins ?? [],
|
|
206
|
+
// experimental
|
|
207
|
+
experimentalDefinePropProposal: vueOptions.experimentalDefinePropProposal ?? false,
|
|
208
|
+
experimentalResolveStyleCssClasses: vueOptions.experimentalResolveStyleCssClasses ?? 'scoped',
|
|
209
|
+
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
|
|
210
|
+
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
|
|
211
|
+
experimentalModelPropName: vueOptions.experimentalModelPropName ?? {
|
|
212
|
+
'': {
|
|
213
|
+
input: true
|
|
214
|
+
},
|
|
215
|
+
value: {
|
|
216
|
+
input: { type: 'text' },
|
|
217
|
+
textarea: true,
|
|
218
|
+
select: true
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
experimentalUseElementAccessInTemplate: vueOptions.experimentalUseElementAccessInTemplate ?? false,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
exports.resolveVueCompilerOptions = resolveVueCompilerOptions;
|
|
225
|
+
//# sourceMappingURL=ts.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
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-template-compiler/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
|