@vue/language-core 3.1.6 → 3.1.7

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.
@@ -33,10 +33,10 @@ function* generateWorker(options, ctx) {
33
33
  const { expression: options } = componentOptions ?? exportDefault;
34
34
  yield* (0, utils_1.generateSfcBlockSection)(script, 0, options.start, codeFeatures_1.codeFeatures.all);
35
35
  yield exportExpression;
36
- yield* (0, utils_1.generateSfcBlockSection)(script, options.end, script.content.length, codeFeatures_1.codeFeatures.all, true);
36
+ yield* (0, utils_1.generateSfcBlockSection)(script, options.end, script.content.length, codeFeatures_1.codeFeatures.all);
37
37
  }
38
38
  else {
39
- yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all, true);
39
+ yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
40
40
  yield `export default ${exportExpression}${utils_1.endOfLine}`;
41
41
  }
42
42
  // <script setup>
@@ -88,7 +88,7 @@ function* generateWorker(options, ctx) {
88
88
  label: wrapRight || '[Missing optionsWrapper[1]]',
89
89
  });
90
90
  }
91
- yield* (0, utils_1.generateSfcBlockSection)(script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all, true);
91
+ yield* (0, utils_1.generateSfcBlockSection)(script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all);
92
92
  yield* generateExportDeclareEqual(script);
