@vue/language-core 3.0.3 → 3.0.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 (47) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/codegen/codeFeatures.d.ts +20 -17
  4. package/lib/codegen/codeFeatures.js +23 -13
  5. package/lib/codegen/globalTypes.d.ts +2 -2
  6. package/lib/codegen/globalTypes.js +27 -24
  7. package/lib/codegen/script/context.d.ts +0 -6
  8. package/lib/codegen/script/index.d.ts +2 -1
  9. package/lib/codegen/script/index.js +16 -4
  10. package/lib/codegen/script/scriptSetup.js +4 -5
  11. package/lib/codegen/template/context.d.ts +0 -19
  12. package/lib/codegen/template/context.js +0 -6
  13. package/lib/codegen/template/element.js +23 -21
  14. package/lib/codegen/template/elementDirectives.js +10 -10
  15. package/lib/codegen/template/elementEvents.d.ts +1 -1
  16. package/lib/codegen/template/elementEvents.js +23 -20
  17. package/lib/codegen/template/elementProps.js +17 -24
  18. package/lib/codegen/template/index.d.ts +3 -2
  19. package/lib/codegen/template/index.js +21 -8
  20. package/lib/codegen/template/interpolation.js +5 -3
  21. package/lib/codegen/template/slotOutlet.js +6 -5
  22. package/lib/codegen/template/styleScopedClasses.js +3 -2
  23. package/lib/codegen/template/templateChild.js +2 -1
  24. package/lib/codegen/template/vFor.js +6 -4
  25. package/lib/codegen/template/vIf.js +2 -1
  26. package/lib/codegen/template/vSlot.js +11 -9
  27. package/lib/codegen/tenp.d.ts +1 -0
  28. package/lib/codegen/tenp.js +3 -0
  29. package/lib/codegen/utils/index.d.ts +0 -10
  30. package/lib/codegen/utils/index.js +0 -27
  31. package/lib/parsers/scriptSetupRanges.d.ts +0 -1
  32. package/lib/parsers/scriptSetupRanges.js +4 -40
  33. package/lib/parsers/utils.d.ts +12 -0
  34. package/lib/parsers/utils.js +95 -0
  35. package/lib/plugins/file-css.d.ts +3 -0
  36. package/lib/plugins/file-css.js +57 -0
  37. package/lib/plugins/file-vue.js +16 -1
  38. package/lib/plugins/vue-root-tags.js +2 -9
  39. package/lib/plugins/vue-style-css.d.ts +3 -0
  40. package/lib/plugins/vue-style-css.js +62 -0
  41. package/lib/plugins/vue-tsx.d.ts +2 -20
  42. package/lib/plugins/vue-tsx.js +18 -20
  43. package/lib/types.d.ts +1 -1
  44. package/lib/utils/collectBindings.d.ts +12 -0
  45. package/lib/utils/collectBindings.js +29 -0
  46. package/lib/utils/ts.js +20 -18
  47. package/package.json +4 -4
@@ -2,8 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptSetupRanges = parseScriptSetupRanges;
4
4
  exports.parseBindingRanges = parseBindingRanges;
5
- exports.findBindingVars = findBindingVars;
6
- const utils_1 = require("../codegen/utils");
5
+ const collectBindings_1 = require("../utils/collectBindings");
7
6
  const shared_1 = require("../utils/shared");
8
7
  const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
9
8
  function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
@@ -147,7 +146,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
147
146
  };
148
147
  if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
149
148
  defineProps.destructured = new Map();
