@weapp-vite/web 1.3.18 → 1.3.20

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 (103) hide show
  1. package/dist/compiler/wxml/attributes.mjs.map +1 -1
  2. package/dist/compiler/wxml/compile.mjs.map +1 -1
  3. package/dist/compiler/wxml/dependency.mjs.map +1 -1
  4. package/dist/compiler/wxml/interpolation.mjs.map +1 -1
  5. package/dist/compiler/wxml/navigation.mjs.map +1 -1
  6. package/dist/compiler/wxml/parser.mjs.map +1 -1
  7. package/dist/compiler/wxml/renderer.mjs.map +1 -1
  8. package/dist/compiler/wxml/specialNodes.mjs.map +1 -1
  9. package/dist/compiler/wxs.mjs.map +1 -1
  10. package/dist/css/wxss.mjs.map +1 -1
  11. package/dist/plugin/entry.mjs.map +1 -1
  12. package/dist/plugin/files.mjs.map +1 -1
  13. package/dist/plugin/index.mjs.map +1 -1
  14. package/dist/plugin/navigation.mjs.map +1 -1
  15. package/dist/plugin/path.mjs.map +1 -1
  16. package/dist/plugin/register.mjs.map +1 -1
  17. package/dist/plugin/scan.mjs.map +1 -1
  18. package/dist/plugin/scanConfig.mjs.map +1 -1
  19. package/dist/plugin/state.mjs.map +1 -1
  20. package/dist/runtime/button/helpers.mjs.map +1 -1
  21. package/dist/runtime/button/index.mjs.map +1 -1
  22. package/dist/runtime/button/style.mjs.map +1 -1
  23. package/dist/runtime/component/behavior.mjs.map +1 -1
  24. package/dist/runtime/component/dom.mjs.map +1 -1
  25. package/dist/runtime/component/element.mjs +3 -2
  26. package/dist/runtime/component/element.mjs.map +1 -1
  27. package/dist/runtime/component/events.mjs.map +1 -1
  28. package/dist/runtime/component/index.mjs.map +1 -1
  29. package/dist/runtime/component/state.mjs +2 -1
  30. package/dist/runtime/component/state.mjs.map +1 -1
  31. package/dist/runtime/component/utils.mjs.map +1 -1
  32. package/dist/runtime/execution.mjs.map +1 -1
  33. package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
  34. package/dist/runtime/legacyTemplate/expression.mjs.map +1 -1
  35. package/dist/runtime/legacyTemplate/index.mjs.map +1 -1
  36. package/dist/runtime/navigationBar/index.mjs.map +1 -1
  37. package/dist/runtime/polyfill/ad.mjs.map +1 -1
  38. package/dist/runtime/polyfill/appState.mjs.map +1 -1
  39. package/dist/runtime/polyfill/async.mjs.map +1 -1
  40. package/dist/runtime/polyfill/auth.mjs.map +1 -1
  41. package/dist/runtime/polyfill/authApi.mjs.map +1 -1
  42. package/dist/runtime/polyfill/background.mjs.map +1 -1
  43. package/dist/runtime/polyfill/canvasContext.mjs.map +1 -1
  44. package/dist/runtime/polyfill/capability.mjs.map +1 -1
  45. package/dist/runtime/polyfill/cloud.mjs.map +1 -1
  46. package/dist/runtime/polyfill/device.mjs.map +1 -1
  47. package/dist/runtime/polyfill/deviceApi.mjs.map +1 -1
  48. package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -1
  49. package/dist/runtime/polyfill/filePicker.mjs.map +1 -1
  50. package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -1
  51. package/dist/runtime/polyfill/files.mjs.map +1 -1
  52. package/dist/runtime/polyfill/index.mjs.map +1 -1
  53. package/dist/runtime/polyfill/interaction.mjs.map +1 -1
  54. package/dist/runtime/polyfill/interactionApi.mjs.map +1 -1
  55. package/dist/runtime/polyfill/location.mjs.map +1 -1
  56. package/dist/runtime/polyfill/locationApi.mjs.map +1 -1
  57. package/dist/runtime/polyfill/mediaActions.mjs.map +1 -1
  58. package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -1
  59. package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -1
  60. package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -1
  61. package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -1
  62. package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -1
  63. package/dist/runtime/polyfill/mediaInfo.mjs.map +1 -1
  64. package/dist/runtime/polyfill/mediaPicker.mjs.map +1 -1
  65. package/dist/runtime/polyfill/mediaProcess.mjs.map +1 -1
  66. package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
  67. package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -1
  68. package/dist/runtime/polyfill/network/request.mjs.map +1 -1
  69. package/dist/runtime/polyfill/network/requestBridge.mjs.map +1 -1
  70. package/dist/runtime/polyfill/network/status.mjs.map +1 -1
  71. package/dist/runtime/polyfill/platformApi.mjs.map +1 -1
  72. package/dist/runtime/polyfill/platformRuntime.mjs.map +1 -1
  73. package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -1
  74. package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -1
  75. package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -1
  76. package/dist/runtime/polyfill/routeRuntime/url.mjs.map +1 -1
  77. package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
  78. package/dist/runtime/polyfill/runtimeCapabilityApi.mjs.map +1 -1
  79. package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -1
  80. package/dist/runtime/polyfill/runtimeInfra.mjs.map +1 -1
  81. package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -1
  82. package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -1
  83. package/dist/runtime/polyfill/storage.mjs.map +1 -1
  84. package/dist/runtime/polyfill/storageAsync.mjs.map +1 -1
  85. package/dist/runtime/polyfill/subscribe.mjs.map +1 -1
  86. package/dist/runtime/polyfill/system.mjs.map +1 -1
  87. package/dist/runtime/polyfill/systemApi.mjs.map +1 -1
  88. package/dist/runtime/polyfill/ui.mjs.map +1 -1
  89. package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -1
  90. package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -1
  91. package/dist/runtime/polyfill/videoContext.mjs.map +1 -1
  92. package/dist/runtime/polyfill/vkSession.mjs.map +1 -1
  93. package/dist/runtime/polyfill/windowResize.mjs.map +1 -1
  94. package/dist/runtime/polyfill/worker.mjs.map +1 -1
  95. package/dist/runtime/renderContext.mjs.map +1 -1
  96. package/dist/runtime/rpx.mjs.map +1 -1
  97. package/dist/runtime/style.mjs.map +1 -1
  98. package/dist/runtime/utils/object.mjs +8 -0
  99. package/dist/runtime/utils/object.mjs.map +1 -0
  100. package/dist/runtime/warning.mjs.map +1 -1
  101. package/dist/shared/slugify.mjs.map +1 -1
  102. package/dist/shared/wxml.mjs.map +1 -1
  103. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.mjs","names":[],"sources":["../../../src/compiler/wxml/attributes.ts"],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport {\n CONTROL_ATTRS,\n EVENT_KIND_ALIAS,\n EVENT_PREFIX_RE,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport { buildExpression, parseInterpolations } from './interpolation'\n\nexport function extractFor(attribs: Record<string, string>) {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n const key = resolveControlAttributeValue(attribs, 'key')\n const restAttribs: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n restAttribs[name] = value\n }\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n return { expr, itemName, indexName, key, restAttribs }\n}\n\nexport function isConditionalElement(node: RenderNode): node is RenderElementNode {\n if (node.type !== 'element') {\n return false\n }\n const attribs = node.attribs ?? {}\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\n}\n\nexport function stripControlAttributes(attribs: Record<string, string>) {\n const result: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (!CONTROL_ATTRS.has(name)) {\n result[name] = value\n }\n }\n return result\n}\n\nfunction parseEventAttribute(name: string) {\n if (name.includes(':')) {\n const [prefix, rawEvent] = name.split(':', 2)\n return { prefix, rawEvent }\n }\n const match = EVENT_PREFIX_RE.exec(name)\n if (!match) {\n return undefined\n }\n return { prefix: name.slice(0, name.length - match[1].length), rawEvent: match[1] }\n}\n\nexport function resolveComponentTagName(name: string, componentTags?: Record<string, string>) {\n if (!componentTags) {\n return undefined\n }\n return componentTags[name] ?? componentTags[name.toLowerCase()]\n}\n\nconst PROPERTY_BIND_EXCLUSIONS = new Set(['class', 'style', 'id', 'slot'])\n\nfunction shouldBindAsProperty(name: string) {\n if (PROPERTY_BIND_EXCLUSIONS.has(name)) {\n return false\n }\n if (name.startsWith('data-') || name.startsWith('aria-')) {\n return false\n }\n return true\n}\n\nfunction normalizePropertyName(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function renderAttributes(\n attribs: Record<string, string>,\n scopeVar: string,\n wxsVar: string,\n options?: { skipControl?: boolean, preferProperty?: boolean },\n) {\n let buffer = ''\n for (const [rawName, rawValue] of Object.entries(attribs)) {\n if (options?.skipControl && CONTROL_ATTRS.has(rawName)) {\n continue\n }\n const eventInfo = parseEventAttribute(rawName)\n if (eventInfo) {\n const event = eventInfo.rawEvent.toLowerCase()\n const handlerExpr = buildExpression(parseInterpolations(rawValue ?? ''), scopeVar, wxsVar)\n const domEvent = EVENT_KIND_ALIAS[event] ?? event\n const flags = {\n catch: eventInfo.prefix.includes('catch'),\n capture: eventInfo.prefix.includes('capture'),\n }\n buffer += ` @${domEvent}=\\${ctx.event(${JSON.stringify(event)}, ${handlerExpr}, ${scopeVar}, ${wxsVar}, ${JSON.stringify(flags)})}`\n continue\n }\n const useProperty = options?.preferProperty && shouldBindAsProperty(rawName)\n const name = useProperty ? normalizePropertyName(rawName) : normalizeAttributeName(rawName)\n const expr = buildExpression(parseInterpolations(rawValue ?? ''), scopeVar, wxsVar)\n buffer += ` ${useProperty ? '.' : ''}${name}=\\${${expr}}`\n }\n return buff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xml/attributes.ts"],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport {\n CONTROL_ATTRS,\n EVENT_KIND_ALIAS,\n EVENT_PREFIX_RE,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport { buildExpression, parseInterpolations } from './interpolation'\n\nexport function extractFor(attribs: Record<string, string>) {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n const key = resolveControlAttributeValue(attribs, 'key')\n const restAttribs: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n restAttribs[name] = value\n }\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n return { expr, itemName, indexName, key, restAttribs }\n}\n\nexport function isConditionalElement(node: RenderNode): node is RenderElementNode {\n if (node.type !== 'element') {\n return false\n }\n const attribs = node.attribs ?? {}\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\n}\n\nexport function stripControlAttributes(attribs: Record<string, string>) {\n const result: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (!CONTROL_ATTRS.has(name)) {\n result[name] = value\n }\n }\n return result\n}\n\nfunction parseEventAttribute(name: string) {\n if (name.includes(':')) {\n const [prefix, rawEvent] = name.split(':', 2)\n return { prefix, rawEvent }\n }\n const match = EVENT_PREFIX_RE.exec(name)\n if (!match) {\n return undefined\n }\n return { prefix: name.slice(0, name.length - match[1].length), rawEvent: match[1] }\n}\n\nexport function resolveComponentTagName(name: string, componentTags?: Record<string, string>) {\n if (!componentTags) {\n return undefined\n }\n return componentTags[name] ?? componentTags[name.toLowerCase()]\n}\n\nconst PROPERTY_BIND_EXCLUSIONS = new Set(['class', 'style', 'id', 'slot'])\n\nfunction shouldBindAsProperty(name: string) {\n if (PROPERTY_BIND_EXCLUSIONS.has(name)) {\n return false\n }\n if (name.startsWith('data-') || name.startsWith('aria-')) {\n return false\n }\n return true\n}\n\nfunction normalizePropertyName(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function renderAttributes(\n attribs: Record<string, string>,\n scopeVar: string,\n wxsVar: string,\n options?: { skipControl?: boolean, preferProperty?: boolean },\n) {\n let buffer = ''\n for (const [rawName, rawValue] of Object.entries(attribs)) {\n if (options?.skipControl && CONTROL_ATTRS.has(rawName)) {\n continue\n }\n const eventInfo = parseEventAttribute(rawName)\n if (eventInfo) {\n const event = eventInfo.rawEvent.toLowerCase()\n const handlerExpr = buildExpression(parseInterpolations(rawValue ?? ''), scopeVar, wxsVar)\n const domEvent = EVENT_KIND_ALIAS[event] ?? event\n const flags = {\n catch: eventInfo.prefix.includes('catch'),\n capture: eventInfo.prefix.includes('capture'),\n }\n buffer += ` @${domEvent}=\\${ctx.event(${JSON.stringify(event)}, ${handlerExpr}, ${scopeVar}, ${wxsVar}, ${JSON.stringify(flags)})}`\n continue\n }\n const useProperty = options?.preferProperty && shouldBindAsProperty(rawName)\n const name = useProperty ? normalizePropertyName(rawName) : normalizeAttributeName(rawName)\n const expr = buildExpression(parseInterpolations(rawValue ?? ''), scopeVar, wxsVar)\n buffer += ` ${useProperty ? '.' : ''}${name}=\\${${expr}}`\n }\n return buffer\n}\n"],"mappings":";;;;AAWA,SAAgB,WAAW,SAAiC;CAC1D,MAAM,OAAO,6BAA6B,SAAS,MAAM;CACzD,MAAM,WAAW,6BAA6B,SAAS,WAAW,EAAE,MAAM,IAAI;CAC9E,IAAI,YAAY,6BAA6B,SAAS,YAAY,EAAE,MAAM,IAAI;CAC9E,MAAM,MAAM,6BAA6B,SAAS,MAAM;CACxD,MAAM,cAAsC,EAAE;CAC9C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,EAAE;EACnD,IAAI,cAAc,IAAI,KA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SAAgB,iBACd,SACA,UACA,QACA,SACA;CACA,IAAI,SAAS;CACb,KAAK,MAAM,CAAC,SAAS,aAAa,OAAO,QAAQ,QAAQ,EAAE;EACzD,IAAI,SAAS,eAAe,cAAc,IAAI,QAAQ,EACpD;EAEF,MAAM,YAAY,oBAAoB,QAAQ;EAC9C,IAAI,WAAW;GACb,MAAM,QAAQ,UAAU,SAAS,aAAa;GAC9C,MAAM,cAAc,gBAAgB,oBAAoB,YAAY,GAAG,EAAE,UAAU,OAAO;GAC1F,MAAM,WAAW,iBAAiB,UAAU;GAC5C,MAAM,QAAQ;IACZ,OAAO,UAAU,OAAO,SAAS,QAAQ;IACzC,SAAS,UAAU,OAAO,SAAS,UAAU;IAC9C;GACD,UAAU,KAAK,SAAS,gBAAgB,KAAK,UAAU,MAAM,CAAC,IAAI,YAAY,IAAI,SAAS,IAAI,OAAO,IAAI,KAAK,UAAU,MAAM,CAAC;GAChI;;EAEF,MAAM,cAAc,SAAS,kBAAkB,qBAAqB,QAAQ;EAC5E,MAAM,OAAO,cAAc,sBAAsB,QAAQ,GAAG,uBAAuB,QAAQ;EAC3F,MAAM,OAAO,gBAAgB,oBAAoB,YAAY,GAAG,EAAE,UAAU,OAAO;EACnF,UAAU,IAAI,cAAc,MAAM,KAAK,KAAK,MAAM,KAAK;;CAEzD,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"compile.mjs","names":[],"sources":["../../../src/compiler/wxml/compile.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n TemplateDefinition,\n WxmlCompileOptions,\n WxmlCompileResult,\n WxsEntry,\n} from './types'\n\nimport { readFileSync } from 'node:fs'\nimport { addDependency, createDependencyContext, warnCircularTemplate, warnReadTemplate } from './dependency'\nimport { buildNavigationBarAttrs, extractNavigationBarFromPageMeta } from './navigation'\nimport { parseWxml } from './parser'\nimport { renderer } from './renderer'\nimport { collectSpecialNodes, normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from './specialNodes'\n\nexport function compileWxml(options: WxmlCompileOptions): WxmlCompileResult {\n const dependencyContext = options.dependencyContext ?? createDependencyContext()\n const expandDependencies = options.expandDependencies ?? !options.dependencyContext\n const warnings = dependencyContext.warnings\n\n const expandDependencyTree = (dependencies: string[], importer: string) => {\n for (const target of dependencies) {\n if (!target) {\n continue\n }\n if (dependencyContext.active.has(target)) {\n warnCircularTemplate(dependencyContext, importer, target)\n continue\n }\n if (dependencyContext.visited.has(target)) {\n continue\n }\n dependencyContext.visited.add(target)\n dependencyContext.active.add(target)\n let source: string\n try {\n source = readFileSync(target, 'utf8')\n }\n catch {\n warnReadTemplate(dependencyContext, target)\n dependencyContext.active.delete(target)\n continue\n }\n try {\n const result = compileWxml({\n id: target,\n source,\n resolveTemplatePath: options.resolveTemplatePath,\n resolveWxsPath: options.resolveWxsPath,\n dependencyContext,\n expandDependencies: false,\n })\n expandDependencyTree(result.dependencies, target)\n }\n catch (error) {\n if (error instanceof Error && error.message) {\n warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`)\n }\n }\n dependencyContext.active.delete(target)\n }\n }\n\n let nodes = parseWxml(options.source)\n let navigationBarAttrs: Record<string, string> | undefined\n if (options.navigationBar) {\n const extracted = extractNavigationBarFromPageMeta(nodes)\n nodes = extracted.nodes\n if (extracted.warnings.length > 0) {\n warnings.push(...extracted.warnings)\n }\n navigationBarAttrs = extracted.attrs\n }\n\n const templates: TemplateDefinition[] = []\n const includes: IncludeEntry[] = []\n const imports: ImportEntry[] = []\n const wxs: WxsEntry[] = []\n const wxsModules = new Map<string, string>()\n\n const renderNodesList = collectSpecialNodes(nodes, {\n templates,\n includes,\n imports,\n wxs,\n wxsModules,\n warnings,\n sourceId: options.id,\n resolveTemplate: (raw: string) => options.resolveTemplatePath(raw, options.id),\n resolveWxs: (raw: string) => options.resolveWxsPath(raw, options.id),\n })\n\n if (options.navigationBar && options.navigationBar.config.navigationStyle !== 'custom') {\n const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs)\n renderNodesList.unshift({\n type: 'element',\n name: 'weapp-navigation-bar',\n attribs: attrs,\n })\n }\n\n const importLines: string[] = [\n `import { html } from 'lit'`,\n `import { repeat } from 'lit/directives/repeat.js'`,\n ]\n const bodyLines: string[] = []\n const directDependencies: string[] = []\n\n for (const entry of imports) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { templates as ${entry.importName} } from '${importPath}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of includes) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { render as ${entry.importName} } from '${importPath}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of wxs) {\n if (entry.kind === 'src') {\n const baseImport = normalizeTemplatePath(toRelativeImport(options.id, entry.value))\n const importPath = shouldMarkWxsImport(entry.value)\n ? `${baseImport}?wxs`\n : baseImport\n importLines.push(`import ${entry.importName} from '${importPath}'`)\n addDependency(entry.value, dependencyContext, directDependencies)\n }\n }\n\n if (templates.length > 0 || imports.length > 0) {\n const templatePairs: string[] = []\n for (const entry of imports) {\n templatePairs.push(`...${entry.importName}`)\n }\n for (const template of templates) {\n const rendered = renderer.renderNodes(template.nodes, 'scope', '__wxs_modules', options.componentTags)\n templatePairs.push(`${JSON.stringify(template.name)}: (scope, ctx) => ${rendered}`)\n }\n bodyLines.push(`const __templates = { ${templatePairs.join(', ')} }`)\n }\n else {\n bodyLines.push(`const __templates = {}`)\n }\n\n if (wxs.length > 0) {\n bodyLines.push(`const __wxs_inline_cache = Object.create(null)`)\n bodyLines.push(`let __wxs_modules = {}`)\n const wxsMapEntries: string[] = []\n for (const entry of wxs) {\n if (entry.kind === 'inline') {\n const inlineCode = entry.value.trim()\n const cacheKey = JSON.stringify(entry.module)\n if (inlineCode) {\n bodyLines.push(`function ${entry.importName}(ctx) {`)\n bodyLines.push(` if (!__wxs_inline_cache[${cacheKey}]) {`)\n bodyLines.push(` __wxs_inline_cache[${cacheKey}] = ctx.createWxsModule(${JSON.stringify(inlineCode)}, ${JSON.stringify(options.id)})`)\n bodyLines.push(` }`)\n bodyLines.push(` return __wxs_inline_cache[${cacheKey}]`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`function ${entry.importName}() { return {} }`)\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}(ctx)`)\n continue\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}`)\n }\n bodyLines.push(`function __resolveWxsModules(ctx) {`)\n bodyLines.push(` return { ${wxsMapEntries.join(', ')} }`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`const __wxs_modules = {}`)\n }\n\n const includesRender = includes.map(entry => `${entry.importName}(scope, ctx)`)\n const renderContent = renderer.renderNodes(renderNodesList, 'scope', '__wxs_modules', options.componentTags)\n const contentExpr = includesRender.length > 0\n ? `[${[...includesRender, renderContent].join(', ')}]`\n : renderContent\n\n bodyLines.push(`export function render(scope, ctx) {`)\n if (wxs.length > 0) {\n bodyLines.push(` __wxs_modules = __resolveWxsModules(ctx)`)\n }\n bodyLines.push(` return ${contentExpr}`)\n bodyLines.push(`}`)\n bodyLines.push(`export const templates = __templates`)\n bodyLines.push(`export default render`)\n\n if (expandDependencies) {\n dependencyContext.visited.add(options.id)\n dependencyContext.active.add(options.id)\n expandDependencyTree(directDependencies, options.id)\n dependencyContext.active.delete(options.id)\n }\n\n const code = [...importLines, '', ...bodyLines].join('\\n')\n const dependencies = expandDependencies ? dependencyContext.dependencies : directDependencies\n return {\n code,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n"],"mappings":";;;;;;;;AAgBA,SAAgB,YAAY,SAAgD;CAC1E,MAAM,oBAAoB,QAAQ,qBAAqB,yBAAyB;CAChF,MAAM,qBAAqB,QAAQ,sBAAsB,CAAC,QAAQ;CAClE,MAAM,WAAW,kBAAkB;CAEnC,MAAM,wBAAwB,cAAwB,aAAqB;AACzE,O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uCAAuC;AACtD,KAAI,IAAI,SAAS,EACf,WAAU,KAAK,6CAA6C;AAE9D,WAAU,KAAK,YAAY,cAAc;AACzC,WAAU,KAAK,IAAI;AACnB,WAAU,KAAK,uCAAuC;AACtD,WAAU,KAAK,wBAAwB;AAEvC,KAAI,oBAAoB;AACtB,oBAAkB,QAAQ,IAAI,QAAQ,GAAG;AACzC,oBAAkB,OAAO,IAAI,QAAQ,GAAG;AACxC,uBAAqB,oBAAoB,QAAQ,GAAG;AACpD,oBAAkB,OAAO,OAAO,QAAQ,GAAG;;AAK7C,QAAO;EACL,MAHW;GAAC,GAAG;GAAa;GAAI,GAAG;GAAU,CAAC,KAAK,KAAK;EAIxD,cAHmB,qBAAqB,kBAAkB,eAAe;EAIzE,UAAU,SAAS,SAAS,IAAI,WAAW;EAC5C"}
