@vue/language-core 3.3.4 → 3.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/lib/codegen/codeFeatures.d.ts +24 -84
  4. package/lib/codegen/codeFeatures.js +46 -4
  5. package/lib/codegen/names.d.ts +4 -5
  6. package/lib/codegen/names.js +4 -5
  7. package/lib/codegen/script/index.js +5 -5
  8. package/lib/codegen/script/scriptSetup.js +4 -4
  9. package/lib/codegen/style/common.js +7 -11
  10. package/lib/codegen/style/index.d.ts +55 -27
  11. package/lib/codegen/style/index.js +3 -3
  12. package/lib/codegen/template/context.d.ts +55 -124
  13. package/lib/codegen/template/context.js +187 -269
  14. package/lib/codegen/template/element.js +16 -15
  15. package/lib/codegen/template/elementDirectives.js +11 -11
  16. package/lib/codegen/template/elementEvents.js +76 -73
  17. package/lib/codegen/template/elementProps.js +12 -12
  18. package/lib/codegen/template/index.d.ts +55 -27
  19. package/lib/codegen/template/index.js +7 -7
  20. package/lib/codegen/template/interpolation.js +28 -28
  21. package/lib/codegen/template/objectProperty.js +5 -5
  22. package/lib/codegen/template/propertyAccess.js +1 -1
  23. package/lib/codegen/template/slotOutlet.js +8 -10
  24. package/lib/codegen/template/styleScopedClasses.js +4 -4
  25. package/lib/codegen/template/vFor.js +3 -3
  26. package/lib/codegen/template/vIf.js +4 -4
  27. package/lib/codegen/template/vSlot.js +9 -9
  28. package/lib/codegen/utils/boundary.d.ts +7 -2
  29. package/lib/codegen/utils/boundary.js +15 -9
  30. package/lib/codegen/utils/camelized.js +5 -13
  31. package/lib/codegen/utils/escaped.js +4 -9
  32. package/lib/codegen/utils/index.d.ts +1 -1
  33. package/lib/codegen/utils/index.js +3 -3
  34. package/lib/codegen/utils/stringLiteralKey.js +3 -3
  35. package/lib/codegen/utils/unicode.d.ts +1 -1
  36. package/lib/codegen/utils/unicode.js +4 -4
  37. package/lib/languagePlugin.js +2 -1
  38. package/lib/parsers/scriptRanges.d.ts +2 -2
  39. package/lib/parsers/scriptRanges.js +3 -10
  40. package/lib/parsers/scriptSetupRanges.d.ts +2 -2
  41. package/lib/parsers/scriptSetupRanges.js +3 -10
  42. package/lib/parsers/utils.d.ts +1 -0
  43. package/lib/parsers/utils.js +10 -0
  44. package/lib/parsers/vueCompilerOptions.js +2 -2
  45. package/lib/plugins/file-html.js +4 -4
  46. package/lib/plugins/file-md.js +15 -15
  47. package/lib/plugins/file-vue.js +2 -2
  48. package/lib/plugins/vue-root-tags.js +3 -3
  49. package/lib/plugins/vue-sfc-customblocks.js +2 -2
  50. package/lib/plugins/vue-sfc-scripts.js +2 -4
  51. package/lib/plugins/vue-sfc-styles.js +3 -3
  52. package/lib/plugins/vue-sfc-template.js +2 -2
  53. package/lib/plugins/vue-style-css.js +86 -33
  54. package/lib/plugins/vue-template-html.js +3 -3
  55. package/lib/plugins/vue-template-inline-css.js +2 -7
  56. package/lib/plugins/vue-template-inline-ts.js +4 -5
  57. package/lib/plugins/vue-tsx.d.ts +61 -31
  58. package/lib/plugins/vue-tsx.js +26 -23
  59. package/lib/plugins.d.ts +0 -1
  60. package/lib/plugins.js +0 -15
  61. package/lib/utils/forEachTemplateNode.js +36 -43
  62. package/lib/virtualCode/index.js +2 -2
  63. package/package.json +2 -2
  64. package/types/template-helpers.d.ts +15 -25
  65. package/lib/plugins/shared.d.ts +0 -2
  66. package/lib/plugins/shared.js +0 -12