150
- const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name);
149
+ const identifiers = (0, collectBindings_1.collectBindingIdentifiers)(ts, parent.name);
151
150
  for (const { id, isRest, initializer } of identifiers) {
152
151
  const name = _getNodeText(id);
153
152
  if (isRest) {
@@ -267,8 +266,8 @@ function parseBindingRanges(ts, ast) {
267
266
  ts.forEachChild(ast, node => {
268
267
  if (ts.isVariableStatement(node)) {
269
268
  for (const decl of node.declarationList.declarations) {
270
- const vars = _findBindingVars(decl.name);
271
- bindings.push(...vars.map(range => ({ range })));
269
+ const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
270
+ bindings.push(...ranges.map(range => ({ range })));
272
271
  }
273
272
  }
274
273
  else if (ts.isFunctionDeclaration(node)) {
@@ -332,41 +331,6 @@ function parseBindingRanges(ts, ast) {
332
331
  function _getNodeText(node) {
333
332
  return (0, shared_1.getNodeText)(ts, node, ast);
334
333
  }
335
- function _findBindingVars(left) {
336
- return findBindingVars(ts, left, ast);
337
- }
338
- }
339
- function findBindingVars(ts, left, ast) {
340
- const vars = [];
341
- worker(left);
342
- return vars;
343
- function worker(node) {
344
- if (ts.isIdentifier(node)) {
345
- vars.push((0, shared_1.getStartEnd)(ts, node, ast));
346
- }
347
- // { ? } = ...
348
- // [ ? ] = ...
349
- else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
350
- for (const property of node.elements) {
351
- if (ts.isBindingElement(property)) {
352
- worker(property.name);
353
- }
354
- }
355
- }
356
- // { foo: ? } = ...
357
- else if (ts.isPropertyAssignment(node)) {
358
- worker(node.initializer);
359
- }
360
- // { foo } = ...
361
- else if (ts.isShorthandPropertyAssignment(node)) {
362
- vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
363
- }
364
- // { ...? } = ...
365
- // [ ...? ] = ...
366
- else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
367
- worker(node.expression);
368
- }
369
- }
370
334
  }
371
335
  function getStatementRange(ts, parents, node, ast) {
372
336
  let statementRange;
@@ -0,0 +1,12 @@
1
+ import type * as ts from 'typescript';
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
+ }[];
9
+ export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
10
+ start: number;
11
+ end: number;
12
+ } | undefined;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseBindingRanges = parseBindingRanges;
4
+ exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
5
+ const collectBindings_1 = require("../utils/collectBindings");
6
+ const shared_1 = require("../utils/shared");
7
+ function parseBindingRanges(ts, ast) {
8
+ const bindings = [];
9
+ ts.forEachChild(ast, node => {
10
+ if (ts.isVariableStatement(node)) {
11
+ for (const decl of node.declarationList.declarations) {
12
+ const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
13
+ bindings.push(...ranges.map(range => ({ range })));
14
+ }
15
+ }
16
+ else if (ts.isFunctionDeclaration(node)) {
17
+ if (node.name && ts.isIdentifier(node.name)) {
18
+ bindings.push({
19
+ range: _getStartEnd(node.name),
20
+ });
21
+ }
22
+ }
23
+ else if (ts.isClassDeclaration(node)) {
24
+ if (node.name) {
25
+ bindings.push({
26
+ range: _getStartEnd(node.name),
27
+ });
28
+ }
29
+ }
30
+ else if (ts.isEnumDeclaration(node)) {
31
+ bindings.push({
32
+ range: _getStartEnd(node.name),
33
+ });
34
+ }
35
+ if (ts.isImportDeclaration(node)) {
36
+ const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
37
+ if (node.importClause && !node.importClause.isTypeOnly) {
38
+ const { name, namedBindings } = node.importClause;
39
+ if (name) {
40
+ bindings.push({
41
+ range: _getStartEnd(name),
42
+ moduleName,
43
+ isDefaultImport: true,
44
+ });
45
+ }
46
+ if (namedBindings) {
47
+ if (ts.isNamedImports(namedBindings)) {
48
+ for (const element of namedBindings.elements) {
49
+ if (element.isTypeOnly) {
50
+ continue;
51
+ }
52
+ bindings.push({
53
+ range: _getStartEnd(element.name),
54
+ moduleName,
55
+ isDefaultImport: element.propertyName?.text === 'default',
56
+ });
57
+ }
58
+ }
59
+ else {
60
+ bindings.push({
61
+ range: _getStartEnd(namedBindings.name),
62
+ moduleName,
63
+ isNamespace: true,
64
+ });
65
+ }
66
+ }
67
+ }
68
+ }
69
+ });
70
+ return bindings;
71
+ function _getStartEnd(node) {
72
+ return (0, shared_1.getStartEnd)(ts, node, ast);
73
+ }
74
+ function _getNodeText(node) {
75
+ return (0, shared_1.getNodeText)(ts, node, ast);
76
+ }
77
+ }
78
+ function getClosestMultiLineCommentRange(ts, node, parents, ast) {
79
+ for (let i = parents.length - 1; i >= 0; i--) {
80
+ if (ts.isStatement(node)) {
81
+ break;
82
+ }
83
+ node = parents[i];
84
+ }
85
+ const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
86
+ ?.reverse()
87
+ .find(range => range.kind === 3);
88
+ if (comment) {
89
+ return {
90
+ start: comment.pos,
91
+ end: comment.end,
92
+ };
93
+ }
94
+ }
95
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const parseSfc_1 = require("../utils/parseSfc");
4
+ const plugin = ({ vueCompilerOptions }) => {
5
+ return {
6
+ version: 2.1,
7
+ getLanguageId(fileName) {
8
+ if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
9
+ return 'vue';
10
+ }
11
+ },
12
+ isValidFile(_fileName, languageId) {
13
+ return languageId === 'vue';
14
+ },
15
+ parseSFC2(_fileName, languageId, content) {
16
+ if (languageId !== 'vue') {
17
+ return;
18
+ }
19
+ return (0, parseSfc_1.parse)(content);
20
+ },
21
+ updateSFC(sfc, change) {
22
+ const blocks = [
23
+ sfc.descriptor.template,
24
+ sfc.descriptor.script,
25
+ sfc.descriptor.scriptSetup,
26
+ ...sfc.descriptor.styles,
27
+ ...sfc.descriptor.customBlocks,
28
+ ].filter(block => !!block);
29
+ const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset);
30
+ if (!hitBlock) {
31
+ return;
32
+ }
33
+ const oldContent = hitBlock.content;
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);
37
+ // #3449
38
+ const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
39
+ const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
40
+ if (insertedEndTag) {
41
+ return;
42
+ }
43
+ const lengthDiff = change.newText.length - (change.end - change.start);
44
+ for (const block of blocks) {
45
+ if (block.loc.start.offset > change.end) {
46
+ block.loc.start.offset += lengthDiff;
47
+ }
48
+ if (block.loc.end.offset >= change.end) {
49
+ block.loc.end.offset += lengthDiff;
50
+ }
51
+ }
52
+ return sfc;
53
+ },
54
+ };
55
+ };
56
+ exports.default = plugin;
57
+ //# sourceMappingURL=file-css.js.map
@@ -16,7 +16,22 @@ const plugin = ({ vueCompilerOptions }) => {
16
16
  if (languageId !== 'vue') {
17
17
  return;
18
18
  }
19
- return (0, parseSfc_1.parse)(content);
19
+ const sfc = (0, parseSfc_1.parse)(content);
20
+ for (const error of sfc.errors) {
21
+ // Handle 'Element is missing end tag.' error, see #4893
22
+ if ('code' in error && error.code === 24 && sfc.descriptor.template
23
+ && error.loc?.start.line === sfc.descriptor.template.loc.start.line) {
24
+ const template = sfc.descriptor.template;
25
+ const templateText = template.content;
26
+ const endTagOffset = templateText.lastIndexOf('<');
27
+ const endTagText = templateText.slice(endTagOffset).trimEnd();
28
+ if ('</template>'.startsWith(endTagText)) {
29
+ sfc.descriptor.template.loc.end.offset = template.loc.start.offset + endTagOffset;
30
+ template.content = templateText.slice(0, endTagOffset);
31
+ }
32
+ }
33
+ }
34
+ return sfc;
20
35
  },
