@vue/language-core 1.8.5 → 1.8.6

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.
@@ -37,6 +37,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
37
37
  emitsTypeArg: undefined,
38
38
  emitsTypeNums: 0,
39
39
  exposeRuntimeArg: undefined,
40
+ leadingCommentEndOffset: 0,
40
41
  importSectionEndOffset: 0,
41
42
  defineProps: undefined,
42
43
  propsAssignName: undefined,
@@ -229,7 +230,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
229
230
  if (!scriptSetupRanges)
230
231
  return;
231
232
  codes.push([
232
- sfc.scriptSetup.content.substring(0, scriptSetupRanges.importSectionEndOffset),
233
+ sfc.scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
233
234
  'scriptSetup',
234
235
  0,
235
236
  language_core_1.FileRangeCapabilities.full,
@@ -585,7 +585,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
585
585
  blockConditions.push(condition);
586
586
  inScope = true;
587
587
  }
588
- generateDirectives(node, var_originalComponent);
588
+ generateDirectives(node);
589
589
  generateElReferences(node); // <el ref="foo" />
590
590
  if (sfc.styles.some(s => s.scoped || vueCompilerOptions.experimentalResolveStyleCssClasses === 'always')) {
591
591
  generateClassScoped(node);
@@ -1019,7 +1019,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
1019
1019
  }
1020
1020
  }
1021
1021
  }
1022
- function generateDirectives(node, componentVar) {
1022
+ function generateDirectives(node) {
1023
1023
  for (const prop of node.props) {
1024
1024
  if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
1025
1025
  && prop.name !== 'slot'
@@ -1052,7 +1052,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
1052
1052
  apply: getRenameApply(prop.name),
1053
1053
  },
1054
1054
  },
1055
- ], ')', '(', ['', 'template', prop.loc.start.offset, capabilitiesPresets.diagnosticOnly], componentVar, vueCompilerOptions.strictTemplates ? '' : ' as any', ['', 'template', prop.loc.start.offset + 'v-'.length + prop.name.length, capabilitiesPresets.diagnosticOnly], ', ');
1055
+ ], ')', '(');
1056
1056
  if (prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
1057
1057
  codes.push(['', 'template', prop.exp.loc.start.offset, capabilitiesPresets.diagnosticOnly], ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, capabilitiesPresets.all, '(', ')'), ['', 'template', prop.exp.loc.end.offset, capabilitiesPresets.diagnosticOnly]);
1058
1058
  formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal));
@@ -10,11 +10,17 @@ function createLanguage(compilerOptions = {}, _vueCompilerOptions = {}, ts = req
10
10
  const vueCompilerOptions = (0, ts_1.resolveVueCompilerOptions)(_vueCompilerOptions);
11
11
  patchResolveModuleNames(ts, vueCompilerOptions);
12
12
  const vueLanguagePlugin = (0, plugins_1.getDefaultVueLanguagePlugins)(ts, compilerOptions, vueCompilerOptions, codegenStack);
13
+ const allowLanguageIds = new Set(['vue']);
14
+ if (vueCompilerOptions.extensions.includes('.md')) {
15
+ allowLanguageIds.add('markdown');
16
+ }
17
+ if (vueCompilerOptions.extensions.includes('.html')) {
18
+ allowLanguageIds.add('html');
19
+ }
13
20
  const languageModule = {
14
21
  createVirtualFile(fileName, snapshot, languageId) {
15
- if (languageId === 'vue'
16
- || (!languageId
17
- && vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext)))) {
22
+ if ((languageId && allowLanguageIds.has(languageId))
23
+ || (!languageId && vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext)))) {
18
24
  return new sourceFile_1.VueFile(fileName, snapshot, vueCompilerOptions, vueLanguagePlugin, ts, codegenStack);
19
25
  }
20
26
  },
@@ -3,6 +3,7 @@ import type { VueCompilerOptions, TextRange } from '../types';
3
3
  export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> {
4
4
  }
5
5
  export declare function parseScriptSetupRanges(ts: typeof import('typescript/lib/tsserverlibrary'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
6
+ leadingCommentEndOffset: number;
6
7
  importSectionEndOffset: number;
7
8
  bindings: TextRange[];
8
9
  withDefaultsArg: TextRange | undefined;
@@ -19,6 +19,8 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
19
19
  const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
20
20
  const defineProp = [];
21
21
  const bindings = parseBindingRanges(ts, ast, false);
22
+ const text = ast.getFullText();
23
+ const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
22
24
  ast.forEachChild(node => {
23
25
  const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
24
26
  if (!foundNonImportExportNode
@@ -27,7 +29,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
27
29
  && !ts.isEmptyStatement(node)
28
30
  // fix https://github.com/vuejs/language-tools/issues/1223
29
31
  && !ts.isImportEqualsDeclaration(node)) {
30
- const commentRanges = ts.getLeadingCommentRanges(ast.getFullText(), node.getFullStart());
32
+ const commentRanges = ts.getLeadingCommentRanges(text, node.getFullStart());
31
33
  if (commentRanges?.length) {
32
34
  const commentRange = commentRanges.sort((a, b) => a.pos - b.pos)[0];
33
35
  importSectionEndOffset = commentRange.pos;
@@ -40,6 +42,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
40
42
  });
41
43
  ast.forEachChild(child => visitNode(child, ast));
42
44
  return {
45
+ leadingCommentEndOffset,
43
46
  importSectionEndOffset,
44
47
  bindings,
45
48
  withDefaultsArg,
@@ -51,7 +51,7 @@ declare function __VLS_getVForSourceType<T>(source: T): [
51
51
  declare function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
52
52
  declare function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
53
53
  declare function __VLS_directiveFunction<T>(dir: T):
54
- T extends import('${vueCompilerOptions.lib}').ObjectDirective<infer E, infer V> | import('${vueCompilerOptions.lib}').FunctionDirective<infer E, infer V> ? (el: E, value: V) => void
54
+ T extends import('${vueCompilerOptions.lib}').ObjectDirective<infer E, infer V> | import('${vueCompilerOptions.lib}').FunctionDirective<infer E, infer V> ? (value: V) => void
55
55
  : T;
56
56
  declare function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
57
57
  declare function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -34,5 +34,5 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "gitHead": "971820b55ea42cb7e8c8ba7c35c8998d5572b420"
37
+ "gitHead": "9da8afee02bc7251ae97716480ba31f8aff2794a"
38
38
  }