@vue/language-core 2.0.18 → 2.0.20

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.
@@ -40,7 +40,7 @@ function* generateScript(options) {
40
40
  const isExportRawObject = exportDefault
41
41
  && options.sfc.script.content[exportDefault.expression.start] === '{';
42
42
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
43
- yield (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
43
+ yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
44
44
  if (exportDefault) {
45
45
  yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
46
46
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
@@ -99,7 +99,7 @@ function* generateScript(options) {
99
99
  }
100
100
  }
101
101
  else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
102
- yield (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
102
+ yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
103
103
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
104
104
  }
105
105
  yield common_1.endOfLine;
@@ -6,7 +6,8 @@ const component_1 = require("./component");
6
6
  const template_1 = require("./template");
7
7
  function* generateInternalComponent(options, ctx, templateCodegenCtx) {
8
8
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
9
- yield `const __VLS_internalComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
9
+ yield `let __VLS_defineComponent!: typeof import('${options.vueCompilerOptions.lib}').defineComponent${common_1.endOfLine}`;
10
+ yield `const __VLS_internalComponent = __VLS_defineComponent({${common_1.newLine}`;
10
11
  yield `setup() {${common_1.newLine}`;
11
12
  yield `return {${common_1.newLine}`;
12
13
  if (ctx.bypassDefineComponent) {
@@ -48,7 +49,7 @@ function* generateInternalComponent(options, ctx, templateCodegenCtx) {
48
49
  yield `})${common_1.endOfLine}`; // defineComponent {
49
50
  }
50
51
  else if (options.sfc.script) {
51
- yield `const __VLS_internalComponent = (await import('./${options.fileBaseName}')).default${common_1.endOfLine}`;
52
+ yield `let __VLS_internalComponent!: typeof import('./${options.fileBaseName}').default${common_1.endOfLine}`;
52
53
  }
53
54
  else {
54
55
  yield `const __VLS_internalComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${common_1.endOfLine}`;
@@ -2,5 +2,5 @@ import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
2
2
  import type { Code, Sfc } from '../../types';
3
3
  import type { ScriptCodegenContext } from './context';
4
4
  import { ScriptCodegenOptions } from './index';
5
- export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Code;
5
+ export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
6
  export declare function generateScriptSetup(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
@@ -5,13 +5,14 @@ const common_1 = require("../common");
5
5
  const component_1 = require("./component");
6
6
  const index_1 = require("./index");
7
7
  const template_1 = require("./template");
8
- function generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
9
- return [
10
- scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + common_1.newLine,
8
+ function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
9
+ yield [
10
+ scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
11
11
  'scriptSetup',
12
12
  0,
13
13
  index_1.codeFeatures.all,
14
14
  ];
15
+ yield common_1.newLine;
15
16
  }
16
17
  exports.generateScriptSetupImports = generateScriptSetupImports;
17
18
  function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
@@ -341,9 +342,9 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
341
342
  yield common_1.endOfLine;
342
343
  }
343
344
  function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
344
- yield `let __VLS_modelEmitsType!: {}`;
345
- if (scriptSetupRanges.defineProp.length) {
346
- yield ` & ReturnType<typeof import('${options.vueCompilerOptions.lib}').defineEmits<{${common_1.newLine}`;
345
+ yield `const __VLS_modelEmitsType = `;
346
+ if (scriptSetupRanges.defineProp.filter(p => p.isModel).length) {
347
+ yield `(await import('${options.vueCompilerOptions.lib}')).defineEmits<{${common_1.newLine}`;
347
348
  for (const defineProp of scriptSetupRanges.defineProp) {
348
349
  if (!defineProp.isModel) {
349
350
  continue;
@@ -362,7 +363,10 @@ function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
362
363
  }
363
364
  yield `]${common_1.endOfLine}`;
364
365
  }
365
- yield `}>>`;
366
+ yield `}>()`;
367
+ }
368
+ else {
369
+ yield `{}`;
366
370
  }
367
371
  yield common_1.endOfLine;
368
372
  }
@@ -85,13 +85,14 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
85
85
  yield common_1.endOfLine;
86
86
  }
87
87
  else if (!isComponentTag) {
88
+ yield `// @ts-ignore${common_1.newLine}`;
88
89
  yield `const ${var_originalComponent} = ({} as `;
89
90
  for (const componentName of possibleOriginalNames) {
90
91
  yield `'${componentName}' extends keyof typeof __VLS_ctx ? { '${getCanonicalComponentName(node.tag)}': typeof __VLS_ctx`;
91
92
  yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, componentName);
92
93
  yield ` }: `;
93
94
  }
94
- yield `typeof __VLS_resolvedLocalAndGlobalComponents)`;
95
+ yield `typeof __VLS_resolvedLocalAndGlobalComponents)${common_1.newLine}`;
95
96
  yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, getCanonicalComponentName(node.tag), startTagOffset, ctx.codeFeatures.verification);
96
97
  yield common_1.endOfLine;
97
98
  // hover support
@@ -135,6 +136,7 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
135
136
  else {
136
137
  yield `const ${var_originalComponent} = {} as any${common_1.endOfLine}`;
137
138
  }
139
+ yield `// @ts-ignore${common_1.newLine}`;
138
140
  yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`;
139
141
  yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
140
142
  yield `}))${common_1.endOfLine}`;
@@ -157,7 +159,7 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
157
159
  componentCtxVar = var_defineComponentCtx;
158
160
  currentComponent = node;
159
161
  for (const failedExp of propsFailedExps) {
160
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
162
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.node.loc.source, failedExp.node.loc, failedExp.node.loc.start.offset, ctx.codeFeatures.all, failedExp.prefix, failedExp.suffix);
161
163
  yield common_1.endOfLine;
162
164
  }
163
165
  yield* generateVScope(options, ctx, node, props);
@@ -195,7 +197,7 @@ function* generateElement(options, ctx, node, currentComponent, componentCtxVar)
195
197
  yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, true, propsFailedExps), `}`);
196
198
  yield `)${common_1.endOfLine}`;
197
199
  for (const failedExp of propsFailedExps) {
198
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
200
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.node.loc.source, failedExp.node.loc, failedExp.node.loc.start.offset, ctx.codeFeatures.all, failedExp.prefix, failedExp.suffix);
199
201
  yield common_1.endOfLine;
200
202
  }
201
203
  yield* generateVScope(options, ctx, node, node.props);
@@ -51,14 +51,6 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
51
51
  yield* generateEventExpression(options, ctx, prop);
52
52
  yield `}${common_1.endOfLine}`;
53
53
  }
54
- else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
55
- && prop.name === 'on'
56
- && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
57
- // for vue 2 nameless event
58
- // https://github.com/johnsoncodehk/vue-tsc/issues/67
59
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '$event => {(', ')}');
60
- yield common_1.endOfLine;
61
- }
62
54
  }
63
55
  return usedComponentEventsVar;
64
56
  }
@@ -104,7 +96,7 @@ function* generateEventExpression(options, ctx, prop) {
104
96
  const ast = (0, common_1.createTsAst)(options.ts, prop.exp, prop.exp.content);
105
97
  const _isCompoundExpression = isCompoundExpression(options.ts, ast);
106
98
  if (_isCompoundExpression) {
107
- yield `$event => {${common_1.newLine}`;
99
+ yield `(...[$event]) => {${common_1.newLine}`;
108
100
  ctx.addLocalVariable('$event');
109
101
  prefix = '';
110
102
  suffix = '';
@@ -2,4 +2,8 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], enableCodeFeatures: boolean, propsFailedExps?: CompilerDOM.SimpleExpressionNode[]): Generator<Code>;
5
+ export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], enableCodeFeatures: boolean, propsFailedExps?: {
6
+ node: CompilerDOM.SimpleExpressionNode;
7
+ prefix: string;
8
+ suffix: string;
9
+ }[]): Generator<Code>;
@@ -31,22 +31,23 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
31
31
  yield `...{ '${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any }, `;
32
32
  }
33
33
  }
34
- else {
35
- if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
36
- && prop.arg.loc.source.startsWith('[')
37
- && prop.arg.loc.source.endsWith(']')) {
38
- propsFailedExps?.push(prop.arg);
39
- }
40
- if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
41
- propsFailedExps?.push(prop.exp);
42
- }
34
+ else if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
35
+ && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
36
+ && prop.arg.loc.source.startsWith('[')
37
+ && prop.arg.loc.source.endsWith(']')) {
38
+ propsFailedExps?.push({ node: prop.arg, prefix: '(', suffix: ')' });
39
+ propsFailedExps?.push({ node: prop.exp, prefix: '() => {', suffix: '}' });
40
+ }
41
+ else if (!prop.arg
42
+ && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
43
+ propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
43
44
  }
