@vue/language-core 3.0.7-alpha.1 → 3.1.0-alpha.0

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 (54) hide show
  1. package/lib/codegen/globalTypes.js +19 -13
  2. package/lib/codegen/localTypes.d.ts +2 -4
  3. package/lib/codegen/localTypes.js +10 -33
  4. package/lib/codegen/script/component.d.ts +0 -3
  5. package/lib/codegen/script/component.js +15 -22
  6. package/lib/codegen/script/componentSelf.js +1 -1
  7. package/lib/codegen/script/context.d.ts +2 -4
  8. package/lib/codegen/script/index.d.ts +4 -6
  9. package/lib/codegen/script/index.js +70 -63
  10. package/lib/codegen/script/scriptSetup.js +142 -143
  11. package/lib/codegen/script/template.d.ts +1 -3
  12. package/lib/codegen/script/template.js +90 -16
  13. package/lib/codegen/template/context.js +1 -1
  14. package/lib/codegen/template/element.js +4 -6
  15. package/lib/codegen/template/elementProps.js +6 -11
  16. package/lib/codegen/template/index.d.ts +1 -1
  17. package/lib/codegen/template/index.js +12 -13
  18. package/lib/codegen/template/slotOutlet.js +2 -3
  19. package/lib/codegen/template/styleScopedClasses.js +1 -2
  20. package/lib/codegen/template/vFor.js +1 -1
  21. package/lib/codegen/template/vSlot.js +1 -1
  22. package/lib/codegen/tenp.d.ts +1 -0
  23. package/lib/codegen/tenp.js +3 -0
  24. package/lib/codegen/utils/index.d.ts +1 -0
  25. package/lib/codegen/utils/index.js +7 -0
  26. package/lib/compilerOptions.js +3 -8
  27. package/lib/languagePlugin.js +8 -19
  28. package/lib/parsers/scriptRanges.d.ts +0 -1
  29. package/lib/parsers/scriptRanges.js +6 -9
  30. package/lib/parsers/scriptSetupRanges.d.ts +0 -6
  31. package/lib/parsers/scriptSetupRanges.js +9 -95
  32. package/lib/parsers/utils.d.ts +12 -0
  33. package/lib/parsers/utils.js +95 -0
  34. package/lib/plugins/file-css.d.ts +3 -0
  35. package/lib/plugins/file-css.js +57 -0
  36. package/lib/plugins/vue-template-inline-ts.js +2 -3
  37. package/lib/plugins/vue-tsx.d.ts +2 -5
  38. package/lib/plugins/vue-tsx.js +16 -13
  39. package/lib/types.d.ts +1 -1
  40. package/lib/utils/parseCssClassNames.d.ts +4 -0
  41. package/lib/utils/parseCssClassNames.js +17 -0
  42. package/lib/utils/parseCssImports.d.ts +4 -0
  43. package/lib/utils/parseCssImports.js +19 -0
  44. package/lib/utils/parseCssVars.d.ts +6 -0
  45. package/lib/utils/parseCssVars.js +26 -0
  46. package/lib/utils/shared.d.ts +1 -2
  47. package/lib/utils/shared.js +0 -4
  48. package/lib/virtualFile/computedSfc.js +4 -4
  49. package/lib/virtualFile/vueFile.d.ts +5 -10
  50. package/lib/virtualFile/vueFile.js +3 -10
  51. package/package.json +2 -3
  52. package/lib/utils/ts.js +0 -296
  53. package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
  54. package/lib/utils/vue2TemplateCompiler.js +0 -90
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generate;
4
4
  exports.forEachElementNode = forEachElementNode;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
- const shared_1 = require("../../utils/shared");
7
6
  const codeFeatures_1 = require("../codeFeatures");
8
7
  const utils_1 = require("../utils");
9
8
  const wrapWith_1 = require("../utils/wrapWith");
