@vue/language-core 3.0.0-beta.3 → 3.0.0-beta.5

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.
Files changed (45) hide show
  1. package/lib/codegen/globalTypes.js +14 -10
  2. package/lib/codegen/localTypes.js +23 -8
  3. package/lib/codegen/script/component.js +2 -1
  4. package/lib/codegen/script/index.js +14 -1
  5. package/lib/codegen/script/scriptSetup.js +41 -21
  6. package/lib/codegen/template/context.d.ts +2 -1
  7. package/lib/codegen/template/context.js +3 -1
  8. package/lib/codegen/template/element.js +10 -6
  9. package/lib/codegen/template/elementEvents.js +1 -1
  10. package/lib/codegen/template/elementProps.js +6 -2
  11. package/lib/codegen/template/index.js +5 -3
  12. package/lib/codegen/template/interpolation.js +9 -12
  13. package/lib/codegen/template/slotOutlet.js +2 -1
  14. package/lib/codegen/template/styleScopedClasses.js +2 -2
  15. package/lib/codegen/template/templateChild.js +2 -1
  16. package/lib/codegen/template/vFor.js +1 -1
  17. package/lib/codegen/template/vSlot.js +1 -1
  18. package/lib/codegen/utils/escaped.d.ts +1 -1
  19. package/lib/codegen/utils/index.d.ts +1 -1
  20. package/lib/codegen/utils/index.js +1 -2
  21. package/lib/codegen/utils/wrapWith.d.ts +1 -1
  22. package/lib/languagePlugin.js +13 -4
  23. package/lib/parsers/scriptRanges.d.ts +1 -0
  24. package/lib/parsers/scriptRanges.js +7 -0
  25. package/lib/parsers/scriptSetupRanges.js +4 -8
  26. package/lib/parsers/vueCompilerOptions.js +0 -1
  27. package/lib/plugins/file-html.js +3 -3
  28. package/lib/plugins/file-md.js +2 -1
  29. package/lib/plugins/file-vue.js +3 -4
  30. package/lib/plugins/vue-sfc-scripts.js +4 -2
  31. package/lib/plugins/vue-template-html.js +3 -4
  32. package/lib/plugins/vue-template-inline-ts.js +3 -1
  33. package/lib/plugins/vue-tsx.d.ts +2 -0
  34. package/lib/plugins/vue-tsx.js +2 -1
  35. package/lib/types.d.ts +1 -1
  36. package/lib/utils/parseCssImports.js +1 -1
  37. package/lib/utils/shared.d.ts +1 -0
  38. package/lib/utils/shared.js +4 -0
  39. package/lib/utils/ts.js +3 -1
  40. package/lib/utils/vue2TemplateCompiler.d.ts +2 -0
  41. package/lib/utils/vue2TemplateCompiler.js +90 -0
  42. package/lib/virtualFile/computedEmbeddedCodes.js +22 -11
  43. package/lib/virtualFile/computedSfc.d.ts +2 -0
  44. package/lib/virtualFile/computedSfc.js +94 -32
  45. package/package.json +5 -4
@@ -5,6 +5,7 @@ const shared_1 = require("../utils/shared");
5
5
  const scriptSetupRanges_1 = require("./scriptSetupRanges");
6
6
  function parseScriptRanges(ts, ast, hasScriptSetup) {
7
7
  let exportDefault;
8
+ let classBlockEnd;
8
9
  const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
9
10
  ts.forEachChild(ast, raw => {
10
11
  if (ts.isExportAssignment(raw)) {
@@ -57,9 +58,15 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
57
58
  };
58
59
  }
59
60
  }
61
+ if (ts.isClassDeclaration(raw)
62
+ && raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
63
+ && raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)) {
64
+ classBlockEnd = raw.end - 1;
65
+ }
60
66
  });
61
67
  return {
62
68
  exportDefault,
69
+ classBlockEnd,
63
70
  bindings,
64
71
  };