44
45
  }
45
46
  }
46
47
  for (const prop of props) {
47
48
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
48
- && (prop.name === 'bind' || prop.name === 'model')
49
- && (prop.name === 'model' || prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)
49
+ && ((prop.name === 'bind' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)
50
+ || prop.name === 'model')
50
51
  && (!prop.exp || prop.exp.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION)) {
51
52
  let propName;
52
53
  if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
@@ -60,7 +61,7 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
60
61
  if (propName === undefined
61
62
  || options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
62
63
  if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
63
- propsFailedExps?.push(prop.exp);
64
+ propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
64
65
  }
65
66
  continue;
66
67
  }
@@ -15,4 +15,3 @@ export interface TemplateCodegenOptions {
15
15
  }
16
16
  export declare function generateTemplate(options: TemplateCodegenOptions): Generator<Code, TemplateCodegenContext>;
17
17
  export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
18
- export declare function isFragment(node: CompilerDOM.IfNode | CompilerDOM.ForNode): boolean | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFragment = exports.forEachElementNode = exports.generateTemplate = void 0;
3
+ exports.forEachElementNode = exports.generateTemplate = void 0;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
5
  const common_1 = require("../common");
6
6
  const context_1 = require("./context");
@@ -138,8 +138,4 @@ function* forEachElementNode(node) {
138
138
  }
