@vue/language-core 1.8.19 → 1.8.21

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.
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computedSfc = void 0;
4
+ const parseCssClassNames_1 = require("../utils/parseCssClassNames");
5
+ const parseCssVars_1 = require("../utils/parseCssVars");
6
+ const computeds_1 = require("computeds");
7
+ function computedSfc(ts, plugins, fileName, snapshot, parsed) {
8
+ const untrackedSnapshot = () => {
9
+ (0, computeds_1.pauseTracking)();
10
+ const res = snapshot();
11
+ (0, computeds_1.resetTracking)();
12
+ return res;
13
+ };
14
+ const template = computedNullableSfcBlock('template', 'html', (0, computeds_1.computed)(() => parsed()?.descriptor.template ?? undefined), (_block, base) => {
15
+ const compiledAst = computedTemplateAst(base);
16
+ return mergeObject(base, {
17
+ get ast() { return compiledAst()?.ast; },
18
+ get errors() { return compiledAst()?.errors; },
19
+ get warnings() { return compiledAst()?.warnings; },
20
+ });
21
+ });
22
+ const script = computedNullableSfcBlock('script', 'js', (0, computeds_1.computed)(() => parsed()?.descriptor.script ?? undefined), (block, base) => {
23
+ const src = (0, computeds_1.computed)(() => block().src);
24
+ const srcOffset = (0, computeds_1.computed)(() => {
25
+ const _src = src();
26
+ return _src ? untrackedSnapshot().getText(0, base.startTagEnd).lastIndexOf(_src) - base.startTagEnd : -1;
27
+ });
28
+ const ast = (0, computeds_1.computed)(() => ts.createSourceFile(fileName + '.' + base.lang, base.content, ts.ScriptTarget.Latest));
29
+ return mergeObject(base, {
30
+ get src() { return src(); },
31
+ get srcOffset() { return srcOffset(); },
32
+ get ast() { return ast(); },
33
+ });
34
+ });
35
+ const scriptSetup = computedNullableSfcBlock('scriptSetup', 'js', (0, computeds_1.computed)(() => parsed()?.descriptor.scriptSetup ?? undefined), (block, base) => {
36
+ const generic = (0, computeds_1.computed)(() => {
37
+ const _block = block();
38
+ return typeof _block.attrs.generic === 'string' ? _block.attrs.generic : undefined;
39
+ });
40
+ const genericOffset = (0, computeds_1.computed)(() => {
41
+ const _generic = generic();
42
+ return _generic !== undefined ? untrackedSnapshot().getText(0, base.startTagEnd).lastIndexOf(_generic) - base.startTagEnd : -1;
43
+ });
44
+ const ast = (0, computeds_1.computed)(() => ts.createSourceFile(fileName + '.' + base.lang, base.content, ts.ScriptTarget.Latest));
45
+ return mergeObject(base, {
46
+ get generic() { return generic(); },
47
+ get genericOffset() { return genericOffset(); },
48
+ get ast() { return ast(); },
49
+ });
50
+ });
51
+ const styles = (0, computeds_1.computedArray)((0, computeds_1.computed)(() => parsed()?.descriptor.styles ?? []), (block, i) => {
52
+ const base = computedSfcBlock('style_' + i, 'css', block);
53
+ const module = (0, computeds_1.computed)(() => typeof block().module === 'string' ? block().module : block().module ? '$style' : undefined);
54
+ const scoped = (0, computeds_1.computed)(() => !!block().scoped);
55
+ const cssVars = (0, computeds_1.computed)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)]);
56
+ const classNames = (0, computeds_1.computed)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)]);
57
+ return (0, computeds_1.computed)(() => mergeObject(base, {
58
+ get module() { return module(); },
59
+ get scoped() { return scoped(); },
60
+ get cssVars() { return cssVars(); },
61
+ get classNames() { return classNames(); },
62
+ }));
63
+ });
64
+ const customBlocks = (0, computeds_1.computedArray)((0, computeds_1.computed)(() => parsed()?.descriptor.customBlocks ?? []), (block, i) => {
65
+ const base = computedSfcBlock('customBlock_' + i, 'txt', block);
66
+ const type = (0, computeds_1.computed)(() => block().type);
67
+ return (0, computeds_1.computed)(() => mergeObject(base, {
68
+ get type() { return type(); },
69
+ }));
70
+ });
71
+ return {
72
+ get template() { return template(); },
73
+ get script() { return script(); },
74
+ get scriptSetup() { return scriptSetup(); },
75
+ get styles() { return styles; },
76
+ get customBlocks() { return customBlocks; },
77
+ get templateAst() { return template()?.ast; },
78
+ get scriptAst() { return script()?.ast; },
79
+ get scriptSetupAst() { return scriptSetup()?.ast; },
80
+ };
81
+ function computedTemplateAst(base) {
82
+ let cache;
83
+ return (0, computeds_1.computed)(() => {
84
+ if (cache?.template === base.content) {
85
+ return {
86
+ errors: [],
87
+ warnings: [],
88
+ ast: cache?.result.ast,
89
+ };
90
+ }
91
+ // incremental update
92
+ if (cache?.plugin.updateSFCTemplate) {
93
+ const change = untrackedSnapshot().getChangeRange(cache.snapshot);
94
+ if (change) {
95
+ (0, computeds_1.pauseTracking)();
96
+ const templateOffset = base.startTagEnd;
97
+ (0, computeds_1.resetTracking)();
98
+ const newText = untrackedSnapshot().getText(change.span.start, change.span.start + change.newLength);
99
+ const newResult = cache.plugin.updateSFCTemplate(cache.result, {
100
+ start: change.span.start - templateOffset,
101
+ end: change.span.start + change.span.length - templateOffset,
102
+ newText,
103
+ });
104
+ if (newResult) {
105
+ cache.template = base.content;
106
+ cache.snapshot = untrackedSnapshot();
107
+ cache.result = newResult;
108
+ return {
109
+ errors: [],
110
+ warnings: [],
111
+ ast: newResult.ast,
112
+ };
113
+ }
114
+ }
115
+ }
116
+ const errors = [];
117
+ const warnings = [];
118
+ let options = {
119
+ onError: (err) => errors.push(err),
120
+ onWarn: (err) => warnings.push(err),
121
+ expressionPlugins: ['typescript'],
122
+ };
123
+ for (const plugin of plugins) {
124
+ if (plugin.resolveTemplateCompilerOptions) {
125
+ options = plugin.resolveTemplateCompilerOptions(options);
126
+ }
127
+ }
128
+ for (const plugin of plugins) {
129
+ let result;
130
+ try {
131
+ result = plugin.compileSFCTemplate?.(base.lang, base.content, options);
132
+ }
133
+ catch (e) {
134
+ const err = e;
135
+ errors.push(err);
136
+ }
137
+ if (result || errors.length) {
138
+ if (result && !errors.length && !warnings.length) {
139
+ cache = {
140
+ template: base.content,
141
+ snapshot: untrackedSnapshot(),
142
+ result: result,
143
+ plugin,
144
+ };
145
+ }
146
+ else {
147
+ cache = undefined;
148
+ }
149
+ return {
150
+ errors,
151
+ warnings,
152
+ ast: result?.ast,
153
+ };
154
+ }
155
+ }
156
+ return {
157
+ errors,
158
+ warnings,
159
+ ast: undefined,
160
+ };
161
+ });
162
+ }
163
+ function computedNullableSfcBlock(name, defaultLang, block, resolve) {
164
+ const hasBlock = (0, computeds_1.computed)(() => !!block());
165
+ return (0, computeds_1.computed)(() => {
166
+ if (!hasBlock()) {
167
+ return;
168
+ }
169
+ const _block = (0, computeds_1.computed)(() => block());
170
+ return resolve(_block, computedSfcBlock(name, defaultLang, _block));
171
+ });
172
+ }
173
+ function computedSfcBlock(name, defaultLang, block) {
174
+ const lang = (0, computeds_1.computed)(() => block().lang ?? defaultLang);
175
+ const attrs = (0, computeds_1.computed)(() => block().attrs); // TODO: computed it
176
+ const content = (0, computeds_1.computed)(() => block().content);
177
+ const startTagEnd = (0, computeds_1.computed)(() => block().loc.start.offset);
178
+ const endTagStart = (0, computeds_1.computed)(() => block().loc.end.offset);
179
+ const start = (0, computeds_1.computed)(() => untrackedSnapshot().getText(0, startTagEnd()).lastIndexOf('<' + block().type));
180
+ const end = (0, computeds_1.computed)(() => endTagStart() + untrackedSnapshot().getText(endTagStart(), untrackedSnapshot().getLength()).indexOf('>') + 1);
181
+ return {
182
+ name,
183
+ get lang() { return lang(); },
184
+ get attrs() { return attrs(); },
185
+ get content() { return content(); },
186
+ get startTagEnd() { return startTagEnd(); },
187
+ get endTagStart() { return endTagStart(); },
188
+ get start() { return start(); },
189
+ get end() { return end(); },
190
+ };
191
+ }
192
+ }
193
+ exports.computedSfc = computedSfc;
194
+ function mergeObject(a, b) {
195
+ return Object.defineProperties(a, Object.getOwnPropertyDescriptors(b));
196
+ }
197
+ //# sourceMappingURL=computedSfc.js.map
@@ -0,0 +1,5 @@
1
+ import type { SFCParseResult } from '@vue/compiler-sfc';
2
+ import type * as ts from 'typescript/lib/tsserverlibrary';
3
+ import { VueLanguagePlugin } from '../types';
4
+ export declare function computedVueSfc(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, snapshot: () => ts.IScriptSnapshot): () => SFCParseResult | undefined;
5
+ //# sourceMappingURL=computedVueSfc.d.ts.map
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computedVueSfc = void 0;
4
+ const computeds_1 = require("computeds");
5
+ function computedVueSfc(plugins, fileName, snapshot) {
6
+ let cache;
7
+ return (0, computeds_1.computed)(() => {
8
+ // incremental update
9
+ if (cache?.plugin.updateSFC) {
10
+ const change = snapshot().getChangeRange(cache.snapshot);
11
+ if (change) {
12
+ const newSfc = cache.plugin.updateSFC(cache.sfc, {
13
+ start: change.span.start,
14
+ end: change.span.start + change.span.length,
15
+ newText: snapshot().getText(change.span.start, change.span.start + change.newLength),
16
+ });
17
+ if (newSfc) {
18
+ cache.snapshot = snapshot();
19
+ // force dirty
20
+ cache.sfc = JSON.parse(JSON.stringify(newSfc));
21
+ return cache.sfc;
22
+ }
23
+ }
24
+ }
25
+ for (const plugin of plugins) {
26
+ const sfc = plugin.parseSFC?.(fileName, snapshot().getText(0, snapshot().getLength()));
27
+ if (sfc) {
28
+ if (!sfc.errors.length) {
29
+ cache = {
30
+ snapshot: snapshot(),
31
+ sfc,
32
+ plugin,
33
+ };
34
+ }
35
+ return sfc;
36
+ }
37
+ }
38
+ });
39
+ }
40
+ exports.computedVueSfc = computedVueSfc;
41
+ //# sourceMappingURL=computedVueSfc.js.map
@@ -0,0 +1,13 @@
1
+ import { FileCapabilities, FileKind, FileRangeCapabilities, MirrorBehaviorCapabilities } from '@volar/language-core';
2
+ import { Mapping, Segment, StackNode } from '@volar/source-map';
3
+ export declare class VueEmbeddedFile {
4
+ fileName: string;
5
+ content: Segment<FileRangeCapabilities>[];
6
+ contentStacks: StackNode[];
7
+ parentFileName?: string;
8
+ kind: FileKind;
9
+ capabilities: FileCapabilities;
10
+ mirrorBehaviorMappings: Mapping<[MirrorBehaviorCapabilities, MirrorBehaviorCapabilities]>[];
11
+ constructor(fileName: string, content: Segment<FileRangeCapabilities>[], contentStacks: StackNode[]);
12
+ }
13
+ //# sourceMappingURL=embeddedFile.d.ts.map
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VueEmbeddedFile = void 0;
4
+ const language_core_1 = require("@volar/language-core");
5
+ class VueEmbeddedFile {
6
+ constructor(fileName, content, contentStacks) {
7
+ this.fileName = fileName;
8
+ this.content = content;
9
+ this.contentStacks = contentStacks;
10
+ this.kind = language_core_1.FileKind.TextFile;
11
+ this.capabilities = {};
12
+ this.mirrorBehaviorMappings = [];
13
+ }
14
+ }
15
+ exports.VueEmbeddedFile = VueEmbeddedFile;
16
+ //# sourceMappingURL=embeddedFile.js.map
@@ -0,0 +1,28 @@
1
+ import { FileCapabilities, FileKind, VirtualFile } from '@volar/language-core';
2
+ import { Stack } from '@volar/source-map';
3
+ import type * as ts from 'typescript/lib/tsserverlibrary';
4
+ import { VueCompilerOptions, VueLanguagePlugin } from '../types';
5
+ import { Signal } from 'computeds';
6
+ export declare class VueFile implements VirtualFile {
7
+ fileName: string;
8
+ initSnapshot: ts.IScriptSnapshot;
9
+ vueCompilerOptions: VueCompilerOptions;
10
+ plugins: ReturnType<VueLanguagePlugin>[];
11
+ ts: typeof import('typescript/lib/tsserverlibrary');
12
+ codegenStack: boolean;
13
+ _snapshot: Signal<ts.IScriptSnapshot>;
14
+ getVueSfc: () => import("@vue/compiler-sfc").SFCParseResult | undefined;
15
+ sfc: import("../types").Sfc;
16
+ getMappings: () => import("@volar/source-map").Mapping<import("@volar/language-core").FileRangeCapabilities>[];
17
+ getEmbeddedFiles: () => VirtualFile[];
18
+ capabilities: FileCapabilities;
19
+ kind: FileKind;
20
+ codegenStacks: Stack[];
21
+ get embeddedFiles(): VirtualFile[];
22
+ get mainScriptName(): string;
23
+ get snapshot(): ts.IScriptSnapshot;
24
+ get mappings(): import("@volar/source-map").Mapping<import("@volar/language-core").FileRangeCapabilities>[];
25
+ constructor(fileName: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: ReturnType<VueLanguagePlugin>[], ts: typeof import('typescript/lib/tsserverlibrary'), codegenStack: boolean);
26
+ update(newSnapshot: ts.IScriptSnapshot): void;
27
+ }
28
+ //# sourceMappingURL=vueFile.d.ts.map
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VueFile = void 0;
4
+ const language_core_1 = require("@volar/language-core");
5
+ const computedFiles_1 = require("./computedFiles");
6
+ const computedMappings_1 = require("./computedMappings");
7
+ const computedSfc_1 = require("./computedSfc");
8
+ const computedVueSfc_1 = require("./computedVueSfc");
9
+ const computeds_1 = require("computeds");
10
+ const jsxReg = /^\.(js|ts)x?$/;
11
+ class VueFile {
12
+ get embeddedFiles() {
13
+ return this.getEmbeddedFiles();
14
+ }
15
+ get mainScriptName() {
16
+ let res = '';
17
+ (0, language_core_1.forEachEmbeddedFile)(this, file => {
18
+ if (file.kind === language_core_1.FileKind.TypeScriptHostFile && file.fileName.replace(this.fileName, '').match(jsxReg)) {
19
+ res = file.fileName;
20
+ }
21
+ });
22
+ return res;
23
+ }
24
+ get snapshot() {
25
+ return this._snapshot();
26
+ }
27
+ get mappings() {
28
+ return this.getMappings();
29
+ }
30
+ constructor(fileName, initSnapshot, vueCompilerOptions, plugins, ts, codegenStack) {
31
+ this.fileName = fileName;
32
+ this.initSnapshot = initSnapshot;
33
+ this.vueCompilerOptions = vueCompilerOptions;
34
+ this.plugins = plugins;
35
+ this.ts = ts;
36
+ this.codegenStack = codegenStack;
37
+ // computeds
38
+ this.getVueSfc = (0, computedVueSfc_1.computedVueSfc)(this.plugins, this.fileName, () => this._snapshot());
39
+ this.sfc = (0, computedSfc_1.computedSfc)(this.ts, this.plugins, this.fileName, () => this._snapshot(), this.getVueSfc);
40
+ this.getMappings = (0, computedMappings_1.computedMappings)(() => this._snapshot(), this.sfc);
41
+ this.getEmbeddedFiles = (0, computedFiles_1.computedFiles)(this.plugins, this.fileName, this.sfc, this.codegenStack);
42
+ // others
43
+ this.capabilities = language_core_1.FileCapabilities.full;
44
+ this.kind = language_core_1.FileKind.TextFile;
45
+ this.codegenStacks = [];
46
+ this._snapshot = (0, computeds_1.signal)(initSnapshot);
47
+ }
48
+ update(newSnapshot) {
49
+ this._snapshot.set(newSnapshot);
50
+ }
51
+ }
52
+ exports.VueFile = VueFile;
53
+ //# sourceMappingURL=vueFile.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "1.8.19",
3
+ "version": "1.8.21",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -10,14 +10,14 @@
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/vuejs/language-tools.git",
13
- "directory": "packages/vue-language-core"
13
+ "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "~1.10.4",
17
- "@volar/source-map": "~1.10.4",
16
+ "@volar/language-core": "~1.10.5",
17
+ "@volar/source-map": "~1.10.5",
18
18
  "@vue/compiler-dom": "^3.3.0",