@@ -33,9 +32,8 @@ function* generateTemplate(options, ctx) {
33
32
  if (options.propsAssignName) {
34
33
  ctx.addLocalVariable(options.propsAssignName);
35
34
  }
36
- const slotsPropertyName = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
37
35
  if (options.vueCompilerOptions.inferTemplateDollarSlots) {
38
- ctx.dollarVars.add(slotsPropertyName);
36
+ ctx.dollarVars.add('$slots');
39
37
  }
40
38
  if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
41
39
  ctx.dollarVars.add('$attrs');
@@ -51,17 +49,19 @@ function* generateTemplate(options, ctx) {
51
49
  }
52
50
  yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
53
51
  yield* ctx.generateHoistVariables();
54
- const speicalTypes = [
55
- [slotsPropertyName, yield* generateSlots(options, ctx)],
52
+ const dollarTypes = [
53
+ ['$slots', yield* generateSlots(options, ctx)],
56
54
  ['$attrs', yield* generateInheritedAttrs(options, ctx)],
57
55
  ['$refs', yield* generateTemplateRefs(options, ctx)],
58
56
  ['$el', yield* generateRootEl(ctx)],
59
- ];
60
- yield `var __VLS_dollars!: {${utils_1.newLine}`;
61
- for (const [name, type] of speicalTypes) {
62
- yield `${name}: ${type}${utils_1.endOfLine}`;
57
+ ].filter(([name]) => ctx.dollarVars.has(name));
58
+ if (dollarTypes.length) {
59
+ yield `var __VLS_dollars!: {${utils_1.newLine}`;
60
+ for (const [name, type] of dollarTypes) {
61
+ yield `${name}: ${type}${utils_1.endOfLine}`;
62
+ }
63
+ yield `} & { [K in keyof import('${options.vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
63
64
  }
64
- yield `} & { [K in keyof import('${options.vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
65
65
  }
66
66
  function* generateSlots(options, ctx) {
67
67
  if (!options.hasDefineSlots) {
@@ -79,7 +79,7 @@ function* generateSlots(options, ctx) {
79
79
  }
80
80
  yield `?: (props: typeof ${slot.propsVar}) => any }`;
81
81
  }
82
- yield `${utils_1.endOfLine}`;
82
+ yield utils_1.endOfLine;
83
83
  }
84
84
  return `__VLS_Slots`;
85
85
  }
@@ -160,8 +160,7 @@ function* forEachElementNode(node) {
160
160
  }
161
161
  else if (node.type === CompilerDOM.NodeTypes.IF) {
162
162
  // v-if / v-else-if / v-else
163
- for (let i = 0; i < node.branches.length; i++) {
164
- const branch = node.branches[i];
163
+ for (const branch of node.branches) {
165
164
  for (const childNode of branch.children) {
166
165
  yield* forEachElementNode(childNode);
167
166
  }
@@ -19,8 +19,7 @@ function* generateSlotOutlet(options, ctx, node) {
19
19
  if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
20
20
  return prop.name === 'name';
21
21
  }
22
- if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
23
- && prop.name === 'bind'
22
+ if (prop.name === 'bind'
24
23
  && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
25
24
  return prop.arg.content === 'name';
26
25
  }
@@ -48,7 +47,7 @@ function* generateSlotOutlet(options, ctx, node) {
48
47
  else {
49
48
  codes = [`['default']`];
50
49
  }
51
- yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}`, ...codes);
50
+ yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification, options.slotsAssignName ?? '__VLS_slots', ...codes);
52
51
  }
53
52
  else {
54
53
  yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `'default'`), `]`);
@@ -47,10 +47,9 @@ function collectStyleScopedClassReferences(options, ctx, node) {
47
47
  }
48
48
  }
49
49
  else {
50
- let isWrapped = false;
51
50
  const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
52
51
  if (content) {
53
- const classes = collectClasses(content, startOffset + (isWrapped ? 1 : 0));
52
+ const classes = collectClasses(content, startOffset);
54
53
  ctx.scopedClasses.push(...classes);
55
54
  }
56
55
  else {
@@ -40,7 +40,7 @@ function* generateVFor(options, ctx, node) {
40
40
  for (const argument of node.codegenNode?.children.arguments ?? []) {
41
41
  if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
42
42
  && argument.returns?.type === CompilerDOM.NodeTypes.VNODE_CALL
43
- && argument.returns?.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
43
+ && argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
44
44
  if (argument.returns.tag !== CompilerDOM.FRAGMENT) {
45
45
  isFragment = false;
46
46
  continue;
@@ -73,7 +73,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
73
73
  function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
74
74
  const { ts } = options;
75
75
  const statement = ast.statements[0];
76
- if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
76
+ if (!statement || !ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
77
77
  return;
78
78
  }
79
79
  const { expression } = statement;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=tenp.js.map
@@ -8,3 +8,4 @@ export declare const identifierRegex: RegExp;
8
8
  export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
9
9
  export declare function createTsAst(ts: typeof import('typescript'), inlineTsAsts: Map<string, ts.SourceFile> | undefined, text: string): ts.SourceFile;
10
10
  export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
11
+ export declare function generatePartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
@@ -4,6 +4,8 @@ exports.identifierRegex = exports.combineLastMapping = exports.endOfLine = expor
4
4
  exports.normalizeAttributeValue = normalizeAttributeValue;
5
5
  exports.createTsAst = createTsAst;
6
6
  exports.generateSfcBlockSection = generateSfcBlockSection;
7
+ exports.generatePartiallyEnding = generatePartiallyEnding;
8
+ const codeFeatures_1 = require("../codeFeatures");
7
9
  exports.newLine = `\n`;
8
10
  exports.endOfLine = `;${exports.newLine}`;
9
11
  exports.combineLastMapping = { __combineOffset: 1 };
@@ -35,4 +37,9 @@ function generateSfcBlockSection(block, start, end, features) {
35
37
  features,
36
38
  ];
37
39
  }
40
+ function* generatePartiallyEnding(source, end, mark, delimiter = 'debugger') {
41
+ yield delimiter;
42
+ yield [``, source, end, codeFeatures_1.codeFeatures.verification];
43
+ yield `/* PartiallyEnd: ${mark} */${exports.newLine}`;
44
+ }
38
45
  //# sourceMappingURL=index.js.map
@@ -245,9 +245,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
245
245
  ],
246
246
  dataAttributes: [],
247
247
  htmlAttributes: ['aria-*'],
248
- optionsWrapper: target >= 2.7
249
- ? [`(await import('${lib}')).defineComponent(`, `)`]
250
- : [`(await import('${lib}')).default.extend(`, `)`],
248
+ optionsWrapper: [`(await import('${lib}')).defineComponent(`, `)`],
251
249
  macros: {
252
250
  defineProps: ['defineProps'],
253
251
  defineSlots: ['defineSlots'],
@@ -277,13 +275,10 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
277
275
  };
278
276
  }
279
277
  function writeGlobalTypes(vueOptions, writeFile) {
280
- const originalFn = vueOptions.globalTypesPath;
281
- if (!originalFn) {
282
- return;
283
- }
284
278
  const writed = new Set();
279
+ const { globalTypesPath } = vueOptions;
285
280
  vueOptions.globalTypesPath = (fileName) => {
286
- const result = originalFn(fileName);
281
+ const result = globalTypesPath(fileName);
287
282
  if (result && !writed.has(result)) {
288
283
  writed.add(result);
289
284
  writeFile(result, (0, globalTypes_1.generateGlobalTypes)(vueOptions));
@@ -6,7 +6,6 @@ exports.getAllExtensions = getAllExtensions;
6
6
  const language_core_1 = require("@volar/language-core");
7
7
  const CompilerDOM = require("@vue/compiler-dom");
8
8
  const plugins_1 = require("./plugins");
9
- const CompilerVue2 = require("./utils/vue2TemplateCompiler");
10
9
  const vueFile_1 = require("./virtualFile/vueFile");
11
10
  const fileRegistries = [];
12
11
  function getVueFileRegistry(key, plugins) {
@@ -38,12 +37,7 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
38
37
  function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
39
38
  const pluginContext = {
40
39
  modules: {
41
- '@vue/compiler-dom': vueCompilerOptions.target < 3
42
- ? {
43
- ...CompilerDOM,
44
- compile: CompilerVue2.compile,
45
- }
46
- : CompilerDOM,
40
+ '@vue/compiler-dom': CompilerDOM,
47
41
  typescript: ts,
48
42
  },
49
43
  compilerOptions,
@@ -109,17 +103,12 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
109
103
  };
110
104
  }
111
105
  function getAllExtensions(options) {
112
- const result = new Set();
113
- for (const key in options) {
114
- if (key === 'extensions' || key.endsWith('Extensions')) {
115
- const value = options[key];
116
- if (Array.isArray(value) && value.every(v => typeof v === 'string')) {
117
- for (const ext of value) {
118
- result.add(ext);
119
- }
120
- }
121
- }
122
- }
123
- return [...result];
106
+ return [
107
+ ...new Set([
108
+ 'extensions',
109
+ 'vitePressExtensions',
110
+ 'petiteVueExtensions',
111
+ ].flatMap(key => options[key])),
112
+ ];
124
113
  }
125
114
  //# sourceMappingURL=languagePlugin.js.map
@@ -13,7 +13,6 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
13
13
  nameOption: TextRange | undefined;
14
14
  inheritAttrsOption: string | undefined;
15
15
  }) | undefined;
16
- classBlockEnd: number | undefined;
17
16
  bindings: {
18
17
  range: TextRange;
19
18
  moduleName?: string;
@@ -2,11 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptRanges = parseScriptRanges;
4
4
  const shared_1 = require("../utils/shared");
5
- const scriptSetupRanges_1 = require("./scriptSetupRanges");
5
+ const utils_1 = require("./utils");
6
6
  function parseScriptRanges(ts, ast, hasScriptSetup) {
7
7
  let exportDefault;
8
- let classBlockEnd;
9
- const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
8
+ const bindings = hasScriptSetup ? (0, utils_1.parseBindingRanges)(ts, ast) : [];
10
9
  ts.forEachChild(ast, raw => {
11
10
  if (ts.isExportAssignment(raw)) {
12
11
  let node = raw;
@@ -56,17 +55,15 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
56
55
  nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
57
56
  inheritAttrsOption,
58
57
  };
58
+ const comment = (0, utils_1.getClosestMultiLineCommentRange)(ts, raw, [], ast);
59
+ if (comment) {
60
+ exportDefault.start = comment.start;
61
+ }
59
62
  }
60
63
  }
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
- }
66
64
  });
67
65
  return {
68
66
  exportDefault,
69
- classBlockEnd,
70
67
  bindings,
71
68
  };
72
69
  function _getStartEnd(node) {
@@ -66,10 +66,4 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
66
66
  useSlots: CallExpressionRange[];
67
67
  useTemplateRef: UseTemplateRef[];
68
68
  };
69
- export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
70
- range: TextRange;
71
- moduleName?: string;
72
- isDefaultImport?: boolean;
73
- isNamespace?: boolean;
74
- }[];
75
69
  export {};
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptSetupRanges = parseScriptSetupRanges;
4
- exports.parseBindingRanges = parseBindingRanges;
5
4
  const collectBindings_1 = require("../utils/collectBindings");
6
5
  const shared_1 = require("../utils/shared");
7
- const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
6
+ const utils_1 = require("./utils");
7
+ const tsCheckReg = /^\/\/\s*@ts-(?:no)?check(?:$|\s)/;
8
8
  function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
9
9
  const defineModel = [];
10
10
  let defineProps;
@@ -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 = parseBindingRanges(ts, ast);
23
+ let bindings = (0, utils_1.parseBindingRanges)(ts, ast);
24
24
  let foundNonImportExportNode = false;
25
25
  let importSectionEndOffset = 0;
26
26
  ts.forEachChild(ast, node => {
@@ -134,7 +134,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
134
134
  runtimeType,
135
135
  defaultValue,
136
136
  required,
137
- comments: getClosestMultiLineCommentRange(ts, node, parents, ast),
137
+ comments: (0, utils_1.getClosestMultiLineCommentRange)(ts, node, parents, ast),
138
138
  argNode: options,
139
139
  });
140
140
  }
@@ -250,7 +250,9 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
250
250
  }
251
251
  function parseCallExpressionAssignment(node, parent) {
252
252
  return {
253
- name: ts.isVariableDeclaration(parent) ? _getNodeText(parent.name) : undefined,
253
+ name: ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)
254
+ ? _getNodeText(parent.name)
255
+ : undefined,
254
256
  ...parseCallExpression(node),
255
257
  };
256
258
  }
@@ -261,82 +263,11 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
261
263
  return (0, shared_1.getNodeText)(ts, node, ast);
262
264
  }
263
265
  }
264
- function parseBindingRanges(ts, ast) {
265
- const bindings = [];
266
- ts.forEachChild(ast, node => {
267
- if (ts.isVariableStatement(node)) {
268
- for (const decl of node.declarationList.declarations) {
269
- const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
270
- bindings.push(...ranges.map(range => ({ range })));
271
- }
272
- }
273
- else if (ts.isFunctionDeclaration(node)) {
274
- if (node.name && ts.isIdentifier(node.name)) {
275
- bindings.push({
276
- range: _getStartEnd(node.name),
277
- });
278
- }
279
- }
280
- else if (ts.isClassDeclaration(node)) {
281
- if (node.name) {
282
- bindings.push({
283
- range: _getStartEnd(node.name),
284
- });
285
- }
286
- }
287
- else if (ts.isEnumDeclaration(node)) {
288
- bindings.push({
289
- range: _getStartEnd(node.name),
290
- });
291
- }
292
- if (ts.isImportDeclaration(node)) {
293
- const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
294
- if (node.importClause && !node.importClause.isTypeOnly) {
295
- const { name, namedBindings } = node.importClause;
296
- if (name) {
297
- bindings.push({
298
- range: _getStartEnd(name),
299
- moduleName,
300
- isDefaultImport: true,
301
- });
302
- }
303
- if (namedBindings) {
304
- if (ts.isNamedImports(namedBindings)) {
305
- for (const element of namedBindings.elements) {
306
- if (element.isTypeOnly) {
307
- continue;
308
- }
309
- bindings.push({
310
- range: _getStartEnd(element.name),
311
- moduleName,
312
- isDefaultImport: element.propertyName?.text === 'default',
313
- });
314
- }
315
- }
316
- else {
317
- bindings.push({
318
- range: _getStartEnd(namedBindings.name),
319
- moduleName,
320
- isNamespace: true,
321
- });
322
- }
323
- }
324
- }
325
- }
326
- });
327
- return bindings;
328
- function _getStartEnd(node) {
329
- return (0, shared_1.getStartEnd)(ts, node, ast);
330
- }
331
- function _getNodeText(node) {
332
- return (0, shared_1.getNodeText)(ts, node, ast);
333
- }
334
- }
335
266
  function getStatementRange(ts, parents, node, ast) {
336
267
  let statementRange;
337
268
  for (let i = parents.length - 1; i >= 0; i--) {
338
- if (ts.isStatement(parents[i])) {
339
- const statement = parents[i];
269
+ const statement = parents[i];
270
+ if (ts.isStatement(statement)) {
340
271
  ts.forEachChild(statement, child => {
341
272
  const range = (0, shared_1.getStartEnd)(ts, child, ast);
342
273
  statementRange ??= range;
@@ -350,21 +281,4 @@ function getStatementRange(ts, parents, node, ast) {
350
281
  }
351
282
  return statementRange;
352
283
  }
353
- function getClosestMultiLineCommentRange(ts, node, parents, ast) {
354
- for (let i = parents.length - 1; i >= 0; i--) {
355
- if (ts.isStatement(node)) {
356
- break;
357
- }
358
- node = parents[i];
359
- }
360
- const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
361
- ?.reverse()
362
- .find(range => range.kind === 3);
363
- if (comment) {
364
- return {
365
- start: comment.pos,
366
- end: comment.end,
367
- };
368
- }
369
- }
370
284
  //# sourceMappingURL=scriptSetupRanges.js.map
@@ -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
@@ -59,7 +59,7 @@ const plugin = ctx => {
59
59
  return data;
60
60
  }
61
61
  const templateContent = sfc.template.content;
62
- const inlineTsAsts = sfc.template.ast && computedSfc_1.templateInlineTsAsts.get(sfc.template.ast);
62
+ const inlineTsAsts = computedSfc_1.templateInlineTsAsts.get(sfc.template.ast);
63
63
  let i = 0;
64
64
  sfc.template.ast.children.forEach(visit);
65
65
  return data;
@@ -120,8 +120,7 @@ const plugin = ctx => {
120
120
  }
121
121
  }
122
122
  else if (node.type === CompilerDOM.NodeTypes.IF) {
123
- for (let i = 0; i < node.branches.length; i++) {
124
- const branch = node.branches[i];
123
+ for (const branch of node.branches) {
125
124
  if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
126
125
  addFormatCodes(branch.condition.loc.source, branch.condition.loc.start.offset, formatBrackets.if);
127
126
  }
@@ -12,7 +12,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
12
12
  nameOption: import("../types").TextRange | undefined;
13
13
  inheritAttrsOption: string | undefined;
14
14
  }) | undefined;
15
- classBlockEnd: number | undefined;
16
15
  bindings: {
17
16
  range: import("../types").TextRange;
18
17
  moduleName?: string;
@@ -124,11 +123,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
124
123
  bypassDefineComponent: boolean;
125
124
  bindingNames: Set<string>;
126
125
  localTypes: {
127
- generate: (names: string[]) => Generator<string, void, unknown>;
128
- getUsedNames(): Set<string>;
126
+ generate: () => Generator<string, void, unknown>;
129
127
  readonly PrettifyLocal: string;
130
- readonly OmitKeepDiscriminatedUnion: string;
131
- readonly WithDefaults: string;
128
+ readonly WithDefaultsLocal: string;
132
129
  readonly WithSlots: string;
133
130
  readonly PropsChildren: string;
134
131
  readonly TypePropsToOption: string;