139
139
  }
140
140
  exports.forEachElementNode = forEachElementNode;
141
- function isFragment(node) {
142
- return node.codegenNode && 'consequent' in node.codegenNode && 'tag' in node.codegenNode.consequent && node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
143
- }
144
- exports.isFragment = isFragment;
145
141
  //# sourceMappingURL=index.js.map
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseVForNode = exports.generateVFor = void 0;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
5
  const common_1 = require("../common");
6
- const index_1 = require("./index");
7
6
  const interpolation_1 = require("./interpolation");
8
7
  const templateChild_1 = require("./templateChild");
9
8
  function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
@@ -34,17 +33,25 @@ function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
34
33
  for (const varName of forBlockVars) {
35
34
  ctx.addLocalVariable(varName);
36
35
  }
36
+ let isFragment = true;
37
37
  for (const argument of node.codegenNode?.children.arguments ?? []) {
38
38
  if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
39
- && argument.returns.type === CompilerDOM.NodeTypes.VNODE_CALL
40
- && argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
39
+ && argument.returns?.type === CompilerDOM.NodeTypes.VNODE_CALL
40
+ && argument.returns?.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
41
+ if (argument.returns.tag !== CompilerDOM.FRAGMENT) {
42
+ isFragment = false;
43
+ continue;
44
+ }
41
45
  for (const prop of argument.returns.props.properties) {
42
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.value.loc.source, prop.value.loc, prop.value.loc.start.offset, ctx.codeFeatures.all, '(', ')');
43
- yield common_1.endOfLine;
46
+ if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
47
+ && !prop.value.isStatic) {
48
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.value.content, prop.value.loc, prop.value.loc.start.offset, ctx.codeFeatures.all, '(', ')');
49
+ yield common_1.endOfLine;
50
+ }
44
51
  }
45
52
  }
46
53
  }
47
- if ((0, index_1.isFragment)(node)) {
54
+ if (isFragment) {
48
55
  yield* ctx.resetDirectiveComments('end of v-for start');
49
56
  }
50
57
  let prev;
@@ -4,7 +4,6 @@ exports.generateVIf = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const common_1 = require("../common");
7
- const index_1 = require("./index");
8
7
  const interpolation_1 = require("./interpolation");
9
8
  const templateChild_1 = require("./templateChild");
10
9
  function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
@@ -33,7 +32,7 @@ function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
33
32
  yield ` `;
34
33
  }
35
34
  yield `{${common_1.newLine}`;
36
- if ((0, index_1.isFragment)(node)) {
35
+ if (isFragment(node)) {
37
36
  yield* ctx.resetDirectiveComments('end of v-if start');
38
37
  }
39
38
  let prev;
@@ -50,4 +49,10 @@ function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
50
49
  ctx.blockConditions.length = originalBlockConditionsLength;
51
50
  }
52
51
  exports.generateVIf = generateVIf;
52
+ function isFragment(node) {
53
+ return node.codegenNode
54
+ && 'consequent' in node.codegenNode
55
+ && 'tag' in node.codegenNode.consequent
56
+ && node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
57
+ }
53
58
  //# sourceMappingURL=vIf.js.map