93
93
  if (wrapLeft) {
94
94
  yield wrapLeft;
@@ -104,7 +104,7 @@ function* generateWorker(options, ctx) {
104
104
  yield* (0, utils_1.generateSfcBlockSection)(script, expression.end, script.content.length, codeFeatures_1.codeFeatures.all);
105
105
  }
106
106
  else {
107
- yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all, true);
107
+ yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
108
108
  yield* generateExportDeclareEqual(script);
109
109
  yield `(await import('${vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
110
110
  yield* (0, template_1.generateTemplate)(options, ctx);
@@ -81,7 +81,7 @@ function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic,
81
81
  }
82
82
  yield `) => void${utils_1.endOfLine}`;
83
83
  yield ` attrs: any${utils_1.endOfLine}`;
84
- yield ` slots: ${names.Slots}${utils_1.endOfLine}`;
84
+ yield ` slots: ${hasSlotsType(options) ? names.Slots : `{}`}${utils_1.endOfLine}`;
85
85
  yield ` emit: ${emitTypes.length ? emitTypes.join(` & `) : `{}`}${utils_1.endOfLine}`;
86
86
  yield `}${utils_1.endOfLine}`;
87
87
  yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
@@ -194,7 +194,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
194
194
  }));
195
195
  }
196
196
  }
197
- yield* (0, transform_1.generateCodeWithTransforms)(Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset), scriptSetup.content.length, transforms, (start, end) => (0, utils_1.generateSfcBlockSection)(scriptSetup, start, end, codeFeatures_1.codeFeatures.all, end === scriptSetup.content.length));
197
+ yield* (0, transform_1.generateCodeWithTransforms)(Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset), scriptSetup.content.length, transforms, (start, end) => (0, utils_1.generateSfcBlockSection)(scriptSetup, start, end, codeFeatures_1.codeFeatures.all));
198
198
  yield* generateMacros(options);
199
199
  yield* generateModels(scriptSetup, scriptSetupRanges);
200
200
  yield* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges);
@@ -304,7 +304,8 @@ function* generateStyleScopedClassReferences({ template, ts }, node) {
304
304
  if (ts.isPropertyAssignment(property)) {
305
305
  const { name } = property;
306
306
  if (ts.isIdentifier(name)) {
307
- yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, name.text, name.end - name.text.length + startOffset);
307
+ const text = (0, shared_2.getNodeText)(ts, name, ast);
308
+ yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, name.end - text.length + startOffset);
308
309
  }
309
310
  else if (ts.isStringLiteral(name)) {
310
311
  literals.push(name);
@@ -317,7 +318,8 @@ function* generateStyleScopedClassReferences({ template, ts }, node) {
317
318
  }
318
319
  }
319
320
  else if (ts.isShorthandPropertyAssignment(property)) {
320
- yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, property.name.text, property.name.end - property.name.text.length + startOffset);
321
+ const text = (0, shared_2.getNodeText)(ts, property.name, ast);
322
+ yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, property.name.end - text.length + startOffset);
321
323
  }
322
324
  }
323
325
  }
@@ -1,8 +1,8 @@
1
1
  import type * as ts from 'typescript';
2
- import type { Code, SfcBlock, VueCodeInformation } from '../../types';
2
+ import type { Code, Sfc, SfcBlock, VueCodeInformation } from '../../types';
3
3
  export declare const newLine = "\n";
4
4
  export declare const endOfLine = ";\n";
5
5
  export declare const identifierRegex: RegExp;
6
6
  export declare function getTypeScriptAST(ts: typeof import('typescript'), block: SfcBlock, text: string): ts.SourceFile;
7
- export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation, partiallyEnd?: boolean): Generator<Code>;
7
+ export declare function generateSfcBlockSection(block: NonNullable<Sfc['script' | 'scriptSetup']>, start: number, end: number, features: VueCodeInformation): Generator<Code>;
8
8
  export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>;
@@ -34,18 +34,20 @@ function getTypeScriptAST(ts, block, text) {
34
34
  cacheMap[1].set(text, [ast, 1]);
35
35
  return ast;
36
36
  }
37
- function* generateSfcBlockSection(block, start, end, features, partiallyEnd = false) {
38
- yield [
39
- block.content.slice(start, end),
40
- block.name,
41
- start,
42
- features,
43
- ];
37
+ function* generateSfcBlockSection(block, start, end, features) {
38
+ const text = block.content.slice(start, end);
39
+ yield [text, block.name, start, features];
44
40
  // #3632
45
- if (partiallyEnd) {
46
- yield `;`;
47
- yield ['', block.name, end, codeFeatures_1.codeFeatures.verification];
48
- yield exports.newLine;
41
+ if ('parseDiagnostics' in block.ast) {
42
+ const emptyEndLength = text.length - text.trimEnd().length;
43
+ for (const diag of block.ast.parseDiagnostics) {
44
+ if (diag.start >= end - emptyEndLength) {
45
+ yield `;`;
46
+ yield ['', block.name, end, codeFeatures_1.codeFeatures.verification];
47
+ yield exports.newLine;
48
+ break;
49
+ }
50
+ }
49
51
  }
50
52
  }
51
53
  function* forEachNode(ts, node) {
@@ -47,14 +47,14 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
47
47
  createVirtualCode(scriptId, languageId, snapshot) {
48
48
  const fileName = asFileName(scriptId);
49
49
  if (plugins.some(plugin => plugin.isValidFile?.(fileName, languageId))) {
50
- const code = fileRegistry.get(fileName);
50
+ const code = fileRegistry.get(String(scriptId));
51
51
  if (code) {
52
52
  code.update(snapshot);
53
53
  return code;
54
54
  }
55
55
  else {
56
56
  const code = new virtualCode_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
57
- fileRegistry.set(fileName, code);
57
+ fileRegistry.set(String(scriptId), code);
58
58
  return code;
59
59
  }
60
60
  }
@@ -64,8 +64,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
64
64
  return code;
65
65
  },
66
66
  disposeVirtualCode(scriptId) {
67
- const fileName = asFileName(scriptId);
68
- fileRegistry.delete(fileName);
67
+ fileRegistry.delete(String(scriptId));
69
68
  },
70
69
  typescript: {
71
70
  extraFileExtensions: getAllExtensions(vueCompilerOptions)
@@ -1,8 +1,8 @@
1
1
  import type * as ts from 'typescript';
2
- import type { TextRange } from '../types';
2
+ import type { TextRange, VueCompilerOptions } from '../types';
3
3
  export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
4
4
  }
5
- export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean): {
5
+ export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
6
6
  exportDefault: (TextRange & {
7
7
  expression: TextRange;
8
8
  }) | undefined;
@@ -16,10 +16,6 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
16
16
  name: TextRange | undefined;
17
17
  inheritAttrs: string | undefined;
18
18
  } | undefined;
19
- bindings: {
20
- range: TextRange;
21
- moduleName?: string;
22
- isDefaultImport?: boolean;
23
- isNamespace?: boolean;
24
- }[];
19
+ bindings: TextRange[];
20
+ components: TextRange[];
25
21
  };
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptRanges = parseScriptRanges;
4
4
  const shared_1 = require("../utils/shared");
5
5
  const utils_1 = require("./utils");
6
- function parseScriptRanges(ts, ast, hasScriptSetup) {
6
+ function parseScriptRanges(ts, ast, vueCompilerOptions) {
7
7
  let exportDefault;
8
8
  let componentOptions;
9
- const bindings = hasScriptSetup ? (0, utils_1.parseBindingRanges)(ts, ast) : [];
9
+ const { bindings, components } = (0, utils_1.parseBindingRanges)(ts, ast, vueCompilerOptions.extensions);
10
10
  ts.forEachChild(ast, raw => {
11
11
  if (ts.isExportAssignment(raw)) {
12
12
  exportDefault = {
@@ -70,6 +70,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
70
70
  exportDefault,
71
71
  componentOptions,
72
72
  bindings,
73
+ components,
73
74
  };
74
75
  function _getStartEnd(node) {
75
76
  return (0, shared_1.getStartEnd)(ts, node, ast);
@@ -48,12 +48,8 @@ export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRan
48
48
  export declare function parseScriptSetupRanges(ts: typeof import('typescript'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
49
49
  leadingCommentEndOffset: number;
50
50
  importSectionEndOffset: number;
51
- bindings: {
52
- range: TextRange;
53
- moduleName?: string;
54
- isDefaultImport?: boolean;
55
- isNamespace?: boolean;
56
- }[];
51
+ bindings: TextRange[];
52
+ components: TextRange[];
57
53
  defineModel: DefineModel[];
58
54
  defineProps: DefineProps | undefined;
59
55
  withDefaults: WithDefaults | undefined;
@@ -20,7 +20,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
20
20
  const text = ast.text;
21
21
  const leadingCommentRanges = ts.getLeadingCommentRanges(text, 0)?.reverse() ?? [];
22
22
  const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckReg.test(text.slice(range.pos, range.end)))?.end ?? 0;
23
- let bindings = (0, utils_1.parseBindingRanges)(ts, ast);
23
+ let { bindings, components } = (0, utils_1.parseBindingRanges)(ts, ast, vueCompilerOptions.extensions);
24
24
  let foundNonImportExportNode = false;
25
25
  let importSectionEndOffset = 0;
26
26
  ts.forEachChild(ast, node => {
@@ -48,7 +48,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
48
48
  });
49
49
  ts.forEachChild(ast, node => visitNode(node, [ast]));
50
50
  const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
51
- bindings = bindings.filter(({ range }) => {
51
+ bindings = bindings.filter(range => {
52
52
  const name = text.slice(range.start, range.end);
53
53
  return !templateRefNames.has(name);
54
54
  });
@@ -56,6 +56,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
56
56
  leadingCommentEndOffset,
57
57
  importSectionEndOffset,
58
58
  bindings,
59
+ components,
59
60
  defineModel,
60
61
  defineProps,
61
62
  withDefaults,
@@ -1,11 +1,9 @@
1
1
  import type * as ts from 'typescript';
2
2
  import type { TextRange } from '../types';
3
- export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
4
- range: TextRange;
5
- moduleName?: string;
6
- isDefaultImport?: boolean;
7
- isNamespace?: boolean;
8
- }[];
3
+ export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile, componentExtsensions: string[]): {
4
+ bindings: TextRange[];
5
+ components: TextRange[];
6
+ };
9
7
  export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
10
8
  start: number;
11
9
  end: number;
@@ -4,44 +4,37 @@ exports.parseBindingRanges = parseBindingRanges;
4
4
  exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
5
5
  const collectBindings_1 = require("../utils/collectBindings");
6
6
  const shared_1 = require("../utils/shared");
7
- function parseBindingRanges(ts, ast) {
7
+ function parseBindingRanges(ts, ast, componentExtsensions) {
8
8
  const bindings = [];
9
+ const components = [];
9
10
  ts.forEachChild(ast, node => {
10
11
  if (ts.isVariableStatement(node)) {
11
12
  for (const decl of node.declarationList.declarations) {
12
13
  const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
13
- bindings.push(...ranges.map(range => ({ range })));
14
+ bindings.push(...ranges);
14
15
  }
15
16
  }
16
17
  else if (ts.isFunctionDeclaration(node)) {
17
18
  if (node.name && ts.isIdentifier(node.name)) {
18
- bindings.push({
19
- range: _getStartEnd(node.name),
20
- });
19
+ bindings.push(_getStartEnd(node.name));
21
20
  }
22
21
  }
23
22
  else if (ts.isClassDeclaration(node)) {
24
23
  if (node.name) {
25
- bindings.push({
26
- range: _getStartEnd(node.name),
27
- });
24
+ bindings.push(_getStartEnd(node.name));
28
25
  }
29
26
  }
30
27
  else if (ts.isEnumDeclaration(node)) {
31
- bindings.push({
32
- range: _getStartEnd(node.name),
33
- });
28
+ bindings.push(_getStartEnd(node.name));
34
29
  }
35
30
  if (ts.isImportDeclaration(node)) {
36
31
  const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
37
32
  if (node.importClause && !node.importClause.isTypeOnly) {
38
33
  const { name, namedBindings } = node.importClause;
39
34
  if (name) {
40
- bindings.push({
41
- range: _getStartEnd(name),
42
- moduleName,
43
- isDefaultImport: true,
44
- });
35
+ if (componentExtsensions.some(ext => moduleName.endsWith(ext))) {
36
+ components.push(_getStartEnd(name));
37
+ }
45
38
  }
46
39
  if (namedBindings) {
47
40
  if (ts.isNamedImports(namedBindings)) {
@@ -49,25 +42,27 @@ function parseBindingRanges(ts, ast) {
49
42
  if (element.isTypeOnly) {
50
43
  continue;
51
44
  }
52
- bindings.push({
53
- range: _getStartEnd(element.name),
54
- moduleName,
55
- isDefaultImport: element.propertyName?.text === 'default',
56
- });
45
+ if (element.propertyName
46
+ && _getNodeText(element.propertyName) === 'default'
47
+ && componentExtsensions.some(ext => moduleName.endsWith(ext))) {
48
+ components.push(_getStartEnd(element.name));
49
+ }
50
+ else {
51
+ bindings.push(_getStartEnd(element.name));
52
+ }
57
53
  }
58
54
  }
59
55
  else {
60
- bindings.push({
61
- range: _getStartEnd(namedBindings.name),
62
- moduleName,
63
- isNamespace: true,
64
- });
56
+ bindings.push(_getStartEnd(namedBindings.name));
65
57
  }
66
58
  }
67
59
  }
68
60
  }
69
61
  });
70
- return bindings;
62
+ return {
63
+ bindings,
64
+ components,
65
+ };
71
66
  function _getStartEnd(node) {
72
67
  return (0, shared_1.getStartEnd)(ts, node, ast);
73
68
  }
@@ -14,22 +14,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
14
14
  name: import("../types").TextRange | undefined;
15
15
  inheritAttrs: string | undefined;
16
16
  } | undefined;
17
- bindings: {
18
- range: import("../types").TextRange;
19
- moduleName?: string;
20
- isDefaultImport?: boolean;
21
- isNamespace?: boolean;
22
- }[];
17
+ bindings: import("../types").TextRange[];
18
+ components: import("../types").TextRange[];
23
19
  } | undefined;
24
20
  getScriptSetupRanges: () => {
25
21
  leadingCommentEndOffset: number;
26
22
  importSectionEndOffset: number;
27
- bindings: {
28
- range: import("../types").TextRange;
29
- moduleName?: string;
30
- isDefaultImport?: boolean;
31
- isNamespace?: boolean;
32
- }[];
23
+ bindings: import("../types").TextRange[];
24
+ components: import("../types").TextRange[];
33
25
  defineModel: {
34
26
  localName?: import("../types").TextRange;
35
27
  name?: import("../types").TextRange;
@@ -188,7 +180,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
188
180
  } | undefined;
189
181
  getImportComponentNames: () => Set<string>;
190
182
  getSetupExposed: () => Set<string>;
191
- getSetupConsts: () => Set<string>;
192
183
  }>;
193
184
  declare const plugin: VueLanguagePlugin;
194
185
  export default plugin;
@@ -61,7 +61,7 @@ function useCodegen(fileName, sfc, ctx) {
61
61
  return ctx.vueCompilerOptions;
62
62
  });
63
63
  const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang)
64
- ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup)
64
+ ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, getResolvedOptions())
65
65
  : undefined);
66
66
  const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
67
67
  ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
@@ -70,23 +70,13 @@ function useCodegen(fileName, sfc, ctx) {
70
70
  const names = new Set();
71
71
  const scriptSetupRanges = getScriptSetupRanges();
72
72
  if (sfc.scriptSetup && scriptSetupRanges) {
73
- for (const { range, moduleName, isDefaultImport, isNamespace } of scriptSetupRanges.bindings) {
74
- if (moduleName
75
- && isDefaultImport
76
- && !isNamespace
77
- && ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
78
- names.add(sfc.scriptSetup.content.slice(range.start, range.end));
79
- }
73
+ for (const range of scriptSetupRanges.components) {
74
+ names.add(sfc.scriptSetup.content.slice(range.start, range.end));
80
75
  }
81
76
  const scriptRange = getScriptRanges();
82
77
  if (sfc.script && scriptRange) {
83
- for (const { range, moduleName, isDefaultImport, isNamespace } of scriptRange.bindings) {
84
- if (moduleName
85
- && isDefaultImport
86
- && !isNamespace
87
- && ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
88
- names.add(sfc.script.content.slice(range.start, range.end));
89
- }
78
+ for (const range of scriptRange.components) {
79
+ names.add(sfc.script.content.slice(range.start, range.end));
90
80
  }
91
81
  }
92
82
  }
@@ -176,13 +166,13 @@ function useCodegen(fileName, sfc, ctx) {
176
166
  if (!sfc.scriptSetup || !scriptSetupRanges) {
177
167
  return allVars;
178
168
  }
179
- for (const { range } of scriptSetupRanges.bindings) {
169
+ for (const range of scriptSetupRanges.bindings) {
180
170
  const name = sfc.scriptSetup.content.slice(range.start, range.end);
181
171
  allVars.add(name);
182
172
  }
183
173
  const scriptRanges = getScriptRanges();
184
174
  if (sfc.script && scriptRanges) {
185
- for (const { range } of scriptRanges.bindings) {
175
+ for (const range of scriptRanges.bindings) {
186
176
  const name = sfc.script.content.slice(range.start, range.end);
187
177
  allVars.add(name);
188
178
  }
@@ -236,7 +226,6 @@ function useCodegen(fileName, sfc, ctx) {
236
226
  getGeneratedTemplate,
237
227
  getImportComponentNames,
238
228
  getSetupExposed,
239
- getSetupConsts,
240
229
  };
241
230
  }
242
231
  //# sourceMappingURL=vue-tsx.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.1.6",
3
+ "version": "3.1.7",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -36,5 +36,5 @@
36
36
  "optional": true
37
37
  }
38
38
  },
39
- "gitHead": "341c06897f7f46606dddb8dd6d9e74e9c7844f02"
39
+ "gitHead": "20dcd47c0cb4ce30e2c5e3ef1986ce297c218a06"
40
40
  }