@vue/language-core 1.8.21 → 1.8.24

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.
@@ -4,7 +4,7 @@ exports.generate = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
5
  const source_map_1 = require("@volar/source-map");
6
6
  const muggle = require("muggle-string");
7
- const path_1 = require("path");
7
+ const path = require("path-browserify");
8
8
  const shared_1 = require("../utils/shared");
9
9
  const transform_1 = require("../utils/transform");
10
10
  function generate(ts, fileName, script, scriptSetup, styles, // TODO: computed it
@@ -91,6 +91,7 @@ lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOpti
91
91
  default: D[K]
92
92
  }> : P[K]
93
93
  };\n`);
94
+ codes.push(`type __VLS_Prettify<T> = { [K in keyof T]: T[K]; } & {};\n`);
94
95
  }
95
96
  if (usedHelperTypes.WithTemplateSlots) {
96
97
  codes.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): {\n`, `${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;\n`);
@@ -193,7 +194,7 @@ lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOpti
193
194
  if (!script)
194
195
  return;
195
196
  if (!!scriptSetup && scriptRanges?.exportDefault) {
196
- addVirtualCode('script', scriptRanges.exportDefault.end, script.content.length);
197
+ addVirtualCode('script', scriptRanges.exportDefault.expression.end, script.content.length);
197
198
  }
198
199
  }
199
200
  function generateScriptSetupImports() {
@@ -208,19 +209,6 @@ lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOpti
208
209
  language_core_1.FileRangeCapabilities.full,
209
210
  ]);
210
211
  }
211
- function generateExportDefaultEndMapping() {
212
- if (!scriptSetup) {
213
- return;
214
- }
215
- // fix https://github.com/vuejs/language-tools/issues/1127
216
- codes.push([
217
- '',
218
- 'scriptSetup',
219
- scriptSetup.content.length,
220
- { diagnostic: true },
221
- ]);
222
- codes.push(`\n`);
223
- }
224
212
  function generateScriptSetupAndTemplate() {
225
213
  if (!scriptSetup || !scriptSetupRanges) {
226
214
  return;
@@ -343,7 +331,6 @@ lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOpti
343
331
  scriptSetupGeneratedOffset = generateSetupFunction(false, 'return', definePropMirrors);
344
332
  codes.push(`})()`);
345
333
  }
346
- generateExportDefaultEndMapping();
347
334
  if (scriptSetupGeneratedOffset !== undefined) {
348
335
  for (const defineProp of scriptSetupRanges.defineProp) {
349
336
  if (!defineProp.name) {
@@ -508,9 +495,6 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
508
495
  codes.push(`;\n`);
509
496
  }
510
497
  }
511
- if (mode === 'export') {
512
- generateExportDefaultEndMapping();
513
- }
514
498
  return scriptSetupGeneratedOffset;
515
499
  }
516
500
  function generateComponent(functional) {
@@ -524,7 +508,6 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
524
508
  else {
525
509
  codes.push(`(await import('${vueCompilerOptions.lib}')).defineComponent({\n`);
526
510
  }
527
- generateComponentOptions(functional);
528
511
  codes.push(`setup() {\n`);
529
512
  codes.push(`return {\n`);
530
513
  generateSetupReturns();
@@ -533,6 +516,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
533
516
  }
534
517
  codes.push(`};\n`);
535
518
  codes.push(`},\n`);
519
+ generateComponentOptions(functional);
536
520
  codes.push(`})`);
537
521
  }