@@ -1,9 +1,5 @@
1
1
  import { type LanguagePlugin } from '@volar/language-core';
2
2
  import type * as ts from 'typescript';
3
- import type { VueCompilerOptions, VueLanguagePlugin } from './types';
3
+ import type { VueCompilerOptions } from './types';
4
4
  import { VueVirtualCode } from './virtualFile/vueFile';
5
- export interface _Plugin extends LanguagePlugin<VueVirtualCode> {
6
- getCanonicalFileName: (fileName: string) => string;
7
- pluginContext: Parameters<VueLanguagePlugin>[0];
8
- }
9
- export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (scriptId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): _Plugin;
5
+ export declare function createVueLanguagePlugin<T>(ts: typeof import('typescript'), asFileName: (scriptId: T) => string, getProjectVersion: () => string, isRootFile: (fileName: string) => boolean, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): LanguagePlugin<T, VueVirtualCode>;
@@ -38,7 +38,7 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
38
38
  ];
39
39
  return JSON.stringify(values);
40
40
  }
41
- function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, getProjectVersion, getScriptFileNames, compilerOptions, vueCompilerOptions) {
41
+ function createVueLanguagePlugin(ts, asFileName, getProjectVersion, isRootFile, compilerOptions, vueCompilerOptions) {
42
42
  const pluginContext = {
43
43
  modules: {
44
44
  '@vue/compiler-dom': vueCompilerOptions.target < 3
@@ -57,38 +57,30 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
57
57
  const vueSfcPlugin = (0, file_vue_1.default)(pluginContext);
58
58
  const vitePressSfcPlugin = (0, file_md_1.default)(pluginContext);
59
59
  const petiteVueSfcPlugin = (0, file_html_1.default)(pluginContext);
60
- const getCanonicalFileName = useCaseSensitiveFileNames
61
- ? (fileName) => fileName
62
- : (fileName) => fileName.toLowerCase();
63
- let canonicalRootFileNames = new Set();
64
60
  let canonicalRootFileNamesVersion;
65
61
  return {
66
- getCanonicalFileName,
67
- pluginContext,
68
62
  getLanguageId(scriptId) {
69
- if (vueCompilerOptions.extensions.some(ext => scriptId.endsWith(ext))) {
63
+ if (vueCompilerOptions.extensions.some(ext => asFileName(scriptId).endsWith(ext))) {
70
64
  return 'vue';
71
65
  }
72
- if (vueCompilerOptions.vitePressExtensions.some(ext => scriptId.endsWith(ext))) {
66
+ if (vueCompilerOptions.vitePressExtensions.some(ext => asFileName(scriptId).endsWith(ext))) {
73
67
  return 'markdown';
74
68
  }
75
- if (vueCompilerOptions.petiteVueExtensions.some(ext => scriptId.endsWith(ext))) {
69
+ if (vueCompilerOptions.petiteVueExtensions.some(ext => asFileName(scriptId).endsWith(ext))) {
76
70
  return 'html';
77
71
  }
78
72
  },
79
73
  createVirtualCode(scriptId, languageId, snapshot) {
80
74
  if (languageId === 'vue' || languageId === 'markdown' || languageId === 'html') {
81
- const fileName = getFileName(scriptId);
82
- const projectVersion = getProjectVersion();
83
- if (projectVersion !== canonicalRootFileNamesVersion) {
84
- canonicalRootFileNames = new Set([...getScriptFileNames()].map(getCanonicalFileName));
85
- canonicalRootFileNamesVersion = projectVersion;
86
- }
87
- if (!pluginContext.globalTypesHolder && canonicalRootFileNames.has(getCanonicalFileName(fileName))) {
88
- pluginContext.globalTypesHolder = fileName;
75
+ const fileName = asFileName(scriptId);
76
+ if (!pluginContext.globalTypesHolder && getProjectVersion() !== canonicalRootFileNamesVersion) {
77
+ canonicalRootFileNamesVersion = getProjectVersion();
78
+ if (isRootFile(fileName)) {
79
+ pluginContext.globalTypesHolder = fileName;
80
+ }
89
81
  }
90
82
  const fileRegistry = getFileRegistry(pluginContext.globalTypesHolder === fileName);
91
- const code = fileRegistry.get(scriptId);
83
+ const code = fileRegistry.get(fileName);
92
84
  if (code) {
93
85
  code.update(snapshot);
94
86
  return code;
@@ -99,7 +91,7 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
99
91
  : languageId === 'markdown'
100
92
  ? [vitePressSfcPlugin, ...basePlugins]
101
93
  : [vueSfcPlugin, ...basePlugins], ts);
102
- fileRegistry.set(scriptId, code);
94
+ fileRegistry.set(fileName, code);
103
95
  return code;
104
96
  }
105
97
  }
@@ -59,8 +59,16 @@ const plugin = () => {
59
59
  }
60
60
  return sfc;
61
61
  function transformRange(block) {
62
- block.loc.start.offset = file2VueSourceMap.getSourceOffset(block.loc.start.offset)?.[0] ?? -1;
63
- block.loc.end.offset = file2VueSourceMap.getSourceOffset(block.loc.end.offset)?.[0] ?? -1;
62
+ block.loc.start.offset = -1;
63
+ block.loc.end.offset = -1;
64
+ for (const [start] of file2VueSourceMap.getSourceOffsets(block.loc.start.offset)) {
65
+ block.loc.start.offset = start;
66
+ break;
67
+ }
68
+ for (const [end] of file2VueSourceMap.getSourceOffsets(block.loc.end.offset)) {
69
+ block.loc.end.offset = end;
70
+ break;
71
+ }
64
72
  }
65
73
  }
66
74
  };
@@ -7,7 +7,6 @@ const vFor_1 = require("../codegen/template/vFor");
7
7
  const CompilerDOM = require("@vue/compiler-dom");
8
8
  const codeFeatures = {
9
9
  format: true,
10
- // autoInserts: true, // TODO: support vue-autoinsert-parentheses
11
10
  };
12
11
  const formatBrackets = {
13
12
  normal: ['`${', '}`;'],
@@ -68,7 +68,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
68
68
  lang: () => string;
69
69
  generatedScript: () => {
70
70
  codes: Code[];
71
- linkedCodeMappings: Mapping<any>[];
71
+ linkedCodeMappings: Mapping<unknown>[];
72
72
  };
73
73
  generatedTemplate: () => {
74
74
  codes: Code[];
@@ -149,21 +149,30 @@ function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, nameToBlock
149
149
  return (0, computeds_1.computed)(() => {
150
150
  return codes().map(_file => {
151
151
  const { code, snapshot } = _file();
152
- const mappings = (0, language_core_1.buildMappings)(code.content);
152
+ const mappings = (0, language_core_1.buildMappings)(code.content.map(segment => {
153
+ if (typeof segment === 'string') {
154
+ return segment;
155
+ }
156
+ const source = segment[1];
157
+ if (source === undefined) {
158
+ return segment;
159
+ }
160
+ const block = nameToBlock()[source];
161
+ if (!block) {
162
+ // console.warn('Unable to find block: ' + source);
163
+ return segment;
164
+ }
165
+ return [
166
+ segment[0],
167
+ undefined,
168
+ segment[2] + block.startTagEnd,
169
+ segment[3],
170
+ ];
171
+ }));
153
172
  const newMappings = [];
154
173
  let lastValidMapping;
155
174
  for (let i = 0; i < mappings.length; i++) {
156
175
  const mapping = mappings[i];
157
- if (mapping.source !== undefined) {
158
- const block = nameToBlock()[mapping.source];
159
- if (block) {
160
- mapping.sourceOffsets = mapping.sourceOffsets.map(offset => offset + block.startTagEnd);
161
- }
162
- else {
163
- // ignore
164
- }
165
- mapping.source = undefined;
166
- }
167
176
  if (mapping.data.__combineOffsetMapping !== undefined) {
168
177
  const offsetMapping = mappings[i - mapping.data.__combineOffsetMapping];
169
178
  if (typeof offsetMapping === 'string' || !offsetMapping) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "2.0.18",
3
+ "version": "2.0.20",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/language-core"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "~2.2.4",
15
+ "@volar/language-core": "~2.3.0-alpha.14",
16
16
  "@vue/compiler-dom": "^3.4.0",
17
17
  "@vue/shared": "^3.4.0",
18
18
  "computeds": "^0.0.1",
@@ -34,5 +34,5 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "gitHead": "7aac2805f03b17e4c624335f509d502002bb75a8"
37
+ "gitHead": "e1a5d2f136bf60a772c9655f9f5474c7f71a2ff9"
38
38
  }