@weapp-vite/volar 2.1.13 → 2.2.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.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -19,17 +19,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
19
19
  value: mod,
20
20
  enumerable: true
21
21
  }) : target, mod));
22
- //#endregion
23
22
  let node_module = require("node:module");
24
23
  let node_path = require("node:path");
25
24
  node_path = __toESM(node_path);
26
25
  let node_process = require("node:process");
27
26
  node_process = __toESM(node_process);
28
27
  let _weapp_core_schematics = require("@weapp-core/schematics");
29
- //#region package.json
28
+ // package.json
30
29
  var name = "@weapp-vite/volar";
31
- //#endregion
32
- //#region src/constants.ts
30
+ // src/constants.ts
33
31
  const BLOCK_TYPE = "json";
34
32
  const JSONC_LANG = "jsonc";
35
33
  const JSON_LANG = "json";
@@ -54,8 +52,7 @@ const VOID_CAPABILITIES = {
54
52
  structure: false,
55
53
  format: false
56
54
  };
57
- //#endregion
58
- //#region src/schema.ts
55
+ // src/schema.ts
59
56
  /**
60
57
  * 为小程序配置生成 JSON Schema
61
58
  * 为支持 JSON Schema 的编辑器提供验证和自动补全
@@ -72,8 +69,7 @@ function getSchemaForType(type) {
72
69
  if (!definition) return null;
73
70
  return definition.schema;
74
71
  }
75
- //#endregion
76
- //#region src/jsonBlock.ts
72
+ // src/jsonBlock.ts
77
73
  function normalizeFilename(filename) {
78
74
  if (!filename) return "";
79
75
  return filename.replace(BACKSLASH_RE, "/");
@@ -237,8 +233,7 @@ function resolveEmbeddedJsonBlock(fileName, sfc, embeddedCode, tsModule, hasSche
237
233
  FULL_CAPABILITIES
238
234
  ]);
239
235
  }
240
- //#endregion
241
- //#region src/parseSfc.ts
236
+ // src/parseSfc.ts
242
237
  function advancePosition(position, source, start = 0, end = source.length) {
243
238
  let lines = 0;
244
239
  let lastNewline = -1;
@@ -407,8 +402,7 @@ function updateSfc(sfc, change) {
407
402
  sfc.descriptor.source = source.slice(0, change.start) + change.newText + source.slice(change.end);
408
403
  return sfc;
409
404
  }
410
- //#endregion
411
- //#region src/scriptSetup.ts
405
+ // src/scriptSetup.ts
412
406
  function collectWxsModuleNames(templateContent) {
413
407
  if (!templateContent) return [];
414
408
  const names = /* @__PURE__ */ new Set();