65
72
  function _getStartEnd(node) {
@@ -343,8 +343,7 @@ function findBindingVars(ts, left, ast) {
343
343
  function worker(node) {
344
344
  if (ts.isIdentifier(node)) {
345
345
  vars.push((0, shared_1.getStartEnd)(ts, node, ast));
346
- }
347
- // { ? } = ...
346
+ } // { ? } = ...
348
347
  // [ ? ] = ...
349
348
  else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
350
349
  for (const property of node.elements) {
@@ -352,16 +351,13 @@ function findBindingVars(ts, left, ast) {
352
351
  worker(property.name);
353
352
  }
354
353
  }
355
- }
356
- // { foo: ? } = ...
354
+ } // { foo: ? } = ...
357
355
  else if (ts.isPropertyAssignment(node)) {
358
356
  worker(node.initializer);
359
- }
360
- // { foo } = ...
357
+ } // { foo } = ...
361
358
  else if (ts.isShorthandPropertyAssignment(node)) {
362
359
  vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
363
- }
364
- // { ...? } = ...
360
+ } // { ...? } = ...
365
361
  // [ ...? ] = ...
366
362
  else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
367
363
  worker(node.expression);
@@ -13,7 +13,6 @@ function parseVueCompilerOptions(comments) {
13
13
  }
14
14
  }
15
15
  catch { }
16
- ;
17
16
  })
18
17
  .filter(item => !!item);
19
18
  if (entries.length) {
@@ -53,8 +53,7 @@ const plugin = ({ vueCompilerOptions }) => {
53
53
  type: 'style',
54
54
  lang,
55
55
  });
56
- }
57
- // ignore `<script src="...">`
56
+ } // ignore `<script src="...">`
58
57
  else if (tag === 'script' && !attrs.includes('src=')) {
59
58
  let type = attrs.includes('type=') ? 'scriptSetup' : 'script';
60
59
  sfc.descriptor[type] = {
@@ -69,7 +68,8 @@ const plugin = ({ vueCompilerOptions }) => {
69
68
  lang,
70
69
  };
71
70
  }
72
- templateContent = templateContent.slice(0, match.index) + ' '.repeat(matchText.length) + templateContent.slice(match.index + matchText.length);
71
+ templateContent = templateContent.slice(0, match.index) + ' '.repeat(matchText.length)
72
+ + templateContent.slice(match.index + matchText.length);
73
73
  }
74
74
  sfc.descriptor.template = {
75
75
  attrs: {},
@@ -47,7 +47,8 @@ const plugin = ({ vueCompilerOptions }) => {
47
47
  const matchText = match[0];
48
48
  codes.push([matchText, undefined, match.index]);
49
49
  codes.push('\n\n');
50
- content = content.slice(0, match.index) + ' '.repeat(matchText.length) + content.slice(match.index + matchText.length);
50
+ content = content.slice(0, match.index) + ' '.repeat(matchText.length)
51
+ + content.slice(match.index + matchText.length);
51
52
  }
52
53
  }
53
54
  content = content
@@ -31,10 +31,9 @@ const plugin = ({ vueCompilerOptions }) => {
31
31
  return;
32
32
  }
33
33
  const oldContent = hitBlock.content;
34
- const newContent = hitBlock.content =
35
- hitBlock.content.slice(0, change.start - hitBlock.loc.start.offset)
36
- + change.newText
37
- + hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
34
+ const newContent = hitBlock.content = hitBlock.content.slice(0, change.start - hitBlock.loc.start.offset)
35
+ + change.newText
36
+ + hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
38
37
  // #3449
39
38
  const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
40
39
  const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
@@ -14,8 +14,10 @@ const plugin = () => {
14
14
  return names;
15
15
  },
16
16
  resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