21
36
  updateSFC(sfc, change) {
22
37
  const blocks = [
@@ -15,23 +15,16 @@ const plugin = () => {
15
15
  if (embeddedFile.id === 'root_tags') {
16
16
  embeddedFile.content.push([sfc.content, undefined, 0, shared_1.allCodeFeatures]);
17
17
  for (const block of [
18
+ sfc.template,
18
19
  sfc.script,
19
20
  sfc.scriptSetup,
20
- sfc.template,
21
21
  ...sfc.styles,
22
22
  ...sfc.customBlocks,
23
23
  ]) {
24
24
  if (!block) {
25
25
  continue;
26
26
  }
27
- let content = block.content;
28
- if (content.endsWith('\r\n')) {
29
- content = content.slice(0, -2);
30
- }
31
- else if (content.endsWith('\n')) {
32
- content = content.slice(0, -1);
33
- }
34
- const offset = content.lastIndexOf('\n') + 1;
27
+ const offset = block.content.lastIndexOf('\n', block.content.lastIndexOf('\n') - 1) + 1;
35
28
  // fix folding range end position failed to mapping
36
29
  (0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, sfc.content.slice(block.startTagEnd, block.startTagEnd + offset), [
37
30
  '',
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const plugin = () => {
4
+ return {
5
+ version: 2.2,
6
+ compileSFCStyle(_lang, style) {
7
+ return {
8
+ imports: [...parseCssImports(style)],
9
+ bindings: [...parseCssBindings(style)],
10
+ classNames: [...parseCssClassNames(style)],
11
+ };
12
+ },
13
+ };
14
+ };
15
+ exports.default = plugin;
16
+ const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
17
+ const cssBindingReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
18
+ const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
19
+ const commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
20
+ const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
21
+ function* parseCssImports(css) {
22
+ const matches = css.matchAll(cssImportReg);
23
+ for (const match of matches) {
24
+ let text = match[0];
25
+ let offset = match.index;
26
+ if (text.startsWith("'") || text.startsWith('"')) {
27
+ text = text.slice(1, -1);
28
+ offset += 1;
29
+ }
30
+ if (text) {
31
+ yield { text, offset };
32
+ }
33
+ }
34
+ }
35
+ function* parseCssBindings(css) {
36
+ css = fillBlank(css, commentReg);
37
+ const matchs = css.matchAll(cssBindingReg);
38
+ for (const match of matchs) {
39
+ const matchText = match.slice(1).find(t => t);
40
+ if (matchText) {
41
+ const offset = match.index + css.slice(match.index).indexOf(matchText);
42
+ yield { offset, text: matchText };
43
+ }
44
+ }
45
+ }
46
+ function* parseCssClassNames(css) {
47
+ css = fillBlank(css, commentReg, fragmentReg);
48
+ const matches = css.matchAll(cssClassNameReg);
49
+ for (const match of matches) {
50
+ const matchText = match[1];
51
+ if (matchText) {
52
+ yield { offset: match.index, text: matchText };
53
+ }
54
+ }
55
+ }
56
+ function fillBlank(css, ...regs) {
57
+ for (const reg of regs) {
58
+ css = css.replace(reg, match => ' '.repeat(match.length));
59
+ }
60
+ return css;
61
+ }
62
+ //# sourceMappingURL=vue-style-css.js.map
@@ -1,5 +1,6 @@
1
1
  import type { Code, Sfc, VueLanguagePlugin } from '../types';
2
2
  export declare const tsCodegen: WeakMap<Sfc, {
3
+ getLang: () => string;
3
4
  getScriptRanges: () => {
4
5
  exportDefault: (import("../types").TextRange & {
5
6
  expression: import("../types").TextRange;
@@ -115,7 +116,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
115
116
  name?: string;
116
117
  })[];
117
118
  } | undefined;
118
- getLang: () => string;
119
+ getSetupSlotsAssignName: () => string | undefined;
119
120
  getGeneratedScript: () => {
120
121
  codes: Code[];
121
122
  generatedTemplate: boolean;
@@ -148,25 +149,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
148
149
  offset: number;
149
150
  };
150
151
  };
151
- codeFeatures: {
152
- all: import("../types").VueCodeInformation;
153
- verification: import("../types").VueCodeInformation;
154
- completion: import("../types").VueCodeInformation;
155
- additionalCompletion: import("../types").VueCodeInformation;
156
- withoutCompletion: import("../types").VueCodeInformation;
157
- navigation: import("../types").VueCodeInformation;
158
- navigationWithoutRename: import("../types").VueCodeInformation;
159
- navigationAndCompletion: import("../types").VueCodeInformation;
160
- navigationAndAdditionalCompletion: import("../types").VueCodeInformation;
161
- navigationAndVerification: import("../types").VueCodeInformation;
162
- withoutNavigation: import("../types").VueCodeInformation;
163
- semanticWithoutHighlight: import("../types").VueCodeInformation;
164
- withoutHighlight: import("../types").VueCodeInformation;
165
- withoutHighlightAndNavigation: import("../types").VueCodeInformation;
166
- withoutHighlightAndCompletion: import("../types").VueCodeInformation;
167
- withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
168
- withoutSemantic: import("../types").VueCodeInformation;
169
- };
170
152
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
171
153
  inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
172
154
  inVFor: boolean;
@@ -144,8 +144,7 @@ function createTsx(fileName, sfc, ctx) {
144
144
  if (getResolvedOptions().skipTemplateCodegen || !sfc.template) {
145
145
  return;
146
146
  }
147
- const codes = [];
148
- const codegen = (0, template_1.generateTemplate)({
147
+ const options = {
149
148
  ts,
150
149
  compilerOptions: ctx.compilerOptions,
151
150
  vueCompilerOptions: getResolvedOptions(),
@@ -159,21 +158,23 @@ function createTsx(fileName, sfc, ctx) {
159
158
  propsAssignName: getSetupPropsAssignName(),
160
159
  inheritAttrs: getSetupInheritAttrs(),
161
160
  selfComponentName: getComponentSelfName(),
162
- });
163
- let current = codegen.next();
164
- while (!current.done) {
165
- const code = current.value;
161
+ };
162
+ const context = (0, template_1.createTemplateCodegenContext)(options, sfc.template.ast);
163
+ const codegen = (0, template_1.generateTemplate)(options, context);
164
+ const codes = [];
165
+ for (const code of codegen) {
166
+ if (typeof code === 'object') {
167
+ code[3] = context.resolveCodeFeatures(code[3]);
168
+ }
166
169
  codes.push(code);
167
- current = codegen.next();
168
170
  }
169
171
  return {
170
- ...current.value,
172
+ ...context,
171
173
  codes,
172
174
  };
173
175
  });
174
176
  const getGeneratedScript = (0, alien_signals_1.computed)(() => {
175
- const codes = [];
176
- const codegen = (0, script_1.generateScript)({
177
+ const options = {
177
178
  ts,
178
179
  compilerOptions: ctx.compilerOptions,
179
180
  vueCompilerOptions: getResolvedOptions(),
@@ -185,22 +186,19 @@ function createTsx(fileName, sfc, ctx) {
185
186
  templateCodegen: getGeneratedTemplate(),
186
187
  destructuredPropNames: getSetupDestructuredPropNames(),
187
188
  templateRefNames: getSetupTemplateRefNames(),
188
- });
189
- let current = codegen.next();
190
- while (!current.done) {
191
- const code = current.value;
192
- codes.push(code);
193
- current = codegen.next();
194
- }
189
+ };
190
+ const context = (0, script_1.createScriptCodegenContext)(options);
191
+ const codegen = (0, script_1.generateScript)(options, context);
195
192
  return {
196
- ...current.value,
197
- codes,
193
+ ...context,
194
+ codes: [...codegen],
198
195
  };
199
196
  });
200
197
  return {
198
+ getLang,
201
199
  getScriptRanges,
202
200
  getScriptSetupRanges,
203
- getLang,
201
+ getSetupSlotsAssignName,
204
202
  getGeneratedScript,
205
203
  getGeneratedTemplate,
206
204
  };
package/lib/types.d.ts CHANGED
@@ -20,7 +20,7 @@ export type Code = Segment<VueCodeInformation>;
20
20
  export interface VueCompilerOptions {
21
21
  target: number;
22
22
  lib: string;
23
- globalTypesPath: (fileName: string) => string | undefined;
23
+ globalTypesPath: (fileName: string) => string | void;
24
24
  extensions: string[];
25
25
  vitePressExtensions: string[];
26
26
  petiteVueExtensions: string[];
@@ -0,0 +1,12 @@
1
+ import type * as ts from 'typescript';
2
+ export declare function collectBindingNames(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string[];
3
+ export declare function collectBindingRanges(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): import("../types").TextRange[];
4
+ export declare function collectBindingIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
5
+ id: ts.Identifier;
6
+ isRest: boolean;
7
+ initializer: ts.Expression | undefined;
8
+ }[], isRest?: boolean, initializer?: ts.Expression | undefined): {
9
+ id: ts.Identifier;
10
+ isRest: boolean;
11
+ initializer: ts.Expression | undefined;
12
+ }[];
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectBindingNames = collectBindingNames;
4
+ exports.collectBindingRanges = collectBindingRanges;
5
+ exports.collectBindingIdentifiers = collectBindingIdentifiers;
6
+ const shared_1 = require("./shared");
7
+ function collectBindingNames(ts, node, ast) {
8
+ return collectBindingIdentifiers(ts, node).map(({ id }) => (0, shared_1.getNodeText)(ts, id, ast));
9
+ }
10
+ function collectBindingRanges(ts, node, ast) {
11
+ return collectBindingIdentifiers(ts, node).map(({ id }) => (0, shared_1.getStartEnd)(ts, id, ast));
12
+ }
13
+ function collectBindingIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
14
+ if (ts.isIdentifier(node)) {
15
+ results.push({ id: node, isRest, initializer });
16
+ }
17
+ else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
18
+ for (const el of node.elements) {
19
+ if (ts.isBindingElement(el)) {
20
+ collectBindingIdentifiers(ts, el.name, results, !!el.dotDotDotToken, el.initializer);
21
+ }
22
+ }
23
+ }
24
+ else {
25
+ ts.forEachChild(node, node => collectBindingIdentifiers(ts, node, results, false));
26
+ }
27
+ return results;
28
+ }
29
+ //# sourceMappingURL=collectBindings.js.map
package/lib/utils/ts.js CHANGED
@@ -179,23 +179,25 @@ class CompilerOptionsResolver {
179
179
  // https://vuejs.org/guide/essentials/forms.html#form-input-bindings
180
180
  experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
181
181
  };
182
- if (this.fileExists && this.globalTypesPath === undefined) {
183
- const fileDirToGlobalTypesPath = new Map();
184
- resolvedOptions.globalTypesPath = fileName => {
185
- const fileDir = path_browserify_1.posix.dirname(fileName);
186
- if (fileDirToGlobalTypesPath.has(fileDir)) {
187
- return fileDirToGlobalTypesPath.get(fileDir);
188
- }
189
- const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
190
- const result = root
191
- ? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
192
- : undefined;
193
- fileDirToGlobalTypesPath.set(fileDir, result);
194
- return result;
195
- };
196
- }
197
- else {
198
- resolvedOptions.globalTypesPath = () => this.globalTypesPath;
182
+ if (resolvedOptions.globalTypesPath === shared_1.NOOP) {
183
+ if (this.fileExists && this.globalTypesPath === undefined) {
184
+ const fileDirToGlobalTypesPath = new Map();
185
+ resolvedOptions.globalTypesPath = fileName => {
186
+ const fileDir = path_browserify_1.posix.dirname(fileName);
187
+ if (fileDirToGlobalTypesPath.has(fileDir)) {
188
+ return fileDirToGlobalTypesPath.get(fileDir);
189
+ }
190
+ const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
191
+ const result = root
192
+ ? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
193
+ : undefined;
194
+ fileDirToGlobalTypesPath.set(fileDir, result);
195
+ return result;
196
+ };
197
+ }
198
+ else {
199
+ resolvedOptions.globalTypesPath = () => this.globalTypesPath;
200
+ }
199
201
  }
200
202
  return resolvedOptions;
201
203
  }
@@ -239,7 +241,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
239
241
  return {
240
242
  target,
241
243
  lib,
242
- globalTypesPath: () => undefined,
244
+ globalTypesPath: shared_1.NOOP,
243
245
  extensions: ['.vue'],
244
246
  vitePressExtensions: [],
245
247
  petiteVueExtensions: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "2.4.20",
16
+ "@volar/language-core": "2.4.22",
17
17
  "@vue/compiler-dom": "^3.5.0",
18
18
  "@vue/compiler-vue2": "^2.7.16",
19
19
  "@vue/shared": "^3.5.0",
@@ -26,7 +26,7 @@
26
26
  "@types/node": "^22.10.4",
27
27
  "@types/path-browserify": "^1.0.1",
28
28
  "@types/picomatch": "^4.0.0",
29
- "@volar/typescript": "2.4.20",
29
+ "@volar/typescript": "2.4.22",
30
30
  "@vue/compiler-sfc": "^3.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -37,5 +37,5 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
- "gitHead": "129f30ff8d8d976abf0431063be5c6c4cf88f0fd"
40
+ "gitHead": "036b6b1882179d35586e16f2a5cba5150e5d18e6"
41
41
  }