@@ -77,26 +77,26 @@ function* generateSlotOutlet(options, ctx, node) {
77
77
  else {
78
78
  codes = [`['default']`];
79
79
  }
80
- const token = yield* (0, boundary_1.startBoundary)('template', nameProp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
80
+ const boundary = yield* boundary_1.Boundary.start('template', nameProp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
81
81
  yield options.slotsAssignName ?? names_1.names.slots;
82
82
  yield* codes;
83
- yield (0, boundary_1.endBoundary)(token, nameProp.loc.end.offset);
83
+ yield boundary.end(nameProp.loc.end.offset);
84
84
  }
85
85
  else {
86
- const token = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
86
+ const boundary = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
87
87
  yield `${options.slotsAssignName ?? names_1.names.slots}[`;
88
- const token2 = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
88
+ const boundary2 = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
89
89
  yield `'default'`;
90
- yield (0, boundary_1.endBoundary)(token2, startTagEndOffset);
90
+ yield boundary2.end(startTagEndOffset);
91
91
  yield `]`;
92
- yield (0, boundary_1.endBoundary)(token, startTagEndOffset);
92
+ yield boundary.end(startTagEndOffset);
93
93
  }
94
94
  yield `)(`;
95
- const token = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
95
+ const boundary = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
96
96
  yield `{${utils_1.newLine}`;
97
97
  yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
98
98
  yield `}`;
99
- yield (0, boundary_1.endBoundary)(token, startTagEndOffset);
99
+ yield boundary.end(startTagEndOffset);
100
100
  yield `)${utils_1.endOfLine}`;
101
101
  }
102
102
  else {
@@ -109,7 +109,6 @@ function* generateSlotOutlet(options, ctx, node) {
109
109
  name: nameProp.value.content,
110
110
  offset: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
111
111
  tagRange: [startTagOffset, startTagOffset + node.tag.length],
112
- nodeLoc: node.loc,
113
112
  propsVar: ctx.getHoistVariable(propsVar),
114
113
  });
115
114
  }
@@ -134,7 +133,6 @@ function* generateSlotOutlet(options, ctx, node) {
134
133
  ctx.slots.push({
135
134
  name: 'default',
136
135
  tagRange: [startTagOffset, startTagEndOffset],
137
- nodeLoc: node.loc,
138
136
  propsVar: ctx.getHoistVariable(propsVar),
139
137
  });
140
138
  }
@@ -7,7 +7,7 @@ const names_1 = require("../names");
7
7
  const utils_1 = require("../utils");
8
8
  const boundary_1 = require("../utils/boundary");
9
9
  const escaped_1 = require("../utils/escaped");
