@wevu/compiler 6.25.1 → 7.0.1

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/README.md CHANGED
@@ -39,6 +39,31 @@ console.log(result.script)
39
39
  console.log(result.template)
40
40
  ```
41
41
 
42
+ ### 编译诊断
43
+
44
+ `compileTemplate` 始终返回 `diagnostics`,`compileSfc` / `compileJsxFile` 在存在模板或 JSX 诊断时返回 `diagnostics`。每条诊断包含稳定的 `code`、`severity`、`filename`、`source` 和可选 `loc`:
45
+
46
+ 这是一次 clean cutover:原有 `warnings: string[]` 字段已移除,调用方应改读 `diagnostics`,需要展示文本时使用 `diagnostic.message`。
47
+
48
+ ```ts
49
+ import { compileTemplate } from '@wevu/compiler'
50
+
51
+ const result = compileTemplate(
52
+ '<view v-html="html" />',
53
+ '/project/src/pages/index.vue',
54
+ )
55
+
56
+ for (const diagnostic of result.diagnostics) {
57
+ if (diagnostic.code === 'WV1001') {
58
+ console.warn(diagnostic.message, diagnostic.loc)
59
+ }
60
+ }
61
+ ```
62
+
63
+ 稳定 code:`WV1001`(模板转换警告)、`WV1002`(模板表达式警告)、`WV1003`(JSX 警告)、`WV2001`(模板解析错误)、`WV2002`(模板编译错误)。
64
+
65
+ `loc.start` / `loc.end` 使用半开区间;`offset` 从 0 开始,`line` / `column` 从 1 开始。`compileSfc` 会将内联 `<template>` 位置映射到完整 SFC 源码;外部 `<template src>` 则使用解析后的外部文件名和其自身位置。模板与 JSX 自有诊断会按 `diagnostic.message` 原样、仅一次地适配到 `warn` 回调,结构化消费应使用结果中的 `diagnostics`。
66
+
42
67
  使用页面特性工具:
43
68
 
44
69
  ```ts