19
- "@vue/reactivity": "^3.3.0",
20
19
  "@vue/shared": "^3.3.0",
20
+ "computeds": "^0.0.1",
21
21
  "minimatch": "^9.0.3",
22
22
  "muggle-string": "^0.3.1",
23
23
  "vue-template-compiler": "^2.7.14"
@@ -34,5 +34,5 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "gitHead": "2e17f3c9cfa827c71e1ed07331730b3ee2596b76"
37
+ "gitHead": "46ae2ff1c155e51291fd584c0c3a32ed3dace7a5"
38
38
  }
@@ -1,79 +0,0 @@
1
- import { FileCapabilities, VirtualFile, FileKind, FileRangeCapabilities, MirrorBehaviorCapabilities } from '@volar/language-core';
2
- import { Mapping, Segment, StackNode, Stack } from '@volar/source-map';
3
- import type * as CompilerDOM from '@vue/compiler-dom';
4
- import type { SFCBlock, SFCParseResult, SFCScriptBlock, SFCStyleBlock, SFCTemplateBlock } from '@vue/compiler-sfc';
5
- import { ComputedRef } from '@vue/reactivity';
6
- import type * as ts from 'typescript/lib/tsserverlibrary';
7
- import { Sfc, SfcBlock, VueLanguagePlugin } from './types';
8
- import { VueCompilerOptions } from './types';
9
- export declare class VueEmbeddedFile {
10
- fileName: string;
11
- content: Segment<FileRangeCapabilities>[];
12
- contentStacks: StackNode[];
13
- parentFileName?: string;
14
- kind: FileKind;
15
- capabilities: FileCapabilities;
16
- mirrorBehaviorMappings: Mapping<[MirrorBehaviorCapabilities, MirrorBehaviorCapabilities]>[];
17
- constructor(fileName: string, content: Segment<FileRangeCapabilities>[], contentStacks: StackNode[]);
18
- }
19
- export declare class VueFile implements VirtualFile {
20
- fileName: string;
21
- snapshot: ts.IScriptSnapshot;
22
- vueCompilerOptions: VueCompilerOptions;
23
- plugins: ReturnType<VueLanguagePlugin>[];
24
- ts: typeof import('typescript/lib/tsserverlibrary');
25
- codegenStack: boolean;
26
- parsedSfcCache: {
27
- snapshot: ts.IScriptSnapshot;
28
- sfc: SFCParseResult;
29
- plugin: ReturnType<VueLanguagePlugin>;
30
- } | undefined;
31
- compiledSFCTemplateCache: {
32
- template: string;
33
- snapshot: ts.IScriptSnapshot;
34
- result: CompilerDOM.CodegenResult;
35
- plugin: ReturnType<VueLanguagePlugin>;
36
- } | undefined;
37
- capabilities: FileCapabilities;
38
- kind: FileKind;
39
- mappings: Mapping<FileRangeCapabilities>[];
40
- codegenStacks: Stack[];
41
- get compiledSFCTemplate(): {
42
- errors: CompilerDOM.CompilerError[];
43
- warnings: CompilerDOM.CompilerError[];
44
- ast: CompilerDOM.RootNode | undefined;
45
- } | undefined;
46
- get mainScriptName(): string;
47
- get embeddedFiles(): VirtualFile[];
48
- sfc: Sfc;
49
- _sfcBlocks: ComputedRef<Record<string, SfcBlock>>;
50
- _compiledSfcTemplate: ComputedRef<{
51
- errors: CompilerDOM.CompilerError[];
52
- warnings: CompilerDOM.CompilerError[];
53
- ast: CompilerDOM.RootNode | undefined;
54
- } | undefined>;
55
- _pluginEmbeddedFiles: ComputedRef<{
56
- file: VueEmbeddedFile;
57
- snapshot: ts.IScriptSnapshot;
58
- mappings: Mapping<FileRangeCapabilities>[];
59
- codegenStacks: Stack[];
60
- }[]>[];
61
- _allEmbeddedFiles: ComputedRef<{
62
- file: VueEmbeddedFile;
63
- snapshot: ts.IScriptSnapshot;
64
- mappings: Mapping<FileRangeCapabilities>[];
65
- codegenStacks: Stack[];
66
- }[]>;
67
- _embeddedFiles: ComputedRef<VirtualFile[]>;
68
- constructor(fileName: string, snapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: ReturnType<VueLanguagePlugin>[], ts: typeof import('typescript/lib/tsserverlibrary'), codegenStack: boolean);
69
- update(newScriptSnapshot: ts.IScriptSnapshot): void;
70
- onUpdate(): void;
71
- parseSfc(): SFCParseResult | undefined;
72
- parseTemplateBlock(block: SFCTemplateBlock): NonNullable<Sfc['template']>;
73
- parseScriptBlock(block: SFCScriptBlock): NonNullable<Sfc['script']>;
74
- parseScriptSetupBlock(block: SFCScriptBlock): NonNullable<Sfc['scriptSetup']>;
75
- parseStyleBlock(block: SFCStyleBlock, i: number): Sfc['styles'][number];
76
- parseCustomBlock(block: SFCBlock, i: number): Sfc['customBlocks'][number];
77
- parseBlock(block: SFCBlock): Omit<SfcBlock, 'name' | 'lang'>;
78
- }
79
- //# sourceMappingURL=sourceFile.d.ts.map