@vue/language-core 3.0.7-alpha.1 → 3.1.0-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/lib/codegen/globalTypes.js +19 -13
- package/lib/codegen/localTypes.d.ts +2 -4
- package/lib/codegen/localTypes.js +10 -33
- package/lib/codegen/script/component.d.ts +0 -3
- package/lib/codegen/script/component.js +15 -22
- package/lib/codegen/script/componentSelf.js +1 -1
- package/lib/codegen/script/context.d.ts +2 -4
- package/lib/codegen/script/index.d.ts +4 -6
- package/lib/codegen/script/index.js +70 -63
- package/lib/codegen/script/scriptSetup.js +142 -143
- package/lib/codegen/script/template.d.ts +1 -3
- package/lib/codegen/script/template.js +90 -16
- package/lib/codegen/template/context.js +1 -1
- package/lib/codegen/template/element.js +4 -6
- package/lib/codegen/template/elementProps.js +6 -11
- package/lib/codegen/template/index.d.ts +1 -1
- package/lib/codegen/template/index.js +12 -13
- package/lib/codegen/template/slotOutlet.js +2 -3
- package/lib/codegen/template/styleScopedClasses.js +1 -2
- package/lib/codegen/template/vFor.js +1 -1
- package/lib/codegen/template/vSlot.js +1 -1
- package/lib/codegen/tenp.d.ts +1 -0
- package/lib/codegen/tenp.js +3 -0
- package/lib/codegen/utils/index.d.ts +1 -0
- package/lib/codegen/utils/index.js +7 -0
- package/lib/compilerOptions.js +3 -8
- package/lib/languagePlugin.js +8 -19
- package/lib/parsers/scriptRanges.d.ts +0 -1
- package/lib/parsers/scriptRanges.js +6 -9
- package/lib/parsers/scriptSetupRanges.d.ts +0 -6
- package/lib/parsers/scriptSetupRanges.js +9 -95
- package/lib/parsers/utils.d.ts +12 -0
- package/lib/parsers/utils.js +95 -0
- package/lib/plugins/file-css.d.ts +3 -0
- package/lib/plugins/file-css.js +57 -0
- package/lib/plugins/vue-template-inline-ts.js +2 -3
- package/lib/plugins/vue-tsx.d.ts +2 -5
- package/lib/plugins/vue-tsx.js +16 -13
- package/lib/types.d.ts +1 -1
- package/lib/utils/parseCssClassNames.d.ts +4 -0
- package/lib/utils/parseCssClassNames.js +17 -0
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/parseCssVars.d.ts +6 -0
- package/lib/utils/parseCssVars.js +26 -0
- package/lib/utils/shared.d.ts +1 -2
- package/lib/utils/shared.js +0 -4
- package/lib/virtualFile/computedSfc.js +4 -4
- package/lib/virtualFile/vueFile.d.ts +5 -10
- package/lib/virtualFile/vueFile.js +3 -10
- package/package.json +2 -3
- package/lib/utils/ts.js +0 -296
- package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
- package/lib/utils/vue2TemplateCompiler.js +0 -90
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -31,9 +31,7 @@ const plugin = ctx => {
|
|
|
31
31
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
32
32
|
const codegen = useCodegen(fileName, sfc);
|
|
33
33
|
const tsx = codegen.getGeneratedScript();
|
|
34
|
-
|
|
35
|
-
embeddedFile.content = [...tsx.codes];
|
|
36
|
-
}
|
|
34
|
+
embeddedFile.content = [...tsx.codes];
|
|
37
35
|
}
|
|
38
36
|
},
|
|
39
37
|
};
|
|
@@ -120,25 +118,30 @@ function createTsx(fileName, sfc, ctx) {
|
|
|
120
118
|
return newNames;
|
|
121
119
|
});
|
|
122
120
|
const setupHasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
|
|
123
|
-
const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
|
|
124
121
|
const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
|
|
122
|
+
const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
|
|
125
123
|
const getSetupInheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
126
124
|
const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs
|
|
127
125
|
?? getScriptRanges()?.exportDefault?.inheritAttrsOption;
|
|
128
126
|
return value !== 'false';
|
|
129
127
|
});
|
|
130
128
|
const getComponentSelfName = (0, alien_signals_1.computed)(() => {
|
|
129
|
+
let name;
|
|
131
130
|
const { exportDefault } = getScriptRanges() ?? {};
|
|
132
131
|
if (sfc.script && exportDefault?.nameOption) {
|
|
133
|
-
|
|
134
|
-
return sfc.script.content.slice(nameOption.start + 1, nameOption.end - 1);
|
|
132
|
+
name = sfc.script.content.slice(exportDefault.nameOption.start + 1, exportDefault.nameOption.end - 1);
|
|
135
133
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
else {
|
|
135
|
+
const { defineOptions } = getScriptSetupRanges() ?? {};
|
|
136
|
+
if (sfc.scriptSetup && defineOptions?.name) {
|
|
137
|
+
name = defineOptions.name;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const baseName = path.basename(fileName);
|
|
141
|
+
name = baseName.slice(0, baseName.lastIndexOf('.'));
|
|
142
|
+
}
|
|
139
143
|
}
|
|
140
|
-
|
|
141
|
-
return (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
|
|
144
|
+
return (0, shared_1.capitalize)((0, shared_1.camelize)(name));
|
|
142
145
|
});
|
|
143
146
|
const getGeneratedTemplate = (0, alien_signals_1.computed)(() => {
|
|
144
147
|
if (getResolvedOptions().skipTemplateCodegen || !sfc.template) {
|
|
@@ -154,8 +157,8 @@ function createTsx(fileName, sfc, ctx) {
|
|
|
154
157
|
destructuredPropNames: getSetupDestructuredPropNames(),
|
|
155
158
|
templateRefNames: getSetupTemplateRefNames(),
|
|
156
159
|
hasDefineSlots: setupHasDefineSlots(),
|
|
157
|
-
slotsAssignName: getSetupSlotsAssignName(),
|
|
158
160
|
propsAssignName: getSetupPropsAssignName(),
|
|
161
|
+
slotsAssignName: getSetupSlotsAssignName(),
|
|
159
162
|
inheritAttrs: getSetupInheritAttrs(),
|
|
160
163
|
selfComponentName: getComponentSelfName(),
|
|
161
164
|
});
|
|
@@ -165,7 +168,7 @@ function createTsx(fileName, sfc, ctx) {
|
|
|
165
168
|
ts,
|
|
166
169
|
compilerOptions: ctx.compilerOptions,
|
|
167
170
|
vueCompilerOptions: getResolvedOptions(),
|
|
168
|
-
sfc
|
|
171
|
+
sfc,
|
|
169
172
|
fileName,
|
|
170
173
|
lang: getLang(),
|
|
171
174
|
scriptRanges: getScriptRanges(),
|
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' | 'globalTypesPath' | 'plugins'>> & {
|
|
10
10
|
strictTemplates?: boolean;
|
|
11
|
-
target?: 'auto' |
|
|
11
|
+
target?: 'auto' | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
|
|
12
12
|
globalTypesPath?: string;
|
|
13
13
|
plugins?: string[];
|
|
14
14
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCssClassNames = parseCssClassNames;
|
|
4
|
+
const parseCssVars_1 = require("./parseCssVars");
|
|
5
|
+
const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
|
|
6
|
+
const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
|
|
7
|
+
function* parseCssClassNames(css) {
|
|
8
|
+
css = (0, parseCssVars_1.fillBlank)(css, parseCssVars_1.commentReg, fragmentReg);
|
|
9
|
+
const matches = css.matchAll(cssClassNameReg);
|
|
10
|
+
for (const match of matches) {
|
|
11
|
+
const matchText = match[1];
|
|
12
|
+
if (matchText) {
|
|
13
|
+
yield { offset: match.index, text: matchText };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=parseCssClassNames.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCssImports = parseCssImports;
|
|
4
|
+
const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
|
|
5
|
+
function* parseCssImports(css) {
|
|
6
|
+
const matches = css.matchAll(cssImportReg);
|
|
7
|
+
for (const match of matches) {
|
|
8
|
+
let text = match[0];
|
|
9
|
+
let offset = match.index;
|
|
10
|
+
if (text.startsWith("'") || text.startsWith('"')) {
|
|
11
|
+
text = text.slice(1, -1);
|
|
12
|
+
offset += 1;
|
|
13
|
+
}
|
|
14
|
+
if (text) {
|
|
15
|
+
yield { text, offset };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=parseCssImports.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/cssVars.ts#L47-L61
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.commentReg = void 0;
|
|
5
|
+
exports.parseCssVars = parseCssVars;
|
|
6
|
+
exports.fillBlank = fillBlank;
|
|
7
|
+
const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
|
|
8
|
+
exports.commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
|
|
9
|
+
function* parseCssVars(css) {
|
|
10
|
+
css = fillBlank(css, exports.commentReg);
|
|
11
|
+
const matchs = css.matchAll(vBindCssVarReg);
|
|
12
|
+
for (const match of matchs) {
|
|
13
|
+
const matchText = match.slice(1).find(t => t);
|
|
14
|
+
if (matchText) {
|
|
15
|
+
const offset = match.index + css.slice(match.index).indexOf(matchText);
|
|
16
|
+
yield { offset, text: matchText };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function fillBlank(css, ...regs) {
|
|
21
|
+
for (const reg of regs) {
|
|
22
|
+
css = css.replace(reg, match => ' '.repeat(match.length));
|
|
23
|
+
}
|
|
24
|
+
return css;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=parseCssVars.js.map
|
package/lib/utils/shared.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type * as ts from 'typescript';
|
|
|
3
3
|
import type { Sfc, TextRange } from '../types';
|
|
4
4
|
export { hyphenate as hyphenateTag } from '@vue/shared';
|
|
5
5
|
export declare function hyphenateAttr(str: string): string;
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): number[];
|
|
6
|
+
export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): [number] | [number, number];
|
|
8
7
|
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
9
8
|
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
package/lib/utils/shared.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hyphenateTag = void 0;
|
|
4
4
|
exports.hyphenateAttr = hyphenateAttr;
|
|
5
|
-
exports.getSlotsPropertyName = getSlotsPropertyName;
|
|
6
5
|
exports.getElementTagOffsets = getElementTagOffsets;
|
|
7
6
|
exports.getStartEnd = getStartEnd;
|
|
8
7
|
exports.getNodeText = getNodeText;
|
|
@@ -17,9 +16,6 @@ function hyphenateAttr(str) {
|
|
|
17
16
|
}
|
|
18
17
|
return hyphencase;
|
|
19
18
|
}
|
|
20
|
-
function getSlotsPropertyName(vueVersion) {
|
|
21
|
-
return vueVersion < 3 ? '$scopedSlots' : '$slots';
|
|
22
|
-
}
|
|
23
19
|
function getElementTagOffsets(node, template) {
|
|
24
20
|
const tagOffsets = [
|
|
25
21
|
template.content.indexOf(node.tag, node.loc.start.offset),
|
|
@@ -18,7 +18,7 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
18
18
|
const getComments = (0, alien_signals_1.computed)(oldValue => {
|
|
19
19
|
const newValue = getParseResult()?.descriptor.comments ?? [];
|
|
20
20
|
if (oldValue?.length === newValue.length
|
|
21
|
-
&& oldValue
|
|
21
|
+
&& oldValue.every((v, i) => v === newValue[i])) {
|
|
22
22
|
return oldValue;
|
|
23
23
|
}
|
|
24
24
|
return newValue;
|
|
@@ -27,13 +27,13 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
27
27
|
const compiledAst = computedTemplateAst(base);
|
|
28
28
|
return mergeObject(base, {
|
|
29
29
|
get ast() {
|
|
30
|
-
return compiledAst()
|
|
30
|
+
return compiledAst().ast;
|
|
31
31
|
},
|
|
32
32
|
get errors() {
|
|
33
|
-
return compiledAst()
|
|
33
|
+
return compiledAst().errors;
|
|
34
34
|
},
|
|
35
35
|
get warnings() {
|
|
36
|
-
return compiledAst()
|
|
36
|
+
return compiledAst().warnings;
|
|
37
37
|
},
|
|
38
38
|
});
|
|
39
39
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { VirtualCode } from '@volar/language-core';
|
|
1
|
+
import type { CodeInformation, Mapping, VirtualCode } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { VueCompilerOptions, VueLanguagePluginReturn } from '../types';
|
|
4
|
+
import { computedSfc } from './computedSfc';
|
|
4
5
|
export declare class VueVirtualCode implements VirtualCode {
|
|
5
6
|
fileName: string;
|
|
6
7
|
languageId: string;
|
|
@@ -8,22 +9,16 @@ export declare class VueVirtualCode implements VirtualCode {
|
|
|
8
9
|
vueCompilerOptions: VueCompilerOptions;
|
|
9
10
|
plugins: VueLanguagePluginReturn[];
|
|
10
11
|
ts: typeof import('typescript');
|
|
11
|
-
id
|
|
12
|
+
readonly id = "main";
|
|
13
|
+
readonly sfc: ReturnType<typeof computedSfc>;
|
|
12
14
|
private _snapshot;
|
|
13
15
|
private _vueSfc;
|
|
14
|
-
private _sfc;
|
|
15
16
|
private _embeddedCodes;
|
|
16
17
|
private _mappings;
|
|
17
18
|
get snapshot(): ts.IScriptSnapshot;
|
|
18
19
|
get vueSfc(): import("@vue/compiler-sfc").SFCParseResult | undefined;
|
|
19
|
-
get sfc(): import("../types").Sfc;
|
|
20
20
|
get embeddedCodes(): VirtualCode[];
|
|
21
|
-
get mappings():
|
|
22
|
-
sourceOffsets: number[];
|
|
23
|
-
generatedOffsets: number[];
|
|
24
|
-
lengths: number[];
|
|
25
|
-
data: import("@volar/language-core").CodeInformation;
|
|
26
|
-
}[];
|
|
21
|
+
get mappings(): Mapping<CodeInformation>[];
|
|
27
22
|
constructor(fileName: string, languageId: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: VueLanguagePluginReturn[], ts: typeof import('typescript'));
|
|
28
23
|
update(newSnapshot: ts.IScriptSnapshot): void;
|
|
29
24
|
}
|
|
@@ -7,16 +7,12 @@ const computedEmbeddedCodes_1 = require("./computedEmbeddedCodes");
|
|
|
7
7
|
const computedSfc_1 = require("./computedSfc");
|
|
8
8
|
const computedVueSfc_1 = require("./computedVueSfc");
|
|
9
9
|
class VueVirtualCode {
|
|
10
|
-
// others
|
|
11
10
|
get snapshot() {
|
|
12
11
|
return this._snapshot();
|
|
13
12
|
}
|
|
14
13
|
get vueSfc() {
|
|
15
14
|
return this._vueSfc();
|
|
16
15
|
}
|
|
17
|
-
get sfc() {
|
|
18
|
-
return this._sfc;
|
|
19
|
-
}
|
|
20
16
|
get embeddedCodes() {
|
|
21
17
|
return this._embeddedCodes();
|
|
22
18
|
}
|
|
@@ -30,13 +26,11 @@ class VueVirtualCode {
|
|
|
30
26
|
this.vueCompilerOptions = vueCompilerOptions;
|
|
31
27
|
this.plugins = plugins;
|
|
32
28
|
this.ts = ts;
|
|
33
|
-
// sources
|
|
34
29
|
this.id = 'main';
|
|
35
|
-
this._snapshot = (0, alien_signals_1.signal)(
|
|
36
|
-
// computeds
|
|
30
|
+
this._snapshot = (0, alien_signals_1.signal)(initSnapshot);
|
|
37
31
|
this._vueSfc = (0, computedVueSfc_1.computedVueSfc)(this.plugins, this.fileName, this.languageId, this._snapshot);
|
|
38
|
-
this.
|
|
39
|
-
this._embeddedCodes = (0, computedEmbeddedCodes_1.computedEmbeddedCodes)(this.plugins, this.fileName, this.
|
|
32
|
+
this.sfc = (0, computedSfc_1.computedSfc)(this.ts, this.plugins, this.fileName, this._snapshot, this._vueSfc);
|
|
33
|
+
this._embeddedCodes = (0, computedEmbeddedCodes_1.computedEmbeddedCodes)(this.plugins, this.fileName, this.sfc);
|
|
40
34
|
this._mappings = (0, alien_signals_1.computed)(() => {
|
|
41
35
|
const snapshot = this._snapshot();
|
|
42
36
|
return [{
|
|
@@ -46,7 +40,6 @@ class VueVirtualCode {
|
|
|
46
40
|
data: plugins_1.allCodeFeatures,
|
|
47
41
|
}];
|
|
48
42
|
});
|
|
49
|
-
this._snapshot(initSnapshot);
|
|
50
43
|
}
|
|
51
44
|
update(newSnapshot) {
|
|
52
45
|
this._snapshot(newSnapshot);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0-alpha.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@volar/language-core": "2.4.23",
|
|
17
17
|
"@vue/compiler-dom": "^3.5.0",
|
|
18
|
-
"@vue/compiler-vue2": "^2.7.16",
|
|
19
18
|
"@vue/shared": "^3.5.0",
|
|
20
19
|
"alien-signals": "^2.0.5",
|
|
21
20
|
"muggle-string": "^0.4.1",
|
|
@@ -37,5 +36,5 @@
|
|
|
37
36
|
"optional": true
|
|
38
37
|
}
|
|
39
38
|
},
|
|
40
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "adcbd8b1a7bf432844230755de999d22b95dc160"
|
|
41
40
|
}
|
package/lib/utils/ts.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
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("./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.configRoots = new Set();
|
|
87
|
-
this.options = {};
|
|
88
|
-
this.plugins = [];
|
|
89
|
-
}
|
|
90
|
-
addConfig(options, rootDir) {
|
|
91
|
-
this.configRoots.add(rootDir);
|
|
92
|
-
for (const key in options) {
|
|
93
|
-
switch (key) {
|
|
94
|
-
case 'target':
|
|
95
|
-
if (options[key] === 'auto') {
|
|
96
|
-
this.target = findVueVersion(rootDir);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.target = options[key];
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
102
|
-
case 'globalTypesPath':
|
|
103
|
-
if (options[key] !== undefined) {
|
|
104
|
-
this.globalTypesPath = path_browserify_1.posix.join(rootDir, options[key]);
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
case 'plugins':
|
|
108
|
-
this.plugins = (options.plugins ?? [])
|
|
109
|
-
.flatMap((pluginPath) => {
|
|
110
|
-
try {
|
|
111
|
-
const resolvedPath = resolvePath(pluginPath, rootDir);
|
|
112
|
-
if (resolvedPath) {
|
|
113
|
-
const plugin = require(resolvedPath);
|
|
114
|
-
plugin.__moduleName = pluginPath;
|
|
115
|
-
return plugin;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
console.warn('[Vue] Load plugin failed:', pluginPath);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
console.warn('[Vue] Resolve plugin path failed:', pluginPath, error);
|
|
123
|
-
}
|
|
124
|
-
return [];
|
|
125
|
-
});
|
|
126
|
-
break;
|
|
127
|
-
default:
|
|
128
|
-
// @ts-expect-error
|
|
129
|
-
this.options[key] = options[key];
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (options.target === undefined) {
|
|
134
|
-
this.target ??= findVueVersion(rootDir);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
build(defaults) {
|
|
138
|
-
defaults ??= getDefaultCompilerOptions(this.target, this.options.lib, this.options.strictTemplates);
|
|
139
|
-
const resolvedOptions = {
|
|
140
|
-
...defaults,
|
|
141
|
-
...this.options,
|
|
142
|
-
plugins: this.plugins,
|
|
143
|
-
macros: {
|
|
144
|
-
...defaults.macros,
|
|
145
|
-
...this.options.macros,
|
|
146
|
-
},
|
|
147
|
-
composables: {
|
|
148
|
-
...defaults.composables,
|
|
149
|
-
...this.options.composables,
|
|
150
|
-
},
|
|
151
|
-
fallthroughComponentNames: [
|
|
152
|
-
...defaults.fallthroughComponentNames,
|
|
153
|
-
...this.options.fallthroughComponentNames ?? [],
|
|
154
|
-
].map(shared_2.hyphenateTag),
|
|
155
|
-
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
|
|
156
|
-
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
|
|
157
|
-
experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
|
|
158
|
-
};
|
|
159
|
-
if (resolvedOptions.globalTypesPath === shared_1.NOOP) {
|
|
160
|
-
if (this.fileExists && this.globalTypesPath === undefined) {
|
|
161
|
-
const fileDirToGlobalTypesPath = new Map();
|
|
162
|
-
resolvedOptions.globalTypesPath = fileName => {
|
|
163
|
-
const fileDir = path_browserify_1.posix.dirname(fileName);
|
|
164
|
-
if (fileDirToGlobalTypesPath.has(fileDir)) {
|
|
165
|
-
return fileDirToGlobalTypesPath.get(fileDir);
|
|
166
|
-
}
|
|
167
|
-
const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
|
|
168
|
-
const result = root
|
|
169
|
-
? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
|
|
170
|
-
: undefined;
|
|
171
|
-
fileDirToGlobalTypesPath.set(fileDir, result);
|
|
172
|
-
return result;
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
resolvedOptions.globalTypesPath = () => this.globalTypesPath;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return resolvedOptions;
|
|
180
|
-
}
|
|
181
|
-
findNodeModulesRoot(dir, lib) {
|
|
182
|
-
while (!this.fileExists(path_browserify_1.posix.join(dir, 'node_modules', lib, 'package.json'))) {
|
|
183
|
-
const parentDir = path_browserify_1.posix.dirname(dir);
|
|
184
|
-
if (dir === parentDir) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
dir = parentDir;
|
|
188
|
-
}
|
|
189
|
-
return dir;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
exports.CompilerOptionsResolver = CompilerOptionsResolver;
|
|
193
|
-
function findVueVersion(rootDir) {
|
|
194
|
-
const resolvedPath = resolvePath('vue/package.json', rootDir);
|
|
195
|
-
if (resolvedPath) {
|
|
196
|
-
const vuePackageJson = require(resolvedPath);
|
|
197
|
-
const versionNumbers = vuePackageJson.version.split('.');
|
|
198
|
-
return Number(versionNumbers[0] + '.' + versionNumbers[1]);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
// console.warn('Load vue/package.json failed from', folder);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function resolvePath(scriptPath, root) {
|
|
205
|
-
try {
|
|
206
|
-
if (require?.resolve) {
|
|
207
|
-
return require.resolve(scriptPath, { paths: [root] });
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
// console.warn('failed to resolve path:', scriptPath, 'require.resolve is not supported in web');
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
catch {
|
|
214
|
-
// console.warn(error);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = false) {
|
|
218
|
-
return {
|
|
219
|
-
target,
|
|
220
|
-
lib,
|
|
221
|
-
globalTypesPath: shared_1.NOOP,
|
|
222
|
-
extensions: ['.vue'],
|
|
223
|
-
vitePressExtensions: [],
|
|
224
|
-
petiteVueExtensions: [],
|
|
225
|
-
jsxSlots: false,
|
|
226
|
-
strictVModel: strictTemplates,
|
|
227
|
-
strictCssModules: false,
|
|
228
|
-
checkUnknownProps: strictTemplates,
|
|
229
|
-
checkUnknownEvents: strictTemplates,
|
|
230
|
-
checkUnknownDirectives: strictTemplates,
|
|
231
|
-
checkUnknownComponents: strictTemplates,
|
|
232
|
-
inferComponentDollarEl: false,
|
|
233
|
-
inferComponentDollarRefs: false,
|
|
234
|
-
inferTemplateDollarAttrs: false,
|
|
235
|
-
inferTemplateDollarEl: false,
|
|
236
|
-
inferTemplateDollarRefs: false,
|
|
237
|
-
inferTemplateDollarSlots: false,
|
|
238
|
-
skipTemplateCodegen: false,
|
|
239
|
-
fallthroughAttributes: false,
|
|
240
|
-
resolveStyleImports: false,
|
|
241
|
-
resolveStyleClassNames: 'scoped',
|
|
242
|
-
fallthroughComponentNames: [
|
|
243
|
-
'Transition',
|
|
244
|
-
'KeepAlive',
|
|
245
|
-
'Teleport',
|
|
246
|
-
'Suspense',
|
|
247
|
-
],
|
|
248
|
-
dataAttributes: [],
|
|
249
|
-
htmlAttributes: ['aria-*'],
|
|
250
|
-
optionsWrapper: target >= 2.7
|
|
251
|
-
? [`(await import('${lib}')).defineComponent(`, `)`]
|
|
252
|
-
: [`(await import('${lib}')).default.extend(`, `)`],
|
|
253
|
-
macros: {
|
|
254
|
-
defineProps: ['defineProps'],
|
|
255
|
-
defineSlots: ['defineSlots'],
|
|
256
|
-
defineEmits: ['defineEmits'],
|
|
257
|
-
defineExpose: ['defineExpose'],
|
|
258
|
-
defineModel: ['defineModel'],
|
|
259
|
-
defineOptions: ['defineOptions'],
|
|
260
|
-
withDefaults: ['withDefaults'],
|
|
261
|
-
},
|
|
262
|
-
composables: {
|
|
263
|
-
useAttrs: ['useAttrs'],
|
|
264
|
-
useCssModule: ['useCssModule'],
|
|
265
|
-
useSlots: ['useSlots'],
|
|
266
|
-
useTemplateRef: ['useTemplateRef', 'templateRef'],
|
|
267
|
-
},
|
|
268
|
-
plugins: [],
|
|
269
|
-
experimentalModelPropName: {
|
|
270
|
-
'': {
|
|
271
|
-
input: true,
|
|
272
|
-
},
|
|
273
|
-
value: {
|
|
274
|
-
input: { type: 'text' },
|
|
275
|
-
textarea: true,
|
|
276
|
-
select: true,
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function writeGlobalTypes(vueOptions, writeFile) {
|
|
282
|
-
const originalFn = vueOptions.globalTypesPath;
|
|
283
|
-
if (!originalFn) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
const writed = new Set();
|
|
287
|
-
vueOptions.globalTypesPath = (fileName) => {
|
|
288
|
-
const result = originalFn(fileName);
|
|
289
|
-
if (result && !writed.has(result)) {
|
|
290
|
-
writed.add(result);
|
|
291
|
-
writeFile(result, (0, globalTypes_1.generateGlobalTypes)(vueOptions));
|
|
292
|
-
}
|
|
293
|
-
return result;
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
//# sourceMappingURL=ts.js.map
|