package/dist/index.d.mts CHANGED
@@ -92,6 +92,37 @@ declare const WE_VU_INTERNAL_TEMPLATE_APIS: readonly ["normalizeClass", "normali
92
92
  */
93
93
  declare function resolveWevuInternalImportModuleId(apiName: string): "virtual:weapp-vite/runtime" | "virtual:weapp-vite/runtime/reactivity" | "virtual:weapp-vite/runtime/template";
94
94
  //#endregion
95
+ //#region src/types/diagnostics.d.ts
96
+ type CompilerDiagnosticCode = 'WV1002' | 'WV1003' | 'WV2002' | 'WV2001' | 'WV1001';
97
+ type CompilerDiagnosticSeverity = 'error' | 'warning';
98
+ type CompilerDiagnosticSource = 'expression' | 'jsx' | 'script' | 'sfc' | 'style' | 'template';
99
+ /**
100
+ * 编译源码中的位置。行号和列号均从 1 开始,偏移量从 0 开始。
101
+ */
102
+ interface SourcePosition {
103
+ offset: number;
104
+ line: number;
105
+ column: number;
106
+ }
107
+ /**
108
+ * 编译源码中的半开区间,结束位置不包含在范围内。
109
+ */
110
+ interface SourceSpan {
111
+ start: SourcePosition;
112
+ end: SourcePosition;
113
+ }
114
+ /**
115
+ * 可供构建工具和编辑器稳定消费的编译诊断。
116
+ */
117
+ interface CompilerDiagnostic {
118
+ code: CompilerDiagnosticCode;
119
+ severity: CompilerDiagnosticSeverity;
120
+ message: string;
121
+ filename: string;
122
+ source: CompilerDiagnosticSource;
123
+ loc?: SourceSpan;
124
+ }
125
+ //#endregion
95
126
  //#region src/types/json.d.ts
96
127
  /**
97
128
  * JSON 合并阶段枚举。
@@ -172,6 +203,7 @@ interface ResolveSfcBlockSrcOptions {
172
203
  declare function resolveSfcBlockSrc(descriptor: SFCDescriptor, filename: string, options?: ResolveSfcBlockSrcOptions): Promise<{
173
204
  descriptor: SFCDescriptor;
174
205
  deps: string[];
206
+ templateResolvedId?: string;
175
207
  }>;
176
208
  //#endregion
177
209
  //#region src/plugins/utils/vueSfc.d.ts
@@ -303,7 +335,7 @@ interface InlineExpressionAsset {
303
335
  */
304
336
  interface TemplateCompileResult {
305
337
  code: string;
306
- warnings: string[];
338
+ diagnostics: CompilerDiagnostic[];
307
339
  scopedSlotComponents?: ScopedSlotComponentAsset[];
308
340
  slotFallbackWrapperComponent?: SlotFallbackWrapperComponentAsset;
309
341
  componentGenerics?: Record<string, true>;
@@ -521,6 +553,7 @@ interface VueTransformResult {
521
553
  template?: string;
522
554
  style?: string;
523
555
  config?: string;
556
+ diagnostics?: CompilerDiagnostic[];
524
557
  cssModules?: Record<string, Record<string, string>>;
525
558
  scopedSlotComponents?: TemplateCompileResult['scopedSlotComponents'];
526
559
  slotFallbackWrapperComponent?: TemplateCompileResult['slotFallbackWrapperComponent'];
@@ -1155,4 +1188,4 @@ interface CollectVueTemplateTagsOptions {
1155
1188
  */
1156
1189
  declare function collectVueTemplateTags(template: string, options: CollectVueTemplateTagsOptions): Set<string>;
1157
1190
  //#endregion
1158
- export { type AstEngineName, type AutoImportTagsOptions, type AutoUsingComponentsOptions, CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, type ClassStyleBinding, type ClassStyleRuntime, type CollectVueTemplateTagsOptions, type CompileVueFileOptions, type ForParseResult, type InlineExpressionAsset, type JsLikeLang, type JsonConfig, type JsonMergeContext, type JsonMergeStage, type JsonMergeStrategy, type MiniProgramPlatform, type ModuleResolver, type MpPlatform, RESERVED_VUE_COMPONENT_TAGS, type ReadAndParseSfcOptions, type ResolveSfcBlockSrcOptions, type ResolvedUsingComponentInfo, type ResolvedUsingComponentPath, type ScopedSlotComponentAsset, type SlotFallbackWrapperComponentAsset, type SlotFallbackWrapperStrategy, type StyleCompileOptions, type StyleCompileResult, type TemplateCompileOptions, type TemplateCompileResult, type TemplateRefBinding, type TransformResult, type TransformScriptOptions, type TransformUniAppSourceOptions, type UniAppCompatibilityTarget, VUE_COMPONENT_TAG_RE, VUE_SFC_BLOCK_TYPES, type VueSfcBlockChanges, type VueSfcBlockSignatures, type VueSfcBlockType, type VueSfcHmrSignatures, type VueTransformResult, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, WE_VU_INTERNAL_REACTIVITY_APIS, WE_VU_INTERNAL_REACTIVITY_MODULE_ID, WE_VU_INTERNAL_RUNTIME_MODULE_ID, WE_VU_INTERNAL_TEMPLATE_APIS, WE_VU_INTERNAL_TEMPLATE_MODULE_ID, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, WE_VU_RUNTIME_MODULE_IDS, type WevuDefaults, WevuPageFeatureFlag, WevuPageHookName, WevuRuntimeApiName, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, classifyVueSfcBlockChanges, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeatureFlagsIntoOptionsObject, injectWevuPageFeaturesInJs, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isInvalidate, isJsonLikeLang, isUniAppCompatibilityFile, isWevuRuntimeModuleId, loadCache, mayContainJsonMacro, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveVueSfcHasTemplate, resolveVueSfcHmrSignatures, resolveVueSfcNonJsonSignature, resolveVueSfcScriptSignature, resolveVueSfcStyleIndependentSignature, resolveVueSfcTailwindContentSignature, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformNestedWxssVars, transformScript, transformScript as transformSfcScript, transformUniAppConditionalCode, transformUniAppSource, transformVueDeepSelectors, ttPlatform, wechatPlatform };
1191
+ export { type AstEngineName, type AutoImportTagsOptions, type AutoUsingComponentsOptions, CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, type ClassStyleBinding, type ClassStyleRuntime, type CollectVueTemplateTagsOptions, type CompileVueFileOptions, type CompilerDiagnostic, type CompilerDiagnosticCode, type CompilerDiagnosticSeverity, type CompilerDiagnosticSource, type ForParseResult, type InlineExpressionAsset, type JsLikeLang, type JsonConfig, type JsonMergeContext, type JsonMergeStage, type JsonMergeStrategy, type MiniProgramPlatform, type ModuleResolver, type MpPlatform, RESERVED_VUE_COMPONENT_TAGS, type ReadAndParseSfcOptions, type ResolveSfcBlockSrcOptions, type ResolvedUsingComponentInfo, type ResolvedUsingComponentPath, type ScopedSlotComponentAsset, type SlotFallbackWrapperComponentAsset, type SlotFallbackWrapperStrategy, type SourcePosition, type SourceSpan, type StyleCompileOptions, type StyleCompileResult, type TemplateCompileOptions, type TemplateCompileResult, type TemplateRefBinding, type TransformResult, type TransformScriptOptions, type TransformUniAppSourceOptions, type UniAppCompatibilityTarget, VUE_COMPONENT_TAG_RE, VUE_SFC_BLOCK_TYPES, type VueSfcBlockChanges, type VueSfcBlockSignatures, type VueSfcBlockType, type VueSfcHmrSignatures, type VueTransformResult, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, WE_VU_INTERNAL_REACTIVITY_APIS, WE_VU_INTERNAL_REACTIVITY_MODULE_ID, WE_VU_INTERNAL_RUNTIME_MODULE_ID, WE_VU_INTERNAL_TEMPLATE_APIS, WE_VU_INTERNAL_TEMPLATE_MODULE_ID, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, WE_VU_RUNTIME_MODULE_IDS, type WevuDefaults, WevuPageFeatureFlag, WevuPageHookName, WevuRuntimeApiName, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, classifyVueSfcBlockChanges, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeatureFlagsIntoOptionsObject, injectWevuPageFeaturesInJs, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isInvalidate, isJsonLikeLang, isUniAppCompatibilityFile, isWevuRuntimeModuleId, loadCache, mayContainJsonMacro, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveVueSfcHasTemplate, resolveVueSfcHmrSignatures, resolveVueSfcNonJsonSignature, resolveVueSfcScriptSignature, resolveVueSfcStyleIndependentSignature, resolveVueSfcTailwindContentSignature, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformNestedWxssVars, transformScript, transformScript as transformSfcScript, transformUniAppConditionalCode, transformUniAppSource, transformVueDeepSelectors, ttPlatform, wechatPlatform };