1
+ {"version":3,"file":"compile.mjs","names":[],"sources":["../../../src/compiler/wxml/compile.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n TemplateDefinition,\n WxmlCompileOptions,\n WxmlCompileResult,\n WxsEntry,\n} from './types'\n\nimport { readFileSync } from 'node:fs'\nimport { addDependency, createDependencyContext, warnCircularTemplate, warnReadTemplate } from './dependency'\nimport { buildNavigationBarAttrs, extractNavigationBarFromPageMeta } from './navigation'\nimport { parseWxml } from './parser'\nimport { renderer } from './renderer'\nimport { collectSpecialNodes, normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from './specialNodes'\n\nexport function compileWxml(options: WxmlCompileOptions): WxmlCompileResult {\n const dependencyContext = options.dependencyContext ?? createDependencyContext()\n const expandDependencies = options.expandDependencies ?? !options.dependencyContext\n const warnings = dependencyContext.warnings\n\n const expandDependencyTree = (dependencies: string[], importer: string) => {\n for (const target of dependencies) {\n if (!target) {\n continue\n }\n if (dependencyContext.active.has(target)) {\n warnCircularTemplate(dependencyContext, importer, target)\n continue\n }\n if (dependencyContext.visited.has(target)) {\n continue\n }\n dependencyContext.visited.add(target)\n dependencyContext.active.add(target)\n let source: string\n try {\n source = readFileSync(target, 'utf8')\n }\n catch {\n warnReadTemplate(dependencyContext, target)\n dependencyContext.active.delete(target)\n continue\n }\n try {\n const result = compileWxml({\n id: target,\n source,\n resolveTemplatePath: options.resolveTemplatePath,\n resolveWxsPath: options.resolveWxsPath,\n dependencyContext,\n expandDependencies: false,\n })\n expandDependencyTree(result.dependencies, target)\n }\n catch (error) {\n if (error instanceof Error && error.message) {\n warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`)\n }\n }\n dependencyContext.active.delete(target)\n }\n }\n\n let nodes = parseWxml(options.source)\n let navigationBarAttrs: Record<string, string> | undefined\n if (options.navigationBar) {\n const extracted = extractNavigationBarFromPageMeta(nodes)\n nodes = extracted.nodes\n if (extracted.warnings.length > 0) {\n warnings.push(...extracted.warnings)\n }\n navigationBarAttrs = extracted.attrs\n }\n\n const templates: TemplateDefinition[] = []\n const includes: IncludeEntry[] = []\n const imports: ImportEntry[] = []\n const wxs: WxsEntry[] = []\n const wxsModules = new Map<string, string>()\n\n const renderNodesList = collectSpecialNodes(nodes, {\n templates,\n includes,\n imports,\n wxs,\n wxsModules,\n warnings,\n sourceId: options.id,\n resolveTemplate: (raw: string) => options.resolveTemplatePath(raw, options.id),\n resolveWxs: (raw: string) => options.resolveWxsPath(raw, options.id),\n })\n\n if (options.navigationBar && options.navigationBar.config.navigationStyle !== 'custom') {\n const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs)\n renderNodesList.unshift({\n type: 'element',\n name: 'weapp-navigation-bar',\n attribs: attrs,\n })\n }\n\n const importLines: string[] = [\n `import { html } from 'lit'`,\n `import { repeat } from 'lit/directives/repeat.js'`,\n ]\n const bodyLines: string[] = []\n const directDependencies: string[] = []\n\n for (const entry of imports) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { templates as ${entry.importName} } from '${importPath}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of includes) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { render as ${entry.importName} } from '${importPath}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of wxs) {\n if (entry.kind === 'src') {\n const baseImport = normalizeTemplatePath(toRelativeImport(options.id, entry.value))\n const importPath = shouldMarkWxsImport(entry.value)\n ? `${baseImport}?wxs`\n : baseImport\n importLines.push(`import ${entry.importName} from '${importPath}'`)\n addDependency(entry.value, dependencyContext, directDependencies)\n }\n }\n\n if (templates.length > 0 || imports.length > 0) {\n const templatePairs: string[] = []\n for (const entry of imports) {\n templatePairs.push(`...${entry.importName}`)\n }\n for (const template of templates) {\n const rendered = renderer.renderNodes(template.nodes, 'scope', '__wxs_modules', options.componentTags)\n templatePairs.push(`${JSON.stringify(template.name)}: (scope, ctx) => ${rendered}`)\n }\n bodyLines.push(`const __templates = { ${templatePairs.join(', ')} }`)\n }\n else {\n bodyLines.push(`const __templates = {}`)\n }\n\n if (wxs.length > 0) {\n bodyLines.push(`const __wxs_inline_cache = Object.create(null)`)\n bodyLines.push(`let __wxs_modules = {}`)\n const wxsMapEntries: string[] = []\n for (const entry of wxs) {\n if (entry.kind === 'inline') {\n const inlineCode = entry.value.trim()\n const cacheKey = JSON.stringify(entry.module)\n if (inlineCode) {\n bodyLines.push(`function ${entry.importName}(ctx) {`)\n bodyLines.push(` if (!__wxs_inline_cache[${cacheKey}]) {`)\n bodyLines.push(` __wxs_inline_cache[${cacheKey}] = ctx.createWxsModule(${JSON.stringify(inlineCode)}, ${JSON.stringify(options.id)})`)\n bodyLines.push(` }`)\n bodyLines.push(` return __wxs_inline_cache[${cacheKey}]`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`function ${entry.importName}() { return {} }`)\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}(ctx)`)\n continue\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}`)\n }\n bodyLines.push(`function __resolveWxsModules(ctx) {`)\n bodyLines.push(` return { ${wxsMapEntries.join(', ')} }`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`const __wxs_modules = {}`)\n }\n\n const includesRender = includes.map(entry => `${entry.importName}(scope, ctx)`)\n const renderContent = renderer.renderNodes(renderNodesList, 'scope', '__wxs_modules', options.componentTags)\n const contentExpr = includesRender.length > 0\n ? `[${[...includesRender, renderContent].join(', ')}]`\n : renderContent\n\n bodyLines.push(`export function render(scope, ctx) {`)\n if (wxs.length > 0) {\n bodyLines.push(` __wxs_modules = __resolveWxsModules(ctx)`)\n }\n bodyLines.push(` return ${contentExpr}`)\n bodyLines.push(`}`)\n bodyLines.push(`export const templates = __templates`)\n bodyLines.push(`export default render`)\n\n if (expandDependencies) {\n dependencyContext.visited.add(options.id)\n dependencyContext.active.add(options.id)\n expandDependencyTree(directDependencies, options.id)\n dependencyContext.active.delete(options.id)\n }\n\n const code = [...importLines, '', ...bodyLines].join('\\n')\n const dependencies = expandDependencies ? dependencyContext.dependencies : directDependencies\n return {\n code,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n"],"mappings":";;;;;;;;AAgBA,SAAgB,YAAY,SAAgD;CAC1E,MAAM,oBAAoB,QAAQ,qBAAqB,yBAAyB;CAChF,MAAM,qBAAqB,QAAQ,sBAAsB,CAAC,QAAQ;CAClE,MAAM,WAAW,kBAAkB;CAEnC,MAAM,wBAAwB,cAAwB,aAAqB;EACzE,KAAK,MAAM,UAAU,cAAc;GACjC,IAAI,CAAC,QACH;GAEF,IAAI,kBAAkB,OAAO,IAAI,OAAO,EAAE;IACxC,qBAAqB,mBAAmB,UAAU,OAAO;IACzD;;GAEF,IAAI,kBAAkB,QAAQ,IAAI,OAAO,EACvC;GAEF,kBAAkB,QAAQ,IAAI,OAAO;GACrC,kBAAkB,OAAO,IAAI,OAAO;GACpC,IAAI;GACJ,IAAI;IACF,SAAS,aAAa,QAAQ,OAAO;WAEjC;IACJ,iBAAiB,mBAAmB,OAA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C,OAAO;EACL,MAHW;GAAC,GAAG;GAAa;GAAI,GAAG;GAAU,CAAC,KAAK,KAG/C;EACJ,cAHmB,qBAAqB,kBAAkB,eAAe;EAIzE,UAAU,SAAS,SAAS,IAAI,WAAW;EAC5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"dependency.mjs","names":[],"sources":["../../../src/compiler/wxml/dependency.ts"],"sourcesContent":["import type { WxmlDependencyContext } from './types'\n\nexport function createDependencyContext(): WxmlDependencyContext {\n return {\n warnings: [],\n dependencies: [],\n dependencySet: new Set(),\n visited: new Set(),\n active: new Set(),\n circularWarnings: new Set(),\n }\n}\n\nexport function addDependency(\n value: string,\n context: WxmlDependencyContext,\n direct?: string[],\n) {\n if (!context.dependencySet.has(value)) {\n context.dependencySet.add(value)\n context.dependencies.push(value)\n direct?.push(value)\n }\n}\n\nexport function warnReadTemplate(context: WxmlDependencyContext, target: string) {\n context.warnings.push(`[web] 无法读取模板依赖: ${target}`)\n}\n\nexport function warnCircularTemplate(\n context: WxmlDependencyContext,\n from: string,\n target: string,\n) {\n const key = `${from}=>${target}`\n if (context.circularWarnings.has(key)) {\n return\n }\n context.circularWarnings.add(key)\n context.warnings.push(`[web] WXML 循环引用: ${from} -> ${target}`)\n}\n"],"mappings":";AAEA,SAAgB,0BAAiD;AAC/D,QAAO;EACL,UAAU,EAAE;EACZ,cAAc,EAAE;EAChB,+BAAe,IAAI,KAAK;EACxB,yBAAS,IAAI,KAAK;EAClB,wBAAQ,IAAI,KAAK;EACjB,kCAAkB,IAAI,KAAK;EAC5B;;AAGH,SAAgB,cACd,OACA,SACA,QACA;AACA,KAAI,CAAC,QAAQ,cAAc,IAAI,MAAM,EAAE;AACrC,UAAQ,cAAc,IAAI,MAAM;AAChC,UAAQ,aAAa,KAAK,MAAM;AAChC,UAAQ,KAAK,MAAM;;;AAIvB,SAAgB,iBAAiB,SAAgC,QAAgB;AAC/E,SAAQ,SAAS,KAAK,mBAAmB,SAAS;;AAGpD,SAAgB,qBACd,SACA,MACA,QACA;CACA,MAAM,MAAM,GAAG,KAAK,IAAI;AACxB,KAAI,QAAQ,iBAAiB,IAAI,IAAI,CACnC;AAEF,SAAQ,iBAAiB,IAAI,IAAI;AACjC,SAAQ,SAAS,KAAK,oBAAoB,KAAK,MAAM,SAAS"}
1
+ {"version":3,"file":"dependency.mjs","names":[],"sources":["../../../src/compiler/wxml/dependency.ts"],"sourcesContent":["import type { WxmlDependencyContext } from './types'\n\nexport function createDependencyContext(): WxmlDependencyContext {\n return {\n warnings: [],\n dependencies: [],\n dependencySet: new Set(),\n visited: new Set(),\n active: new Set(),\n circularWarnings: new Set(),\n }\n}\n\nexport function addDependency(\n value: string,\n context: WxmlDependencyContext,\n direct?: string[],\n) {\n if (!context.dependencySet.has(value)) {\n context.dependencySet.add(value)\n context.dependencies.push(value)\n direct?.push(value)\n }\n}\n\nexport function warnReadTemplate(context: WxmlDependencyContext, target: string) {\n context.warnings.push(`[web] 无法读取模板依赖: ${target}`)\n}\n\nexport function warnCircularTemplate(\n context: WxmlDependencyContext,\n from: string,\n target: string,\n) {\n const key = `${from}=>${target}`\n if (context.circularWarnings.has(key)) {\n return\n }\n context.circularWarnings.add(key)\n context.warnings.push(`[web] WXML 循环引用: ${from} -> ${target}`)\n}\n"],"mappings":";AAEA,SAAgB,0BAAiD;CAC/D,OAAO;EACL,UAAU,EAAE;EACZ,cAAc,EAAE;EAChB,+BAAe,IAAI,KAAK;EACxB,yBAAS,IAAI,KAAK;EAClB,wBAAQ,IAAI,KAAK;EACjB,kCAAkB,IAAI,KAAK;EAC5B;;AAGH,SAAgB,cACd,OACA,SACA,QACA;CACA,IAAI,CAAC,QAAQ,cAAc,IAAI,MAAM,EAAE;EACrC,QAAQ,cAAc,IAAI,MAAM;EAChC,QAAQ,aAAa,KAAK,MAAM;EAChC,QAAQ,KAAK,MAAM;;;AAIvB,SAAgB,iBAAiB,SAAgC,QAAgB;CAC/E,QAAQ,SAAS,KAAK,mBAAmB,SAAS;;AAGpD,SAAgB,qBACd,SACA,MACA,QACA;CACA,MAAM,MAAM,GAAG,KAAK,IAAI;CACxB,IAAI,QAAQ,iBAAiB,IAAI,IAAI,EACnC;CAEF,QAAQ,iBAAiB,IAAI,IAAI;CACjC,QAAQ,SAAS,KAAK,oBAAoB,KAAK,MAAM,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"interpolation.mjs","names":[],"sources":["../../../src/compiler/wxml/interpolation.ts"],"sourcesContent":["import type { InterpolationPart } from './types'\n\nexport function parseInterpolations(value: string): InterpolationPart[] {\n const parts: InterpolationPart[] = []\n if (!value.includes('{{')) {\n return [{ type: 'text', value }]\n }\n let cursor = 0\n while (cursor < value.length) {\n const start = value.indexOf('{{', cursor)\n if (start === -1) {\n parts.push({ type: 'text', value: value.slice(cursor) })\n break\n }\n if (start > cursor) {\n parts.push({ type: 'text', value: value.slice(cursor, start) })\n }\n const end = value.indexOf('}}', start + 2)\n if (end === -1) {\n parts.push({ type: 'text', value: value.slice(start) })\n break\n }\n const expr = value.slice(start + 2, end).trim()\n if (expr) {\n parts.push({ type: 'expr', value: expr })\n }\n cursor = end + 2\n }\n return parts\n}\n\nexport function buildExpression(parts: InterpolationPart[], scopeVar: string, wxsVar: string) {\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1 && parts[0]?.type === 'text') {\n return JSON.stringify(parts[0].value)\n }\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n return `ctx.eval(${JSON.stringify(parts[0].value)}, ${scopeVar}, ${wxsVar})`\n }\n const segments = parts.map((part) => {\n if (part.type === 'text') {\n return JSON.stringify(part.value)\n }\n return `ctx.eval(${JSON.stringify(part.value)}, ${scopeVar}, ${wxsVar})`\n })\n return `(${segments.join(' + ')})`\n}\n\nfunction hasTopLevelColon(expression: string) {\n let depth = 0\n let inSingleQuote = false\n let inDoubleQuote = false\n let inTemplate = false\n let escaped = false\n let sawTopLevelQuestion = false\n\n for (let index = 0; index < expression.length; index += 1) {\n const char = expression[index]!\n\n if (inSingleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\\'') {\n inSingleQuote = false\n }\n continue\n }\n if (inDoubleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = false\n }\n continue\n }\n if (inTemplate) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '`') {\n inTemplate = false\n }\n continue\n }\n\n if (char === '\\'') {\n inSingleQuote = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = true\n continue\n }\n if (char === '`') {\n inTemplate = true\n continue\n }\n\n if (char === '(' || char === '[' || char === '{') {\n depth += 1\n continue\n }\n if (char === ')' || char === ']' || char === '}') {\n depth = Math.max(0, depth - 1)\n continue\n }\n\n if (depth !== 0) {\n continue\n }\n\n if (char === '?') {\n sawTopLevelQuestion = true\n continue\n }\n if (char === ':') {\n return !sawTopLevelQuestion\n }\n }\n\n return false\n}\n\nfunction shouldWrapShorthandObject(expression: string) {\n const trimmed = expression.trim()\n if (!trimmed) {\n return false\n }\n if (trimmed.startsWith('{') || trimmed.startsWith('[') || trimmed.startsWith('(')) {\n return false\n }\n return hasTopLevelColon(trimmed)\n}\n\nexport function buildTemplateDataExpression(raw: string, scopeVar: string, wxsVar: string) {\n const trimmed = raw.trim()\n const parts = parseInterpolations(trimmed)\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n const expr = parts[0].value.trim()\n if (expr) {\n const normalizedExpr = shouldWrapShorthandObject(expr) ? `{ ${expr} }` : expr\n return buildExpression([{ type: 'expr', value: normalizedExpr }], scopeVar, wxsVar)\n }\n }\n return buildExpression(parseInterpolations(raw), scopeVar, wxsVar)\n}\n"],"mappings":";AAEA,SAAgB,oBAAoB,OAAoC;CACtE,MAAM,QAA6B,EAAE;AACrC,KAAI,CAAC,MAAM,SAAS,KAAK,CACvB,QAAO,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AEzF,MAAM,QAAQ,oBADE,IAAI,MAAM,CACgB;AAC1C,KAAI,MAAM,WAAW,KAAK,MAAM,IAAI,SAAS,QAAQ;EACnD,MAAM,OAAO,MAAM,GAAG,MAAM,MAAM;AAClC,MAAI,KAEF,QAAO,gBAAgB,CAAC;GAAE,MAAM;GAAQ,OADjB,0BAA0B,KAAK,GAAG,KAAK,KAAK,MAAM;GACV,CAAC,EAAE,UAAU,OAAO;;AAGvF,QAAO,gBAAgB,oBAAoB,IAAI,EAAE,UAAU,OAAO"}
1
+ {"version":3,"file":"interpolation.mjs","names":[],"sources":["../../../src/compiler/wxml/interpolation.ts"],"sourcesContent":["import type { InterpolationPart } from './types'\n\nexport function parseInterpolations(value: string): InterpolationPart[] {\n const parts: InterpolationPart[] = []\n if (!value.includes('{{')) {\n return [{ type: 'text', value }]\n }\n let cursor = 0\n while (cursor < value.length) {\n const start = value.indexOf('{{', cursor)\n if (start === -1) {\n parts.push({ type: 'text', value: value.slice(cursor) })\n break\n }\n if (start > cursor) {\n parts.push({ type: 'text', value: value.slice(cursor, start) })\n }\n const end = value.indexOf('}}', start + 2)\n if (end === -1) {\n parts.push({ type: 'text', value: value.slice(start) })\n break\n }\n const expr = value.slice(start + 2, end).trim()\n if (expr) {\n parts.push({ type: 'expr', value: expr })\n }\n cursor = end + 2\n }\n return parts\n}\n\nexport function buildExpression(parts: InterpolationPart[], scopeVar: string, wxsVar: string) {\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1 && parts[0]?.type === 'text') {\n return JSON.stringify(parts[0].value)\n }\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n return `ctx.eval(${JSON.stringify(parts[0].value)}, ${scopeVar}, ${wxsVar})`\n }\n const segments = parts.map((part) => {\n if (part.type === 'text') {\n return JSON.stringify(part.value)\n }\n return `ctx.eval(${JSON.stringify(part.value)}, ${scopeVar}, ${wxsVar})`\n })\n return `(${segments.join(' + ')})`\n}\n\nfunction hasTopLevelColon(expression: string) {\n let depth = 0\n let inSingleQuote = false\n let inDoubleQuote = false\n let inTemplate = false\n let escaped = false\n let sawTopLevelQuestion = false\n\n for (let index = 0; index < expression.length; index += 1) {\n const char = expression[index]!\n\n if (inSingleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\\'') {\n inSingleQuote = false\n }\n continue\n }\n if (inDoubleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = false\n }\n continue\n }\n if (inTemplate) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '`') {\n inTemplate = false\n }\n continue\n }\n\n if (char === '\\'') {\n inSingleQuote = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = true\n continue\n }\n if (char === '`') {\n inTemplate = true\n continue\n }\n\n if (char === '(' || char === '[' || char === '{') {\n depth += 1\n continue\n }\n if (char === ')' || char === ']' || char === '}') {\n depth = Math.max(0, depth - 1)\n continue\n }\n\n if (depth !== 0) {\n continue\n }\n\n if (char === '?') {\n sawTopLevelQuestion = true\n continue\n }\n if (char === ':') {\n return !sawTopLevelQuestion\n }\n }\n\n return false\n}\n\nfunction shouldWrapShorthandObject(expression: string) {\n const trimmed = expression.trim()\n if (!trimmed) {\n return false\n }\n if (trimmed.startsWith('{') || trimmed.startsWith('[') || trimmed.startsWith('(')) {\n return false\n }\n return hasTopLevelColon(trimmed)\n}\n\nexport function buildTemplateDataExpression(raw: string, scopeVar: string, wxsVar: string) {\n const trimmed = raw.trim()\n const parts = parseInterpolations(trimmed)\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n const expr = parts[0].value.trim()\n if (expr) {\n const normalizedExpr = shouldWrapShorthandObject(expr) ? `{ ${expr} }` : expr\n return buildExpression([{ type: 'expr', value: normalizedExpr }], scopeVar, wxsVar)\n }\n }\n return buildExpression(parseInterpolations(raw), scopeVar, wx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AAW,IAAI,IAAI,QAAQ,WAAW,IAAI,EAC/E,OAAO;CAET,OAAO,iBAAiB,QAAQ;;AAGlC,SAAgB,4BAA4B,KAAa,UAAkB,QAAgB;CAEzF,MAAM,QAAQ,oBADE,IAAI,MACqB,CAAC;CAC1C,IAAI,MAAM,WAAW,KAAK,MAAM,IAAI,SAAS,QAAQ;EACnD,MAAM,OAAO,MAAM,GAAG,MAAM,MAAM;EAClC,IAAI,MAEF,OAAO,gBAAgB,CAAC;GAAE,MAAM;GAAQ,OADjB,0BAA0B,KAAK,GAAG,KAAK,KAAK,MAAM;GACV,CAAC,EAAE,UAAU,OAAO;;CAGvF,OAAO,gBAAgB,oBAAoB,IAAI,EAAE,UAAU,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"navigation.mjs","names":[],"sources":["../../../src/compiler/wxml/navigation.ts"],"sourcesContent":["import type { NavigationBarConfig, RenderElementNode, RenderNode } from './types'\n\nconst NAVIGATION_BAR_ATTRS = new Set([\n 'title',\n 'background-color',\n 'text-style',\n 'front-color',\n 'loading',\n])\n\nfunction stripPageMetaNodes(nodes: RenderNode[]): RenderNode[] {\n const stripped: RenderNode[] = []\n for (const node of nodes) {\n if (node.type === 'element' && node.name === 'page-meta') {\n continue\n }\n if (node.type === 'element' && node.children?.length) {\n const nextChildren = stripPageMetaNodes(node.children)\n if (nextChildren !== node.children) {\n stripped.push({ ...node, children: nextChildren })\n continue\n }\n }\n stripped.push(node)\n }\n return stripped\n}\n\nfunction pickNavigationBarAttrs(attribs: Record<string, string> | undefined) {\n if (!attribs) {\n return undefined\n }\n const picked: Record<string, string> = {}\n for (const [key, value] of Object.entries(attribs)) {\n if (NAVIGATION_BAR_ATTRS.has(key)) {\n picked[key] = value\n }\n }\n return Object.keys(picked).length > 0 ? picked : undefined\n}\n\nfunction findNavigationBarInPageMeta(node: RenderElementNode) {\n const children = node.children ?? []\n for (const child of children) {\n if (child.type === 'element' && child.name === 'navigation-bar') {\n return child\n }\n }\n return undefined\n}\n\nexport function extractNavigationBarFromPageMeta(nodes: RenderNode[]): {\n nodes: RenderNode[]\n attrs?: Record<string, string>\n warnings: string[]\n} {\n let pageMetaIndex = -1\n let navigationBar: RenderElementNode | undefined\n for (let i = 0; i < nodes.length; i += 1) {\n const node = nodes[i]\n if (node.type === 'element' && node.name === 'page-meta') {\n if (pageMetaIndex === -1) {\n pageMetaIndex = i\n }\n if (!navigationBar) {\n navigationBar = findNavigationBarInPageMeta(node)\n }\n }\n }\n const warnings: string[] = []\n if (pageMetaIndex > 0) {\n warnings.push('[web] page-meta 需要作为页面第一个节点,已忽略其位置约束。')\n }\n const cleaned = pageMetaIndex === -1 ? nodes : stripPageMetaNodes(nodes)\n const attrs = navigationBar ? pickNavigationBarAttrs(navigationBar.attribs) : undefined\n return { nodes: cleaned, attrs, warnings }\n}\n\nfunction toAttributeValue(value: unknown) {\n if (value == null) {\n return undefined\n }\n if (typeof value === 'string') {\n return value\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value)\n }\n return undefined\n}\n\nexport function buildNavigationBarAttrs(\n config: NavigationBarConfig | undefined,\n overrides?: Record<string, string>,\n) {\n const attrs: Record<string, string> = {}\n if (config?.title !== undefined) {\n const value = toAttributeValue(config.title)\n if (value !== undefined) {\n attrs.title = value\n }\n }\n if (config?.backgroundColor !== undefined) {\n const value = toAttributeValue(config.backgroundColor)\n if (value !== undefined) {\n attrs['background-color'] = value\n }\n }\n if (config?.textStyle !== undefined) {\n const value = toAttributeValue(config.textStyle)\n if (value !== undefined) {\n attrs['text-style'] = value\n }\n }\n if (config?.frontColor !== undefined) {\n const value = toAttributeValue(config.frontColor)\n if (value !== undefined) {\n attrs['front-color'] = value\n }\n }\n if (config?.loading) {\n attrs.loading = 'true'\n }\n if (overrides) {\n for (const [key, value] of Object.entries(overrides)) {\n attrs[key] = value\n }\n }\n return attrs\n}\n"],"mappings":";AAEA,MAAM,uBAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACD,CAA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SAAS,iBAAiB,OAAgB;AACxC,KAAI,SAAS,KACX;AAEF,KAAI,OAAO,UAAU,SACnB,QAAO;AAET,KAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAChD,QAAO,OAAO,MAAM;;AAKxB,SAAgB,wBACd,QACA,WACA;CACA,MAAM,QAAgC,EAAE;AACxC,KAAI,QAAQ,UAAU,QAAW;EAC/B,MAAM,QAAQ,iBAAiB,OAAO,MAAM;AAC5C,MAAI,UAAU,OACZ,OAAM,QAAQ;;AAGlB,KAAI,QAAQ,oBAAoB,QAAW;EACzC,MAAM,QAAQ,iBAAiB,OAAO,gBAAgB;AACtD,MAAI,UAAU,OACZ,OAAM,sBAAsB;;AAGhC,KAAI,QAAQ,cAAc,QAAW;EACnC,MAAM,QAAQ,iBAAiB,OAAO,UAAU;AAChD,MAAI,UAAU,OACZ,OAAM,gBAAgB;;AAG1B,KAAI,QAAQ,eAAe,QAAW;EACpC,MAAM,QAAQ,iBAAiB,OAAO,WAAW;AACjD,MAAI,UAAU,OACZ,OAAM,iBAAiB;;AAG3B,KAAI,QAAQ,QACV,OAAM,UAAU;AAElB,KAAI,UACF,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,CAClD,OAAM,OAAO;AAGjB,QAAO"}
1
+ {"version":3,"file":"navigation.mjs","names":[],"sources":["../../../src/compiler/wxml/navigation.ts"],"sourcesContent":["import type { NavigationBarConfig, RenderElementNode, RenderNode } from './types'\n\nconst NAVIGATION_BAR_ATTRS = new Set([\n 'title',\n 'background-color',\n 'text-style',\n 'front-color',\n 'loading',\n])\n\nfunction stripPageMetaNodes(nodes: RenderNode[]): RenderNode[] {\n const stripped: RenderNode[] = []\n for (const node of nodes) {\n if (node.type === 'element' && node.name === 'page-meta') {\n continue\n }\n if (node.type === 'element' && node.children?.length) {\n const nextChildren = stripPageMetaNodes(node.children)\n if (nextChildren !== node.children) {\n stripped.push({ ...node, children: nextChildren })\n continue\n }\n }\n stripped.push(node)\n }\n return stripped\n}\n\nfunction pickNavigationBarAttrs(attribs: Record<string, string> | undefined) {\n if (!attribs) {\n return undefined\n }\n const picked: Record<string, string> = {}\n for (const [key, value] of Object.entries(attribs)) {\n if (NAVIGATION_BAR_ATTRS.has(key)) {\n picked[key] = value\n }\n }\n return Object.keys(picked).length > 0 ? picked : undefined\n}\n\nfunction findNavigationBarInPageMeta(node: RenderElementNode) {\n const children = node.children ?? []\n for (const child of children) {\n if (child.type === 'element' && child.name === 'navigation-bar') {\n return child\n }\n }\n return undefined\n}\n\nexport function extractNavigationBarFromPageMeta(nodes: RenderNode[]): {\n nodes: RenderNode[]\n attrs?: Record<string, string>\n warnings: string[]\n} {\n let pageMetaIndex = -1\n let navigationBar: RenderElementNode | undefined\n for (let i = 0; i < nodes.length; i += 1) {\n const node = nodes[i]\n if (node.type === 'element' && node.name === 'page-meta') {\n if (pageMetaIndex === -1) {\n pageMetaIndex = i\n }\n if (!navigationBar) {\n navigationBar = findNavigationBarInPageMeta(node)\n }\n }\n }\n const warnings: string[] = []\n if (pageMetaIndex > 0) {\n warnings.push('[web] page-meta 需要作为页面第一个节点,已忽略其位置约束。')\n }\n const cleaned = pageMetaIndex === -1 ? nodes : stripPageMetaNodes(nodes)\n const attrs = navigationBar ? pickNavigationBarAttrs(navigationBar.attribs) : undefined\n return { nodes: cleaned, attrs, warnings }\n}\n\nfunction toAttributeValue(value: unknown) {\n if (value == null) {\n return undefined\n }\n if (typeof value === 'string') {\n return value\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value)\n }\n return undefined\n}\n\nexport function buildNavigationBarAttrs(\n config: NavigationBarConfig | undefined,\n overrides?: Record<string, string>,\n) {\n const attrs: Record<string, string> = {}\n if (config?.title !== undefined) {\n const value = toAttributeValue(config.title)\n if (value !== undefined) {\n attrs.title = value\n }\n }\n if (config?.backgroundColor !== undefined) {\n const value = toAttributeValue(config.backgroundColor)\n if (value !== undefined) {\n attrs['background-color'] = value\n }\n }\n if (config?.textStyle !== undefined) {\n const value = toAttributeValue(config.textStyle)\n if (value !== undefined) {\n attrs['text-style'] = value\n }\n }\n if (config?.frontColor !== undefined) {\n const value = toAttributeValue(config.frontColor)\n if (value !== undefined) {\n attrs['front-color'] = value\n }\n }\n if (config?.loading) {\n attrs.loading = 'true'\n }\n if (overrides) {\n for (const [key, value] of Object.entries(overrides)) {\n attrs[key] = value\n }\n }\n return attrs\n}\n"],"mappings":";AAEA,MAAM,uBAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,mBAAmB,OAAmC;CAC7D,MAAM,WAAyB,EAAE;CACjC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,SAAS,aAAa,KAAK,SAAS,aAC3C;EAEF,IAAI,KAAK,SAAS,aAAa,KAAK,UAAU,QAAQ;GACpD,MAAM,eAAe,mBAAmB,KAAK,SAAS;GACtD,IAAI,iBAAiB,KAAK,UAAU;IAClC,SAAS,KAAK;KAAE,GAAG;KAAM,UAAU;KAAc,CAAC;IAClD;;;EAGJ,SAAS,KAAK,KAAK;;CAErB,OAAO;;AAGT,SAAS,uBAAuB,SAA6C;CAC3E,IAAI,CAAC,SACH;CAEF,MAAM,SAAiC,EAAE;CACzC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,EAChD,IAAI,qBAAqB,IAAI,IAAI,EAC/B,OAAO,OAAO;CAGlB,OAAO,OAAO,KAAK,OAAO,CAAC,SAAS,IAAI,SAAS;;AAGnD,SAAS,4BAA4B,MAAyB;CAC5D,MAAM,WAAW,KAAK,YAAY,EAAE;CACpC,KAAK,MAAM,SAAS,UAClB,IAAI,MAAM,SAAS,aAAa,MAAM,SAAS,kBAC7C,OAAO;;AAMb,SAAgB,iCAAiC,OAI/C;CACA,IAAI,gBAAgB;CACpB,IAAI;CACJ,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxC,MAAM,OAAO,MAAM;EACnB,IAAI,KAAK,SAAS,aAAa,KAAK,SAAS,aAAa;GACxD,IAAI,kBAAkB,IACpB,gBAAgB;GAElB,IAAI,CAAC,eACH,gBAAgB,4BAA4B,KAAK;;;CAIvD,MAAM,WAAqB,EAAE;CAC7B,IAAI,gBAAgB,GAClB,SAAS,KAAK,wCAAwC;CAIxD,OAAO;EAAE,OAFO,kBAAkB,KAAK,QAAQ,mBAAmB,MAAM;EAE/C,OADX,gBAAgB,uBAAuB,cAAc,QAAQ,GAAG;EAC9C;EAAU;;AAG5C,SAAS,iBAAiB,OAAgB;CACxC,IAAI,SAAS,MACX;CAEF,IAAI,OAAO,UAAU,UACnB,OAAO;CAET,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,WAChD,OAAO,OAAO,MAAM;;AAKxB,SAAgB,wBACd,QACA,WACA;CACA,MAAM,QAAgC,EAAE;CACxC,IAAI,QAAQ,UAAU,QAAW;EAC/B,MAAM,QAAQ,iBAAiB,OAAO,MAAM;EAC5C,IAAI,UAAU,QACZ,MAAM,QAAQ;;CAGlB,IAAI,QAAQ,oBAAoB,QAAW;EACzC,MAAM,QAAQ,iBAAiB,OAAO,gBAAgB;EACtD,IAAI,UAAU,QACZ,MAAM,sBAAsB;;CAGhC,IAAI,QAAQ,cAAc,QAAW;EACnC,MAAM,QAAQ,iBAAiB,OAAO,UAAU;EAChD,IAAI,UAAU,QACZ,MAAM,gBAAgB;;CAG1B,IAAI,QAAQ,eAAe,QAAW;EACpC,MAAM,QAAQ,iBAAiB,OAAO,WAAW;EACjD,IAAI,UAAU,QACZ,MAAM,iBAAiB;;CAG3B,IAAI,QAAQ,SACV,MAAM,UAAU;CAElB,IAAI,WACF,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,EAClD,MAAM,OAAO;CAGjB,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"parser.mjs","names":[],"sources":["../../../src/compiler/wxml/parser.ts"],"sourcesContent":["import type { ChildNode, DataNode, Element, Node } from 'domhandler'\n\nimport type { RenderNode } from './types'\n\nimport { parseDocument } from 'htmlparser2'\n\nfunction isRenderableNode(node: Node) {\n if (node.type === 'directive' || node.type === 'comment') {\n return false\n }\n if (node.type === 'text') {\n const data = (node as DataNode).data ?? ''\n return data.trim().length > 0\n }\n return true\n}\n\ntype NodeWithChildren = Node & { children: ChildNode[] }\n\nfunction hasChildren(node: Node): node is NodeWithChildren {\n return Array.isArray((node as NodeWithChildren).children)\n}\n\nfunction toRenderNode(node: Node, children?: RenderNode[]): RenderNode | undefined {\n if (node.type === 'text') {\n const data = (node as DataNode).data ?? ''\n return { type: 'text', data }\n }\n if (node.type === 'tag' || node.type === 'script' || node.type === 'style') {\n const element = node as Element\n return {\n type: 'element',\n name: element.name,\n attribs: element.attribs ?? {},\n children,\n }\n }\n return undefined\n}\n\nfunction convertNode(node: Node): RenderNode | undefined {\n if (!isRenderableNode(node)) {\n return undefined\n }\n const children = (hasChildren(node) && node.children.length > 0)\n ? node.children.map(child => convertNode(child)).filter((child): child is RenderNode => Boolean(child))\n : undefined\n return toRenderNode(node, children)\n}\n\nexport function parseWxml(source: string): RenderNode[] {\n const document = parseDocument(source, {\n xmlMode: true,\n decodeEntities: true,\n recognizeSelfClosing: true,\n })\n const nodes = (document.children ?? []).filter(isRenderableNode)\n return nodes\n .map(node => convertNode(node))\n .filter((node): node is RenderNode => Boolean(node))\n}\n"],"mappings":";;;AAMA,SAAS,iBAAiB,MAAY;AACpC,KAAI,KAAK,SAAS,eAAe,KAAK,SAAS,UAC7C,QAAO;AAET,KAAI,KAAK,SAAS,OAEhB,SADc,KAAkB,QAAQ,IAC5B,MAAM,CAAC,SAAS;AAE9B,QAAO;;AAKT,SAAS,YAAY,MAAsC;AACzD,QAAO,MAAM,QAAS,KAA0B,SAAS;;AAG3D,SAAS,aAAa,MAAY,UAAiD;AACjF,KAAI,KAAK,SAAS,OAEhB,QAAO;EAAE,MAAM;EAAQ,MADT,KAAkB,QAAQ;EACX;AAE/B,KAAI,KAAK,SAAS,SAAS,KAAK,SAAS,YAAY,KAAK,SAAS,SAAS;EAC1E,MAAM,UAAU;AAChB,SAAO;GACL,MAAM;GACN,MAAM,QAAQ;GACd,SAAS,QAAQ,WAAW,EAAE;GAC9B;GACD;;;AAKL,SAAS,YAAY,MAAoC;AACvD,KAAI,CAAC,iBAAiB,KAAK,CACzB;AAKF,QAAO,aAAa,MAHF,YAAY,KAAK,IAAI,KAAK,SAAS,SAAS,IAC1D,KAAK,SAAS,KAAI,UAAS,YAAY,MAAM,CAAC,CAAC,QAAQ,UAA+B,QAAQ,MAAM,CAAC,GACrG,OAC+B;;AAGrC,SAAgB,UAAU,QAA8B;AAOtD,SANiB,cAAc,QAAQ;EACrC,SAAS;EACT,gBAAgB;EAChB,sBAAsB;EACvB,CAAC,CACsB,YAAY,EAAE,EAAE,OAAO,iBAAiB,CAE7D,KAAI,SAAQ,YAAY,KAAK,CAAC,CAC9B,QAAQ,SAA6B,QAAQ,KAAK,CAAC"}
1
+ {"version":3,"file":"parser.mjs","names":[],"sources":["../../../src/compiler/wxml/parser.ts"],"sourcesContent":["import type { ChildNode, DataNode, Element, Node } from 'domhandler'\n\nimport type { RenderNode } from './types'\n\nimport { parseDocument } from 'htmlparser2'\n\nfunction isRenderableNode(node: Node) {\n if (node.type === 'directive' || node.type === 'comment') {\n return false\n }\n if (node.type === 'text') {\n const data = (node as DataNode).data ?? ''\n return data.trim().length > 0\n }\n return true\n}\n\ntype NodeWithChildren = Node & { children: ChildNode[] }\n\nfunction hasChildren(node: Node): node is NodeWithChildren {\n return Array.isArray((node as NodeWithChildren).children)\n}\n\nfunction toRenderNode(node: Node, children?: RenderNode[]): RenderNode | undefined {\n if (node.type === 'text') {\n const data = (node as DataNode).data ?? ''\n return { type: 'text', data }\n }\n if (node.type === 'tag' || node.type === 'script' || node.type === 'style') {\n const element = node as Element\n return {\n type: 'element',\n name: element.name,\n attribs: element.attribs ?? {},\n children,\n }\n }\n return undefined\n}\n\nfunction convertNode(node: Node): RenderNode | undefined {\n if (!isRenderableNode(node)) {\n return undefined\n }\n const children = (hasChildren(node) && node.children.length > 0)\n ? node.children.map(child => convertNode(child)).filter((child): child is RenderNode => Boolean(child))\n : undefined\n return toRenderNode(node, children)\n}\n\nexport function parseWxml(source: string): RenderNode[] {\n const document = parseDocument(source, {\n xmlMode: true,\n decodeEntities: true,\n recognizeSelfClosing: true,\n })\n const nodes = (document.children ?? []).filter(isRenderableNode)\n return nodes\n .map(node => convertNode(node))\n .filter((node): node is RenderNode => Boolean(node))\n}\n"],"mappings":";;;AAMA,SAAS,iBAAiB,MAAY;CACpC,IAAI,KAAK,SAAS,eAAe,KAAK,SAAS,WAC7C,OAAO;CAET,IAAI,KAAK,SAAS,QAEhB,QADc,KAAkB,QAAQ,IAC5B,MAAM,CAAC,SAAS;CAE9B,OAAO;;AAKT,SAAS,YAAY,MAAsC;CACzD,OAAO,MAAM,QAAS,KAA0B,SAAS;;AAG3D,SAAS,aAAa,MAAY,UAAiD;CACjF,IAAI,KAAK,SAAS,QAEhB,OAAO;EAAE,MAAM;EAAQ,MADT,KAAkB,QAAQ;EACX;CAE/B,IAAI,KAAK,SAAS,SAAS,KAAK,SAAS,YAAY,KAAK,SAAS,SAAS;EAC1E,MAAM,UAAU;EAChB,OAAO;GACL,MAAM;GACN,MAAM,QAAQ;GACd,SAAS,QAAQ,WAAW,EAAE;GAC9B;GACD;;;AAKL,SAAS,YAAY,MAAoC;CACvD,IAAI,CAAC,iBAAiB,KAAK,EACzB;CAKF,OAAO,aAAa,MAHF,YAAY,KAAK,IAAI,KAAK,SAAS,SAAS,IAC1D,KAAK,SAAS,KAAI,UAAS,YAAY,MAAM,CAAC,CAAC,QAAQ,UAA+B,QAAQ,MAAM,CAAC,GACrG,OAC+B;;AAGrC,SAAgB,UAAU,QAA8B;CAOtD,QANiB,cAAc,QAAQ;EACrC,SAAS;EACT,gBAAgB;EAChB,sBAAsB;EACvB,CACsB,CAAC,YAAY,EAAE,EAAE,OAAO,iBACnC,CACT,KAAI,SAAQ,YAAY,KAAK,CAAC,CAC9B,QAAQ,SAA6B,QAAQ,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.mjs","names":[],"sources":["../../../src/compiler/wxml/renderer.ts"],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport {\n hasControlAttribute,\n normalizeTagName,\n resolveControlAttributeValue,\n SELF_CLOSING_TAGS,\n} from '../../shared/wxml'\nimport {\n extractFor,\n isConditionalElement,\n renderAttributes,\n resolveComponentTagName,\n stripControlAttributes,\n} from './attributes'\nimport { buildExpression, buildTemplateDataExpression, parseInterpolations } from './interpolation'\n\ninterface RenderElementOptions {\n skipFor?: boolean\n overrideAttribs?: Record<string, string>\n}\n\nexport class Renderer {\n renderNodes(\n nodes: RenderNode[],\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): string {\n const parts: string[] = []\n for (let index = 0; index < nodes.length; index += 1) {\n const node = nodes[index]\n if (isConditionalElement(node)) {\n const { rendered, endIndex } = this.renderConditionalSequence(\n nodes,\n index,\n scopeVar,\n wxsVar,\n componentTags,\n )\n parts.push(rendered)\n index = endIndex\n continue\n }\n parts.push(this.renderNode(node, scopeVar, wxsVar, componentTags))\n }\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1) {\n return parts[0]!\n }\n return `[${parts.join(', ')}]`\n }\n\n private renderConditionalSequence(\n nodes: RenderNode[],\n startIndex: number,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): { rendered: string, endIndex: number } {\n const branches: Array<{ node: RenderElementNode, attribs: Record<string, string> }> = []\n let cursor = startIndex\n while (cursor < nodes.length) {\n const candidate = nodes[cursor]\n if (!isConditionalElement(candidate)) {\n break\n }\n const attribs = candidate.attribs ?? {}\n if (branches.length === 0 && !hasControlAttribute(attribs, 'if')) {\n break\n }\n if (branches.length > 0 && !hasControlAttribute(attribs, 'elif') && !hasControlAttribute(attribs, 'else')) {\n break\n }\n branches.push({ node: candidate, attribs })\n cursor += 1\n if (hasControlAttribute(attribs, 'else')) {\n break\n }\n }\n if (!branches.length) {\n const node = nodes[startIndex]\n if (!node) {\n return { rendered: '\"\"', endIndex: startIndex }\n }\n return { rendered: this.renderNode(node, scopeVar, wxsVar, componentTags), endIndex: startIndex }\n }\n let expr = '\"\"'\n for (let index = branches.length - 1; index >= 0; index -= 1) {\n const { node, attribs } = branches[index]!\n const cleanedAttribs = stripControlAttributes(attribs)\n if (hasControlAttribute(attribs, 'else')) {\n expr = this.renderElement(node, scopeVar, wxsVar, componentTags, { overrideAttribs: cleanedAttribs })\n continue\n }\n const conditionExpr = resolveControlAttributeValue(attribs, 'if')\n ?? resolveControlAttributeValue(attribs, 'elif')\n ?? ''\n const rendered = this.renderElement(node, scopeVar, wxsVar, componentTags, { overrideAttribs: cleanedAttribs })\n const condition = buildExpression(parseInterpolations(conditionExpr), scopeVar, wxsVar)\n expr = `(${condition} ? ${rendered} : ${expr})`\n }\n return { rendered: expr, endIndex: startIndex + branches.length - 1 }\n }\n\n private renderNode(\n node: RenderNode,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): string {\n if (node.type === 'text') {\n const parts = parseInterpolations(node.data ?? '')\n return buildExpression(parts, scopeVar, wxsVar)\n }\n if (node.type === 'element') {\n if (node.name === 'template' && node.attribs?.is) {\n return this.renderTemplateInvoke(node, scopeVar, wxsVar)\n }\n return this.renderElement(node, scopeVar, wxsVar, componentTags)\n }\n return '\"\"'\n }\n\n private renderTemplateInvoke(\n node: RenderElementNode,\n scopeVar: string,\n wxsVar: string,\n ): string {\n const attribs = node.attribs ?? {}\n const isExpr = buildExpression(parseInterpolations(attribs.is ?? ''), scopeVar, wxsVar)\n const dataExpr = attribs.data\n ? buildTemplateDataExpression(attribs.data, scopeVar, wxsVar)\n : undefined\n const scopeExpr = dataExpr\n ? `ctx.mergeScope(${scopeVar}, ${dataExpr})`\n : scopeVar\n return `ctx.renderTemplate(__templates, ${isExpr}, ${scopeExpr}, ctx)`\n }\n\n private renderElement(\n node: RenderElementNode,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n options: RenderElementOptions = {},\n ): string {\n const attribs = options.overrideAttribs ?? node.attribs ?? {}\n if (!options.skipFor) {\n const forInfo = extractFor(node.attribs ?? {})\n if (forInfo.expr) {\n const listExpression = buildExpression(parseInterpolations(forInfo.expr), scopeVar, wxsVar)\n const listExpr = `ctx.normalizeList(${listExpression})`\n const itemVar = forInfo.itemName\n const indexVar = forInfo.indexName\n const scopeExpr = `ctx.createScope(${scopeVar}, { ${itemVar}: ${itemVar}, ${indexVar}: ${indexVar} })`\n const itemRender = this.renderElement(\n node,\n '__scope',\n wxsVar,\n componentTags,\n { skipFor: true, overrideAttribs: forInfo.restAttribs },\n )\n const keyExpr = `ctx.key(${JSON.stringify(forInfo.key ?? '')}, ${itemVar}, ${indexVar}, ${scopeExpr}, ${wxsVar})`\n return `repeat(${listExpr}, (${itemVar}, ${indexVar}) => ${keyExpr}, (${itemVar}, ${indexVar}) => { const __scope = ${scopeExpr}; return ${itemRender}; })`\n }\n }\n\n const customTag = resolveComponentTagName(node.name ?? '', componentTags)\n const tagName = customTag ?? normalizeTagName(node.name ?? '')\n if (tagName === '#fragment') {\n return this.renderNodes(node.children ?? [], scopeVar, wxsVar, componentTags)\n }\n\n const attrs = renderAttributes(attribs, scopeVar, wxsVar, {\n skipControl: true,\n preferProperty: Boolean(customTag),\n })\n const childNodes = node.children ?? []\n const children = childNodes\n .map(child => `\\${${this.renderNode(child, scopeVar, wxsVar, componentTags)}}`)\n .join('')\n if (SELF_CLOSING_TAGS.has(tagName) && childNodes.length === 0) {\n return `html\\`<${tagName}${attrs} />\\``\n }\n return `html\\`<${tagName}${attrs}>${children}</${tagName}>\\``\n }\n}\n\nexport const renderer = new Renderer()\n"],"mappings":";;;;;AAqBA,IAAa,WAAb,MAAsB;CACpB,YACE,OACA,UACA,QACA,eACQ;EACR,MAAM,QAAkB,EAAE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],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport {\n hasControlAttribute,\n normalizeTagName,\n resolveControlAttributeValue,\n SELF_CLOSING_TAGS,\n} from '../../shared/wxml'\nimport {\n extractFor,\n isConditionalElement,\n renderAttributes,\n resolveComponentTagName,\n stripControlAttributes,\n} from './attributes'\nimport { buildExpression, buildTemplateDataExpression, parseInterpolations } from './interpolation'\n\ninterface RenderElementOptions {\n skipFor?: boolean\n overrideAttribs?: Record<string, string>\n}\n\nexport class Renderer {\n renderNodes(\n nodes: RenderNode[],\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): string {\n const parts: string[] = []\n for (let index = 0; index < nodes.length; index += 1) {\n const node = nodes[index]\n if (isConditionalElement(node)) {\n const { rendered, endIndex } = this.renderConditionalSequence(\n nodes,\n index,\n scopeVar,\n wxsVar,\n componentTags,\n )\n parts.push(rendered)\n index = endIndex\n continue\n }\n parts.push(this.renderNode(node, scopeVar, wxsVar, componentTags))\n }\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1) {\n return parts[0]!\n }\n return `[${parts.join(', ')}]`\n }\n\n private renderConditionalSequence(\n nodes: RenderNode[],\n startIndex: number,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): { rendered: string, endIndex: number } {\n const branches: Array<{ node: RenderElementNode, attribs: Record<string, string> }> = []\n let cursor = startIndex\n while (cursor < nodes.length) {\n const candidate = nodes[cursor]\n if (!isConditionalElement(candidate)) {\n break\n }\n const attribs = candidate.attribs ?? {}\n if (branches.length === 0 && !hasControlAttribute(attribs, 'if')) {\n break\n }\n if (branches.length > 0 && !hasControlAttribute(attribs, 'elif') && !hasControlAttribute(attribs, 'else')) {\n break\n }\n branches.push({ node: candidate, attribs })\n cursor += 1\n if (hasControlAttribute(attribs, 'else')) {\n break\n }\n }\n if (!branches.length) {\n const node = nodes[startIndex]\n if (!node) {\n return { rendered: '\"\"', endIndex: startIndex }\n }\n return { rendered: this.renderNode(node, scopeVar, wxsVar, componentTags), endIndex: startIndex }\n }\n let expr = '\"\"'\n for (let index = branches.length - 1; index >= 0; index -= 1) {\n const { node, attribs } = branches[index]!\n const cleanedAttribs = stripControlAttributes(attribs)\n if (hasControlAttribute(attribs, 'else')) {\n expr = this.renderElement(node, scopeVar, wxsVar, componentTags, { overrideAttribs: cleanedAttribs })\n continue\n }\n const conditionExpr = resolveControlAttributeValue(attribs, 'if')\n ?? resolveControlAttributeValue(attribs, 'elif')\n ?? ''\n const rendered = this.renderElement(node, scopeVar, wxsVar, componentTags, { overrideAttribs: cleanedAttribs })\n const condition = buildExpression(parseInterpolations(conditionExpr), scopeVar, wxsVar)\n expr = `(${condition} ? ${rendered} : ${expr})`\n }\n return { rendered: expr, endIndex: startIndex + branches.length - 1 }\n }\n\n private renderNode(\n node: RenderNode,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): string {\n if (node.type === 'text') {\n const parts = parseInterpolations(node.data ?? '')\n return buildExpression(parts, scopeVar, wxsVar)\n }\n if (node.type === 'element') {\n if (node.name === 'template' && node.attribs?.is) {\n return this.renderTemplateInvoke(node, scopeVar, wxsVar)\n }\n return this.renderElement(node, scopeVar, wxsVar, componentTags)\n }\n return '\"\"'\n }\n\n private renderTemplateInvoke(\n node: RenderElementNode,\n scopeVar: string,\n wxsVar: string,\n ): string {\n const attribs = node.attribs ?? {}\n const isExpr = buildExpression(parseInterpolations(attribs.is ?? ''), scopeVar, wxsVar)\n const dataExpr = attribs.data\n ? buildTemplateDataExpression(attribs.data, scopeVar, wxsVar)\n : undefined\n const scopeExpr = dataExpr\n ? `ctx.mergeScope(${scopeVar}, ${dataExpr})`\n : scopeVar\n return `ctx.renderTemplate(__templates, ${isExpr}, ${scopeExpr}, ctx)`\n }\n\n private renderElement(\n node: RenderElementNode,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n options: RenderElementOptions = {},\n ): string {\n const attribs = options.overrideAttribs ?? node.attribs ?? {}\n if (!options.skipFor) {\n const forInfo = extractFor(node.attribs ?? {})\n if (forInfo.expr) {\n const listExpression = buildExpression(parseInterpolations(forInfo.expr), scopeVar, wxsVar)\n const listExpr = `ctx.normalizeList(${listExpression})`\n const itemVar = forInfo.itemName\n const indexVar = forInfo.indexName\n const scopeExpr = `ctx.createScope(${scopeVar}, { ${itemVar}: ${itemVar}, ${indexVar}: ${indexVar} })`\n const itemRender = this.renderElement(\n node,\n '__scope',\n wxsVar,\n componentTags,\n { skipFor: true, overrideAttribs: forInfo.restAttribs },\n )\n const keyExpr = `ctx.key(${JSON.stringify(forInfo.key ?? '')}, ${itemVar}, ${indexVar}, ${scopeExpr}, ${wxsVar})`\n return `repeat(${listExpr}, (${itemVar}, ${indexVar}) => ${keyExpr}, (${itemVar}, ${indexVar}) => { const __scope = ${scopeExpr}; return ${itemRender}; })`\n }\n }\n\n const customTag = resolveComponentTagName(node.name ?? '', componentTags)\n const tagName = customTag ?? normalizeTagName(node.name ?? '')\n if (tagName === '#fragment') {\n return this.renderNodes(node.children ?? [], scopeVar, wxsVar, componentTags)\n }\n\n const attrs = renderAttributes(attribs, scopeVar, wxsVar, {\n skipControl: true,\n preferProperty: Boolean(customTag),\n })\n const childNodes = node.children ?? []\n const children = childNodes\n .map(child => `\\${${this.renderNode(child, scopeVar, wxsVar, componentTags)}}`)\n .join('')\n if (SELF_CLOSING_TAGS.has(tagName) && childNodes.length === 0) {\n return `html\\`<${tagName}${attrs} />\\``\n }\n return `html\\`<${tagName}${attrs}>${children}</${tagName}>\\``\n }\n}\n\nexport const renderer = new Renderer()\n"],"mappings":";;;;;AAqBA,IAAa,WAAb,MAAsB;CACpB,YACE,OACA,UACA,QACA,eACQ;EACR,MAAM,QAAkB,EAAE;EAC1B,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;GACpD,MAAM,OAAO,MAAM;GACnB,IAAI,qBAAqB,KAAK,EAAE;IAC9B,MAAM,EAAE,UAAU,aAAa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IACxB,MAAM,WAAW,QAAQ;IACzB,MAAM,YAAY,mBAAmB,SAAS,MAAM,QAAQ,IAAI,QAAQ,IAAI,SAAS,IAAI,SAAS;IAClG,MAAM,aAAa,KAAK,cACtB,MACA,WACA,QACA,eACA;KAAE,SAAS;KAAM,iBAAiB,QAAQ;KAAa,CACxD;IAED,OAAO,UAAU,SAAS,KAAK,QAAQ,IAAI,SAAS,OAAO,WADhC,KAAK,UAAU,QAAQ,OAAO,GAAG,CAAC,IAAI,QAAQ,IAAI,SAAS,IAAI,UAAU,IAAI,OAAO,GAC5C,KAAK,QAAQ,IAAI,SAAS,yBAAyB,UAAU,WAAW,WAAW;;;EAI1J,MAAM,YAAY,wBAAwB,KAAK,QAAQ,IAAI,cAAc;EACzE,MAAM,UAAU,aAAa,iBAAiB,KAAK,QAAQ,GAAG;EAC9D,IAAI,YAAY,aACd,OAAO,KAAK,YAAY,KAAK,YAAY,EAAE,EAAE,UAAU,QAAQ,cAAc;EAG/E,MAAM,QAAQ,iBAAiB,SAAS,UAAU,QAAQ;GACxD,aAAa;GACb,gBAAgB,QAAQ,UAAU;GACnC,CAAC;EACF,MAAM,aAAa,KAAK,YAAY,EAAE;EACtC,MAAM,WAAW,WACd,KAAI,UAAS,MAAM,KAAK,WAAW,OAAO,UAAU,QAAQ,cAAc,CAAC,GAAG,CAC9E,KAAK,GAAG;EACX,IAAI,kBAAkB,IAAI,QAAQ,IAAI,WAAW,WAAW,GAC1D,OAAO,UAAU,UAAU,MAAM;EAEnC,OAAO,UAAU,UAAU,MAAM,GAAG,SAAS,IAAI,QAAQ;;;AAI7D,MAAa,WAAW,IAAI,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"specialNodes.mjs","names":[],"sources":["../../../src/compiler/wxml/specialNodes.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n RenderNode,\n TemplateDefinition,\n WxsEntry,\n} from './types'\n\nimport { dirname, relative } from 'pathe'\nimport { TEMPLATE_IMPORT_TAG_NAMES, TEMPLATE_INCLUDE_TAG_NAMES } from '../../shared/wxml'\n\nexport function shouldMarkWxsImport(pathname: string) {\n const lower = pathname.toLowerCase()\n if (lower.endsWith('.wxs') || lower.endsWith('.wxs.ts') || lower.endsWith('.wxs.js')) {\n return false\n }\n return lower.endsWith('.ts') || lower.endsWith('.js')\n}\n\ninterface CollectSpecialNodesContext {\n templates: TemplateDefinition[]\n includes: IncludeEntry[]\n imports: ImportEntry[]\n wxs: WxsEntry[]\n wxsModules: Map<string, string>\n warnings: string[]\n sourceId: string\n resolveTemplate: (raw: string) => string | undefined\n resolveWxs: (raw: string) => string | undefined\n}\n\nexport function collectSpecialNodes(nodes: RenderNode[], context: CollectSpecialNodesContext) {\n const renderable: RenderNode[] = []\n for (const node of nodes) {\n if (node.type === 'element') {\n const name = node.name ?? ''\n if (name === 'template' && node.attribs?.name) {\n context.templates.push({\n name: node.attribs.name,\n nodes: collectSpecialNodes(node.children ?? [], context),\n })\n continue\n }\n if (TEMPLATE_IMPORT_TAG_NAMES.includes(name) && node.attribs?.src) {\n const resolved = context.resolveTemplate(node.attribs.src)\n if (resolved) {\n context.imports.push({\n id: resolved,\n importName: `__wxml_import_${context.imports.length}`,\n })\n }\n else {\n context.warnings.push(`[web] 无法解析模板依赖: ${node.attribs.src} (from ${context.sourceId})`)\n }\n continue\n }\n if (TEMPLATE_INCLUDE_TAG_NAMES.includes(name) && node.attribs?.src) {\n const resolved = context.resolveTemplate(node.attribs.src)\n if (resolved) {\n context.includes.push({\n id: resolved,\n importName: `__wxml_include_${context.includes.length}`,\n })\n }\n else {\n context.warnings.push(`[web] 无法解析模板依赖: ${node.attribs.src} (from ${context.sourceId})`)\n }\n continue\n }\n if (name === 'wxs') {\n const moduleName = node.attribs?.module?.trim()\n if (moduleName) {\n const previousSource = context.wxsModules.get(moduleName)\n if (previousSource) {\n context.warnings.push(`[web] WXS 模块名重复: ${moduleName} (from ${context.sourceId})`)\n }\n context.wxsModules.set(moduleName, context.sourceId)\n if (node.attribs?.src) {\n const resolved = context.resolveWxs(node.attribs.src)\n if (resolved) {\n context.wxs.push({\n module: moduleName,\n kind: 'src',\n importName: `__wxs_${context.wxs.length}`,\n value: resolved,\n })\n }\n }\n else {\n const inlineCode = (node.children ?? [])\n .filter(child => child.type === 'text')\n .map(child => child.data ?? '')\n .join('')\n context.wxs.push({\n module: moduleName,\n kind: 'inline',\n importName: `__wxs_${context.wxs.length}`,\n value: inlineCode,\n })\n }\n }\n continue\n }\n if (node.children?.length) {\n node.children = collectSpecialNodes(node.children, context)\n }\n }\n renderable.push(node)\n }\n return renderable\n}\n\nexport function normalizeTemplatePath(pathname: string) {\n return pathname.split('\\\\').join('/')\n}\n\nexport function toRelativeImport(from: string, target: string) {\n const fromDir = dirname(from)\n const rel = relative(fromDir, target)\n if (!rel || rel.startsWith('.')) {\n const fallback = normalizeTemplatePath(target).split('/').pop() ?? ''\n return rel || `./${fallback}`\n }\n return `./${rel}`\n}\n"],"mappings":";;;;AAWA,SAAgB,oBAAoB,UAAkB;CACpD,MAAM,QAAQ,SAAS,aAAa;AACpC,KAAI,MAAM,SAAS,OAAO,IAAI,MAAM,SAAS,UAAU,IAAI,MAAM,SAAS,UAAU,CAClF,QAAO;AAET,QAAO,MAAM,SAAS,MAAM,IAAI,MAAM,SAAS,MAAM;;AAevD,SAAgB,oBAAoB,OAAqB,SAAqC;CAC5F,MAAM,aAA2B,EAAE;AACnC,MAAK,MAAM,QAAQ,OAAO;AACxB,MAAI,KAAK,SAAS,WAAW;GAC3B,MAAM,OAAO,KAAK,QAAQ;AAC1B,OAAI,SAAS,cAAc,KAAK,SAAS,MAAM;AAC7C,YAAQ,UAAU,KAAK;KACrB,MAAM,KAAK,QAAQ;KACnB,OAAO,oBAAoB,KAAK,YAAY,EAAE,EAAE,QAAQ;KACzD,CAAC;AACF;;AAEF,OAAI,0BAA0B,SAAS,KAAK,IAAI,KAAK,SAAS,KAAK;IACjE,MAAM,WAAW,QAAQ,gBAAgB,KAAK,QAA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/D,aAAW,KAAK,KAAK;;AAEvB,QAAO;;AAGT,SAAgB,sBAAsB,UAAkB;AACtD,QAAO,SAAS,MAAM,KAAK,CAAC,KAAK,IAAI;;AAGvC,SAAgB,iBAAiB,MAAc,QAAgB;CAE7D,MAAM,MAAM,SADI,QAAQ,KAAK,EACC,OAAO;AACrC,KAAI,CAAC,OAAO,IAAI,WAAW,IAAI,EAAE;EAC/B,MAAM,WAAW,sBAAsB,OAAO,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI;AACnE,SAAO,OAAO,KAAK;;AAErB,QAAO,KAAK"}
1
+ {"version":3,"file":"specialNodes.mjs","names":[],"sources":["../../../src/compiler/wxml/specialNodes.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n RenderNode,\n TemplateDefinition,\n WxsEntry,\n} from './types'\n\nimport { dirname, relative } from 'pathe'\nimport { TEMPLATE_IMPORT_TAG_NAMES, TEMPLATE_INCLUDE_TAG_NAMES } from '../../shared/wxml'\n\nexport function shouldMarkWxsImport(pathname: string) {\n const lower = pathname.toLowerCase()\n if (lower.endsWith('.wxs') || lower.endsWith('.wxs.ts') || lower.endsWith('.wxs.js')) {\n return false\n }\n return lower.endsWith('.ts') || lower.endsWith('.js')\n}\n\ninterface CollectSpecialNodesContext {\n templates: TemplateDefinition[]\n includes: IncludeEntry[]\n imports: ImportEntry[]\n wxs: WxsEntry[]\n wxsModules: Map<string, string>\n warnings: string[]\n sourceId: string\n resolveTemplate: (raw: string) => string | undefined\n resolveWxs: (raw: string) => string | undefined\n}\n\nexport function collectSpecialNodes(nodes: RenderNode[], context: CollectSpecialNodesContext) {\n const renderable: RenderNode[] = []\n for (const node of nodes) {\n if (node.type === 'element') {\n const name = node.name ?? ''\n if (name === 'template' && node.attribs?.name) {\n context.templates.push({\n name: node.attribs.name,\n nodes: collectSpecialNodes(node.children ?? [], context),\n })\n continue\n }\n if (TEMPLATE_IMPORT_TAG_NAMES.includes(name) && node.attribs?.src) {\n const resolved = context.resolveTemplate(node.attribs.src)\n if (resolved) {\n context.imports.push({\n id: resolved,\n importName: `__wxml_import_${context.imports.length}`,\n })\n }\n else {\n context.warnings.push(`[web] 无法解析模板依赖: ${node.attribs.src} (from ${context.sourceId})`)\n }\n continue\n }\n if (TEMPLATE_INCLUDE_TAG_NAMES.includes(name) && node.attribs?.src) {\n const resolved = context.resolveTemplate(node.attribs.src)\n if (resolved) {\n context.includes.push({\n id: resolved,\n importName: `__wxml_include_${context.includes.length}`,\n })\n }\n else {\n context.warnings.push(`[web] 无法解析模板依赖: ${node.attribs.src} (from ${context.sourceId})`)\n }\n continue\n }\n if (name === 'wxs') {\n const moduleName = node.attribs?.module?.trim()\n if (moduleName) {\n const previousSource = context.wxsModules.get(moduleName)\n if (previousSource) {\n context.warnings.push(`[web] WXS 模块名重复: ${moduleName} (from ${context.sourceId})`)\n }\n context.wxsModules.set(moduleName, context.sourceId)\n if (node.attribs?.src) {\n const resolved = context.resolveWxs(node.attribs.src)\n if (resolved) {\n context.wxs.push({\n module: moduleName,\n kind: 'src',\n importName: `__wxs_${context.wxs.length}`,\n value: resolved,\n })\n }\n }\n else {\n const inlineCode = (node.children ?? [])\n .filter(child => child.type === 'text')\n .map(child => child.data ?? '')\n .join('')\n context.wxs.push({\n module: moduleName,\n kind: 'inline',\n importName: `__wxs_${context.wxs.length}`,\n value: inlineCode,\n })\n }\n }\n continue\n }\n if (node.children?.length) {\n node.children = collectSpecialNodes(node.children, context)\n }\n }\n renderable.push(node)\n }\n return renderable\n}\n\nexport function normalizeTemplatePath(pathname: string) {\n return pathname.split('\\\\').join('/')\n}\n\nexport function toRelativeImport(from: string, target: string) {\n const fromDir = dirname(from)\n const rel = relative(fromDir, target)\n if (!rel || rel.startsWith('.')) {\n const fallback = normalizeTemplatePath(target).split('/').pop() ?? ''\n return rel || `./${fallback}`\n }\n return `./${rel}`\n}\n"],"mappings":";;;;AAWA,SAAgB,oBAAoB,UAAkB;CACpD,MAAM,QAAQ,SAAS,aAAa;CAC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,GAAG;KAEpF,QAAQ,WAAW,IAAI,YAAY,QAAQ,SAAS;KACpD,IAAI,KAAK,SAAS,KAAK;MACrB,MAAM,WAAW,QAAQ,WAAW,KAAK,QAAQ,IAAI;MACrD,IAAI,UACF,QAAQ,IAAI,KAAK;OACf,QAAQ;OACR,MAAM;OACN,YAAY,SAAS,QAAQ,IAAI;OACjC,OAAO;OACR,CAAC;YAGD;MACH,MAAM,cAAc,KAAK,YAAY,EAAE,EACpC,QAAO,UAAS,MAAM,SAAS,OAAO,CACtC,KAAI,UAAS,MAAM,QAAQ,GAAG,CAC9B,KAAK,GAAG;MACX,QAAQ,IAAI,KAAK;OACf,QAAQ;OACR,MAAM;OACN,YAAY,SAAS,QAAQ,IAAI;OACjC,OAAO;OACR,CAAC;;;IAGN;;GAEF,IAAI,KAAK,UAAU,QACjB,KAAK,WAAW,oBAAoB,KAAK,UAAU,QAAQ;;EAG/D,WAAW,KAAK,KAAK;;CAEvB,OAAO;;AAGT,SAAgB,sBAAsB,UAAkB;CACtD,OAAO,SAAS,MAAM,KAAK,CAAC,KAAK,IAAI;;AAGvC,SAAgB,iBAAiB,MAAc,QAAgB;CAE7D,MAAM,MAAM,SADI,QAAQ,KACI,EAAE,OAAO;CACrC,IAAI,CAAC,OAAO,IAAI,WAAW,IAAI,EAAE;EAC/B,MAAM,WAAW,sBAAsB,OAAO,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI;EACnE,OAAO,OAAO,KAAK;;CAErB,OAAO,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"wxs.mjs","names":[],"sources":["../../src/compiler/wxs.ts"],"sourcesContent":["export interface WxsTransformResult {\n code: string\n dependencies: string[]\n warnings?: string[]\n}\n\nexport interface WxsTransformOptions {\n resolvePath: (request: string, importer: string) => string | undefined\n toImportPath?: (resolved: string, importer: string) => string\n}\n\nconst REQUIRE_RE = /require\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g\n\nfunction normalizePath(p: string) {\n return p.split('\\\\\\\\').join('/')\n}\n\nfunction isPlainWxsScript(pathname: string) {\n const lower = pathname.toLowerCase()\n if (lower.endsWith('.wxs') || lower.endsWith('.wxs.ts') || lower.endsWith('.wxs.js')) {\n return false\n }\n return lower.endsWith('.ts') || lower.endsWith('.js')\n}\n\nfunction appendWxsQuery(pathname: string) {\n if (pathname.includes('?wxs') || pathname.includes('&wxs')) {\n return pathname\n }\n return `${pathname}${pathname.includes('?') ? '&' : '?'}wxs`\n}\n\nfunction isSupportedRequirePath(request: string) {\n const normalized = request.replace(/\\\\/g, '/')\n return normalized.startsWith('.') || normalized.startsWith('/')\n}\n\nexport function transformWxsToEsm(code: string, id: string, options: WxsTransformOptions): WxsTransformResult {\n const dependencies: string[] = []\n const importLines: string[] = []\n const mapEntries: string[] = []\n const warnings: string[] = []\n\n const seen = new Set<string>()\n while (true) {\n const match = REQUIRE_RE.exec(code)\n if (!match) {\n break\n }\n const request = match[1]\n if (!request || seen.has(request)) {\n continue\n }\n seen.add(request)\n if (!isSupportedRequirePath(request)) {\n warnings.push(`[@weapp-vite/web] WXS require 仅支持相对或绝对路径: ${request} (from ${id})`)\n continue\n }\n const normalizedRequest = request.replace(/\\\\/g, '/')\n const resolved = options.resolvePath(normalizedRequest, id)\n if (!resolved) {\n warnings.push(`[@weapp-vite/web] 无法解析 WXS require: ${request} (from ${id})`)\n continue\n }\n let importPath = normalizePath(options.toImportPath?.(resolved, id) ?? resolved)\n if (isPlainWxsScript(resolved)) {\n importPath = appendWxsQuery(importPath)\n }\n const importName = `__wxs_dep_${dependencies.length}`\n importLines.push(`import ${importName} from '${importPath}'`)\n mapEntries.push(`[${JSON.stringify(request)}, ${importName}]`)\n dependencies.push(resolved)\n }\n\n const requireMap = `const __wxs_require_map = new Map([${mapEntries.join(', ')}])`\n const requireFn = [\n `const __wxs_require_warned = new Set()`,\n `function require(id) {`,\n ` if (__wxs_require_map.has(id)) {`,\n ` return __wxs_require_map.get(id)`,\n ` }`,\n ` if (!__wxs_require_warned.has(id)) {`,\n ` __wxs_require_warned.add(id)`,\n ` if (typeof console !== 'undefined' && typeof console.warn === 'function') {`,\n ` console.warn(\\`[@weapp-vite/web] WXS require 未解析: \\${id}\\`)`,\n ` }`,\n ` }`,\n ` return undefined`,\n `}`,\n ].join('\\\\n')\n const moduleInit = `const module = { exports: {} }\\\\nconst exports = module.exports`\n const helpers = `const getRegExp = (pattern, flags) => new RegExp(pattern, flags)\\\\nconst getDate = (value) => (value == null ? new Date() : new Date(value))`\n\n const body = [\n ...importLines,\n requireMap,\n requireFn,\n moduleInit,\n helpers,\n code,\n `export default module.exports`,\n ].join('\\\\n')\n\n return {\n code: body,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n"],"mappings":";AAWA,MAAM,aAAa;AAEnB,SAAS,cAAc,GAAW;AAChC,QAAO,EAAE,MAAM,OAAO,CAAC,KAAK,IAAI;;AAGlC,SAAS,iBAAiB,UAAkB;CAC1C,MAAM,QAAQ,SAAS,aAAa;AACpC,KAAI,MAAM,SAAS,OAAO,IAAI,MAAM,SAAS,UAAU,IAAI,MAAM,SAAS,UAAU,CAClF,QAAO;AAET,QAAO,MAAM,SAAS,MAAM,IAAI,MAAM,SAAS,MAAM;;AAGvD,SAAS,eAAe,UAAkB;AACxC,KAAI,SAAS,SAAS,OAAO,IAAI,SAAS,SAAS,OAAO,CACxD,QAAO;AAET,QAAO,GAAG,WAAW,SAAS,SAAS,IAAI,GAAG,MAAM,IAAI;;AAG1D,SAAS,uBAAuB,SAAiB;CAC/C,MAAM,aAAa,QAAQ,QAAQ,OAAO,IAAI;AAC9C,QAAO,WAAW,WAAW,IAAI,IAAI,WAAW,WAAW,IAAI;;AAGjE,SAAgB,kBAAkB,MAAc,IAAY,SAAkD;CAC5G,MAAM,eAAyB,EAAE;CACjC,MAAM,cAAwB,EAAE;CAChC,MAAM,aAAuB,EAAE;CAC/B,MAAM,WAAqB,EAAE;CAE7B,MAAM,uBAAO,IAAI,KAAa;AAC9B,QAAO,MAAM;EACX,MAAM,QAAQ,WAAW,KAAK,KAAK;AACnC,MAAI,CAAC,MACH;EAEF,MAAM,UAAU,MAAM;AACtB,MAAI,CAAC,WAAW,KAAK,IAAI,QAAQ,CAC/B;AAEF,OAAK,IAAI,QAAQ;AACjB,MAAI,CAAC,uBAAuB,QAAQ,EAAE;AACpC,YAAS,KAAK,6CAA6C,QAAQ,SAAS,GAAG,GAAG;AAClF;;EAEF,MAAM,oBAAoB,QAAQ,QAAQ,OAAO,IAAI;EACrD,MAAM,WAAW,QAAQ,YAAY,mBAAmB,GAAG;AAC3D,MAAI,CAAC,UAAU;AACb,YAAS,KAAK,uCAAuC,QAAQ,SAAS,GAAG,GAAG;AAC5E;;EAEF,IAAI,aAAa,cAAc,QAAQ,eAAe,UAAU,GAAG,IAAI,SAAS;AAChF,MAAI,iBAAiB,SAAS,CAC5B,cAAa,eAAe,WAAW;EAEzC,MAAM,aAAa,aAAa,aAAa;AAC7C,cAAY,KAAK,UAAU,WAAW,SAAS,WAAW,GAAG;AAC7D,aAAW,KAAK,IAAI,KAAK,UAAU,QAAQ,CAAC,IAAI,WAAW,GAAG;AAC9D,eAAa,KAAK,SAAS;;CAG7B,MAAM,aAAa,sCAAsC,WAAW,KAAK,KAAK,CAAC;CAC/E,MAAM,YAAY;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,KAAK,MAAM;CACb,MAAM,aAAa;CACnB,MAAM,UAAU;AAYhB,QAAO;EACL,MAXW;GACX,GAAG;GACH;GACA;GACA;GACA;GACA;GACA;GACD,CAAC,KAAK,MAAM;EAIX;EACA,UAAU,SAAS,SAAS,IAAI,WAAW;EAC5C"}
1
+ {"version":3,"file":"wxs.mjs","names":[],"sources":["../../src/compiler/wxs.ts"],"sourcesContent":["export interface WxsTransformResult {\n code: string\n dependencies: string[]\n warnings?: string[]\n}\n\nexport interface WxsTransformOptions {\n resolvePath: (request: string, importer: string) => string | undefined\n toImportPath?: (resolved: string, importer: string) => string\n}\n\nconst REQUIRE_RE = /require\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g\n\nfunction normalizePath(p: string) {\n return p.split('\\\\\\\\').join('/')\n}\n\nfunction isPlainWxsScript(pathname: string) {\n const lower = pathname.toLowerCase()\n if (lower.endsWith('.wxs') || lower.endsWith('.wxs.ts') || lower.endsWith('.wxs.js')) {\n return false\n }\n return lower.endsWith('.ts') || lower.endsWith('.js')\n}\n\nfunction appendWxsQuery(pathname: string) {\n if (pathname.includes('?wxs') || pathname.includes('&wxs')) {\n return pathname\n }\n return `${pathname}${pathname.includes('?') ? '&' : '?'}wxs`\n}\n\nfunction isSupportedRequirePath(request: string) {\n const normalized = request.replace(/\\\\/g, '/')\n return normalized.startsWith('.') || normalized.startsWith('/')\n}\n\nexport function transformWxsToEsm(code: string, id: string, options: WxsTransformOptions): WxsTransformResult {\n const dependencies: string[] = []\n const importLines: string[] = []\n const mapEntries: string[] = []\n const warnings: string[] = []\n\n const seen = new Set<string>()\n while (true) {\n const match = REQUIRE_RE.exec(code)\n if (!match) {\n break\n }\n const request = match[1]\n if (!request || seen.has(request)) {\n continue\n }\n seen.add(request)\n if (!isSupportedRequirePath(request)) {\n warnings.push(`[@weapp-vite/web] WXS require 仅支持相对或绝对路径: ${request} (from ${id})`)\n continue\n }\n const normalizedRequest = request.replace(/\\\\/g, '/')\n const resolved = options.resolvePath(normalizedRequest, id)\n if (!resolved) {\n warnings.push(`[@weapp-vite/web] 无法解析 WXS require: ${request} (from ${id})`)\n continue\n }\n let importPath = normalizePath(options.toImportPath?.(resolved, id) ?? resolved)\n if (isPlainWxsScript(resolved)) {\n importPath = appendWxsQuery(importPath)\n }\n const importName = `__wxs_dep_${dependencies.length}`\n importLines.push(`import ${importName} from '${importPath}'`)\n mapEntries.push(`[${JSON.stringify(request)}, ${importName}]`)\n dependencies.push(resolved)\n }\n\n const requireMap = `const __wxs_require_map = new Map([${mapEntries.join(', ')}])`\n const requireFn = [\n `const __wxs_require_warned = new Set()`,\n `function require(id) {`,\n ` if (__wxs_require_map.has(id)) {`,\n ` return __wxs_require_map.get(id)`,\n ` }`,\n ` if (!__wxs_require_warned.has(id)) {`,\n ` __wxs_require_warned.add(id)`,\n ` if (typeof console !== 'undefined' && typeof console.warn === 'function') {`,\n ` console.warn(\\`[@weapp-vite/web] WXS require 未解析: \\${id}\\`)`,\n ` }`,\n ` }`,\n ` return undefined`,\n `}`,\n ].join('\\\\n')\n const moduleInit = `const module = { exports: {} }\\\\nconst exports = module.exports`\n const helpers = `const getRegExp = (pattern, flags) => new RegExp(pattern, flags)\\\\nconst getDate = (value) => (value == null ? new Date() : new Date(value))`\n\n const body = [\n ...importLines,\n requireMap,\n requireFn,\n moduleInit,\n helpers,\n code,\n `export default module.exports`,\n ].join('\\\\n')\n\n return {\n code: body,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n"],"mappings":";AAWA,MAAM,aAAa;AAEnB,SAAS,cAAc,GAAW;CAChC,OAAO,EAAE,MAAM,OAAO,CAAC,KAAK,IAAI;;AAGlC,SAAS,iBAAiB,UAAkB;CAC1C,MAAM,QAAQ,SAAS,aAAa;CACpC,IAAI,MAAM,SAAS,OAAO,IAAI,MAAM,SAAS,UAAU,IAAI,MAAM,SAAS,UAAU,EAClF,OAAO;CAET,OAAO,MAAM,SAAS,MAAM,IAAI,MAAM,SAAS,MAAM;;AAGvD,SAAS,eAAe,UAAkB;CACxC,IAAI,SAAS,SAAS,OAAO,IAAI,SAAS,SAAS,OAAO,EACxD,OAAO;CAET,OAAO,GAAG,WAAW,SAAS,SAAS,IAAI,GAAG,MAAM,IAAI;;AAG1D,SAAS,uBAAuB,SAAiB;CAC/C,MAAM,aAAa,QAAQ,QAAQ,OAAO,IAAI;CAC9C,OAAO,WAAW,WAAW,IAAI,IAAI,WAAW,WAAW,IAAI;;AAGjE,SAAgB,kBAAkB,MAAc,IAAY,SAAkD;CAC5G,MAAM,eAAyB,EAAE;CACj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css/wxss.ts"],"sourcesContent":["export interface WxssTransformOptions {\n /**\n * 1rpx 对应的 CSS 像素数。\n * 默认值近似于 750rpx 设计稿在 375px 屏幕上的换算。\n */\n pxPerRpx?: number\n /**\n * rpx 换算的设计宽度。传入后会把 rpx 转为\n * `calc(var(--rpx) * N)` 以实现响应式缩放。\n */\n designWidth?: number\n /**\n * 用于存储运行时 rpx 大小的 CSS 变量名。\n * @default \"--rpx\"\n */\n rpxVar?: string\n}\n\nexport interface WxssTransformResult {\n css: string\n}\n\nconst RPX_RE = /(-?(?:\\d+(?:\\.\\d+)?|\\.\\d+))rpx/gi\n\nexport function transformWxssToCss(source: string, options?: WxssTransformOptions): WxssTransformResult {\n const rpxVar = options?.rpxVar ?? '--rpx'\n const useVariable = typeof options?.designWidth === 'number' && Number.isFinite(options.designWidth)\n const ratio = options?.pxPerRpx ?? 0.5\n const css = source.replace(RPX_RE, (_, value: string) => {\n const numeric = Number.parseFloat(value)\n if (Number.isNaN(numeric)) {\n return `${value}px`\n }\n if (useVariable) {\n return `calc(var(${rpxVar}) * ${numeric})`\n }\n const converted = Math.round(numeric * ratio * 1000) / 1000\n return `${converted}px`\n })\n return {\n css,\n }\n}\n"],"mappings":";AAsBA,MAAM,SAAS;AAEf,SAAgB,mBAAmB,QAAgB,SAAqD;CACtG,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,cAAc,OAAO,SAAS,gBAAgB,YAAY,OAAO,SAAS,QAAQ,YAAY;CACpG,MAAM,QAAQ,SAAS,YAAY;AAYnC,QAAO,EACL,KAZU,OAAO,QAAQ,SAAS,GAAG,UAAkB;EACvD,MAAM,UAAU,OAAO,WAAW,MAAM;AACxC,MAAI,OAAO,MAAM,QAAQ,CACvB,QAAO,GAAG,MAAM;AAElB,MAAI,YACF,QAAO,YAAY,OAAO,MAAM,QAAQ;AAG1C,SAAO,GADW,KAAK,MAAM,UAAU,QAAQ,IAAK,GAAG,IACnC;GACpB,EAGD"}
1
+ {"version":3,"file":"wxss.mjs","names":[],"sources":["../../src/css/wxss.ts"],"sourcesContent":["export interface WxssTransformOptions {\n /**\n * 1rpx 对应的 CSS 像素数。\n * 默认值近似于 750rpx 设计稿在 375px 屏幕上的换算。\n */\n pxPerRpx?: number\n /**\n * rpx 换算的设计宽度。传入后会把 rpx 转为\n * `calc(var(--rpx) * N)` 以实现响应式缩放。\n */\n designWidth?: number\n /**\n * 用于存储运行时 rpx 大小的 CSS 变量名。\n * @default \"--rpx\"\n */\n rpxVar?: string\n}\n\nexport interface WxssTransformResult {\n css: string\n}\n\nconst RPX_RE = /(-?(?:\\d+(?:\\.\\d+)?|\\.\\d+))rpx/gi\n\nexport function transformWxssToCss(source: string, options?: WxssTransformOptions): WxssTransformResult {\n const rpxVar = options?.rpxVar ?? '--rpx'\n const useVariable = typeof options?.designWidth === 'number' && Number.isFinite(options.designWidth)\n const ratio = options?.pxPerRpx ?? 0.5\n const css = source.replace(RPX_RE, (_, value: string) => {\n const numeric = Number.parseFloat(value)\n if (Number.isNaN(numeric)) {\n return `${value}px`\n }\n if (useVariable) {\n return `calc(var(${rpxVar}) * ${numeric})`\n }\n const converted = Math.round(numeric * ratio * 1000) / 1000\n return `${converted}px`\n })\n return {\n css,\n }\n}\n"],"mappings":";AAsBA,MAAM,SAAS;AAEf,SAAgB,mBAAmB,QAAgB,SAAqD;CACtG,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,cAAc,OAAO,SAAS,gBAAgB,YAAY,OAAO,SAAS,QAAQ,YAAY;CACpG,MAAM,QAAQ,SAAS,YAAY;CAYnC,OAAO,EACL,KAZU,OAAO,QAAQ,SAAS,GAAG,UAAkB;EACvD,MAAM,UAAU,OAAO,WAAW,MAAM;EACxC,IAAI,OAAO,MAAM,QAAQ,EACvB,OAAO,GAAG,MAAM;EAElB,IAAI,aACF,OAAO,YAAY,OAAO,MAAM,QAAQ;EAG1C,OAAO,GADW,KAAK,MAAM,UAAU,QAAQ,IAAK,GAAG,IACnC;GAGjB,EACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"entry.mjs","names":[],"sources":["../../src/plugin/entry.ts"],"sourcesContent":["import type { WxssTransformOptions } from '../css/wxss'\n\nimport type { ScanResult, WeappWebPluginOptions } from './types'\nimport { relativeModuleId, resolveRuntimePolyfillPath, toViteFsImport } from './path'\n\nexport function generateEntryModule(\n result: ScanResult,\n root: string,\n wxssOptions?: WxssTransformOptions,\n pluginOptions?: WeappWebPluginOptions,\n) {\n const runtimePolyfillId = toViteFsImport(resolveRuntimePolyfillPath())\n const importLines: string[] = [`import { initializePageRoutes } from '${runtimePolyfillId}'`]\n const bodyLines: string[] = []\n\n for (const page of result.pages) {\n importLines.push(`import '${relativeModuleId(root, page.script)}'`)\n }\n for (const component of result.components) {\n importLines.push(`import '${relativeModuleId(root, component.script)}'`)\n }\n if (result.app) {\n importLines.push(`import '${relativeModuleId(root, result.app)}'`)\n }\n\n const pageOrder = result.pages.map(page => page.id)\n const rpxConfig = wxssOptions?.designWidth\n ? { designWidth: wxssOptions.designWidth, varName: wxssOptions.rpxVar }\n : undefined\n\n const initOptions: Record<string, any> = {}\n if (rpxConfig) {\n initOptions.rpx = rpxConfig\n }\n if (pluginOptions?.form?.preventDefault !== undefined) {\n initOptions.form = { preventDefault: pluginOptions.form.preventDefault }\n }\n\n const runtimeOptions: Record<string, any> = {}\n if (pluginOptions?.runtime?.executionMode) {\n runtimeOptions.executionMode = pluginOptions.runtime.executionMode\n }\n if (pluginOptions?.runtime?.warnings) {\n runtimeOptions.warnings = pluginOptions.runtime.warnings\n }\n if (Object.keys(runtimeOptions).length > 0) {\n initOptions.runtime = runtimeOptions\n }\n\n const initOptionsCode = Object.keys(initOptions).length > 0 ? `, ${JSON.stringify(initOptions)}` : ''\n bodyLines.push(`initializePageRoutes(${JSON.stringify(pageOrder)}${initOptionsCode})`)\n return [...importLines, ...bodyLines].join('\\n')\n}\n"],"mappings":";;;AAKA,SAAgB,oBACd,QACA,MACA,aACA,eACA;CAEA,MAAM,cAAwB,CAAC,yCADL,eAAe,4BAA4B,CAAC,CACoB,GAAG;CAC7F,MAAM,YAAsB,EAAE;AAE9B,MAAK,MAAM,QAAQ,OAAO,MACxB,aAAY,KAAK,WAAW,iBAAiB,MAAM,KAAK,OAAO,CAAC,GAAG;AAErE,MAAK,MAAM,aAAa,OAAO,WAC7B,aAAY,KAAK,WAAW,iBAAiB,MAAM,UAAU,OAAO,CAAC,GAAG;AAE1E,KAAI,OAAO,IACT,aAAY,KAAK,WAAW,iBAAiB,MAAM,OAAO,IAAI,CAAC,GAAG;CAGpE,MAAM,YAAY,OAAO,MAAM,KAAI,SAAQ,KAAK,GAAG;CACnD,MAAM,YAAY,aAAa,cAC3B;EAAE,aAAa,YAAY;EAAa,SAAS,YAAY;EAAQ,GACrE;CAEJ,MAAM,cAAmC,EAAE;AAC3C,KAAI,UACF,aAAY,MAAM;AAEpB,KAAI,eAAe,MAAM,mBAAmB,OAC1C,aAAY,OAAO,EAAE,gBAAgB,cAAc,KAAK,gBAAgB;CAG1E,MAAM,iBAAsC,EAAE;AAC9C,KAAI,eAAe,SAAS,cAC1B,gBAAe,gBAAgB,cAAc,QAAQ;AAEvD,KAAI,eAAe,SAAS,SAC1B,gBAAe,WAAW,cAAc,QAAQ;AAElD,KAAI,OAAO,KAAK,eAAe,CAAC,SAAS,EACvC,aAAY,UAAU;CAGxB,MAAM,kBAAkB,OAAO,KAAK,YAAY,CAAC,SAAS,IAAI,KAAK,KAAK,UAAU,YAAY,KAAK;AACnG,WAAU,KAAK,wBAAwB,KAAK,UAAU,UAAU,GAAG,gBAAgB,GAAG;AACtF,QAAO,CAAC,GAAG,aAAa,GAAG,UAAU,CAAC,KAAK,KAAK"}
1
+ {"version":3,"file":"entry.mjs","names":[],"sources":["../../src/plugin/entry.ts"],"sourcesContent":["import type { WxssTransformOptions } from '../css/wxss'\n\nimport type { ScanResult, WeappWebPluginOptions } from './types'\nimport { relativeModuleId, resolveRuntimePolyfillPath, toViteFsImport } from './path'\n\nexport function generateEntryModule(\n result: ScanResult,\n root: string,\n wxssOptions?: WxssTransformOptions,\n pluginOptions?: WeappWebPluginOptions,\n) {\n const runtimePolyfillId = toViteFsImport(resolveRuntimePolyfillPath())\n const importLines: string[] = [`import { initializePageRoutes } from '${runtimePolyfillId}'`]\n const bodyLines: string[] = []\n\n for (const page of result.pages) {\n importLines.push(`import '${relativeModuleId(root, page.script)}'`)\n }\n for (const component of result.components) {\n importLines.push(`import '${relativeModuleId(root, component.script)}'`)\n }\n if (result.app) {\n importLines.push(`import '${relativeModuleId(root, result.app)}'`)\n }\n\n const pageOrder = result.pages.map(page => page.id)\n const rpxConfig = wxssOptions?.designWidth\n ? { designWidth: wxssOptions.designWidth, varName: wxssOptions.rpxVar }\n : undefined\n\n const initOptions: Record<string, any> = {}\n if (rpxConfig) {\n initOptions.rpx = rpxConfig\n }\n if (pluginOptions?.form?.preventDefault !== undefined) {\n initOptions.form = { preventDefault: pluginOptions.form.preventDefault }\n }\n\n const runtimeOptions: Record<string, any> = {}\n if (pluginOptions?.runtime?.executionMode) {\n runtimeOptions.executionMode = pluginOptions.runtime.executionMode\n }\n if (pluginOptions?.runtime?.warnings) {\n runtimeOptions.warnings = pluginOptions.runtime.warnings\n }\n if (Object.keys(runtimeOptions).length > 0) {\n initOptions.runtime = runtimeOptions\n }\n\n const initOptionsCode = Object.keys(initOptions).length > 0 ? `, ${JSON.stringify(initOptions)}` : ''\n bodyLines.push(`initializePageRoutes(${JSON.stringify(pageOrder)}${initOptionsCode})`)\n return [...importLines, ...bodyLines].join('\\n')\n}\n"],"mappings":";;;AAKA,SAAgB,oBACd,QACA,MACA,aACA,eACA;CAEA,MAAM,cAAwB,CAAC,yCADL,eAAe,4BAA4B,CACoB,CAAC,GAAG;CAC7F,MAAM,YAAsB,EAAE;CAE9B,KAAK,MAAM,QAAQ,OAAO,OACxB,YAAY,KAAK,WAAW,iBAAiB,MAAM,KAAK,OAAO,CAAC,GAAG;CAErE,KAAK,MAAM,aAAa,OAAO,YAC7B,YAAY,KAAK,WAAW,iBAAiB,MAAM,UAAU,OAAO,CAAC,GAAG;CAE1E,IAAI,OAAO,KACT,YAAY,KAAK,WAAW,iBAAiB,MAAM,OAAO,IAAI,CAAC,GAAG;CAGpE,MAAM,YAAY,OAAO,MAAM,KAAI,SAAQ,KAAK,GAAG;CACnD,MAAM,YAAY,aAAa,cAC3B;EAAE,aAAa,YAAY;EAAa,SAAS,YAAY;EAAQ,GACrE;CAEJ,MAAM,cAAmC,EAAE;CAC3C,IAAI,WACF,YAAY,MAAM;CAEpB,IAAI,eAAe,MAAM,mBAAmB,QAC1C,YAAY,OAAO,EAAE,gBAAgB,cAAc,KAAK,gBAAgB;CAG1E,MAAM,iBAAsC,EAAE;CAC9C,IAAI,eAAe,SAAS,eAC1B,eAAe,gBAAgB,cAAc,QAAQ;CAEvD,IAAI,eAAe,SAAS,UAC1B,eAAe,WAAW,cAAc,QAAQ;CAElD,IAAI,OAAO,KAAK,eAAe,CAAC,SAAS,GACvC,YAAY,UAAU;CAGxB,MAAM,kBAAkB,OAAO,KAAK,YAAY,CAAC,SAAS,IAAI,KAAK,KAAK,UAAU,YAAY,KAAK;CACnG,UAAU,KAAK,wBAAwB,KAAK,UAAU,UAAU,GAAG,gBAAgB,GAAG;CACtF,OAAO,CAAC,GAAG,aAAa,GAAG,UAAU,CAAC,KAAK,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"files.mjs","names":[],"sources":["../../src/plugin/files.ts"],"sourcesContent":["import { fs } from '@weapp-core/shared/fs'\nimport { extname } from 'pathe'\nimport { bundleRequire } from 'rolldown-require'\n\nimport { SCRIPT_EXTS, STYLE_EXTS, TEMPLATE_EXTS } from './constants'\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nexport async function readJsonFile(pathname: string) {\n const candidates = [pathname]\n if (pathname.endsWith('.json')) {\n candidates.push(`${pathname}.ts`, `${pathname}.js`)\n }\n\n for (const candidate of candidates) {\n if (!(await fs.pathExists(candidate))) {\n continue\n }\n if (candidate.endsWith('.json')) {\n const json = await fs.readJson(candidate).catch(() => undefined)\n if (!isRecord(json)) {\n return undefined\n }\n return json\n }\n const { mod } = await bundleRequire({\n filepath: candidate,\n preserveTemporaryFile: true,\n })\n const resolved = typeof mod.default === 'function'\n ? await mod.default()\n : mod.default\n if (!isRecord(resolved)) {\n return undefined\n }\n return resolved\n }\n\n return undefined\n}\n\nexport async function resolveJsonPath(basePath: string) {\n const candidates = [basePath]\n if (basePath.endsWith('.json')) {\n candidates.push(`${basePath}.ts`, `${basePath}.js`)\n }\n for (const candidate of candidates) {\n if (await fs.pathExists(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport async function resolveScriptFile(basePath: string) {\n const ext = extname(basePath)\n if (ext && (await fs.pathExists(basePath))) {\n return basePath\n }\n for (const candidateExt of SCRIPT_EXTS) {\n const candidate = `${basePath}${candidateExt}`\n if (await fs.pathExists(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport async function resolveStyleFile(scriptPath: string) {\n const base = scriptPath.replace(new RegExp(`${extname(scriptPath)}$`), '')\n for (const ext of STYLE_EXTS) {\n const candidate = `${base}${ext}`\n if (await fs.pathExists(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport async function resolveTemplateFile(scriptPath: string) {\n const base = scriptPath.replace(new RegExp(`${extname(scriptPath)}$`), '')\n for (const ext of TEMPLATE_EXTS) {\n const candidate = `${base}${ext}`\n if (await fs.pathExists(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n"],"mappings":";;;;;;AAMA,SAAgB,SAAS,OAAkD;AACzE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;AAG7E,eAAsB,aAAa,UAAkB;CACnD,MAAM,aAAa,CAAC,SAAS;AAC7B,KAAI,SAAS,SAAS,QAAQ,CAC5B,YAAW,KAAK,GAAG,SAAS,MAAM,GAAG,SAAS,KAAK;AAGr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M,YAAY,GAAG,OAAO;AAC5B,MAAI,MAAM,GAAG,WAAW,UAAU,CAChC,QAAO"}
1
+ {"version":3,"file":"files.mjs","names":[],"sources":["../../src/plugin/files.ts"],"sourcesContent":["import { fs } from '@weapp-core/shared/fs'\nimport { extname } from 'pathe'\nimport { bundleRequire } from 'rolldown-require'\n\nimport { SCRIPT_EXTS, STYLE_EXTS, TEMPLATE_EXTS } from './constants'\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nexport async function readJsonFile(pathname: string) {\n const candidates = [pathname]\n if (pathname.endsWith('.json')) {\n candidates.push(`${pathname}.ts`, `${pathname}.js`)\n }\n\n for (const candidate of candidates) {\n if (!(await fs.pathExists(candidate))) {\n continue\n }\n if (candidate.endsWith('.json')) {\n const json = await fs.readJson(candidate).catch(() => undefined)\n if (!isRecord(json)) {\n return undefined\n }\n return json\n }\n const { mod } = await bundleRequire({\n filepath: candidate,\n preserveTemporaryFile: true,\n })\n const resolved = typeof mod.default === 'function'\n ? await mod.default()\n : mod.default\n if (!isRecord(resolved)) {\n return undefined\n }\n return resolved\n }\n\n return undefined\n}\n\nexport async function resolveJsonPath(basePath: string) {\n const candidates = [basePath]\n if (basePath.endsWith('.json')) {\n candidates.push(`${basePath}.ts`, `${basePath}.js`)\n }\n for (const candidate of candidates) {\n if (await fs.pathExists(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport async function resolveScriptFile(basePath: string) {\n const ext = extname(basePath)\n if (ext && (await fs.pathExists(basePath))) {\n return basePath\n }\n for (const candidateExt of SCRIPT_EXTS) {\n const candidate = `${basePath}${candidateExt}`\n if (await fs.pathExists(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport async function resolveStyleFile(scriptPath: string) {\n const base = scriptPath.replace(new RegExp(`${extname(scriptPath)}$`), '')\n for (const ext of STYLE_EXTS) {\n const candidate = `${base}${ext}`\n if (await fs.pathExists(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport async function resolveTemplateFile(scriptPath: string) {\n const base = scriptPath.replace(new RegExp(`${extname(scriptPath)}$`), '')\n for (const ext of TEMPLATE_EXTS) {\n const candidate = `${base}${ext}`\n if (await fs.pathExists(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n"],"mappings":";;;;;;AAMA,SAAgB,SAAS,OAAkD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;AAG7E,eAAsB,aAAa,UAAkB;CACnD,MAAM,aAAa,CAAC,SAAS;CAC7B,IAAI,SAAS,SAAS,QAAQ,EAC5B,WAAW,KAAK,GAAG,SAAS,MAAM,GAAG,SAAS,KAAK;CAGrD,KAAK,MAAM,aAAa,YAAY;EAClC,IAAI,CAAE,MAAM,GAAG,WAAW,UAAU,EAClC;EAEF,IAAI,UAAU,SAAS,QAAQ,EAAE;GAC/B,MAAM,OAAO,MAAM,GAAG,SAAS,UAAU,CAAC,YAAY,OAAU;GAChE,IAAI,CAAC,SAAS,KAAK,EACjB;GAEF,OAAO;;EAET,MAAM,EAAE,QAAQ,MAAM,cAAc;GAClC,UAAU;GACV,uBAAuB;GACxB,CAAC;EACF,MAAM,WAAW,OAAO,IAAI,YAAY,aACpC,MAAM,IAAI,SAAS,GACnB,IAAI;EACR,IAAI,CAAC,SAAS,SAAS,EACrB;EAEF,OAAO;;;AAMX,eAAsB,gBAAgB,UAAkB;CACtD,MAAM,aAAa,CAAC,SAAS;CAC7B,IAAI,SAAS,SAAS,QAAQ,EAC5B,WAAW,KAAK,GAAG,SAAS,MAAM,GAAG,SAAS,KAAK;CAErD,KAAK,MAAM,aAAa,YACtB,IAAI,MAAM,GAAG,WAAW,UAAU,EAChC,OAAO;;AAMb,eAAsB,kBAAkB,UAAkB;CAExD,IADY,QAAQ,SACb,IAAK,MAAM,GAAG,WAAW,SAAS,EACvC,OAAO;CAET,KAAK,MAAM,gBAAgB,aAAa;EACtC,MAAM,YAAY,GAAG,WAAW;EAChC,IAAI,MAAM,GAAG,WAAW,UAAU,EAChC,OAAO;;;AAMb,eAAsB,iBAAiB,YAAoB;CACzD,MAAM,OAAO,WAAW,QAAQ,IAAI,OAAO,GAAG,QAAQ,WAAW,CAAC,GAAG,EAAE,GAAG;CAC1E,KAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,YAAY,GAAG,OAAO;EAC5B,IAAI,MAAM,GAAG,WAAW,UAAU,EAChC,OAAO;;;AAMb,eAAsB,oBAAoB,YAAoB;CAC5D,MAAM,OAAO,WAAW,QAAQ,IAAI,OAAO,GAAG,QAAQ,WAAW,CAAC,GAAG,EAAE,GAAG;CAC1E,KAAK,MAAM,OAAO,eAAe;EAC/B,MAAM,YAAY,GAAG,OAAO;EAC5B,IAAI,MAAM,GAAG,WAAW,UAAU,EAChC,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/index.ts"],"sourcesContent":["import type { SourceMap } from 'magic-string'\nimport type { WeappWebPluginOptions } from './types'\nimport process from 'node:process'\n\nimport { extname, resolve } from 'pathe'\nimport { compileWxml } from '../compiler/wxml'\nimport { transformWxsToEsm } from '../compiler/wxs'\nimport { transformWxssToCss } from '../css/wxss'\nimport { ENTRY_ID, SCRIPT_EXTS, STYLE_EXTS, TEMPLATE_EXTS, TRANSFORM_STYLE_EXTS, WXS_EXTS } from './constants'\nimport { generateEntryModule } from './entry'\nimport { cleanUrl, isHtmlEntry, isInsideDir, normalizePath, resolveTemplatePathSync, resolveWxsPathSync, toRelativeImport } from './path'\nimport { transformScriptModule } from './register'\nimport { scanProject } from './scan'\nimport { createEmptyScanState } from './state'\n\ninterface WebPluginContext {\n warn?: (message: string) => void\n addWatchFile?: (id: string) => void\n}\n\ntype WebTransformResult = { code: string, map: SourceMap | null } | null\n\ninterface WebResolvedConfig {\n root: string\n command: string\n}\n\ninterface WebHmrContext {\n file: string\n}\n\ninterface WeappWebVitePlugin {\n name: string\n enforce?: 'pre' | 'post'\n configResolved?: (this: WebPluginContext, config: WebResolvedConfig) => void | Promise<void>\n buildStart?: (this: WebPluginContext) => void | Promise<void>\n resolveId?: (id: string) => string | null | Promise<string | null>\n load?: (id: string) => string | null | Promise<string | null>\n handleHotUpdate?: (this: WebPluginContext, ctx: WebHmrContext) => void | Promise<void>\n transform?: (\n this: WebPluginContext,\n code: string,\n id: string,\n ) => WebTransformResult | Promise<WebTransformResult>\n}\n\nfunction isTemplateFile(id: string) {\n const lower = id.toLowerCase()\n return TEMPLATE_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction isWxsFile(id: string) {\n const lower = id.toLowerCase()\n return WXS_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction hasWxsQuery(id: string) {\n return id.includes('?wxs') || id.includes('&wxs')\n}\n\nfunction createInlineStyleModule(css: string) {\n const serialized = JSON.stringify(css)\n return [\n `const __weapp_injected_styles__ = new Map()`,\n `function __weapp_createStyleId__(css) {`,\n ` let hash = 2166136261`,\n ` for (let i = 0; i < css.length; i++) {`,\n ` hash ^= css.charCodeAt(i)`,\n ` hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24)`,\n ` }`,\n ` return 'weapp-web-style-' + (hash >>> 0).toString(36)`,\n `}`,\n `function __weapp_removeStyle__(id) {`,\n ` if (typeof document === 'undefined') {`,\n ` return`,\n ` }`,\n ` const style = __weapp_injected_styles__.get(id)`,\n ` if (style) {`,\n ` style.remove()`,\n ` __weapp_injected_styles__.delete(id)`,\n ` }`,\n `}`,\n `function injectStyle(css, id) {`,\n ` if (typeof document === 'undefined') {`,\n ` return () => {}`,\n ` }`,\n ` const styleId = id ?? __weapp_createStyleId__(css)`,\n ` const existing = __weapp_injected_styles__.get(styleId)`,\n ` if (existing) {`,\n ` if (existing.textContent !== css) {`,\n ` existing.textContent = css`,\n ` }`,\n ` return () => __weapp_removeStyle__(styleId)`,\n ` }`,\n ` const style = document.createElement('style')`,\n ` style.id = styleId`,\n ` style.textContent = css`,\n ` document.head.append(style)`,\n ` __weapp_injected_styles__.set(styleId, style)`,\n ` return () => __weapp_removeStyle__(styleId)`,\n `}`,\n `const css = ${serialized}`,\n `export default css`,\n `export function useStyle(id) {`,\n ` return injectStyle(css, id)`,\n `}`,\n ].join('\\n')\n}\n\nexport function weappWebPlugin(options: WeappWebPluginOptions = {}): WeappWebVitePlugin {\n let root = process.cwd()\n let srcRoot = resolve(root, options.srcDir ?? 'src')\n let enableHmr = false\n\n const state = createEmptyScanState()\n const wxssOptions = options.wxss\n\n const resolveTemplatePath = (raw: string, importer: string) => resolveTemplatePathSync(raw, importer, srcRoot)\n const resolveWxsPath = (raw: string, importer: string) => resolveWxsPathSync(raw, importer, srcRoot)\n\n return {\n name: '@weapp-vite/web',\n enforce: 'pre',\n async configResolved(this: WebPluginContext, config: WebResolvedConfig) {\n root = config.root\n srcRoot = resolve(root, options.srcDir ?? 'src')\n enableHmr = config.command === 'serve'\n await scanProject({ srcRoot, warn: this.warn?.bind(this), state })\n },\n async buildStart(this: WebPluginContext) {\n await scanProject({ srcRoot, warn: this.warn?.bind(this), state })\n },\n resolveId(id: string) {\n if (id === '/@weapp-vite/web/entry' || id === '@weapp-vite/web/entry') {\n return ENTRY_ID\n }\n return null\n },\n load(id: string) {\n if (id === ENTRY_ID) {\n return generateEntryModule(state.scanResult, root, wxssOptions, options)\n }\n return null\n },\n async handleHotUpdate(this: WebPluginContext, ctx: WebHmrContext) {\n const clean = cleanUrl(ctx.file)\n if (clean.endsWith('.json') || isTemplateFile(clean) || isWxsFile(clean) || clean.endsWith('.wxss') || SCRIPT_EXTS.includes(extname(clean))) {\n await scanProject({ srcRoot, warn: this.warn?.bind(this), state })\n }\n },\n transform(this: WebPluginContext, code: string, id: string) {\n const clean = cleanUrl(id)\n\n if (isTemplateFile(clean)) {\n if (isHtmlEntry(clean, root)) {\n return null\n }\n const normalizedId = normalizePath(clean)\n if (state.templatePathSet.size > 0) {\n if (!isInsideDir(clean, srcRoot)) {\n return null\n }\n if (!state.templatePathSet.has(normalizedId)) {\n return null\n }\n }\n const navigationConfig = state.pageNavigationMap.get(normalizedId)\n const componentTags = state.templateComponentMap.get(normalizedId)\n const { code: compiled, dependencies, warnings } = compileWxml({\n id: clean,\n source: code,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (isWxsFile(clean) || hasWxsQuery(id)) {\n const { code: compiled, dependencies, warnings } = transformWxsToEsm(code, clean, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (TRANSFORM_STYLE_EXTS.some(ext => clean.endsWith(ext))) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return {\n code: createInlineStyleModule(css),\n map: null,\n }\n }\n\n if (STYLE_EXTS.some(ext => clean.endsWith(ext)) && !clean.endsWith('.wxss')) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return { code: css, map: null }\n }\n\n if (!SCRIPT_EXTS.some(ext => clean.endsWith(ext))) {\n return null\n }\n if (clean.includes('node_modules')) {\n return null\n }\n\n const meta = state.moduleMeta.get(normalizePath(clean))\n if (!meta) {\n return null\n }\n\n return transformScriptModule({\n code,\n cleanId: clean,\n meta,\n enableHmr,\n })\n },\n }\n}\n\nexport type { WeappWebPluginOptions } from './types'\n"],"mappings":";;;;;;;;;;;;;AA8CA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5B,WAAO;KAAE,MAAM;KAAU,KAAK;KAAM;;AAGtC,OAAI,UAAU,MAAM,IAAI,YAAY,GAAG,EAAE;IACvC,MAAM,EAAE,MAAM,UAAU,cAAc,aAAa,kBAAkB,MAAM,OAAO;KAChF,aAAa;KACb,eAAe,UAAU,aAAa,cAAc,iBAAiB,UAAU,SAAS,CAAC;KAC1F,CAAC;IACF,MAAM,eAAe,KAAK;AAC1B,QAAI,aAAa,SAAS,KAAK,aAC7B,MAAK,MAAM,OAAO,aAChB,cAAa,KAAK,MAAM,IAAI;IAGhC,MAAM,OAAO,KAAK;AAClB,QAAI,UAAU,UAAU,KACtB,MAAK,MAAM,WAAW,SACpB,MAAK,KAAK,MAAM,QAAQ;AAG5B,WAAO;KAAE,MAAM;KAAU,KAAK;KAAM;;AAGtC,OAAI,qBAAqB,MAAK,QAAO,MAAM,SAAS,IAAI,CAAC,EAAE;IACzD,MAAM,EAAE,QAAQ,mBAAmB,MAAM,YAAY;AACrD,WAAO;KACL,MAAM,wBAAwB,IAAI;KAClC,KAAK;KACN;;AAGH,OAAI,WAAW,MAAK,QAAO,MAAM,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,SAAS,QAAQ,EAAE;IAC3E,MAAM,EAAE,QAAQ,mBAAmB,MAAM,YAAY;AACrD,WAAO;KAAE,MAAM;KAAK,KAAK;KAAM;;AAGjC,OAAI,CAAC,YAAY,MAAK,QAAO,MAAM,SAAS,IAAI,CAAC,CAC/C,QAAO;AAET,OAAI,MAAM,SAAS,eAAe,CAChC,QAAO;GAGT,MAAM,OAAO,MAAM,WAAW,IAAI,cAAc,MAAM,CAAC;AACvD,OAAI,CAAC,KACH,QAAO;AAGT,UAAO,sBAAsB;IAC3B;IACA,SAAS;IACT;IACA;IACD,CAAC;;EAEL"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/index.ts"],"sourcesContent":["import type { SourceMap } from 'magic-string'\nimport type { WeappWebPluginOptions } from './types'\nimport process from 'node:process'\n\nimport { extname, resolve } from 'pathe'\nimport { compileWxml } from '../compiler/wxml'\nimport { transformWxsToEsm } from '../compiler/wxs'\nimport { transformWxssToCss } from '../css/wxss'\nimport { ENTRY_ID, SCRIPT_EXTS, STYLE_EXTS, TEMPLATE_EXTS, TRANSFORM_STYLE_EXTS, WXS_EXTS } from './constants'\nimport { generateEntryModule } from './entry'\nimport { cleanUrl, isHtmlEntry, isInsideDir, normalizePath, resolveTemplatePathSync, resolveWxsPathSync, toRelativeImport } from './path'\nimport { transformScriptModule } from './register'\nimport { scanProject } from './scan'\nimport { createEmptyScanState } from './state'\n\ninterface WebPluginContext {\n warn?: (message: string) => void\n addWatchFile?: (id: string) => void\n}\n\ntype WebTransformResult = { code: string, map: SourceMap | null } | null\n\ninterface WebResolvedConfig {\n root: string\n command: string\n}\n\ninterface WebHmrContext {\n file: string\n}\n\ninterface WeappWebVitePlugin {\n name: string\n enforce?: 'pre' | 'post'\n configResolved?: (this: WebPluginContext, config: WebResolvedConfig) => void | Promise<void>\n buildStart?: (this: WebPluginContext) => void | Promise<void>\n resolveId?: (id: string) => string | null | Promise<string | null>\n load?: (id: string) => string | null | Promise<string | null>\n handleHotUpdate?: (this: WebPluginContext, ctx: WebHmrContext) => void | Promise<void>\n transform?: (\n this: WebPluginContext,\n code: string,\n id: string,\n ) => WebTransformResult | Promise<WebTransformResult>\n}\n\nfunction isTemplateFile(id: string) {\n const lower = id.toLowerCase()\n return TEMPLATE_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction isWxsFile(id: string) {\n const lower = id.toLowerCase()\n return WXS_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction hasWxsQuery(id: string) {\n return id.includes('?wxs') || id.includes('&wxs')\n}\n\nfunction createInlineStyleModule(css: string) {\n const serialized = JSON.stringify(css)\n return [\n `const __weapp_injected_styles__ = new Map()`,\n `function __weapp_createStyleId__(css) {`,\n ` let hash = 2166136261`,\n ` for (let i = 0; i < css.length; i++) {`,\n ` hash ^= css.charCodeAt(i)`,\n ` hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24)`,\n ` }`,\n ` return 'weapp-web-style-' + (hash >>> 0).toString(36)`,\n `}`,\n `function __weapp_removeStyle__(id) {`,\n ` if (typeof document === 'undefined') {`,\n ` return`,\n ` }`,\n ` const style = __weapp_injected_styles__.get(id)`,\n ` if (style) {`,\n ` style.remove()`,\n ` __weapp_injected_styles__.delete(id)`,\n ` }`,\n `}`,\n `function injectStyle(css, id) {`,\n ` if (typeof document === 'undefined') {`,\n ` return () => {}`,\n ` }`,\n ` const styleId = id ?? __weapp_createStyleId__(css)`,\n ` const existing = __weapp_injected_styles__.get(styleId)`,\n ` if (existing) {`,\n ` if (existing.textContent !== css) {`,\n ` existing.textContent = css`,\n ` }`,\n ` return () => __weapp_removeStyle__(styleId)`,\n ` }`,\n ` const style = document.createElement('style')`,\n ` style.id = styleId`,\n ` style.textContent = css`,\n ` document.head.append(style)`,\n ` __weapp_injected_styles__.set(styleId, style)`,\n ` return () => __weapp_removeStyle__(styleId)`,\n `}`,\n `const css = ${serialized}`,\n `export default css`,\n `export function useStyle(id) {`,\n ` return injectStyle(css, id)`,\n `}`,\n ].join('\\n')\n}\n\nexport function weappWebPlugin(options: WeappWebPluginOptions = {}): WeappWebVitePlugin {\n let root = process.cwd()\n let srcRoot = resolve(root, options.srcDir ?? 'src')\n let enableHmr = false\n\n const state = createEmptyScanState()\n const wxssOptions = options.wxss\n\n const resolveTemplatePath = (raw: string, importer: string) => resolveTemplatePathSync(raw, importer, srcRoot)\n const resolveWxsPath = (raw: string, importer: string) => resolveWxsPathSync(raw, importer, srcRoot)\n\n return {\n name: '@weapp-vite/web',\n enforce: 'pre',\n async configResolved(this: WebPluginContext, config: WebResolvedConfig) {\n root = config.root\n srcRoot = resolve(root, options.srcDir ?? 'src')\n enableHmr = config.command === 'serve'\n await scanProject({ srcRoot, warn: this.warn?.bind(this), state })\n },\n async buildStart(this: WebPluginContext) {\n await scanProject({ srcRoot, warn: this.warn?.bind(this), state })\n },\n resolveId(id: string) {\n if (id === '/@weapp-vite/web/entry' || id === '@weapp-vite/web/entry') {\n return ENTRY_ID\n }\n return null\n },\n load(id: string) {\n if (id === ENTRY_ID) {\n return generateEntryModule(state.scanResult, root, wxssOptions, options)\n }\n return null\n },\n async handleHotUpdate(this: WebPluginContext, ctx: WebHmrContext) {\n const clean = cleanUrl(ctx.file)\n if (clean.endsWith('.json') || isTemplateFile(clean) || isWxsFile(clean) || clean.endsWith('.wxss') || SCRIPT_EXTS.includes(extname(clean))) {\n await scanProject({ srcRoot, warn: this.warn?.bind(this), state })\n }\n },\n transform(this: WebPluginContext, code: string, id: string) {\n const clean = cleanUrl(id)\n\n if (isTemplateFile(clean)) {\n if (isHtmlEntry(clean, root)) {\n return null\n }\n const normalizedId = normalizePath(clean)\n if (state.templatePathSet.size > 0) {\n if (!isInsideDir(clean, srcRoot)) {\n return null\n }\n if (!state.templatePathSet.has(normalizedId)) {\n return null\n }\n }\n const navigationConfig = state.pageNavigationMap.get(normalizedId)\n const componentTags = state.templateComponentMap.get(normalizedId)\n const { code: compiled, dependencies, warnings } = compileWxml({\n id: clean,\n source: code,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (isWxsFile(clean) || hasWxsQuery(id)) {\n const { code: compiled, dependencies, warnings } = transformWxsToEsm(code, clean, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (TRANSFORM_STYLE_EXTS.some(ext => clean.endsWith(ext))) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return {\n code: createInlineStyleModule(css),\n map: null,\n }\n }\n\n if (STYLE_EXTS.some(ext => clean.endsWith(ext)) && !clean.endsWith('.wxss')) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return { code: css, map: null }\n }\n\n if (!SCRIPT_EXTS.some(ext => clean.endsWith(ext))) {\n return null\n }\n if (clean.includes('node_modules')) {\n return null\n }\n\n const meta = state.moduleMeta.get(normalizePath(clean))\n if (!meta) {\n return null\n }\n\n return transformScriptModule({\n code,\n cleanId: clean,\n meta,\n enableHmr,\n })\n },\n }\n}\n\nexport type { WeappWebPluginOptions } from './types'\n"],"mappings":";;;;;;;;;;;;;AA8CA,SAAS,eAAe,IAAY;CAClC,MAAM,QAAQ,GAAG,aAAa;CAC9B,OAAO,cAAc,MAAK,QAAO,MAAM,SAAS,IAAI,CAAC;;AAGvD,SAAS,UAAU,IAAY;CAC7B,MAAM,QAAQ,GAAG,aAAa;CAC9B,OAAO,SAAS,MAAK,QAAO,MAAM,SAAS,IAAI,CAAC;;AAGlD,SAAS,YAAY,IAAY;CAC/B,OAAO,GAAG,SAAS,OAAO,IAAI,GAAG,SAAS,OAAO;;AAGnD,SAAS,wBAAwB,KAAa;CAE5C,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,eAxCiB,KAAK,UAAU,IAwCP;EACzB;EACA;EACA;EACA;EACD,CAAC,KAAK,KAAK;;AAGd,SAAgB,eAAe,UAAiC,EAAE,EAAsB;CACtF,IAAI,OAAO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,IAAI,WAAW,MAAK,QAAO,MAAM,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,SAAS,QAAQ,EAAE;IAC3E,MAAM,EAAE,QAAQ,mBAAmB,MAAM,YAAY;IACrD,OAAO;KAAE,MAAM;KAAK,KAAK;KAAM;;GAGjC,IAAI,CAAC,YAAY,MAAK,QAAO,MAAM,SAAS,IAAI,CAAC,EAC/C,OAAO;GAET,IAAI,MAAM,SAAS,eAAe,EAChC,OAAO;GAGT,MAAM,OAAO,MAAM,WAAW,IAAI,cAAc,MAAM,CAAC;GACvD,IAAI,CAAC,MACH,OAAO;GAGT,OAAO,sBAAsB;IAC3B;IACA,SAAS;IACT;IACA;IACD,CAAC;;EAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"navigation.mjs","names":[],"sources":["../../src/plugin/navigation.ts"],"sourcesContent":["import type { NavigationBarConfig } from '../compiler/wxml'\n\nexport function pickNavigationConfig(source: Record<string, unknown> | undefined): NavigationBarConfig {\n const config: NavigationBarConfig = {}\n if (!source) {\n return config\n }\n if (typeof source.navigationBarTitleText === 'string') {\n config.title = source.navigationBarTitleText\n }\n if (typeof source.navigationBarBackgroundColor === 'string') {\n config.backgroundColor = source.navigationBarBackgroundColor\n }\n if (typeof source.navigationBarTextStyle === 'string') {\n config.textStyle = source.navigationBarTextStyle\n }\n if (typeof source.navigationStyle === 'string') {\n config.navigationStyle = source.navigationStyle\n }\n return config\n}\n\nexport function mergeNavigationConfig(base: NavigationBarConfig, overrides: NavigationBarConfig) {\n return {\n ...base,\n ...overrides,\n }\n}\n"],"mappings":";AAEA,SAAgB,qBAAqB,QAAkE;CACrG,MAAM,SAA8B,EAAE;AACtC,KAAI,CAAC,OACH,QAAO;AAET,KAAI,OAAO,OAAO,2BAA2B,SAC3C,QAAO,QAAQ,OAAO;AAExB,KAAI,OAAO,OAAO,iCAAiC,SACjD,QAAO,kBAAkB,OAAO;AAElC,KAAI,OAAO,OAAO,2BAA2B,SAC3C,QAAO,YAAY,OAAO;AAE5B,KAAI,OAAO,OAAO,oBAAoB,SACpC,QAAO,kBAAkB,OAAO;AAElC,QAAO;;AAGT,SAAgB,sBAAsB,MAA2B,WAAgC;AAC/F,QAAO;EACL,GAAG;EACH,GAAG;EACJ"}
1
+ {"version":3,"file":"navigation.mjs","names":[],"sources":["../../src/plugin/navigation.ts"],"sourcesContent":["import type { NavigationBarConfig } from '../compiler/wxml'\n\nexport function pickNavigationConfig(source: Record<string, unknown> | undefined): NavigationBarConfig {\n const config: NavigationBarConfig = {}\n if (!source) {\n return config\n }\n if (typeof source.navigationBarTitleText === 'string') {\n config.title = source.navigationBarTitleText\n }\n if (typeof source.navigationBarBackgroundColor === 'string') {\n config.backgroundColor = source.navigationBarBackgroundColor\n }\n if (typeof source.navigationBarTextStyle === 'string') {\n config.textStyle = source.navigationBarTextStyle\n }\n if (typeof source.navigationStyle === 'string') {\n config.navigationStyle = source.navigationStyle\n }\n return config\n}\n\nexport function mergeNavigationConfig(base: NavigationBarConfig, overrides: NavigationBarConfig) {\n return {\n ...base,\n ...overrides,\n }\n}\n"],"mappings":";AAEA,SAAgB,qBAAqB,QAAkE;CACrG,MAAM,SAA8B,EAAE;CACtC,IAAI,CAAC,QACH,OAAO;CAET,IAAI,OAAO,OAAO,2BAA2B,UAC3C,OAAO,QAAQ,OAAO;CAExB,IAAI,OAAO,OAAO,iCAAiC,UACjD,OAAO,kBAAkB,OAAO;CAElC,IAAI,OAAO,OAAO,2BAA2B,UAC3C,OAAO,YAAY,OAAO;CAE5B,IAAI,OAAO,OAAO,oBAAoB,UACpC,OAAO,kBAAkB,OAAO;CAElC,OAAO;;AAGT,SAAgB,sBAAsB,MAA2B,WAAgC;CAC/F,OAAO;EACL,GAAG;EACH,GAAG;EACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"path.mjs","names":[],"sources":["../../src/plugin/path.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { dirname, extname, normalize, posix, relative, resolve } from 'pathe'\n\nimport { TEMPLATE_EXTS, WXS_RESOLVE_EXTS } from './constants'\n\nexport function cleanUrl(url: string) {\n const queryIndex = url.indexOf('?')\n if (queryIndex >= 0) {\n return url.slice(0, queryIndex)\n }\n return url\n}\n\nexport function normalizePath(p: string) {\n return posix.normalize(p.split('\\\\').join('/'))\n}\n\nexport function isInsideDir(filePath: string, dir: string) {\n const rel = relative(dir, filePath)\n return rel === '' || (!rel.startsWith('..') && !posix.isAbsolute(rel))\n}\n\nexport function isHtmlEntry(filePath: string, root: string) {\n if (!filePath.toLowerCase().endsWith('.html')) {\n return false\n }\n return normalizePath(filePath) === normalizePath(resolve(root, 'index.html'))\n}\n\nexport function toPosixId(id: string) {\n return normalize(id).split('\\\\').join('/')\n}\n\nexport function toRelativeImport(from: string, target: string) {\n const fromDir = dirname(from)\n const rel = relative(fromDir, target)\n if (!rel || rel.startsWith('.')) {\n return normalizePath(rel || `./${posix.basename(target)}`)\n }\n return `./${normalizePath(rel)}`\n}\n\nexport function appendInlineQuery(id: string) {\n if (id.includes('?')) {\n if (id.includes('?inline') || id.includes('&inline')) {\n return id\n }\n return `${id}&inline`\n }\n return `${id}?inline`\n}\n\nexport function relativeModuleId(root: string, absPath: string) {\n const rel = relative(root, absPath)\n return `/${normalizePath(rel)}`\n}\n\nexport function toViteFsImport(absPath: string) {\n const normalized = normalizePath(absPath)\n return normalized.startsWith('/')\n ? `/@fs${normalized}`\n : `/@fs/${normalized}`\n}\n\nexport function resolveRuntimePolyfillPath() {\n const currentDir = dirname(fileURLToPath(import.meta.url))\n const candidates = [\n resolve(currentDir, '../runtime/index.mjs'),\n resolve(currentDir, './runtime/index.mjs'),\n resolve(currentDir, '../runtime/polyfill.ts'),\n resolve(currentDir, '../runtime/index.ts'),\n ]\n\n for (const candidate of candidates) {\n if (existsSync(candidate)) {\n return candidate\n }\n }\n\n throw new Error('[@weapp-vite/web] Failed to resolve runtime polyfill path.')\n}\n\nexport function resolveImportBase(raw: string, importer: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n if (raw.startsWith('.')) {\n return resolve(dirname(importer), raw)\n }\n if (raw.startsWith('/')) {\n return resolve(srcRoot, raw.slice(1))\n }\n return resolve(srcRoot, raw)\n}\n\nexport function resolveFileWithExtensionsSync(basePath: string, extensions: string[]) {\n if (extname(basePath) && existsSync(basePath)) {\n return basePath\n }\n for (const ext of extensions) {\n const candidate = `${basePath}${ext}`\n if (existsSync(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport function resolveTemplatePathSync(raw: string, importer: string, srcRoot: string) {\n const base = resolveImportBase(raw, importer, srcRoot)\n if (!base) {\n return undefined\n }\n return resolveFileWithExtensionsSync(base, TEMPLATE_EXTS)\n}\n\nexport function resolveWxsPathSync(raw: string, importer: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n let base: string | undefined\n if (raw.startsWith('.')) {\n base = resolve(dirname(importer), raw)\n }\n else if (raw.startsWith('/')) {\n base = resolve(srcRoot, raw.slice(1))\n }\n else {\n return undefined\n }\n return resolveFileWithExtensionsSync(base, WXS_RESOLVE_EXTS)\n}\n"],"mappings":";;;;;;AAMA,SAAgB,SAAS,KAAa;CACpC,MAAM,aAAa,IAAI,QAAQ,IAAI;AACnC,KAAI,cAAc,EAChB,QAAO,IAAI,MAAM,GAAG,WAAW;AAEjC,QAAO;;AAGT,SAAgB,cAAc,GAAW;AACvC,QAAO,MAAM,UAAU,EAAE,MAAM,KAAK,CAAC,KAAK,IAAI,CAAC;;AAGjD,SAAgB,YAAY,UAAkB,KAAa;CACzD,MAAM,MAAM,SAAS,KAAK,SAAS;AACnC,QAAO,QAAQ,MAAO,CAAC,IAAI,WAAW,KAAK,IAAI,CAAC,MAAM,WAAW,IAAI;;AAGvE,SAAgB,YAAY,UAAkB,MAAc;AAC1D,KAAI,CAAC,SAAS,aAAa,CAAC,SAAS,QAAQ,CAC3C,QAAO;AAET,QAAO,cAAc,SAAS,KAAK,cAAc,QAAQ,MAAM,aAAa,CAAC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QAAQ,SAAS,IAAI;;AAG9B,SAAgB,8BAA8B,UAAkB,YAAsB;AACpF,KAAI,QAAQ,SAAS,IAAI,WAAW,SAAS,CAC3C,QAAO;AAET,MAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,YAAY,GAAG,WAAW;AAChC,MAAI,WAAW,UAAU,CACvB,QAAO;;;AAMb,SAAgB,wBAAwB,KAAa,UAAkB,SAAiB;CACtF,MAAM,OAAO,kBAAkB,KAAK,UAAU,QAAQ;AACtD,KAAI,CAAC,KACH;AAEF,QAAO,8BAA8B,MAAM,cAAc;;AAG3D,SAAgB,mBAAmB,KAAa,UAAkB,SAAiB;AACjF,KAAI,CAAC,IACH;CAEF,IAAI;AACJ,KAAI,IAAI,WAAW,IAAI,CACrB,QAAO,QAAQ,QAAQ,SAAS,EAAE,IAAI;UAE/B,IAAI,WAAW,IAAI,CAC1B,QAAO,QAAQ,SAAS,IAAI,MAAM,EAAE,CAAC;KAGrC;AAEF,QAAO,8BAA8B,MAAM,iBAAiB"}
1
+ {"version":3,"file":"path.mjs","names":[],"sources":["../../src/plugin/path.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { dirname, extname, normalize, posix, relative, resolve } from 'pathe'\n\nimport { TEMPLATE_EXTS, WXS_RESOLVE_EXTS } from './constants'\n\nexport function cleanUrl(url: string) {\n const queryIndex = url.indexOf('?')\n if (queryIndex >= 0) {\n return url.slice(0, queryIndex)\n }\n return url\n}\n\nexport function normalizePath(p: string) {\n return posix.normalize(p.split('\\\\').join('/'))\n}\n\nexport function isInsideDir(filePath: string, dir: string) {\n const rel = relative(dir, filePath)\n return rel === '' || (!rel.startsWith('..') && !posix.isAbsolute(rel))\n}\n\nexport function isHtmlEntry(filePath: string, root: string) {\n if (!filePath.toLowerCase().endsWith('.html')) {\n return false\n }\n return normalizePath(filePath) === normalizePath(resolve(root, 'index.html'))\n}\n\nexport function toPosixId(id: string) {\n return normalize(id).split('\\\\').join('/')\n}\n\nexport function toRelativeImport(from: string, target: string) {\n const fromDir = dirname(from)\n const rel = relative(fromDir, target)\n if (!rel || rel.startsWith('.')) {\n return normalizePath(rel || `./${posix.basename(target)}`)\n }\n return `./${normalizePath(rel)}`\n}\n\nexport function appendInlineQuery(id: string) {\n if (id.includes('?')) {\n if (id.includes('?inline') || id.includes('&inline')) {\n return id\n }\n return `${id}&inline`\n }\n return `${id}?inline`\n}\n\nexport function relativeModuleId(root: string, absPath: string) {\n const rel = relative(root, absPath)\n return `/${normalizePath(rel)}`\n}\n\nexport function toViteFsImport(absPath: string) {\n const normalized = normalizePath(absPath)\n return normalized.startsWith('/')\n ? `/@fs${normalized}`\n : `/@fs/${normalized}`\n}\n\nexport function resolveRuntimePolyfillPath() {\n const currentDir = dirname(fileURLToPath(import.meta.url))\n const candidates = [\n resolve(currentDir, '../runtime/index.mjs'),\n resolve(currentDir, './runtime/index.mjs'),\n resolve(currentDir, '../runtime/polyfill.ts'),\n resolve(currentDir, '../runtime/index.ts'),\n ]\n\n for (const candidate of candidates) {\n if (existsSync(candidate)) {\n return candidate\n }\n }\n\n throw new Error('[@weapp-vite/web] Failed to resolve runtime polyfill path.')\n}\n\nexport function resolveImportBase(raw: string, importer: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n if (raw.startsWith('.')) {\n return resolve(dirname(importer), raw)\n }\n if (raw.startsWith('/')) {\n return resolve(srcRoot, raw.slice(1))\n }\n return resolve(srcRoot, raw)\n}\n\nexport function resolveFileWithExtensionsSync(basePath: string, extensions: string[]) {\n if (extname(basePath) && existsSync(basePath)) {\n return basePath\n }\n for (const ext of extensions) {\n const candidate = `${basePath}${ext}`\n if (existsSync(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport function resolveTemplatePathSync(raw: string, importer: string, srcRoot: string) {\n const base = resolveImportBase(raw, importer, srcRoot)\n if (!base) {\n return undefined\n }\n return resolveFileWithExtensionsSync(base, TEMPLATE_EXTS)\n}\n\nexport function resolveWxsPathSync(raw: string, importer: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n let base: string | undefined\n if (raw.startsWith('.')) {\n base = resolve(dirname(importer), raw)\n }\n else if (raw.startsWith('/')) {\n base = resolve(srcRoot, raw.slice(1))\n }\n else {\n return undefined\n }\n return resolveFileWithExtensionsSync(base, WXS_RESOLVE_EXTS)\n}\n"],"mappings":";;;;;;AAMA,SAAgB,SAAS,KAAa;CACpC,MAAM,aAAa,IAAI,QAAQ,IAAI;CACnC,IAAI,cAAc,GAChB,OAAO,IAAI,MAAM,GAAG,WAAW;CAEjC,OAAO;;AAGT,SAAgB,cAAc,GAAW;CACvC,OAAO,MAAM,UAAU,EAAE,MAAM,KAAK,CAAC,KAAK,IAAI,CAAC;;AAGjD,SAAgB,YAAY,UAAkB,KAAa;CACzD,MAAM,MAAM,SAAS,KAAK,SAAS;CACnC,OAAO,QAAQ,MAAO,CAAC,IAAI,WAAW,KAAK,IAAI,CAAC,MAAM,WAAW,IAAI;;AAGvE,SAAgB,YAAY,UAAkB,MAAc;CAC1D,IAAI,CAAC,SAAS,aAAa,CAAC,SAAS,QAAQ,EAC3C,OAAO;CAET,OAAO,cAAc,SAAS,KAAK,cAAc,QAAQ,MAAM,aAAa,CAAC;;AAG/E,SAAgB,UAAU,IAAY;CACpC,OAAO,UAAU,GAAG,CAAC,MAAM,KAAK,CAAC,KAAK,IAAI;;AAG5C,SAAgB,iBAAiB,MAAc,QAAgB;CAE7D,MAAM,MAAM,SADI,QAAQ,KACI,EAAE,OAAO;CACrC,IAAI,CAAC,OAAO,IAAI,WAAW,IAAI,EAC7B,OAAO,cAAc,OAAO,KAAK,MAAM,SAAS,OAAO,GAAG;CAE5D,OAAO,KAAK,cAAc,IAAI;;AAGhC,SAAgB,kBAAkB,IAAY;CAC5C,IAAI,GAAG,SAAS,IAAI,EAAE;EACpB,IAAI,GAAG,SAAS,UAAU,IAAI,GAAG,SAAS,UAAU,EAClD,OAAO;EAET,OAAO,GAAG,GAAG;;CAEf,O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B,OAAO,QAAQ,QAAQ,SAAS,EAAE,IAAI;MAEnC,IAAI,IAAI,WAAW,IAAI,EAC1B,OAAO,QAAQ,SAAS,IAAI,MAAM,EAAE,CAAC;MAGrC;CAEF,OAAO,8BAA8B,MAAM,iBAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"register.mjs","names":[],"sources":["../../src/plugin/register.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { SourceMap } from 'magic-string'\n\nimport type { ModuleMeta } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport MagicString from 'magic-string'\nimport { appendInlineQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from './path'\n\ntype TraverseFunction = typeof _babelTraverse extends (...args: any[]) => any\n ? typeof _babelTraverse\n : typeof _babelTraverse extends { default: infer D }\n ? D\n : typeof _babelTraverse\n\nconst traverseCandidate: any = (() => {\n const mod: any = _babelTraverse\n if (typeof mod === 'function') {\n return mod\n }\n if (mod?.default && typeof mod.default === 'function') {\n return mod.default\n }\n if (mod?.traverse && typeof mod.traverse === 'function') {\n return mod.traverse\n }\n return undefined\n})()\n\nif (typeof traverseCandidate !== 'function') {\n throw new TypeError('[@weapp-vite/web] Failed to resolve @babel/traverse export.')\n}\n\nconst traverse: TraverseFunction = traverseCandidate\n\nfunction mapRegisterIdentifier(kind: ModuleMeta['kind']) {\n if (kind === 'page') {\n return 'Page'\n }\n if (kind === 'component') {\n return 'Component'\n }\n if (kind === 'app') {\n return 'App'\n }\n return ''\n}\n\nfunction getRegisterName(kind: ModuleMeta['kind']) {\n if (kind === 'page') {\n return 'registerPage'\n }\n if (kind === 'component') {\n return 'registerComponent'\n }\n if (kind === 'app') {\n return 'registerApp'\n }\n return undefined\n}\n\nfunction overwriteCall(\n path: NodePath<CallExpression>,\n meta: ModuleMeta,\n registerName: string,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n s: MagicString,\n) {\n const node = path.node\n const callee = node.callee\n if (!t.isIdentifier(callee)) {\n return\n }\n const end = node.end!\n const insertPosition = end - 1\n const metaParts: string[] = [`id: ${JSON.stringify(meta.id)}`]\n if (templateIdent) {\n metaParts.push(`template: ${templateIdent}`)\n }\n if (styleIdent) {\n metaParts.push(`style: ${styleIdent}`)\n }\n const metaCode = `{ ${metaParts.join(', ')} }`\n s.overwrite(callee.start!, callee.end!, registerName)\n s.appendLeft(insertPosition, `, ${metaCode}`)\n}\n\ninterface TransformScriptModuleOptions {\n code: string\n cleanId: string\n meta: ModuleMeta\n enableHmr: boolean\n}\n\nexport function transformScriptModule({\n code,\n cleanId,\n meta,\n enableHmr,\n}: TransformScriptModuleOptions): null | { code: string, map: SourceMap } {\n const registerName = getRegisterName(meta.kind)\n if (!registerName) {\n return null\n }\n\n let ast: ReturnType<typeof parse> | undefined\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n ranges: true,\n })\n }\n catch {\n return null\n }\n\n const s = new MagicString(code)\n let transformed = false\n\n const imports: string[] = []\n const runtimePolyfillId = toViteFsImport(resolveRuntimePolyfillPath())\n const templateIdent = meta.templatePath ? '__weapp_template__' : undefined\n const styleIdent = meta.stylePath ? '__weapp_style__' : undefined\n\n if (meta.templatePath && templateIdent) {\n imports.push(`import ${templateIdent} from '${toRelativeImport(cleanId, meta.templatePath)}'`)\n }\n\n if (meta.stylePath && styleIdent) {\n imports.push(`import ${styleIdent} from '${appendInlineQuery(toRelativeImport(cleanId, meta.stylePath))}'`)\n }\n\n const registerImports = new Set<string>()\n\n traverse(ast, {\n CallExpression(path: NodePath<CallExpression>) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n const name = path.node.callee.name\n if (name === mapRegisterIdentifier(meta.kind)) {\n registerImports.add(registerName)\n overwriteCall(path, meta, registerName, templateIdent, styleIdent, s)\n transformed = true\n }\n },\n })\n\n if (!transformed) {\n return null\n }\n\n if (registerImports.size > 0) {\n imports.unshift(`import { ${Array.from(registerImports).join(', ')} } from '${runtimePolyfillId}'`)\n }\n\n const prefix = `${imports.join('\\n')}\\n`\n s.prepend(prefix)\n\n if (enableHmr) {\n s.append(`\\nif (import.meta.hot) { import.meta.hot.accept() }\\n`)\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({\n hires: true,\n }),\n }\n}\n"],"mappings":";;;;;;;AAkBA,MAAM,2BAAgC;CACpC,MAAM,MAAW;AACjB,KAAI,OAAO,QAAQ,WACjB,QAAO;AAET,KAAI,KAAK,WAAW,OAAO,IAAI,YAAY,WACzC,QAAO,IAAI;AAEb,KAAI,KAAK,YAAY,OAAO,IAAI,aAAa,WAC3C,QAAO,IAAI;IAGX;AAEJ,IAAI,OAAO,sBAAsB,WAC/B,OAAM,IAAI,UAAU,8DAA8D;AAGpF,MAAM,WAA6B;AAEnC,SAAS,sBAAsB,MAA0B;AACvD,KAAI,SAAS,OACX,QAAO;AAET,KAAI,SAAS,YACX,QAAO;AAET,KAAI,SAAS,MACX,QAAO;AAET,QAAO;;AAGT,SAAS,gBAAgB,MAA0B;AACjD,KAAI,SAAS,OACX,QAAO;AAET,KAAI,SAAS,YACX,QAAO;AAET,KAAI,SAAS,MACX,QAAO;;AAKX,SAAS,cACP,MACA,MACA,cACA,eACA,YACA,GACA;CACA,MAAM,OAAO,KAAK;CAClB,MAAM,SAAS,KAAK;AACpB,KAAI,CAAC,EAAE,aAAa,OAAO,CACzB;CAGF,MAAM,iBADM,KAAK,MACY;CAC7B,MAAM,YAAsB,CAAC,OAAO,KAAK,UAAU,KAAK,GAAG,GAAG;AAC9D,KAAI,cACF,WAAU,KAAK,aAAa,gBAAgB;AAE9C,KAAI,WACF,WAAU,KAAK,UAAU,aAAa;CAExC,MAAM,WAAW,KAAK,UAAU,KAAK,KAAK,CAAC;AAC3C,GAAE,UAAU,OAAO,OAAQ,OAAO,KAAM,aAAa;AACrD,GAAE,WAAW,gBAAgB,KAAK,WAAW;;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AwD;AAGnE,QAAO;EACL,MAAM,EAAE,UAAU;EAClB,KAAK,EAAE,YAAY,EACjB,OAAO,MACR,CAAC;EACH"}
1
+ {"version":3,"file":"register.mjs","names":[],"sources":["../../src/plugin/register.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { SourceMap } from 'magic-string'\n\nimport type { ModuleMeta } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport MagicString from 'magic-string'\nimport { appendInlineQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from './path'\n\ntype TraverseFunction = typeof _babelTraverse extends (...args: any[]) => any\n ? typeof _babelTraverse\n : typeof _babelTraverse extends { default: infer D }\n ? D\n : typeof _babelTraverse\n\nconst traverseCandidate: any = (() => {\n const mod: any = _babelTraverse\n if (typeof mod === 'function') {\n return mod\n }\n if (mod?.default && typeof mod.default === 'function') {\n return mod.default\n }\n if (mod?.traverse && typeof mod.traverse === 'function') {\n return mod.traverse\n }\n return undefined\n})()\n\nif (typeof traverseCandidate !== 'function') {\n throw new TypeError('[@weapp-vite/web] Failed to resolve @babel/traverse export.')\n}\n\nconst traverse: TraverseFunction = traverseCandidate\n\nfunction mapRegisterIdentifier(kind: ModuleMeta['kind']) {\n if (kind === 'page') {\n return 'Page'\n }\n if (kind === 'component') {\n return 'Component'\n }\n if (kind === 'app') {\n return 'App'\n }\n return ''\n}\n\nfunction getRegisterName(kind: ModuleMeta['kind']) {\n if (kind === 'page') {\n return 'registerPage'\n }\n if (kind === 'component') {\n return 'registerComponent'\n }\n if (kind === 'app') {\n return 'registerApp'\n }\n return undefined\n}\n\nfunction overwriteCall(\n path: NodePath<CallExpression>,\n meta: ModuleMeta,\n registerName: string,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n s: MagicString,\n) {\n const node = path.node\n const callee = node.callee\n if (!t.isIdentifier(callee)) {\n return\n }\n const end = node.end!\n const insertPosition = end - 1\n const metaParts: string[] = [`id: ${JSON.stringify(meta.id)}`]\n if (templateIdent) {\n metaParts.push(`template: ${templateIdent}`)\n }\n if (styleIdent) {\n metaParts.push(`style: ${styleIdent}`)\n }\n const metaCode = `{ ${metaParts.join(', ')} }`\n s.overwrite(callee.start!, callee.end!, registerName)\n s.appendLeft(insertPosition, `, ${metaCode}`)\n}\n\ninterface TransformScriptModuleOptions {\n code: string\n cleanId: string\n meta: ModuleMeta\n enableHmr: boolean\n}\n\nexport function transformScriptModule({\n code,\n cleanId,\n meta,\n enableHmr,\n}: TransformScriptModuleOptions): null | { code: string, map: SourceMap } {\n const registerName = getRegisterName(meta.kind)\n if (!registerName) {\n return null\n }\n\n let ast: ReturnType<typeof parse> | undefined\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n ranges: true,\n })\n }\n catch {\n return null\n }\n\n const s = new MagicString(code)\n let transformed = false\n\n const imports: string[] = []\n const runtimePolyfillId = toViteFsImport(resolveRuntimePolyfillPath())\n const templateIdent = meta.templatePath ? '__weapp_template__' : undefined\n const styleIdent = meta.stylePath ? '__weapp_style__' : undefined\n\n if (meta.templatePath && templateIdent) {\n imports.push(`import ${templateIdent} from '${toRelativeImport(cleanId, meta.templatePath)}'`)\n }\n\n if (meta.stylePath && styleIdent) {\n imports.push(`import ${styleIdent} from '${appendInlineQuery(toRelativeImport(cleanId, meta.stylePath))}'`)\n }\n\n const registerImports = new Set<string>()\n\n traverse(ast, {\n CallExpression(path: NodePath<CallExpression>) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n const name = path.node.callee.name\n if (name === mapRegisterIdentifier(meta.kind)) {\n registerImports.add(registerName)\n overwriteCall(path, meta, registerName, templateIdent, styleIdent, s)\n transformed = true\n }\n },\n })\n\n if (!transformed) {\n return null\n }\n\n if (registerImports.size > 0) {\n imports.unshift(`import { ${Array.from(registerImports).join(', ')} } from '${runtimePolyfillId}'`)\n }\n\n const prefix = `${imports.join('\\n')}\\n`\n s.prepend(prefix)\n\n if (enableHmr) {\n s.append(`\\nif (import.meta.hot) { import.meta.hot.accept() }\\n`)\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({\n hires: true,\n }),\n }\n}\n"],"mappings":";;;;;;;AAkBA,MAAM,2BAAgC;CACpC,MAAM,MAAW;CACjB,IAAI,OAAO,QAAQ,YACjB,OAAO;CAET,IAAI,KAAK,WAAW,OAAO,IAAI,YAAY,YACzC,OAAO,IAAI;CAEb,IAAI,KAAK,YAAY,OAAO,IAAI,aAAa,YAC3C,OAAO,IAAI;IAGX;AAEJ,IAAI,OAAO,sBAAsB,YAC/B,MAAM,IAAI,UAAU,8DAA8D;AAGpF,MAAM,WAA6B;AAEnC,SAAS,sBAAsB,MAA0B;CACvD,IAAI,SAAS,QACX,OAAO;CAET,IAAI,SAAS,aACX,OAAO;CAET,IAAI,SAAS,OACX,OAAO;CAET,OAAO;;AAGT,SAAS,gBAAgB,MAA0B;CACjD,IAAI,SAAS,QACX,OAAO;CAET,IAAI,SAAS,aACX,OAAO;CAET,IAAI,SAAS,OACX,OAAO;;AAKX,SAAS,cACP,MACA,MACA,cACA,eACA,YACA,GACA;CACA,MAAM,OAAO,KAAK;CAClB,MAAM,SAAS,KAAK;CACpB,IAAI,CAAC,EAAE,aAAa,OAAO,EACzB;CAGF,MAAM,iBADM,KAAK,MACY;CAC7B,MAAM,YAAsB,CAAC,OAAO,KAAK,UAAU,KAAK,GAAG,GAAG;CAC9D,IAAI,eACF,UAAU,KAAK,aAAa,gBAAgB;CAE9C,IAAI,YACF,UAAU,KAAK,UAAU,aAAa;CAExC,MAAM,WAAW,KAAK,UAAU,KAAK,KAAK,CAAC;CAC3C,EAAE,UAAU,OAAO,OAAQ,OAAO,KAAM,aAAa;CACrD,EAAE,WAAW,gBAAgB,KAAK,WAAW;;AAU/C,SAAgB,sBAAsB,EACpC,MACA,SACA,MACA,aACwE;CACxE,MAAM,eAAe,gBAAgB,KAAK,KAA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