10
- const classNameEscapeRegex = /([\\'])/;
10
+ const classNameEscapeRE = /([\\'])/;
11
11
  // For language-service/lib/plugins/vue-scoped-class-links.ts usage
12
12
  exports.references = new WeakMap();
13
13
  function* generateStyleScopedClassReference(block, className, offset, fullStart = offset) {
@@ -27,11 +27,11 @@ function* generateStyleScopedClassReference(block, className, offset, fullStart
27
27
  cache[1].push([className, offset]);
28
28
  }
29
29
  yield `/** @type {${names_1.names.StyleScopedClasses}[`;
30
- const token = yield* (0, boundary_1.startBoundary)(block.name, fullStart, codeFeatures_1.codeFeatures.navigation);
30
+ const boundary = yield* boundary_1.Boundary.start(block.name, fullStart, codeFeatures_1.codeFeatures.navigationAndCompletion);
31
31
  yield `'`;
32
- yield* (0, escaped_1.generateEscaped)(className, block.name, offset, codeFeatures_1.codeFeatures.navigationAndCompletion, classNameEscapeRegex);
32
+ yield* (0, escaped_1.generateEscaped)(className, block.name, offset, boundary.features, classNameEscapeRE);
33
33
  yield `'`;
34
- yield (0, boundary_1.endBoundary)(token, offset + className.length);
34
+ yield boundary.end(offset + className.length);
35
35
  yield `]} */${utils_1.endOfLine}`;
36
36
  }
37
37
  //# sourceMappingURL=styleScopedClasses.js.map
@@ -45,11 +45,11 @@ const templateChild_1 = require("./templateChild");
45
45
  function* generateVFor(options, ctx, node) {
46
46
  const { source } = node.parseResult;
47
47
  const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
48
- const endScope = ctx.startScope();
48
+ const scope = ctx.scope();
49
49
  yield `for (const [`;
50
50
  if (leftExpressionRange && leftExpressionText) {
51
51
  const collectAst = (0, utils_1.getTypeScriptAST)(options.typescript, options.template, `const [${leftExpressionText}]`);
52
- ctx.declare(...(0, collectBindings_1.collectBindingNames)(options.typescript, collectAst, collectAst));
52
+ scope.declare(...(0, collectBindings_1.collectBindingNames)(options.typescript, collectAst, collectAst));
53
53
  yield [
54
54
  leftExpressionText,
55
55
  'template',
@@ -73,7 +73,7 @@ function* generateVFor(options, ctx, node) {
73
73
  yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child, false, true);
74
74
  }
75
75
  ctx.inVFor = inVFor;
76
- yield* endScope();
76
+ yield* scope.end();
77
77
  yield `}${utils_1.newLine}`;
78
78
  }
79
79
  function parseVForNode(node) {
@@ -41,7 +41,7 @@ const utils_1 = require("../utils");
41
41
  const interpolation_1 = require("./interpolation");
42
42
  const templateChild_1 = require("./templateChild");
43
43
  function* generateVIf(options, ctx, node) {
44
- const originalBlockConditionsLength = ctx.blockConditions.length;
44
+ const originalBlockConditionsLength = ctx.conditions.length;
45
45
  for (let i = 0; i < node.branches.length; i++) {
46
46
  const branch = node.branches[i];
47
47
  if (i === 0) {
@@ -57,7 +57,7 @@ function* generateVIf(options, ctx, node) {
57
57
  if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
58
58
  const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, `(`, `)`)];
59
59
  yield* codes;
60
- ctx.blockConditions.push((0, muggle_string_1.toString)(codes));
60
+ ctx.conditions.push((0, muggle_string_1.toString)(codes));
61
61
  addedBlockCondition = true;
62
62
  yield ` `;
63
63
  }
@@ -67,9 +67,9 @@ function* generateVIf(options, ctx, node) {
67
67
  }
68
68
  yield `}${utils_1.newLine}`;
69
69
  if (addedBlockCondition) {
70
- ctx.blockConditions[ctx.blockConditions.length - 1] = `!${ctx.blockConditions[ctx.blockConditions.length - 1]}`;
70
+ ctx.conditions[ctx.conditions.length - 1] = `!${ctx.conditions[ctx.conditions.length - 1]}`;
71
71
  }
72
72
  }
73
- ctx.blockConditions.length = originalBlockConditionsLength;
73
+ ctx.conditions.length = originalBlockConditionsLength;
74
74
  }
75
75
  //# sourceMappingURL=vIf.js.map
@@ -53,29 +53,29 @@ function* generateVSlot(options, ctx, node, slotDir, ctxVar) {
53
53
  yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? codeFeatures_1.codeFeatures.withoutHighlight : codeFeatures_1.codeFeatures.all, false, true);
54
54
  }
55
55
  else {
56
- const token = yield* (0, boundary_1.startBoundary)('template', slotDir.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
56
+ const boundary = yield* boundary_1.Boundary.start('template', slotDir.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
57
57
  yield `default`;
58
- yield (0, boundary_1.endBoundary)(token, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0));
58
+ yield boundary.end(slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0));
59
59
  }
60
60
  }
61
61
  else {
62
62
  yield `const { `;
63
63
  // #932: reference for implicit default slot
64
- const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.navigation);
64
+ const boundary = yield* boundary_1.Boundary.start('template', node.loc.start.offset, codeFeatures_1.codeFeatures.navigation);
65
65
  yield `default`;
66
- yield (0, boundary_1.endBoundary)(token, node.loc.end.offset);
66
+ yield boundary.end(node.loc.end.offset);
67
67
  }
68
68
  yield `: ${slotVar} } = ${ctxVar}.slots!${utils_1.endOfLine}`;
69
- const endScope = ctx.startScope();
69
+ const scope = ctx.scope();
70
70
  if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
71
71
  const slotAst = (0, utils_1.getTypeScriptAST)(options.typescript, options.template, `(${slotDir.exp.content}) => {}`);
72
72
  yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
73
- ctx.declare(...(0, collectBindings_1.collectBindingNames)(options.typescript, slotAst, slotAst));
73
+ scope.declare(...(0, collectBindings_1.collectBindingNames)(options.typescript, slotAst, slotAst));
74
74
  }
75
75
  for (const child of node.children) {
76
76
  yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
77
77
  }
78
- yield* endScope();
78
+ yield* scope.end();
79
79
  if (slotDir) {
80
80
  let isStatic = true;
81
81
  if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
@@ -129,11 +129,11 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
129
129
  yield `] = ${names_1.names.vSlot}(${slotVar}!`;
130
130
  if (types.some(t => t)) {
131
131
  yield `, `;
132
- const token = yield* (0, boundary_1.startBoundary)('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
132
+ const boundary = yield* boundary_1.Boundary.start('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
133
133
  yield `(`;
134
134
  yield* types.flatMap(type => type ? [`_`, type, `, `] : `_, `);
135
135
  yield `) => [] as any`;
136
- yield (0, boundary_1.endBoundary)(token, exp.loc.end.offset);
136
+ yield boundary.end(exp.loc.end.offset);
137
137
  }
138
138
  yield `)${utils_1.endOfLine}`;
139
139
  }
@@ -1,3 +1,8 @@
1
1
  import type { Code, VueCodeInformation } from '../../types';
2
- export declare function startBoundary(source: string, startOffset: number, features: VueCodeInformation): Generator<Code, symbol, unknown>;
3
- export declare function endBoundary(token: symbol, endOffset: number): Code;
2
+ export declare class Boundary {
3
+ source: string;
4
+ features: VueCodeInformation;
5
+ private constructor();
6
+ static start(source: string, offset: number, features: VueCodeInformation): Generator<Code, Boundary>;
7
+ end(offset: number): Code;
8
+ }
@@ -1,13 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startBoundary = startBoundary;
4
- exports.endBoundary = endBoundary;
5
- function* startBoundary(source, startOffset, features) {
6
- const token = Symbol(source);
7
- yield ['', source, startOffset, { ...features, __combineToken: token }];
8
- return token;
9
- }
10
- function endBoundary(token, endOffset) {
11
- return ['', token.description, endOffset, { __combineToken: token }];
3
+ exports.Boundary = void 0;
4
+ class Boundary {
5
+ constructor(source, features) {
6
+ this.source = source;
7
+ this.features = features;
8
+ }
9
+ static *start(source, offset, features) {
10
+ features = { ...features, __combineToken: Symbol() };
11
+ yield [``, source, offset, features];
12
+ return new Boundary(source, features);
13
+ }
14
+ end(offset) {
15
+ return [``, this.source, offset, this.features];
16
+ }
12
17
  }
18
+ exports.Boundary = Boundary;
13
19
  //# sourceMappingURL=boundary.js.map
@@ -4,25 +4,17 @@ exports.generateCamelized = generateCamelized;
4
4
  const shared_1 = require("@vue/shared");
5
5
  function* generateCamelized(code, source, offset, features) {
6
6
  const parts = code.split('-');
7
- const combineToken = features.__combineToken ?? Symbol();
7
+ if (!features.__combineToken) {
8
+ features = { ...features, __combineToken: Symbol() };
9
+ }
8
10
  for (let i = 0; i < parts.length; i++) {
9
11
  const part = parts[i];
10
12
  if (part !== '') {
11
13
  if (i === 0) {
12
- yield [
13
- part,
14
- source,
15
- offset,
16
- { ...features, __combineToken: combineToken },
17
- ];
14
+ yield [part, source, offset, features];
18
15
  }
19
16
  else {
20
- yield [
21
- (0, shared_1.capitalize)(part),
22
- source,
23
- offset,
24
- { __combineToken: combineToken },
25
- ];
17
+ yield [(0, shared_1.capitalize)(part), source, offset, features];
26
18
  }
27
19
  }
28
20
  offset += part.length + 1;
@@ -3,21 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateEscaped = generateEscaped;
4
4
  function* generateEscaped(text, source, offset, features, escapeTarget) {
5
5
  const parts = text.split(escapeTarget);
6
- const combineToken = features.__combineToken ?? Symbol();
6
+ if (!features.__combineToken) {
7
+ features = { ...features, __combineToken: Symbol() };
8
+ }
7
9
  let isEscapeTarget = false;
8
10
  for (let i = 0; i < parts.length; i++) {
9
11
  const part = parts[i];
10
12
  if (isEscapeTarget) {
11
13
  yield `\\`;
12
14
  }
13
- yield [
14
- part,
15
- source,
16
- offset,
17
- i === 0
18
- ? { ...features, __combineToken: combineToken }
19
- : { __combineToken: combineToken },
20
- ];
15
+ yield [part, source, offset, features];
21
16
  offset += part.length;
22
17
  isEscapeTarget = !isEscapeTarget;
23
18
  }
@@ -2,7 +2,7 @@ import type * as ts from 'typescript';
2
2
  import type { Code, IRBlock, IRScript, IRScriptSetup, VueCodeInformation } from '../../types';
3
3
  export declare const newLine = "\n";
4
4
  export declare const endOfLine = ";\n";
5
- export declare const identifierRegex: RegExp;
5
+ export declare const identifierRE: RegExp;
6
6
  export declare function getTypeScriptAST(ts: typeof import('typescript'), block: IRBlock, text: string): ts.SourceFile;
7
7
  export declare function generateSfcBlockSection(block: IRScript | IRScriptSetup, start: number, end: number, features: VueCodeInformation): Generator<Code>;
8
8
  export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.identifierRegex = exports.endOfLine = exports.newLine = void 0;
3
+ exports.identifierRE = exports.endOfLine = exports.newLine = void 0;
4
4
  exports.getTypeScriptAST = getTypeScriptAST;
5
5
  exports.generateSfcBlockSection = generateSfcBlockSection;
6
6
  exports.forEachNode = forEachNode;
7
7
  const codeFeatures_1 = require("../codeFeatures");
8
8
  exports.newLine = `\n`;
9
9
  exports.endOfLine = `;${exports.newLine}`;
10
- exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
11
- const cacheMaps = new Map();
10
+ exports.identifierRE = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
11
+ const cacheMaps = new WeakMap();
12
12
  function getTypeScriptAST(ts, block, text) {
13
13
  if (!cacheMaps.has(block)) {
14
14
  cacheMaps.set(block, [block.content, new Map()]);
@@ -7,11 +7,11 @@ function* generateStringLiteralKey(code, offset, info) {
7
7
  yield `'${code}'`;
8
8
  }
9
9
  else {
10
- const token = yield* (0, boundary_1.startBoundary)('template', offset, info);
10
+ const boundary = yield* boundary_1.Boundary.start('template', offset, info);
11
11
  yield `'`;
12
- yield [code, 'template', offset, { __combineToken: token }];
12
+ yield [code, 'template', offset, boundary.features];
13
13
  yield `'`;
14
- yield (0, boundary_1.endBoundary)(token, offset + code.length);
14
+ yield boundary.end(offset + code.length);
15
15
  }
16
16
  }
17
17
  //# sourceMappingURL=stringLiteralKey.js.map
@@ -1,2 +1,2 @@
1
1
  import type { Code, VueCodeInformation } from '../../types';
2
- export declare function generateUnicode(code: string, offset: number, info: VueCodeInformation): Generator<Code>;
2
+ export declare function generateUnicode(code: string, offset: number, features: VueCodeInformation): Generator<Code>;
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateUnicode = generateUnicode;
4
4
  const boundary_1 = require("./boundary");
5
- function* generateUnicode(code, offset, info) {
5
+ function* generateUnicode(code, offset, features) {
6
6
  if (needToUnicode(code)) {
7
- const token = yield* (0, boundary_1.startBoundary)('template', offset, info);
7
+ const boundary = yield* boundary_1.Boundary.start('template', offset, features);
8
8
  yield toUnicode(code);
9
- yield (0, boundary_1.endBoundary)(token, offset + code.length);
9
+ yield boundary.end(offset + code.length);
10
10
  }
11
11
  else {
12
- yield [code, 'template', offset, info];
12
+ yield [code, 'template', offset, features];
13
13
  }
14
14
  }
15
15
  function needToUnicode(str) {
@@ -40,6 +40,7 @@ const language_core_1 = require("@volar/language-core");
40
40
  const CompilerDOM = __importStar(require("@vue/compiler-dom"));
41
41
  const LanguageCore = __importStar(require("../index"));
42
42
  const plugins_1 = require("./plugins");
43
+ const vue_tsx_1 = require("./plugins/vue-tsx");
43
44
  const virtualCode_1 = require("./virtualCode");
44
45
  const fileRegistries = {};
45
46
  function getVueFileRegistry(compilerOptions, vueCompilerOptions, plugins) {
@@ -111,7 +112,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
111
112
  })),
112
113
  getServiceScript(root) {
113
114
  for (const code of (0, language_core_1.forEachEmbeddedCode)(root)) {
114
- if (/script_(js|jsx|ts|tsx)/.test(code.id)) {
115
+ if (vue_tsx_1.serviceScriptRE.test(code.id)) {
115
116
  const lang = code.id.slice('script_'.length);
116
117
  return {
117
118
  code,
@@ -3,6 +3,8 @@ import type { TextRange, VueCompilerOptions } from '../types';
3
3
  export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
4
4
  }
5
5
  export declare function parseScriptRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
6
+ bindings: TextRange<ts.Node>[];
7
+ components: TextRange<ts.Node>[];
6
8
  exportDefault: (TextRange<ts.Node> & {
7
9
  expression: TextRange<ts.Expression>;
8
10
  isObjectLiteral: boolean;
@@ -16,8 +18,6 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), sourc
16
18
  inheritAttrs: string | undefined;
17
19
  };
18
20
  }) | undefined;
19
- bindings: TextRange<ts.Node>[];
20
- components: TextRange<ts.Node>[];
21
21
  };
22
22
  export declare function parseOptionsFromExtression(ts: typeof import('typescript'), exp: ts.Node, sourceFile: ts.SourceFile): {
23
23
  isObjectLiteral: boolean;
@@ -6,7 +6,6 @@ const shared_1 = require("../utils/shared");
6
6
  const utils_1 = require("./utils");
7
7
  function parseScriptRanges(ts, sourceFile, vueCompilerOptions) {
8
8
  let exportDefault;
9
- const { bindings, components } = (0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions);
10
9
  ts.forEachChild(sourceFile, child => {
11
10
  if (ts.isExportAssignment(child)) {
12
11
  exportDefault = {
@@ -22,16 +21,14 @@ function parseScriptRanges(ts, sourceFile, vueCompilerOptions) {
22
21
  }
23
22
  });
24
23
  return {
24
+ ...(0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions),
25
25
  exportDefault,
26
- bindings,
27
- components,
28
26
  };
29
27
  }
30
28
  function parseOptionsFromExtression(ts, exp, sourceFile) {
31
29
  let obj;
32
- while (isAsExpression(ts, exp) || ts.isParenthesizedExpression(exp)) { // fix https://github.com/vuejs/language-tools/issues/1882
33
- exp = exp.expression;
34
- }
30
+ // #1882
31
+ exp = (0, utils_1.getUnwrappedExpression)(ts, exp);
35
32
  if (ts.isObjectLiteralExpression(exp)) {
36
33
  obj = exp;
37
34
  }
@@ -83,8 +80,4 @@ function parseOptionsFromExtression(ts, exp, sourceFile) {
83
80
  return (0, shared_1.getNodeText)(ts, node, sourceFile);
84
81
  }
85
82
  }
86
- // isAsExpression is missing in tsc
87
- function isAsExpression(ts, node) {
88
- return node.kind === ts.SyntaxKind.AsExpression;
89
- }
90
83
  //# sourceMappingURL=scriptRanges.js.map
@@ -42,10 +42,10 @@ export interface UseTemplateRef extends CallExpressionRange {
42
42
  export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> {
43
43
  }
44
44
  export declare function parseScriptSetupRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
45
- leadingCommentEndOffset: number;
46
- importSectionEndOffset: number;
47
45
  bindings: TextRange<ts.Node>[];
48
46
  components: TextRange<ts.Node>[];
47
+ leadingCommentEndOffset: number;
48
+ importSectionEndOffset: number;
49
49
  defineModel: DefineModel[];
50
50
  defineProps: DefineProps | undefined;
51
51
  withDefaults: CallExpressionRange | undefined;
@@ -4,7 +4,7 @@ exports.parseScriptSetupRanges = parseScriptSetupRanges;
4
4
  const collectBindings_1 = require("../utils/collectBindings");
5
5
  const shared_1 = require("../utils/shared");
6
6
  const utils_1 = require("./utils");
7
- const tsCheckReg = /^\/\/\s*@ts-(?:no)?check(?:$|\s)/;
7
+ const tsCheckRE = /^\/\/\s*@ts-(?:no)?check(?:$|\s)/;
8
8
  function parseScriptSetupRanges(ts, sourceFile, vueCompilerOptions) {
9
9
  const defineModel = [];
10
10
  let defineProps;
@@ -19,8 +19,7 @@ function parseScriptSetupRanges(ts, sourceFile, vueCompilerOptions) {
19
19
  const useTemplateRef = [];
20
20
  const text = sourceFile.text;
21
21
  const leadingCommentRanges = ts.getLeadingCommentRanges(text, 0)?.reverse() ?? [];
22
- const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckReg.test(text.slice(range.pos, range.end)))?.end ?? 0;
23
- let { bindings, components } = (0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions);
22
+ const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckRE.test(text.slice(range.pos, range.end)))?.end ?? 0;
24
23
  let foundNonImportExportNode = false;
25
24
  let importSectionEndOffset = 0;
26
25
  ts.forEachChild(sourceFile, node => {
@@ -47,16 +46,10 @@ function parseScriptSetupRanges(ts, sourceFile, vueCompilerOptions) {
47
46
  foundNonImportExportNode = true;
48
47
  });
49
48
  ts.forEachChild(sourceFile, node => visitNode(node, [sourceFile]));
50
- const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
51
- bindings = bindings.filter(range => {
52
- const name = text.slice(range.start, range.end);
53
- return !templateRefNames.has(name);
54
- });
55
49
  return {
50
+ ...(0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions),
56
51
  leadingCommentEndOffset,
57
52
  importSectionEndOffset,
58
- bindings,
59
- components,
60
53
  defineModel,
61
54
  defineProps,
62
55
  withDefaults,
@@ -5,3 +5,4 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
5
5
  components: TextRange<ts.Node>[];
6
6
  };
7
7
  export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): TextRange | undefined;
8
+ export declare function getUnwrappedExpression(ts: typeof import('typescript'), node: ts.Node): ts.Node;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseBindingRanges = parseBindingRanges;
4
4
  exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
5
+ exports.getUnwrappedExpression = getUnwrappedExpression;
5
6
  const collectBindings_1 = require("../utils/collectBindings");
6
7
  const shared_1 = require("../utils/shared");
7
8
  function parseBindingRanges(ts, ast, componentExtsensions) {
@@ -91,4 +92,13 @@ function getClosestMultiLineCommentRange(ts, node, parents, ast) {
91
92
  };
92
93
  }
93
94
  }
95
+ function getUnwrappedExpression(ts, node) {
96
+ while (ts.isParenthesizedExpression(node)
97
+ || ts.isAssertionExpression(node)
98
+ || ts.isNonNullExpression(node)
99
+ || ts.isSatisfiesExpression(node)) {
100
+ node = node.expression;
101
+ }
102
+ return node;
103
+ }
94
104
  //# sourceMappingURL=utils.js.map
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseVueCompilerOptions = parseVueCompilerOptions;
4
- const syntaxReg = /^\s*@(?<key>.+?)\s+(?<value>.+?)\s*$/m;
4
+ const syntaxRE = /^\s*@(?<key>.+?)\s+(?<value>.+?)\s*$/m;
5
5
  function parseVueCompilerOptions(comments) {
6
6
  const entries = comments
7
7
  .map(text => {
8
8
  try {
9
- const match = text.match(syntaxReg);
9
+ const match = text.match(syntaxRE);
10
10
  if (match) {
11
11
  const { key, value } = match.groups ?? {};
12
12
  return [key, JSON.parse(value)];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const sfcBlockReg = /<(script|style)\b([\s\S]*?)>([\s\S]*?)<\/\1>/g;
4
- const langReg = /\blang\s*=\s*(['"]?)(\S*)\b\1/;
3
+ const sfcBlockRE = /<(script|style)\b([\s\S]*?)>([\s\S]*?)<\/\1>/g;
4
+ const langRE = /\blang\s*=\s*(['"]?)(\S*)\b\1/;
5
5
  const plugin = ({ vueCompilerOptions }) => {
6
6
  return {
7
7
  version: 2.2,
@@ -34,11 +34,11 @@ const plugin = ({ vueCompilerOptions }) => {
34
34
  errors: [],
35
35
  };
36
36
  let templateContent = content;
37
- for (const match of content.matchAll(sfcBlockReg)) {
37
+ for (const match of content.matchAll(sfcBlockRE)) {
38
38
  const matchText = match[0];
39
39
  const tag = match[1];
40
40
  const attrs = match[2];
41
- const lang = attrs.match(langReg)?.[2];
41
+ const lang = attrs.match(langRE)?.[2];
42
42
  const content = match[3];
43
43
  const contentStart = match.index + matchText.indexOf(content);
44
44
  if (tag === 'style') {
@@ -4,14 +4,14 @@ const language_core_1 = require("@volar/language-core");
4
4
  const muggle_string_1 = require("muggle-string");
5
5
  const buildMappings_1 = require("../utils/buildMappings");
6
6
  const parseSfc_1 = require("../utils/parseSfc");
7
- const frontmatterReg = /^---[\s\S]*?\n---(?:\r?\n|$)/;
8
- const codeblockReg = /(`{3}|\${2})[\s\S]+?\1/g;
9
- const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
10
- const sfcBlockReg = /<(script|style)\b[^>]*>([\s\S]*?)<\/\1>/g;
11
- const htmlTagReg = /(?<=<\/?)([a-z][a-z0-9-]*)\b[^>]*(?=>)/gi;
12
- const interpolationReg = /(?<=\{\{)[\s\S]*?(?=\}\})/g;
13
- const inlineCodeReg = /(`{1,2})[^`]+\1/g;
14
- const angleBracketReg = /<[^\s:]*:\S*>/g;
7
+ const frontmatterRE = /^---[\s\S]*?\n---(?:\r?\n|$)/;
8
+ const codeblockRE = /(`{3}|\${2})[\s\S]+?\1/g;
9
+ const codeSnippetImportRE = /^\s*<<<\s*.+/gm;
10
+ const sfcBlockRE = /<(script|style)\b[^>]*>([\s\S]*?)<\/\1>/g;
11
+ const htmlTagRE = /(?<=<\/?)([a-z][a-z0-9-]*)\b[^>]*(?=>)/gi;
12
+ const interpolationRE = /(?<=\{\{)[\s\S]*?(?=\}\})/g;
13
+ const inlineCodeRE = /(`{1,2})[^`]+\1/g;
14
+ const angleBracketRE = /<[^\s:]*:\S*>/g;
15
15
  const plugin = ({ vueCompilerOptions }) => {
16
16
  return {
17
17
  version: 2.2,
@@ -27,23 +27,23 @@ const plugin = ({ vueCompilerOptions }) => {
27
27
  if (languageId !== 'markdown') {
28
28
  return;
29
29
  }
30
- for (const reg of [frontmatterReg, codeblockReg, codeSnippetImportReg]) {
31
- content = content.replace(reg, match => ' '.repeat(match.length));
30
+ for (const pattern of [frontmatterRE, codeblockRE, codeSnippetImportRE]) {
31
+ content = content.replace(pattern, match => ' '.repeat(match.length));
32
32
  }
33
33
  const codes = [];
34
- for (const { 0: text, index } of content.matchAll(sfcBlockReg)) {
34
+ for (const { 0: text, index } of content.matchAll(sfcBlockRE)) {
35
35
  codes.push([text, undefined, index]);
36
36
  codes.push('\n\n');
37
37
  content = content.slice(0, index) + ' '.repeat(text.length) + content.slice(index + text.length);
38
38
  }
39
39
  const ranges = [];
40
- for (const reg of [htmlTagReg, interpolationReg]) {
41
- for (const { 0: text, index } of content.matchAll(reg)) {
40
+ for (const pattern of [htmlTagRE, interpolationRE]) {
41
+ for (const { 0: text, index } of content.matchAll(pattern)) {
42
42
  ranges.push([index, index + text.length]);
43
43
  }
44
44
  }
45
- for (const reg of [inlineCodeReg, angleBracketReg]) {
46
- for (const { 0: text, index } of content.matchAll(reg)) {
45
+ for (const pattern of [inlineCodeRE, angleBracketRE]) {
46
+ for (const { 0: text, index } of content.matchAll(pattern)) {
47
47
  if (ranges.some(([start, end]) => index >= start && index < end)) {
48
48
  continue;
49
49
  }
@@ -50,8 +50,8 @@ const plugin = ({ vueCompilerOptions }) => {
50
50
  + change.newText
51
51
  + hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
52
52
  // #3449
53
- const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
54
- const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
53
+ const endTagRE = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
54
+ const insertedEndTag = endTagRE.test(oldContent) !== endTagRE.test(newContent);
55
55
  if (insertedEndTag) {
56
56
  return;
57
57
  }