538
522
  function generateComponentOptions(functional) {
@@ -633,7 +617,6 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
633
617
  function generateComponentForTemplateUsage(functional, cssIds) {
634
618
  if (scriptSetup && scriptSetupRanges) {
635
619
  codes.push(`const __VLS_internalComponent = (await import('${vueCompilerOptions.lib}')).defineComponent({\n`);
636
- generateComponentOptions(functional);
637
620
  codes.push(`setup() {\n`);
638
621
  codes.push(`return {\n`);
639
622
  generateSetupReturns();
@@ -670,10 +653,11 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
670
653
  }
671
654
  codes.push(`};\n`); // return {
672
655
  codes.push(`},\n`); // setup() {
656
+ generateComponentOptions(functional);
673
657
  codes.push(`});\n`); // defineComponent({
674
658
  }
675
659
  else if (script) {
676
- codes.push(`let __VLS_internalComponent!: typeof import('./${path_1.posix.basename(fileName)}')['default'];\n`);
660
+ codes.push(`let __VLS_internalComponent!: typeof import('./${path.basename(fileName)}')['default'];\n`);
677
661
  }
678
662
  else {
679
663
  codes.push(`const __VLS_internalComponent = (await import('${vueCompilerOptions.lib}')).defineComponent({});\n`);
@@ -708,7 +692,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
708
692
  codes.push(`;\n`);
709
693
  }
710
694
  else if (scriptSetup) {
711
- codes.push(`let __VLS_name!: '${path_1.posix.basename(fileName.substring(0, fileName.lastIndexOf('.')))}';\n`);
695
+ codes.push(`let __VLS_name!: '${path.basename(fileName.substring(0, fileName.lastIndexOf('.')))}';\n`);
712
696
  }
713
697
  else {
714
698
  codes.push(`const __VLS_name = undefined;\n`);
@@ -742,7 +726,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
742
726
  for (let i = 0; i < styles.length; i++) {
743
727
  const style = styles[i];
744
728
  const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
745
- if ((option === 'always' || option === 'scoped') && style.scoped) {
729
+ if (option === 'always' || (option === 'scoped' && style.scoped)) {
746
730
  for (const className of style.classNames) {
747
731
  generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'boolean', true, !style.module);
748
732
  }
@@ -506,11 +506,18 @@ function generate(ts, compilerOptions, vueCompilerOptions, template, shouldGener
506
506
  codes.push(`const ${var_originalComponent} = `, ...createInterpolationCode(dynamicTagExp.loc.source, dynamicTagExp.loc, dynamicTagExp.loc.start.offset, capabilitiesPresets.all, '(', ')'), ';\n');
507
507
  }
508
508
  else {
509
- codes.push(`let ${var_originalComponent}!: `);
509
+ codes.push(`const ${var_originalComponent} = ({} as `);
510
510
  for (const componentName of getPossibleOriginalComponentName(tag)) {
511
- codes.push(`'${componentName}' extends keyof typeof __VLS_ctx ? typeof __VLS_ctx${validTsVarReg.test(componentName) ? `.${componentName}` : `['${componentName}']`} : `);
511
+ codes.push(`'${componentName}' extends keyof typeof __VLS_ctx ? `, `{ '${toCanonicalComponentName(tag)}': typeof __VLS_ctx`, ...createPropertyAccessCode(componentName), ` }: `);
512
512
  }
513
- codes.push(`typeof __VLS_resolvedLocalAndGlobalComponents['${toCanonicalComponentName(tag)}'];\n`);
513
+ codes.push(`typeof __VLS_resolvedLocalAndGlobalComponents)`, ...(tagOffsets.length
514
+ ? createPropertyAccessCode([
515
+ toCanonicalComponentName(tag),
516
+ 'template',
517
+ [tagOffsets[0], tagOffsets[0] + tag.length],
518
+ capabilitiesPresets.diagnosticOnly,
519
+ ])
520
+ : createPropertyAccessCode(toCanonicalComponentName(tag))), ';\n');
514
521
  }
515
522
  if (isIntrinsicElement) {
516
523
  codes.push(`const ${var_functionalComponent} = __VLS_elementAsFunctionalComponent(${var_originalComponent});\n`);
@@ -716,7 +723,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, template, shouldGener
716
723
  const eventsVar = componentCtxVar2EmitEventsVar.get(componentCtxVar);
717
724
  const eventVar = `__VLS_${elementIndex++}`;
718
725
  codes.push(`let ${eventVar} = { '${prop.arg.loc.source}': `, `__VLS_pickEvent(${eventsVar}['${prop.arg.loc.source}'], ({} as __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${componentInstanceVar}>)`, ...createPropertyAccessCode([
719
- (0, shared_1.camelize)('on-' + prop.arg.loc.source),
726
+ (0, shared_1.camelize)('on-' + prop.arg.loc.source), // onClickOutside
720
727
  'template',
721
728
  [prop.arg.loc.start.offset, prop.arg.loc.end.offset],
722
729
  {
@@ -879,6 +886,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, template, shouldGener
879
886
  let camelized = false;
880
887
  if ((!prop.arg || (prop.arg.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */ && prop.arg.isStatic)) // isStatic
881
888
  && (0, shared_2.hyphenateAttr)(attrNameText) === attrNameText
889
+ && !nativeTags.has(node.tag)
882
890
  && !vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(attrNameText, pattern))) {
883
891
  attrNameText = (0, shared_1.camelize)(attrNameText);
884
892
  camelized = true;
@@ -902,7 +910,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, template, shouldGener
902
910
  codes.push(...createObjectPropertyCode([
903
911
  attrNameText,
904
912
  'template',
905
- [prop.arg.loc.start.offset, prop.arg.loc.start.offset + attrNameText.length],
913
+ [prop.arg.loc.start.offset, prop.arg.loc.start.offset + attrNameText.length], // patch style attr,
906
914
  {
907
915
  ...caps_attr,
908
916
  rename: {
@@ -956,6 +964,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, template, shouldGener
956
964
  }
957
965
  let camelized = false;
958
966
  if ((0, shared_2.hyphenateAttr)(prop.name) === prop.name
967
+ && !nativeTags.has(node.tag)
959
968
  && !vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(attrNameText, pattern))) {
960
969
  attrNameText = (0, shared_1.camelize)(prop.name);
961
970
  camelized = true;
@@ -6,5 +6,5 @@ export declare function createVueLanguage(ts: typeof import('typescript/lib/tsse
6
6
  /**
7
7
  * @deprecated planed to remove in 2.0, please use createVueLanguage instead of
8
8
  */
9
- export declare function createLanguages(compilerOptions?: ts.CompilerOptions, vueCompilerOptions?: Partial<VueCompilerOptions>, ts?: typeof import('typescript/lib/tsserverlibrary'), codegenStack?: boolean): Language[];
9
+ export declare function createLanguages(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions?: ts.CompilerOptions, vueCompilerOptions?: Partial<VueCompilerOptions>, codegenStack?: boolean): Language[];
10
10
  //# sourceMappingURL=languageModule.d.ts.map
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLanguages = exports.createVueLanguage = void 0;
4
- const path_1 = require("path");
4
+ const path = require("path-browserify");
5
5
  const plugins_1 = require("./plugins");
6
6
  const vueFile_1 = require("./virtualFile/vueFile");
7
7
  const sharedTypes = require("./utils/globalTypes");
@@ -60,7 +60,7 @@ function createVueLanguage(ts, compilerOptions = {}, _vueCompilerOptions = {}, c
60
60
  },
61
61
  resolveHost(host) {
62
62
  const sharedTypesSnapshot = ts.ScriptSnapshot.fromString(sharedTypes.getTypesCode(vueCompilerOptions));
63
- const sharedTypesFileName = path_1.posix.join(host.rootPath, sharedTypes.baseName);
63
+ const sharedTypesFileName = path.join(host.rootPath, sharedTypes.baseName);
64
64
  return {
65
65
  ...host,
66
66
  resolveModuleName(moduleName, impliedNodeFormat) {
@@ -89,7 +89,7 @@ exports.createVueLanguage = createVueLanguage;
89
89
  /**
90
90
  * @deprecated planed to remove in 2.0, please use createVueLanguage instead of
91
91
  */
92
- function createLanguages(compilerOptions = {}, vueCompilerOptions = {}, ts = require('typescript'), codegenStack = false) {
92
+ function createLanguages(ts, compilerOptions = {}, vueCompilerOptions = {}, codegenStack = false) {
93
93
  return [
94
94
  createVueLanguage(ts, compilerOptions, vueCompilerOptions, codegenStack),
95
95
  ...vueCompilerOptions.experimentalAdditionalLanguageModules?.map(module => require(module)) ?? [],
@@ -9,9 +9,10 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript/lib
9
9
  props: {
10
10
  name?: string | undefined;
11
11
  define?: (TextRange & {
12
- statement: TextRange;
13
12
  arg?: TextRange | undefined;
14
13
  typeArg?: TextRange | undefined;
14
+ } & {
15
+ statement: TextRange;
15
16
  }) | undefined;
16
17
  withDefaults?: (TextRange & {
17
18
  arg?: TextRange | undefined;
@@ -19,11 +20,17 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript/lib
19
20
  };
20
21
  slots: {
21
22
  name?: string | undefined;
22
- define?: TextRange | undefined;
23
+ define?: (TextRange & {
24
+ arg?: TextRange | undefined;
25
+ typeArg?: TextRange | undefined;
26
+ }) | undefined;
23
27
  };
24
28
  emits: {
25
29
  name?: string | undefined;
26
- define?: TextRange | undefined;
30
+ define?: (TextRange & {
31
+ arg?: TextRange | undefined;
32
+ typeArg?: TextRange | undefined;
33
+ }) | undefined;
27
34
  };
28
35
  expose: {
29
36
  name?: string | undefined;
@@ -47,6 +47,13 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
47
47
  function _getStartEnd(node) {
48
48
  return getStartEnd(node, ast);
49
49
  }
50
+ function parseDefineFunction(node) {
51
+ return {
52
+ ..._getStartEnd(node),
53
+ arg: node.arguments.length ? _getStartEnd(node.arguments[0]) : undefined,
54
+ typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
55
+ };
56
+ }
50
57
  function visitNode(node, parents) {
51
58
  const parent = parents[parents.length - 1];
52
59
  if (ts.isCallExpression(node)
@@ -128,25 +135,19 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
128
135
  }
129
136
  }
130
137
  else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
131
- slots.define = _getStartEnd(node);
138
+ slots.define = parseDefineFunction(node);
132
139
  if (ts.isVariableDeclaration(parent)) {
133
140
  slots.name = parent.name.getText(ast);
134
141
  }
135
142
  }
136
143
  else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
137
- emits.define = _getStartEnd(node);
144
+ emits.define = parseDefineFunction(node);
138
145
  if (ts.isVariableDeclaration(parent)) {
139
146
  emits.name = parent.name.getText(ast);
140
147
  }
141
148
  }
142
149
  else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
143
- expose.define = _getStartEnd(node);
144
- if (node.arguments.length) {
145
- expose.define.arg = _getStartEnd(node.arguments[0]);
146
- }
147
- if (node.typeArguments?.length) {
148
- expose.define.typeArg = _getStartEnd(node.typeArguments[0]);
149
- }
150
+ expose.define = parseDefineFunction(node);
150
151
  }
151
152
  else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
152
153
  let statementRange;
@@ -165,7 +166,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
165
166
  statementRange = _getStartEnd(node);
166
167
  }
167
168
  props.define = {
168
- ..._getStartEnd(node),
169
+ ...parseDefineFunction(node),
169
170
  statement: statementRange,
170
171
  };
171
172
  if (ts.isVariableDeclaration(parent)) {
@@ -19,10 +19,17 @@ const plugin = (_ctx) => {
19
19
  if (!hitBlock) {
20
20
  return;
21
21
  }
22
- hitBlock.content =
22
+ const oldContent = hitBlock.content;
23
+ const newContent = hitBlock.content =
23
24
  hitBlock.content.substring(0, change.start - hitBlock.loc.start.offset)
24
25
  + change.newText
25
26
  + hitBlock.content.substring(change.end - hitBlock.loc.start.offset);
27
+ // #3449
28
+ const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
29
+ const insertedEndTag = !!oldContent.match(endTagRegex) !== !!newContent.match(endTagRegex);
30
+ if (insertedEndTag) {
31
+ return;
32
+ }
26
33
  const lengthDiff = change.newText.length - (change.end - change.start);
27
34
  for (const block of blocks) {
28
35
  if (block.loc.start.offset > change.end) {
@@ -5,9 +5,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
5
5
  exportDefault: (import("../types").TextRange & {
6
6
  expression: import("../types").TextRange;
7
7
  args: import("../types").TextRange;
8
- argsNode: import("typescript/lib/tsserverlibrary").ObjectLiteralExpression | undefined;
8
+ argsNode: import("typescript").ObjectLiteralExpression | undefined;
9
9
  componentsOption: import("../types").TextRange | undefined;
10
- componentsOptionNode: import("typescript/lib/tsserverlibrary").ObjectLiteralExpression | undefined;
10
+ componentsOptionNode: import("typescript").ObjectLiteralExpression | undefined;
11
11
  nameOption: import("../types").TextRange | undefined;
12
12
  }) | undefined;
13
13
  bindings: import("../types").TextRange[];
@@ -19,9 +19,10 @@ export declare const tsCodegen: WeakMap<Sfc, {
19
19
  props: {
20
20
  name?: string | undefined;
21
21
  define?: (import("../types").TextRange & {
22
- statement: import("../types").TextRange;
23
22
  arg?: import("../types").TextRange | undefined;
24
23
  typeArg?: import("../types").TextRange | undefined;
24
+ } & {
25
+ statement: import("../types").TextRange;
25
26
  }) | undefined;
26
27
  withDefaults?: (import("../types").TextRange & {
27
28
  arg?: import("../types").TextRange | undefined;
@@ -29,11 +30,17 @@ export declare const tsCodegen: WeakMap<Sfc, {
29
30
  };
30
31
  slots: {
31
32
  name?: string | undefined;
32
- define?: import("../types").TextRange | undefined;
33
+ define?: (import("../types").TextRange & {
34
+ arg?: import("../types").TextRange | undefined;
35
+ typeArg?: import("../types").TextRange | undefined;
36
+ }) | undefined;
33
37
  };
34
38
  emits: {
35
39
  name?: string | undefined;
36
- define?: import("../types").TextRange | undefined;
40
+ define?: (import("../types").TextRange & {
41
+ arg?: import("../types").TextRange | undefined;
42
+ typeArg?: import("../types").TextRange | undefined;
43
+ }) | undefined;
37
44
  };
38
45
  expose: {
39
46
  name?: string | undefined;
@@ -131,7 +131,7 @@ function createTsx(fileName, _sfc, { vueCompilerOptions, compilerOptions, codege
131
131
  }
132
132
  for (const style of _sfc.styles) {
133
133
  const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
134
- if ((option === 'always' || option === 'scoped') && style.scoped) {
134
+ if (option === 'always' || (option === 'scoped' && style.scoped)) {
135
135
  for (const className of style.classNames) {
136
136
  classes.add(className.text.substring(1));
137
137
  }
package/out/plugins.js CHANGED
@@ -14,9 +14,9 @@ const CompilerDOM = require("@vue/compiler-dom");
14
14
  const CompilerVue2 = require("./utils/vue2TemplateCompiler");
15
15
  function getDefaultVueLanguagePlugins(ts, compilerOptions, vueCompilerOptions, codegenStack) {
16
16
  const plugins = [
17
- file_md_1.default,
18
- file_html_1.default,
19
- file_vue_1.default,
17
+ file_md_1.default, // .md for VitePress
18
+ file_html_1.default, // .html for PetiteVue
19
+ file_vue_1.default, // .vue and others for Vue
20
20
  vue_template_html_1.default,
21
21
  vue_sfc_styles_1.default,
22
22
  vue_sfc_customblocks_1.default,
package/out/utils/ts.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveVueCompilerOptions = exports.createParsedCommandLine = exports.createParsedCommandLineByJson = void 0;
4
- const path = require("path");
4
+ const path = require("path-browserify");
5
5
  function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json') {
6
6
  const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
7
7
  ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "1.8.21",
3
+ "version": "1.8.24",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,17 +13,20 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "~1.10.5",
17
- "@volar/source-map": "~1.10.5",
16
+ "@volar/language-core": "~1.11.1",
17
+ "@volar/source-map": "~1.11.1",
18
18
  "@vue/compiler-dom": "^3.3.0",
19
19
  "@vue/shared": "^3.3.0",
20
20
  "computeds": "^0.0.1",
21
21
  "minimatch": "^9.0.3",
22
22
  "muggle-string": "^0.3.1",
23
+ "path-browserify": "^1.0.1",
23
24
  "vue-template-compiler": "^2.7.14"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/minimatch": "^5.1.2",
28
+ "@types/node": "latest",
29
+ "@types/path-browserify": "^1.0.1",
27
30
  "@vue/compiler-sfc": "^3.3.0"
28
31
  },
29
32
  "peerDependencies": {
@@ -34,5 +37,5 @@
34
37
  "optional": true
35
38
  }
36
39
  },
37
- "gitHead": "46ae2ff1c155e51291fd584c0c3a32ed3dace7a5"
40
+ "gitHead": "6f850196d6b9cd1bee62104d3d92867cf0b6777e"
38
41
  }