@@ -687,8 +681,78 @@ function createDefineOptionsTemplateDeclarations(code, tsModule, lang) {
687
681
  function resolveScriptSetupLang(lang) {
688
682
  return lang === "js" ? "js" : "ts";
689
683
  }
690
- //#endregion
691
- //#region src/index.ts
684
+ // src/templateRef.ts
685
+ const SERVICE_SCRIPT_RE = /^script_([jt]sx?)$/;
686
+ const WHITESPACE_RE = /\s/;
687
+ const LINE_TERMINATOR_RE = /[\n\r\u2028\u2029]/;
688
+ const BROWSER_ELEMENTS = "Omit<SVGElementTagNameMap, keyof HTMLElementTagNameMap> & HTMLElementTagNameMap";
689
+ const MINI_PROGRAM_ELEMENTS = "import('wevu').MiniProgramTemplateRefElements";
690
+ const LOCAL_ELEMENTS = `Omit<${BROWSER_ELEMENTS}, keyof ${MINI_PROGRAM_ELEMENTS}> & ${MINI_PROGRAM_ELEMENTS}`;
691
+ /** 线性扫描首条上游语法指令,保留跨行分隔符及空白 key/value 的匹配边界。 */
692
+ function readCompilerDirective(comment) {
693
+ let cursor = 0;
694
+ while (cursor < comment.length) {
695
+ while (cursor < comment.length && WHITESPACE_RE.test(comment[cursor])) cursor += 1;
696
+ if (cursor === comment.length) return;
697
+ if (comment[cursor] !== "@") {
698
+ while (cursor < comment.length && !LINE_TERMINATOR_RE.test(comment[cursor])) cursor += 1;
699
+ continue;
700
+ }
701
+ const keyStart = cursor + 1;
702
+ if (keyStart === comment.length || LINE_TERMINATOR_RE.test(comment[keyStart])) {
703
+ cursor = keyStart;
704
+ continue;
705
+ }
706
+ let separator = keyStart + 1;
707
+ while (separator < comment.length && !WHITESPACE_RE.test(comment[separator])) separator += 1;
708
+ if (separator === comment.length) return;
709
+ let valueStart = separator;
710
+ while (valueStart < comment.length && WHITESPACE_RE.test(comment[valueStart])) valueStart += 1;
711
+ const key = comment.slice(keyStart, separator);
712
+ if (valueStart === comment.length) {
713
+ valueStart -= 1;
714
+ while (valueStart > separator && LINE_TERMINATOR_RE.test(comment[valueStart])) valueStart -= 1;
715
+ return valueStart > separator ? {
716
+ key,
717
+ value: comment[valueStart]
718
+ } : void 0;
719
+ }
720
+ let valueEnd = valueStart;
721
+ while (valueEnd < comment.length && !LINE_TERMINATOR_RE.test(comment[valueEnd])) valueEnd += 1;
722
+ while (valueEnd > valueStart && WHITESPACE_RE.test(comment[valueEnd - 1])) valueEnd -= 1;
723
+ return {
724
+ key,
725
+ value: comment.slice(valueStart, valueEnd)
726
+ };
727
+ }
728
+ }
729
+ /** 仅解析文件级 lib 覆盖,保持上游每条注释首个配置与最后有效配置的语义。 */
730
+ function resolveTemplateRefLib(baseLib, comments) {
731
+ let lib = baseLib;
732
+ for (const comment of comments) {
733
+ const directive = readCompilerDirective(comment);
734
+ if (directive?.key !== "lib") continue;
735
+ try {
736
+ lib = JSON.parse(directive.value);
737
+ } catch {}
738
+ }
739
+ return lib;
740
+ }
741
+ /** 在上游服务脚本生成后,用模块局部类型覆盖小程序原生 ref,避免修改浏览器全局声明。 */
742
+ function createTemplateRefPlugin(baseLib) {
743
+ return {
744
+ name: "@weapp-vite/volar:template-ref",
745
+ version: PLUGIN_VERSION,
746
+ order: 1,
747
+ resolveEmbeddedCode(_fileName, sfc, embeddedCode) {
748
+ const match = SERVICE_SCRIPT_RE.exec(embeddedCode.id);
749
+ if (!match || resolveTemplateRefLib(baseLib, sfc.comments) !== "wevu") return;
750
+ const declaration = match[1].startsWith("j") ? `/** @typedef {${LOCAL_ELEMENTS}} __VLS_Elements */` : `type __VLS_Elements = ${LOCAL_ELEMENTS};`;
751
+ embeddedCode.content.push(`\n${declaration}\n`);
752
+ }
753
+ };
754
+ }
755
+ // src/index.ts
692
756
  const require$1 = (0, node_module.createRequire)(typeof module !== "undefined" && module.filename ? module.filename : node_path.default.join(node_process.default.cwd(), "weapp-vite-volar.cjs"));
693
757
  let hasSchematicsTypes = false;
694
758
  try {
@@ -748,7 +812,7 @@ const plugin = (ctx) => {
748
812
  syncScriptBlockSource(scriptSetup);
749
813
  } else descriptor.scriptSetup = createSyntheticScriptSetup(wxsModuleNames);
750
814
  }
751
- return {
815
+ const parserPlugin = {
752
816
  name,
753
817
  version: PLUGIN_VERSION,
754
818
  order: -1,
@@ -772,6 +836,6 @@ const plugin = (ctx) => {
772
836
  resolveEmbeddedJsonBlock(fileName, sfc, embeddedCode, tsModule, hasSchematicsTypes);
773
837
  }
774
838
  };
839
+ return ctx?.vueCompilerOptions ? [parserPlugin, createTemplateRefPlugin(ctx.vueCompilerOptions.lib)] : parserPlugin;
775
840
  };
776
- //#endregion
777
841
  module.exports = plugin;
package/dist/index.mjs CHANGED
@@ -2,10 +2,9 @@ import { createRequire } from "node:module";
2
2
  import path from "node:path";
3
3
  import process from "node:process";
4
4
  import { JSON_SCHEMA_DEFINITIONS } from "@weapp-core/schematics";
5
- //#region package.json
5
+ // package.json
6
6
  var name = "@weapp-vite/volar";
7
- //#endregion
8
- //#region src/constants.ts
7
+ // src/constants.ts
9
8
  const BLOCK_TYPE = "json";
10
9
  const JSONC_LANG = "jsonc";
11
10
  const JSON_LANG = "json";
@@ -30,8 +29,7 @@ const VOID_CAPABILITIES = {
30
29
  structure: false,
31
30
  format: false
32
31
  };
33
- //#endregion
34
- //#region src/schema.ts
32
+ // src/schema.ts
35
33
  /**
36
34
  * 为小程序配置生成 JSON Schema
37
35
  * 为支持 JSON Schema 的编辑器提供验证和自动补全
@@ -48,8 +46,7 @@ function getSchemaForType(type) {
48
46
  if (!definition) return null;
49
47
  return definition.schema;
50
48
  }
51
- //#endregion
52
- //#region src/jsonBlock.ts
49
+ // src/jsonBlock.ts
53
50
  function normalizeFilename(filename) {
54
51
  if (!filename) return "";
55
52
  return filename.replace(BACKSLASH_RE, "/");
@@ -213,8 +210,7 @@ function resolveEmbeddedJsonBlock(fileName, sfc, embeddedCode, tsModule, hasSche
213
210
  FULL_CAPABILITIES
214
211
  ]);
215
212
  }
216
- //#endregion
217
- //#region src/parseSfc.ts
213
+ // src/parseSfc.ts
218
214
  function advancePosition(position, source, start = 0, end = source.length) {
219
215
  let lines = 0;
220
216
  let lastNewline = -1;
@@ -383,8 +379,7 @@ function updateSfc(sfc, change) {
383
379
  sfc.descriptor.source = source.slice(0, change.start) + change.newText + source.slice(change.end);
384
380
  return sfc;
385
381
  }
386
- //#endregion
387
- //#region src/scriptSetup.ts
382
+ // src/scriptSetup.ts
388
383
  function collectWxsModuleNames(templateContent) {
389
384
  if (!templateContent) return [];
390
385
  const names = /* @__PURE__ */ new Set();
@@ -663,8 +658,78 @@ function createDefineOptionsTemplateDeclarations(code, tsModule, lang) {
663
658
  function resolveScriptSetupLang(lang) {
664
659
  return lang === "js" ? "js" : "ts";
665
660
  }
666
- //#endregion
667
- //#region src/index.ts
661
+ // src/templateRef.ts
662
+ const SERVICE_SCRIPT_RE = /^script_([jt]sx?)$/;
663
+ const WHITESPACE_RE = /\s/;
664
+ const LINE_TERMINATOR_RE = /[\n\r\u2028\u2029]/;
665
+ const BROWSER_ELEMENTS = "Omit<SVGElementTagNameMap, keyof HTMLElementTagNameMap> & HTMLElementTagNameMap";
666
+ const MINI_PROGRAM_ELEMENTS = "import('wevu').MiniProgramTemplateRefElements";
667
+ const LOCAL_ELEMENTS = `Omit<${BROWSER_ELEMENTS}, keyof ${MINI_PROGRAM_ELEMENTS}> & ${MINI_PROGRAM_ELEMENTS}`;
668
+ /** 线性扫描首条上游语法指令,保留跨行分隔符及空白 key/value 的匹配边界。 */
669
+ function readCompilerDirective(comment) {
670
+ let cursor = 0;
671
+ while (cursor < comment.length) {
672
+ while (cursor < comment.length && WHITESPACE_RE.test(comment[cursor])) cursor += 1;
673
+ if (cursor === comment.length) return;
674
+ if (comment[cursor] !== "@") {
675
+ while (cursor < comment.length && !LINE_TERMINATOR_RE.test(comment[cursor])) cursor += 1;
676
+ continue;
677
+ }
678
+ const keyStart = cursor + 1;
679
+ if (keyStart === comment.length || LINE_TERMINATOR_RE.test(comment[keyStart])) {
680
+ cursor = keyStart;
681
+ continue;
682
+ }
683
+ let separator = keyStart + 1;
684
+ while (separator < comment.length && !WHITESPACE_RE.test(comment[separator])) separator += 1;
685
+ if (separator === comment.length) return;
686
+ let valueStart = separator;
687
+ while (valueStart < comment.length && WHITESPACE_RE.test(comment[valueStart])) valueStart += 1;
688
+ const key = comment.slice(keyStart, separator);
689
+ if (valueStart === comment.length) {
690
+ valueStart -= 1;
691
+ while (valueStart > separator && LINE_TERMINATOR_RE.test(comment[valueStart])) valueStart -= 1;
692
+ return valueStart > separator ? {
693
+ key,
694
+ value: comment[valueStart]
695
+ } : void 0;
696
+ }
697
+ let valueEnd = valueStart;
698
+ while (valueEnd < comment.length && !LINE_TERMINATOR_RE.test(comment[valueEnd])) valueEnd += 1;
699
+ while (valueEnd > valueStart && WHITESPACE_RE.test(comment[valueEnd - 1])) valueEnd -= 1;
700
+ return {
701
+ key,
702
+ value: comment.slice(valueStart, valueEnd)
703
+ };
704
+ }
705
+ }
706
+ /** 仅解析文件级 lib 覆盖,保持上游每条注释首个配置与最后有效配置的语义。 */
707
+ function resolveTemplateRefLib(baseLib, comments) {
708
+ let lib = baseLib;
709
+ for (const comment of comments) {
710
+ const directive = readCompilerDirective(comment);
711
+ if (directive?.key !== "lib") continue;
712
+ try {
713
+ lib = JSON.parse(directive.value);
714
+ } catch {}
715
+ }
716
+ return lib;
717
+ }
718
+ /** 在上游服务脚本生成后,用模块局部类型覆盖小程序原生 ref,避免修改浏览器全局声明。 */
719
+ function createTemplateRefPlugin(baseLib) {
720
+ return {
721
+ name: "@weapp-vite/volar:template-ref",
722
+ version: PLUGIN_VERSION,
723
+ order: 1,
724
+ resolveEmbeddedCode(_fileName, sfc, embeddedCode) {
725
+ const match = SERVICE_SCRIPT_RE.exec(embeddedCode.id);
726
+ if (!match || resolveTemplateRefLib(baseLib, sfc.comments) !== "wevu") return;
727
+ const declaration = match[1].startsWith("j") ? `/** @typedef {${LOCAL_ELEMENTS}} __VLS_Elements */` : `type __VLS_Elements = ${LOCAL_ELEMENTS};`;
728
+ embeddedCode.content.push(`\n${declaration}\n`);
729
+ }
730
+ };
731
+ }
732
+ // src/index.ts
668
733
  const require = createRequire(typeof module !== "undefined" && module.filename ? module.filename : path.join(process.cwd(), "weapp-vite-volar.cjs"));
669
734
  let hasSchematicsTypes = false;
670
735
  try {
@@ -724,7 +789,7 @@ const plugin = (ctx) => {
724
789
  syncScriptBlockSource(scriptSetup);
725
790
  } else descriptor.scriptSetup = createSyntheticScriptSetup(wxsModuleNames);
726
791
  }
727
- return {
792
+ const parserPlugin = {
728
793
  name,
729
794
  version: PLUGIN_VERSION,
730
795
  order: -1,
@@ -748,6 +813,6 @@ const plugin = (ctx) => {
748
813
  resolveEmbeddedJsonBlock(fileName, sfc, embeddedCode, tsModule, hasSchematicsTypes);
749
814
  }
750
815
  };
816
+ return ctx?.vueCompilerOptions ? [parserPlugin, createTemplateRefPlugin(ctx.vueCompilerOptions.lib)] : parserPlugin;
751
817
  };
752
- //#endregion
753
818
  export { plugin as default };
@@ -0,0 +1,5 @@
1
+ import type { VueLanguagePluginReturn } from '@vue/language-core';
2
+ /** 仅解析文件级 lib 覆盖,保持上游每条注释首个配置与最后有效配置的语义。 */
3
+ export declare function resolveTemplateRefLib(baseLib: string, comments: readonly string[]): unknown;
4
+ /** 在上游服务脚本生成后,用模块局部类型覆盖小程序原生 ref,避免修改浏览器全局声明。 */
5
+ export declare function createTemplateRefPlugin(baseLib: string): VueLanguagePluginReturn;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-vite/volar",
3
- "version": "2.1.13",
3
+ "version": "2.2.0",
4
4
  "description": "Volar plugin for weapp-vite - Provides IntelliSense and type checking for WeChat mini-program config blocks",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -41,14 +41,14 @@
41
41
  "dist"
42
42
  ],
43
43
  "engines": {
44
- "node": "^20.19.0 || >=22.12.0"
44
+ "node": "^22.23.4 || ^24.22.1 || >=26.12.1"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public",
48
48
  "registry": "https://registry.npmjs.org"
49
49
  },
50
50
  "dependencies": {
51
- "@weapp-core/schematics": "6.2.9"
51
+ "@weapp-core/schematics": "6.3.0"
52
52
  },
53
53
  "scripts": {
54
54
  "benchmark": "node --import tsx benchmark/sfc.ts",