17
- const script = embeddedFile.id === 'script_raw' ? sfc.script
18
- : embeddedFile.id === 'scriptsetup_raw' ? sfc.scriptSetup
17
+ const script = embeddedFile.id === 'script_raw'
18
+ ? sfc.script
19
+ : embeddedFile.id === 'scriptsetup_raw'
20
+ ? sfc.scriptSetup
19
21
  : undefined;
20
22
  if (script) {
21
23
  embeddedFile.content.push([
@@ -171,10 +171,9 @@ const plugin = ({ modules }) => {
171
171
  function tryUpdateNodeLoc(loc) {
172
172
  delete loc.__endOffset;
173
173
  if (withinChangeRange(loc)) {
174
- loc.source =
175
- loc.source.slice(0, change.start - loc.start.offset)
176
- + change.newText
177
- + loc.source.slice(change.end - loc.start.offset);
174
+ loc.source = loc.source.slice(0, change.start - loc.start.offset)
175
+ + change.newText
176
+ + loc.source.slice(change.end - loc.start.offset);
178
177
  loc.__endOffset = loc.end.offset;
179
178
  loc.end.offset += lengthDiff;
180
179
  return true;
@@ -5,6 +5,7 @@ const elementEvents_1 = require("../codegen/template/elementEvents");
5
5
  const templateChild_1 = require("../codegen/template/templateChild");
6
6
  const vFor_1 = require("../codegen/template/vFor");
7
7
  const utils_1 = require("../codegen/utils");
8
+ const computedSfc_1 = require("../virtualFile/computedSfc");
8
9
  const codeFeatures = {
9
10
  format: true,
10
11
  };
@@ -58,6 +59,7 @@ const plugin = ctx => {
58
59
  return data;
59
60
  }
60
61
  const templateContent = sfc.template.content;
62
+ const inlineTsAsts = sfc.template.ast && computedSfc_1.templateInlineTsAsts.get(sfc.template.ast);
61
63
  let i = 0;
62
64
  sfc.template.ast.children.forEach(visit);
63
65
  return data;
@@ -85,7 +87,7 @@ const plugin = ctx => {
85
87
  && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
86
88
  ) {
87
89
  if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
88
- const ast = (0, utils_1.createTsAst)(ctx.modules.typescript, sfc.template.ast, prop.exp.content);
90
+ const ast = (0, utils_1.createTsAst)(ctx.modules.typescript, inlineTsAsts, prop.exp.content);
89
91
  if ((0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)) {
90
92
  addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.event);
91
93
  }
@@ -11,6 +11,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
11
11
  nameOption: import("../types").TextRange | undefined;
12
12
  inheritAttrsOption: string | undefined;
13
13
  }) | undefined;
14
+ classBlockEnd: number | undefined;
14
15
  bindings: {
15
16
  range: import("../types").TextRange;
16
17
  moduleName?: string;
@@ -167,6 +168,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
167
168
  withoutSemantic: import("../types").VueCodeInformation;
168
169
  };
169
170
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
171
+ inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
170
172
  inVFor: boolean;
171
173
  slots: {
172
174
  name: string;
@@ -129,7 +129,8 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
129
129
  const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
130
130
  const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
131
131
  const getSetupInheritAttrs = (0, alien_signals_1.computed)(() => {
132
- const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs ?? getScriptRanges()?.exportDefault?.inheritAttrsOption;
132
+ const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs
133
+ ?? getScriptRanges()?.exportDefault?.inheritAttrsOption;
133
134
  return value !== 'false';
134
135
  });
135
136
  const getComponentSelfName = (0, alien_signals_1.computed)(() => {
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' | 'plugins'>> & {
10
10
  strictTemplates?: boolean;
11
- target?: 'auto' | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
11
+ target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
12
12
  plugins?: string[];
13
13
  };
14
14
  export interface VueCodeInformation extends CodeInformation {
@@ -7,7 +7,7 @@ function* parseCssImports(css) {
7
7
  for (const match of matches) {
8
8
  let text = match[0];
9
9
  let offset = match.index;
10
- if (text.startsWith('\'') || text.startsWith('"')) {
10
+ if (text.startsWith("'") || text.startsWith('"')) {
11
11
  text = text.slice(1, -1);
12
12
  offset += 1;
13
13
  }
@@ -2,5 +2,6 @@ import type * as ts from 'typescript';
2
2
  import type { TextRange } from '../types';
3
3
  export { hyphenate as hyphenateTag } from '@vue/shared';
4
4
  export declare function hyphenateAttr(str: string): string;
5
+ export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
5
6
  export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
6
7
  export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hyphenateTag = void 0;
4
4
  exports.hyphenateAttr = hyphenateAttr;
5
+ exports.getSlotsPropertyName = getSlotsPropertyName;
5
6
  exports.getStartEnd = getStartEnd;
6
7
  exports.getNodeText = getNodeText;
7
8
  const shared_1 = require("@vue/shared");
@@ -15,6 +16,9 @@ function hyphenateAttr(str) {
15
16
  }
16
17
  return hyphencase;
17
18
  }
19
+ function getSlotsPropertyName(vueVersion) {
20
+ return vueVersion < 3 ? '$scopedSlots' : '$slots';
21
+ }
18
22
  function getStartEnd(ts, node, ast) {
19
23
  return {
20
24
  start: ts.getTokenPosOfNode(node, ast),
package/lib/utils/ts.js CHANGED
@@ -242,7 +242,9 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
242
242
  ],
243
243
  dataAttributes: [],
244
244
  htmlAttributes: ['aria-*'],
245
- optionsWrapper: [`(await import('${lib}')).defineComponent(`, `)`],
245
+ optionsWrapper: target >= 2.7
246
+ ? [`(await import('${lib}')).defineComponent(`, `)`]
247
+ : [`(await import('${lib}')).default.extend(`, `)`],
246
248
  macros: {
247
249
  defineProps: ['defineProps'],
248
250
  defineSlots: ['defineSlots'],
@@ -0,0 +1,2 @@
1
+ import * as CompilerDOM from '@vue/compiler-dom';
2
+ export declare const compile: typeof CompilerDOM.compile;
@@ -0,0 +1,90 @@
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/compiler-vue2/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 => {
61
+ throw error;
62
+ });
63
+ const isModuleMode = options.mode === 'module';
64
+ const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
65
+ if (!prefixIdentifiers && options.cacheHandlers) {
66
+ onError(CompilerDOM.createCompilerError(49));
67
+ }
68
+ if (options.scopeId && !isModuleMode) {
69
+ onError(CompilerDOM.createCompilerError(50));
70
+ }
71
+ const ast = CompilerDOM.baseParse(template, options);
72
+ const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset(prefixIdentifiers);
73
+ // v-for > v-if in vue 2
74
+ const transformIf = nodeTransforms[1];
75
+ const transformFor = nodeTransforms[3];
76
+ nodeTransforms[1] = transformFor;
77
+ nodeTransforms[3] = transformIf;
78
+ CompilerDOM.transform(ast, Object.assign({}, options, {
79
+ prefixIdentifiers,
80
+ nodeTransforms: [
81
+ ...nodeTransforms,
82
+ ...(options.nodeTransforms || []), // user transforms
83
+ ],
84
+ directiveTransforms: Object.assign({}, directiveTransforms, options.directiveTransforms || {}),
85
+ }));
86
+ return CompilerDOM.generate(ast, Object.assign({}, options, {
87
+ prefixIdentifiers,
88
+ }));
89
+ }
90
+ //# sourceMappingURL=vue2TemplateCompiler.js.map
@@ -177,7 +177,8 @@ function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, getBlockByN
177
177
  if (mapping.data.__combineOffset !== undefined) {
178
178
  const offsetMapping = mappings[i - mapping.data.__combineOffset];
179
179
  if (typeof offsetMapping === 'string' || !offsetMapping) {
180
- throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: ' + mapping.data.__combineOffset);
180
+ throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: '
181
+ + mapping.data.__combineOffset);
181
182
  }
182
183
  offsetMapping.sourceOffsets.push(...mapping.sourceOffsets);
183
184
  offsetMapping.generatedOffsets.push(...mapping.generatedOffsets);
@@ -235,16 +236,26 @@ function fullDiffTextChangeRange(oldText, newText) {
235
236
  }
236
237
  function resolveCommonLanguageId(lang) {
237
238
  switch (lang) {
238
- case 'js': return 'javascript';
239
- case 'cjs': return 'javascript';
240
- case 'mjs': return 'javascript';
241
- case 'ts': return 'typescript';
242
- case 'cts': return 'typescript';
243
- case 'mts': return 'typescript';
244
- case 'jsx': return 'javascriptreact';
245
- case 'tsx': return 'typescriptreact';
246
- case 'pug': return 'jade';
247
- case 'md': return 'markdown';
239
+ case 'js':
240
+ return 'javascript';
241
+ case 'cjs':
242
+ return 'javascript';
243
+ case 'mjs':
244
+ return 'javascript';
245
+ case 'ts':
246
+ return 'typescript';
247
+ case 'cts':
248
+ return 'typescript';
249
+ case 'mts':
250
+ return 'typescript';
251
+ case 'jsx':
252
+ return 'javascriptreact';
253
+ case 'tsx':
254
+ return 'typescriptreact';
255
+ case 'pug':
256
+ return 'jade';
257
+ case 'md':
258
+ return 'markdown';
248
259
  }
249
260
  return lang;
250
261
  }
@@ -1,4 +1,6 @@
1
+ import type * as CompilerDOM from '@vue/compiler-dom';
1
2
  import type { SFCParseResult } from '@vue/compiler-sfc';
2
3
  import type * as ts from 'typescript';
3
4
  import type { Sfc, VueLanguagePluginReturn } from '../types';
5
+ export declare const templateInlineTsAsts: WeakMap<CompilerDOM.RootNode, Map<string, ts.SourceFile>>;
4
6
  export declare function computedSfc(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, getSnapshot: () => ts.IScriptSnapshot, getParseResult: () => SFCParseResult | undefined): Sfc;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.templateInlineTsAsts = void 0;
3
4
  exports.computedSfc = computedSfc;
4
5
  const alien_signals_1 = require("alien-signals");
5
6
  const parseCssClassNames_1 = require("../utils/parseCssClassNames");
6
7
  const parseCssImports_1 = require("../utils/parseCssImports");
7
8
  const parseCssVars_1 = require("../utils/parseCssVars");
8
9
  const signals_1 = require("../utils/signals");
10
+ exports.templateInlineTsAsts = new WeakMap();
9
11
  function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
10
12
  const getUntrackedSnapshot = () => {
11
13
  const pausedSub = (0, alien_signals_1.setCurrentSub)(undefined);
@@ -27,9 +29,15 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
27
29
  const getTemplate = computedNullableSfcBlock('template', 'html', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.template ?? undefined), (_block, base) => {
28
30
  const compiledAst = computedTemplateAst(base);
29
31
  return mergeObject(base, {
30
- get ast() { return compiledAst()?.ast; },
31
- get errors() { return compiledAst()?.errors; },
32
- get warnings() { return compiledAst()?.warnings; },
32
+ get ast() {
33
+ return compiledAst()?.ast;
34
+ },
35
+ get errors() {
36
+ return compiledAst()?.errors;
37
+ },
38
+ get warnings() {
39
+ return compiledAst()?.warnings;
40
+ },
33
41
  });
34
42
  });
35
43
  const getScript = computedNullableSfcBlock('script', 'js', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.script ?? undefined), (block, base) => {
@@ -44,8 +52,12 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
44
52
  return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
45
53
  });
46
54
  return mergeObject(base, {
47
- get src() { return getSrc(); },
48
- get ast() { return getAst(); },
55
+ get src() {
56
+ return getSrc();
57
+ },
58
+ get ast() {
59
+ return getAst();
60
+ },
49
61
  });
50
62
  });
51
63
  const getOriginalScriptSetup = computedNullableSfcBlock('scriptSetup', 'js', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.scriptSetup ?? undefined), (block, base) => {
@@ -60,15 +72,19 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
60
72
  return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
61
73
  });
62
74
  return mergeObject(base, {
63
- get generic() { return getGeneric(); },
64
- get ast() { return getAst(); },
75
+ get generic() {
76
+ return getGeneric();
77
+ },
78
+ get ast() {
79
+ return getAst();
80
+ },
65
81
  });
66
82
  });
67
83
  const hasScript = (0, alien_signals_1.computed)(() => !!getParseResult()?.descriptor.script);
68
84
  const hasScriptSetup = (0, alien_signals_1.computed)(() => !!getParseResult()?.descriptor.scriptSetup);
69
85
  const getScriptSetup = (0, alien_signals_1.computed)(() => {
70
86
  if (!hasScript() && !hasScriptSetup()) {
71
- //#region monkey fix: https://github.com/vuejs/language-tools/pull/2113
87
+ // #region monkey fix: https://github.com/vuejs/language-tools/pull/2113
72
88
  return {
73
89
  content: '',
74
90
  lang: 'ts',
@@ -94,36 +110,67 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
94
110
  const getCssVars = (0, signals_1.computedItems)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
95
111
  const getClassNames = (0, signals_1.computedItems)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
96
112
  return () => mergeObject(base, {
97
- get src() { return getSrc(); },
98
- get module() { return getModule(); },
99
- get scoped() { return getScoped(); },
100
- get imports() { return getImports(); },
101
- get cssVars() { return getCssVars(); },
102
- get classNames() { return getClassNames(); },
113
+ get src() {
114
+ return getSrc();
115
+ },
116
+ get module() {
117
+ return getModule();
118
+ },
119
+ get scoped() {
120
+ return getScoped();
121
+ },
122
+ get imports() {
123
+ return getImports();
124
+ },
125
+ get cssVars() {
126
+ return getCssVars();
127
+ },
128
+ get classNames() {
129
+ return getClassNames();
130
+ },
103
131
  });
104
132
  });
105
133
  const customBlocks = (0, signals_1.computedArray)((0, alien_signals_1.computed)(() => getParseResult()?.descriptor.customBlocks ?? []), (getBlock, i) => {
106
134
  const base = computedSfcBlock('custom_block_' + i, 'txt', getBlock);
107
135
  const getType = (0, alien_signals_1.computed)(() => getBlock().type);
108
136
  return () => mergeObject(base, {
109
- get type() { return getType(); },
137
+ get type() {
138
+ return getType();
139
+ },
110
140
  });
111
141
  });
112
142
  return {
113
- get content() { return getContent(); },
114
- get comments() { return getComments(); },
115
- get template() { return getTemplate(); },
116
- get script() { return getScript(); },
117
- get scriptSetup() { return getScriptSetup(); },
118
- get styles() { return styles; },
119
- get customBlocks() { return customBlocks; },
143
+ get content() {
144
+ return getContent();
145
+ },
146
+ get comments() {
147
+ return getComments();
148
+ },
149
+ get template() {
150
+ return getTemplate();
151
+ },
152
+ get script() {
153
+ return getScript();
154
+ },
155
+ get scriptSetup() {
156
+ return getScriptSetup();
157
+ },
158
+ get styles() {
159
+ return styles;
160
+ },
161
+ get customBlocks() {
162
+ return customBlocks;
163
+ },
120
164
  };
121
165
  function computedTemplateAst(base) {
122
166
  let cache;
123
167
  let inlineTsAsts;
124
168
  function updateInlineTsAsts(newAst, oldAst) {
125
- const newTsAsts = newAst.__volar_inlineTsAsts ??= new Map();
126
- const oldTsAsts = oldAst?.__volar_inlineTsAsts ?? inlineTsAsts;
169
+ let newTsAsts = exports.templateInlineTsAsts.get(newAst);
170
+ if (!newTsAsts) {
171
+ exports.templateInlineTsAsts.set(newAst, newTsAsts = new Map());
172
+ }
173
+ const oldTsAsts = oldAst && exports.templateInlineTsAsts.get(oldAst) || inlineTsAsts;
127
174
  if (oldTsAsts) {
128
175
  for (const [text, ast] of oldTsAsts) {
129
176
  if (!ast.__volar_used) {
@@ -238,16 +285,31 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
238
285
  const getStartTagEnd = (0, alien_signals_1.computed)(() => getBlock().loc.start.offset);
239
286
  const getEndTagStart = (0, alien_signals_1.computed)(() => getBlock().loc.end.offset);
240
287
  const getStart = (0, alien_signals_1.computed)(() => getUntrackedSnapshot().getText(0, getStartTagEnd()).lastIndexOf('<' + getBlock().type));
241
- const getEnd = (0, alien_signals_1.computed)(() => getEndTagStart() + getUntrackedSnapshot().getText(getEndTagStart(), getUntrackedSnapshot().getLength()).indexOf('>') + 1);
288
+ const getEnd = (0, alien_signals_1.computed)(() => getEndTagStart()
289
+ + getUntrackedSnapshot().getText(getEndTagStart(), getUntrackedSnapshot().getLength()).indexOf('>') + 1);
242
290
  return {
243
291
  name,
244
- get lang() { return getLang(); },
245
- get attrs() { return getAttrs(); },
246
- get content() { return getContent(); },
247
- get startTagEnd() { return getStartTagEnd(); },
248
- get endTagStart() { return getEndTagStart(); },
249
- get start() { return getStart(); },
250
- get end() { return getEnd(); },
292
+ get lang() {
293
+ return getLang();
294
+ },
295
+ get attrs() {
296
+ return getAttrs();
297
+ },
298
+ get content() {
299
+ return getContent();
300
+ },
301
+ get startTagEnd() {
302
+ return getStartTagEnd();
303
+ },
304
+ get endTagStart() {
305
+ return getEndTagStart();
306
+ },
307
+ get start() {
308
+ return getStart();
309
+ },
310
+ get end() {
311
+ return getEnd();
312
+ },
251
313
  };
252
314
  }
253
315
  function computedAttrValue(key, base, getBlock) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.0-beta.3",
3
+ "version": "3.0.0-beta.5",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,8 +13,9 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "2.4.14",
16
+ "@volar/language-core": "2.4.15",
17
17
  "@vue/compiler-dom": "^3.5.0",
18
+ "@vue/compiler-vue2": "^2.7.16",
18
19
  "@vue/shared": "^3.5.0",
19
20
  "alien-signals": "^2.0.5",
20
21
  "minimatch": "^10.0.1",
@@ -24,7 +25,7 @@
24
25
  "devDependencies": {
25
26
  "@types/node": "^22.10.4",
26
27
  "@types/path-browserify": "^1.0.1",
27
- "@volar/typescript": "2.4.14",
28
+ "@volar/typescript": "2.4.15",
28
29
  "@vue/compiler-sfc": "^3.5.0"
29
30
  },
30
31
  "peerDependencies": {
@@ -35,5 +36,5 @@
35
36
  "optional": true
36
37
  }
37
38
  },
38
- "gitHead": "17e3beabc13e9eb59a82fb1a9f0252fd6685e444"
39
+ "gitHead": "3a4648914c60c90444d939cf762a016a4318ca09"
39
40
  }