@dimina-kit/compiler 0.0.2-dev.20260728065133 → 0.0.2-dev.20260728095034

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 (25) hide show
  1. package/dist/compile-core.browser.js +14759 -16081
  2. package/dist/compile-core.node-chunks/chunk-2VRS523Z.js +8 -0
  3. package/dist/compile-core.node-chunks/chunk-LUD2P6RM.js +211 -0
  4. package/dist/compile-core.node-chunks/{chunk-M62ZDT7T.js → chunk-QJ34C5KK.js} +66 -542
  5. package/dist/compile-core.node-chunks/{logic-compiler-AEZPY2MO.js → logic-compiler-2SQFOFEO.js} +113 -37
  6. package/dist/compile-core.node-chunks/style-compiler-ZEJ3XLTS.js +277 -0
  7. package/dist/compile-core.node-chunks/{view-compiler-2SMUHAPD.js → view-compiler-WQNV7H5G.js} +161 -425
  8. package/dist/compile-core.node.js +6 -11
  9. package/dist/pool.node-chunks/{chunk-CKQISGZS.js → chunk-7FGOYOXU.js} +66 -542
  10. package/dist/pool.node-chunks/chunk-C7GEIDCP.js +211 -0
  11. package/dist/pool.node-chunks/chunk-KLXXOLDF.js +8 -0
  12. package/dist/pool.node-chunks/{chunk-WX4462A5.js → chunk-PDHO4Y56.js} +6 -11
  13. package/dist/pool.node-chunks/{logic-compiler-P4T4OMTG.js → logic-compiler-BODAINZQ.js} +113 -37
  14. package/dist/pool.node-chunks/style-compiler-TUNDVSR5.js +277 -0
  15. package/dist/pool.node-chunks/{view-compiler-2D7HPYIN.js → view-compiler-HOFFL63K.js} +161 -425
  16. package/dist/pool.node.js +2 -2
  17. package/dist/stage-worker.browser.js +1940 -3262
  18. package/dist/stage-worker.node.js +2 -2
  19. package/package.json +3 -3
  20. package/dist/compile-core.node-chunks/chunk-23PCGQQU.js +0 -141
  21. package/dist/compile-core.node-chunks/chunk-QYHGF3MS.js +0 -1601
  22. package/dist/compile-core.node-chunks/style-compiler-4PHMBQIC.js +0 -470
  23. package/dist/pool.node-chunks/chunk-LGB3AH5C.js +0 -1601
  24. package/dist/pool.node-chunks/chunk-VHWKAXDL.js +0 -141
  25. package/dist/pool.node-chunks/style-compiler-W7EA2Y7R.js +0 -470
@@ -1,16 +1,10 @@
1
1
  import {
2
- checkTemplateCompatibility,
3
- getTemplateDirectiveName,
4
- takeCompatibilityWarnings
5
- } from "./chunk-QYHGF3MS.js";
2
+ checkTemplateCompatibility
3
+ } from "./chunk-LUD2P6RM.js";
6
4
  import {
7
- concatSourcemap,
8
- createLineSourcemap,
9
5
  isMainThread,
10
- mergeSourcemap,
11
- parentPort,
12
- remapSourcemap
13
- } from "./chunk-23PCGQQU.js";
6
+ parentPort
7
+ } from "./chunk-2VRS523Z.js";
14
8
  import {
15
9
  collectAssets,
16
10
  fs_default,
@@ -18,18 +12,15 @@ import {
18
12
  getAppId,
19
13
  getComponent,
20
14
  getContentByPath,
21
- getDependencyGraph,
22
15
  getTargetPath,
23
16
  getTemplateExts,
24
17
  getViewScriptExts,
25
18
  getViewScriptTags,
26
19
  getWorkPath,
27
20
  resetStoreInfo,
28
- resolveAssetSourcePath,
29
21
  tagWhiteList,
30
- toMiniProgramModuleId,
31
22
  transformRpx
32
- } from "./chunk-M62ZDT7T.js";
23
+ } from "./chunk-QJ34C5KK.js";
33
24
 
34
25
  // ../../dimina/fe/packages/compiler/src/core/view-compiler.js
35
26
  import path from "node:path";
@@ -288,12 +279,10 @@ function transformTextInterpolation(text) {
288
279
  var compileResCache = /* @__PURE__ */ new Map();
289
280
  var wxsModuleRegistry = /* @__PURE__ */ new Set();
290
281
  var wxsFilePathMap = /* @__PURE__ */ new Map();
291
- var enableSourcemap = false;
292
282
  if (!isMainThread) {
293
- parentPort.on("message", async ({ pages, storeInfo, sourcemap }) => {
283
+ parentPort.on("message", async ({ pages, storeInfo }) => {
294
284
  try {
295
285
  resetStoreInfo(storeInfo);
296
- enableSourcemap = !!sourcemap;
297
286
  const progress = {
298
287
  _completedTasks: 0,
299
288
  get completedTasks() {
@@ -311,11 +300,7 @@ if (!isMainThread) {
311
300
  compileResCache.clear();
312
301
  wxsModuleRegistry.clear();
313
302
  wxsFilePathMap.clear();
314
- parentPort.postMessage({
315
- success: true,
316
- compatibilityWarnings: takeCompatibilityWarnings(),
317
- dependencyGraph: getDependencyGraph().toJSON()
318
- });
303
+ parentPort.postMessage({ success: true });
319
304
  } catch (error) {
320
305
  compileResCache.clear();
321
306
  wxsModuleRegistry.clear();
@@ -336,50 +321,34 @@ async function compileML(pages, root, progress) {
336
321
  initWxsFilePathMap(workPath);
337
322
  for (const page of pages) {
338
323
  const scriptRes = /* @__PURE__ */ new Map();
339
- const sourceMapRes = /* @__PURE__ */ new Map();
340
- buildCompileView(page, false, scriptRes, /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), sourceMapRes);
341
- const filename = `${page.path.replace(/\//g, "_")}`;
342
- const outputDir = root ? `${getTargetPath()}/${root}` : `${getTargetPath()}/main`;
343
- if (!fs_default.existsSync(outputDir)) {
344
- fs_default.mkdirSync(outputDir, { recursive: true });
324
+ buildCompileView(page, false, scriptRes, [], /* @__PURE__ */ new Set());
325
+ let mergeRender = "";
326
+ for (const [key, value] of scriptRes.entries()) {
327
+ const amdFormat = `modDefine('${key}', function(require, module, exports) {
328
+ ${value}
329
+ });`;
330
+ const { code: minifiedCode } = await transform(amdFormat, {
331
+ minify: true,
332
+ target: ["es2020"],
333
+ platform: "browser"
334
+ });
335
+ mergeRender += minifiedCode;
345
336
  }
346
- if (enableSourcemap) {
347
- const compileRes = [...scriptRes.entries()].map(([modulePath, code]) => ({
348
- path: modulePath,
349
- code,
350
- map: sourceMapRes.get(modulePath)
351
- }));
352
- const sourcemapFileName = `${filename}.js.map`;
353
- const { bundleCode, sourcemap } = mergeSourcemap(compileRes, `${filename}.js`);
354
- fs_default.writeFileSync(`${outputDir}/${filename}.js`, `${bundleCode}//# sourceMappingURL=${sourcemapFileName}
355
- `);
356
- fs_default.writeFileSync(`${outputDir}/${sourcemapFileName}`, sourcemap);
337
+ scriptRes.clear();
338
+ const filename = `${page.path.replace(/\//g, "_")}`;
339
+ if (root) {
340
+ const subDir = `${getTargetPath()}/${root}`;
341
+ if (!fs_default.existsSync(subDir)) {
342
+ fs_default.mkdirSync(subDir, { recursive: true });
343
+ }
344
+ fs_default.writeFileSync(`${subDir}/${filename}.js`, mergeRender);
357
345
  } else {
358
- let mergeRender = "";
359
- for (const [key, value] of scriptRes.entries()) {
360
- const amdFormat = `modDefine('${key}', function(require, module, exports) {
361
- ${value}
362
- });`;
363
- try {
364
- const { code: minifiedCode } = await transform(amdFormat, {
365
- minify: true,
366
- target: ["es2020"],
367
- platform: "browser"
368
- });
369
- mergeRender += minifiedCode;
370
- } catch (error) {
371
- const location = error.errors?.[0]?.location;
372
- const sourceLines = amdFormat.split("\n");
373
- const sourceHint = location?.line ? sourceLines.slice(Math.max(0, location.line - 3), location.line + 2).map((line, index) => `${Math.max(1, location.line - 2) + index}: ${line.trim()}`).join("\n") : "";
374
- error.message = `\u89C6\u56FE\u6A21\u5757 ${key} \u8F6C\u6362\u5931\u8D25: ${error.message}${sourceHint ? `
375
- ${sourceHint}` : ""}`;
376
- throw error;
377
- }
346
+ const mainDir = `${getTargetPath()}/main`;
347
+ if (!fs_default.existsSync(mainDir)) {
348
+ fs_default.mkdirSync(mainDir, { recursive: true });
378
349
  }
379
- fs_default.writeFileSync(`${outputDir}/${filename}.js`, mergeRender);
350
+ fs_default.writeFileSync(`${mainDir}/${filename}.js`, mergeRender);
380
351
  }
381
- scriptRes.clear();
382
- sourceMapRes.clear();
383
352
  progress.completedTasks++;
384
353
  }
385
354
  }
@@ -410,35 +379,23 @@ function scanWxsFiles(dir, workPath) {
410
379
  function registerWxsModule(modulePath) {
411
380
  wxsModuleRegistry.add(modulePath);
412
381
  }
413
- function getTemplateCompilerOptions(scopeId) {
414
- return {
415
- // https://template-explorer.vuejs.org/
416
- prefixIdentifiers: true,
417
- hoistStatic: false,
418
- cacheHandlers: true,
419
- scopeId,
420
- mode: "function",
421
- inline: true,
422
- // transTag has already rewritten registered built-ins and custom
423
- // components to the reserved dd-* namespace. Every remaining unknown WXML
424
- // tag follows glass-easel's unused-native-node fallback instead of Vue's
425
- // component resolution.
426
- isCustomElement: (tag) => !tag.startsWith("dd-")
427
- };
428
- }
429
382
  function isRegisteredWxsModule(modulePath) {
430
383
  return wxsModuleRegistry.has(modulePath);
431
384
  }
432
- function buildCompileView(module, isComponent = false, scriptRes, activePaths = /* @__PURE__ */ new Set(), inheritedTemplatePaths = /* @__PURE__ */ new Set(), sourceMapRes = /* @__PURE__ */ new Map()) {
385
+ function buildCompileView(module, isComponent = false, scriptRes, depthChain = [], inheritedTemplatePaths = /* @__PURE__ */ new Set()) {
433
386
  const currentPath = module.path;
434
- if (activePaths.has(currentPath)) {
387
+ if (depthChain.includes(currentPath)) {
388
+ console.warn("[view]", `\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
435
389
  return;
436
390
  }
437
- activePaths.add(currentPath);
391
+ if (depthChain.length > 20) {
392
+ console.warn("[view]", `\u68C0\u6D4B\u5230\u6DF1\u5EA6\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
393
+ return;
394
+ }
395
+ depthChain = [...depthChain, currentPath];
438
396
  const allScriptModules = [];
439
397
  const currentInstruction = compileModule(module, isComponent, scriptRes, {
440
- skipTemplatePaths: isComponent ? inheritedTemplatePaths : /* @__PURE__ */ new Set(),
441
- sourceMapRes
398
+ skipTemplatePaths: isComponent ? inheritedTemplatePaths : /* @__PURE__ */ new Set()
442
399
  });
443
400
  if (currentInstruction && currentInstruction.scriptModule) {
444
401
  allScriptModules.push(...currentInstruction.scriptModule);
@@ -448,17 +405,16 @@ function buildCompileView(module, isComponent = false, scriptRes, activePaths =
448
405
  childInheritedTemplatePaths.add(tm.path);
449
406
  }
450
407
  if (module.usingComponents) {
451
- const graphDependencies = getDependencyGraph().getDirectDependencies(module.path, "component");
452
- const componentDependencies = graphDependencies.length > 0 ? graphDependencies : Object.values(module.usingComponents);
453
- for (const componentInfo of componentDependencies) {
408
+ for (const componentInfo of Object.values(module.usingComponents)) {
454
409
  const componentModule = getComponent(componentInfo);
455
410
  if (!componentModule) {
456
411
  continue;
457
412
  }
458
413
  if (componentModule.path === module.path) {
414
+ console.warn("[view]", `\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56\uFF0C\u8DF3\u8FC7\u5904\u7406: ${module.path}`);
459
415
  continue;
460
416
  }
461
- const componentInstruction = buildCompileView(componentModule, true, scriptRes, activePaths, childInheritedTemplatePaths, sourceMapRes);
417
+ const componentInstruction = buildCompileView(componentModule, true, scriptRes, depthChain, childInheritedTemplatePaths);
462
418
  if (componentInstruction && componentInstruction.scriptModule) {
463
419
  for (const sm of componentInstruction.scriptModule) {
464
420
  if (!allScriptModules.find((existing) => existing.path === sm.path)) {
@@ -474,15 +430,13 @@ function buildCompileView(module, isComponent = false, scriptRes, activePaths =
474
430
  scriptRes.set(sm.path, sm.code);
475
431
  }
476
432
  }
477
- compileModuleWithAllWxs(module, scriptRes, allScriptModules, sourceMapRes);
433
+ compileModuleWithAllWxs(module, scriptRes, allScriptModules);
478
434
  }
479
- activePaths.delete(currentPath);
480
435
  return { scriptModule: allScriptModules, templateModule: currentInstruction?.templateModule || [] };
481
436
  }
482
437
  function compileModule(module, isComponent, scriptRes, options = {}) {
483
438
  const skipTemplatePaths = options.skipTemplatePaths || /* @__PURE__ */ new Set();
484
- const sourceMapRes = options.sourceMapRes || /* @__PURE__ */ new Map();
485
- const { tpl, instruction, sourceInfo } = toCompileTemplate(isComponent, module.path, module.usingComponents, module.componentPlaceholder);
439
+ const { tpl, instruction } = toCompileTemplate(isComponent, module.path, module.usingComponents, module.componentPlaceholder);
486
440
  if (!tpl) {
487
441
  return null;
488
442
  }
@@ -512,10 +466,6 @@ function compileModule(module, isComponent, scriptRes, options = {}) {
512
466
  }
513
467
  if (useCache && cachedCode) {
514
468
  scriptRes.set(module.path, cachedCode);
515
- const cachedMap = compileResCache.get(module.path)?.map;
516
- if (enableSourcemap && cachedMap) {
517
- sourceMapRes.set(module.path, cachedMap);
518
- }
519
469
  const allWxsModules2 = collectAllWxsModules(scriptRes, /* @__PURE__ */ new Set(), instruction.scriptModule || []);
520
470
  if (allWxsModules2.length > 0) {
521
471
  const existingModules = instruction.scriptModule || [];
@@ -539,41 +489,44 @@ function compileModule(module, isComponent, scriptRes, options = {}) {
539
489
  // 用于错误提示
540
490
  id: `data-v-${module.id}`,
541
491
  scoped: true,
542
- inMap: enableSourcemap ? createLineSourcemap(processedTpl, sourceInfo.path, sourceInfo.content) : void 0,
543
- compilerOptions: getTemplateCompilerOptions(`data-v-${module.id}`)
492
+ compilerOptions: {
493
+ // https://template-explorer.vuejs.org/
494
+ prefixIdentifiers: true,
495
+ hoistStatic: false,
496
+ cacheHandlers: true,
497
+ scopeId: `data-v-${module.id}`,
498
+ mode: "function",
499
+ inline: true
500
+ }
544
501
  });
545
- const templateResults = [];
502
+ let tplComponents = "{";
546
503
  for (const tm of compileInstruction.templateModule) {
547
- const compiledTemplate = compileTemplate({
504
+ let { code: code2 } = compileTemplate({
548
505
  source: tm.tpl,
549
506
  filename: tm.path,
550
507
  id: `data-v-${module.id}`,
551
508
  scoped: true,
552
- inMap: enableSourcemap && tm.sourceInfo ? createLineSourcemap(tm.tpl, tm.sourceInfo.path, tm.sourceInfo.content, tm.sourceInfo.startLine) : void 0,
553
- compilerOptions: getTemplateCompilerOptions(`data-v-${module.id}`)
554
- });
555
- templateResults.push({
556
- path: tm.path,
557
- ...insertWxsToRenderResult(compiledTemplate.code, compileInstruction.scriptModule, scriptRes, tm.path, compiledTemplate.map)
509
+ compilerOptions: {
510
+ prefixIdentifiers: true,
511
+ hoistStatic: false,
512
+ cacheHandlers: true,
513
+ scopeId: `data-v-${module.id}`,
514
+ mode: "function",
515
+ inline: true
516
+ }
558
517
  });
518
+ code2 = insertWxsToRenderCode(code2, compileInstruction.scriptModule, scriptRes, tm.path);
519
+ tplComponents += `'${tm.path}':${code2},`;
559
520
  }
560
- const renderResult = insertWxsToRenderResult(tplCode.code, compileInstruction.scriptModule, scriptRes, module.path, tplCode.map);
561
- const moduleChunks = [`Module({
521
+ tplComponents += "}";
522
+ const transCode = insertWxsToRenderCode(tplCode.code, compileInstruction.scriptModule, scriptRes, module.path);
523
+ const code = `Module({
562
524
  path: '${module.path}',
563
525
  id: '${module.id}',
564
- appStyleScopeId: ${JSON.stringify(module.appStyleScopeId || null)},
565
- sharedStyleScopeIds: ${JSON.stringify(module.sharedStyleScopeIds || [])},
566
- styleIsolation: ${JSON.stringify(module.styleIsolation || "isolated")},
567
- render: `, renderResult, `,
526
+ render: ${transCode},
568
527
  usingComponents: ${JSON.stringify(module.usingComponents)},
569
- componentPlaceholder: ${JSON.stringify(module.componentPlaceholder || {})},
570
- customTabBar: ${JSON.stringify(module.customTabBar || null)},
571
- tplComponents: {`];
572
- for (const templateResult of templateResults) {
573
- moduleChunks.push(`'${templateResult.path}':`, templateResult, ",");
574
- }
575
- moduleChunks.push("},\n });");
576
- const { code, sourcemap: moduleMap } = concatSourcemap(moduleChunks, module.path);
528
+ tplComponents: ${tplComponents},
529
+ });`;
577
530
  const allWxsModules = collectAllWxsModules(scriptRes, /* @__PURE__ */ new Set(), compileInstruction.scriptModule || []);
578
531
  if (allWxsModules.length > 0) {
579
532
  const existingModules = compileInstruction.scriptModule || [];
@@ -587,25 +540,18 @@ function compileModule(module, isComponent, scriptRes, options = {}) {
587
540
  }
588
541
  const cacheData = {
589
542
  code,
590
- instruction: compileInstruction,
591
- map: enableSourcemap ? moduleMap : null
543
+ instruction: compileInstruction
592
544
  };
593
545
  if (canUseCache) {
594
546
  compileResCache.set(module.path, cacheData);
595
547
  }
596
548
  scriptRes.set(module.path, code);
597
- if (enableSourcemap) {
598
- sourceMapRes.set(module.path, moduleMap);
599
- }
600
549
  return {
601
550
  ...compileInstruction,
602
551
  templateModule
603
552
  };
604
553
  }
605
- function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, filePath, graphOwnerPath = filePath) {
606
- if (wxsFilePath && graphOwnerPath) {
607
- getDependencyGraph().addFile(graphOwnerPath, wxsFilePath, "view");
608
- }
554
+ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, filePath) {
609
555
  let wxsAst;
610
556
  try {
611
557
  wxsAst = parseJs(wxsContent, wxsFilePath || "inline.wxs", "script");
@@ -654,7 +600,7 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
654
600
  resolvedWxsPath = path.resolve(currentWxsDir, requirePath);
655
601
  const relativePath = stripViewScriptExt(resolvedWxsPath.replace(workPath, ""));
656
602
  const moduleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
657
- processWxsDependency(resolvedWxsPath, moduleName, scriptModule, workPath, filePath, graphOwnerPath);
603
+ processWxsDependency(resolvedWxsPath, moduleName, scriptModule, workPath, filePath);
658
604
  replacements.push({
659
605
  start: node.arguments[0].start,
660
606
  end: node.arguments[0].end,
@@ -665,7 +611,7 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
665
611
  resolvedWxsPath = path.resolve(currentWxsDir, requirePath);
666
612
  const relativePath = stripViewScriptExt(resolvedWxsPath.replace(workPath, ""));
667
613
  const depModuleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
668
- processWxsDependency(resolvedWxsPath, depModuleName, scriptModule, workPath, filePath, graphOwnerPath);
614
+ processWxsDependency(resolvedWxsPath, depModuleName, scriptModule, workPath, filePath);
669
615
  replacements.push({
670
616
  start: node.arguments[0].start,
671
617
  end: node.arguments[0].end,
@@ -698,7 +644,7 @@ function isWxsModuleByContent(moduleCode, modulePath = "") {
698
644
  }
699
645
  return false;
700
646
  }
701
- function processWxsDependency(wxsFilePath, moduleName, scriptModule, workPath, filePath, graphOwnerPath = filePath) {
647
+ function processWxsDependency(wxsFilePath, moduleName, scriptModule, workPath, filePath) {
702
648
  if (!fs_default.existsSync(wxsFilePath)) {
703
649
  console.warn(`[view] wxs \u4F9D\u8D56\u6587\u4EF6\u4E0D\u5B58\u5728: ${wxsFilePath}`);
704
650
  return;
@@ -710,15 +656,15 @@ function processWxsDependency(wxsFilePath, moduleName, scriptModule, workPath, f
710
656
  if (!wxsContent) {
711
657
  return;
712
658
  }
713
- const wxsCode = processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, filePath, graphOwnerPath);
659
+ const wxsCode = processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, filePath);
714
660
  registerWxsModule(moduleName);
715
661
  scriptModule.push({
716
662
  path: moduleName,
717
663
  code: wxsCode
718
664
  });
719
665
  }
720
- function compileModuleWithAllWxs(module, scriptRes, allScriptModules, sourceMapRes = /* @__PURE__ */ new Map()) {
721
- const { tpl, instruction, sourceInfo } = toCompileTemplate(false, module.path, module.usingComponents, module.componentPlaceholder);
666
+ function compileModuleWithAllWxs(module, scriptRes, allScriptModules) {
667
+ const { tpl, instruction } = toCompileTemplate(false, module.path, module.usingComponents, module.componentPlaceholder);
722
668
  if (!tpl) {
723
669
  return;
724
670
  }
@@ -732,58 +678,56 @@ function compileModuleWithAllWxs(module, scriptRes, allScriptModules, sourceMapR
732
678
  filename: module.path,
733
679
  id: `data-v-${module.id}`,
734
680
  scoped: true,
735
- inMap: enableSourcemap ? createLineSourcemap(processedTpl, sourceInfo.path, sourceInfo.content) : void 0,
736
- compilerOptions: getTemplateCompilerOptions(`data-v-${module.id}`)
681
+ compilerOptions: {
682
+ prefixIdentifiers: true,
683
+ hoistStatic: false,
684
+ cacheHandlers: true,
685
+ scopeId: `data-v-${module.id}`,
686
+ mode: "function",
687
+ inline: true
688
+ }
737
689
  });
738
- const templateResults = [];
690
+ let tplComponents = "{";
739
691
  for (const tm of mergedInstruction.templateModule) {
740
- const compiledTemplate = compileTemplate({
692
+ let { code: code2 } = compileTemplate({
741
693
  source: tm.tpl,
742
694
  filename: tm.path,
743
695
  id: `data-v-${module.id}`,
744
696
  scoped: true,
745
- inMap: enableSourcemap && tm.sourceInfo ? createLineSourcemap(tm.tpl, tm.sourceInfo.path, tm.sourceInfo.content, tm.sourceInfo.startLine) : void 0,
746
- compilerOptions: getTemplateCompilerOptions(`data-v-${module.id}`)
747
- });
748
- templateResults.push({
749
- path: tm.path,
750
- ...insertWxsToRenderResult(compiledTemplate.code, allScriptModules, scriptRes, tm.path, compiledTemplate.map)
697
+ compilerOptions: {
698
+ prefixIdentifiers: true,
699
+ hoistStatic: false,
700
+ cacheHandlers: true,
701
+ scopeId: `data-v-${module.id}`,
702
+ mode: "function",
703
+ inline: true
704
+ }
751
705
  });
706
+ code2 = insertWxsToRenderCode(code2, allScriptModules, scriptRes, tm.path);
707
+ tplComponents += `'${tm.path}':${code2},`;
752
708
  }
753
- const renderResult = insertWxsToRenderResult(tplCode.code, allScriptModules, scriptRes, module.path, tplCode.map);
754
- const moduleChunks = [`Module({
709
+ tplComponents += "}";
710
+ const transCode = insertWxsToRenderCode(tplCode.code, allScriptModules, scriptRes, module.path);
711
+ const code = `Module({
755
712
  path: '${module.path}',
756
713
  id: '${module.id}',
757
- appStyleScopeId: ${JSON.stringify(module.appStyleScopeId || null)},
758
- sharedStyleScopeIds: ${JSON.stringify(module.sharedStyleScopeIds || [])},
759
- styleIsolation: ${JSON.stringify(module.styleIsolation || "isolated")},
760
- render: `, renderResult, `,
714
+ render: ${transCode},
761
715
  usingComponents: ${JSON.stringify(module.usingComponents)},
762
- componentPlaceholder: ${JSON.stringify(module.componentPlaceholder || {})},
763
- customTabBar: ${JSON.stringify(module.customTabBar || null)},
764
- tplComponents: {`];
765
- for (const templateResult of templateResults) {
766
- moduleChunks.push(`'${templateResult.path}':`, templateResult, ",");
767
- }
768
- moduleChunks.push("},\n });");
769
- const { code, sourcemap: moduleMap } = concatSourcemap(moduleChunks, module.path);
716
+ tplComponents: ${tplComponents},
717
+ });`;
770
718
  const cacheData = {
771
719
  code,
772
- instruction: mergedInstruction,
773
- map: enableSourcemap ? moduleMap : null
720
+ instruction: mergedInstruction
774
721
  };
775
722
  compileResCache.set(module.path, cacheData);
776
723
  scriptRes.set(module.path, code);
777
- if (enableSourcemap) {
778
- sourceMapRes.set(module.path, moduleMap);
779
- }
780
724
  }
781
725
  function processIncludeConditionalAttrs($, elem, includeContent) {
782
726
  const allAttrs = $(elem).attr();
783
727
  const conditionAttrs = {};
784
728
  let hasCondition = false;
785
729
  for (const attrName in allAttrs) {
786
- if (["if", "elif", "else"].includes(getTemplateDirectiveName(attrName))) {
730
+ if (attrName.endsWith(":if") || attrName.endsWith(":elif") || attrName.endsWith(":else")) {
787
731
  conditionAttrs[attrName] = allAttrs[attrName];
788
732
  hasCondition = true;
789
733
  }
@@ -847,17 +791,14 @@ function toCompileTemplate(isComponent, path2, components, componentPlaceholder,
847
791
  if (!fullPath) {
848
792
  return { tpl: void 0 };
849
793
  }
850
- getDependencyGraph().addFile(path2, fullPath, "view");
851
- const sourcePath = toMiniProgramModuleId(fullPath, workPath).replace(buildExtStripRegex(getTemplateExts()), "");
852
794
  const diagnosticSource = fullPath.startsWith(workPath) ? fullPath.slice(workPath.length) : path2;
853
- const originalContent = getContentByPath(fullPath);
854
- let content = originalContent;
855
- if (!content.trim()) {
795
+ let content = getContentByPath(fullPath).trim();
796
+ if (!content) {
856
797
  content = "<block></block>";
857
798
  } else {
858
799
  checkTemplateCompatibility(content, diagnosticSource, components);
859
800
  if (isComponent) {
860
- content = `<component-host name="${path2}">${content}</component-host>`;
801
+ content = `<wrapper name="${path2}">${content}</wrapper>`;
861
802
  } else {
862
803
  const tempRoot = cheerio.load(content, {
863
804
  xmlMode: true,
@@ -877,45 +818,36 @@ function toCompileTemplate(isComponent, path2, components, componentPlaceholder,
877
818
  _useHtmlParser2: true,
878
819
  // 减少内存占用的配置
879
820
  lowerCaseTags: false,
880
- lowerCaseAttributeNames: false,
881
- withStartIndices: true,
882
- withEndIndices: true
821
+ lowerCaseAttributeNames: false
883
822
  });
884
823
  const includeNodes = $("include");
885
824
  includeNodes.each((_, elem) => {
886
825
  const src = $(elem).attr("src");
887
826
  if (src) {
888
- const includeFullPath = resolveTemplateDependencyPath(workPath, sourcePath, src);
889
- getDependencyGraph().addFile(path2, includeFullPath, "view");
827
+ const includeFullPath = getAbsolutePath(workPath, path2, src);
890
828
  let includePath = includeFullPath.replace(workPath, "").replace(buildExtStripRegex(getTemplateExts()), "");
891
829
  const includeDiagnosticSource = includeFullPath.startsWith(workPath) ? includeFullPath.slice(workPath.length) : includePath;
892
830
  if (!includePath.startsWith("/")) {
893
831
  includePath = "/" + includePath;
894
832
  }
895
- const includeContent = getContentByPath(includeFullPath);
896
- if (includeContent.trim()) {
833
+ const includeContent = getContentByPath(includeFullPath).trim();
834
+ if (includeContent) {
897
835
  checkTemplateCompatibility(includeContent, includeDiagnosticSource, components);
898
836
  const $includeContent = cheerio.load(includeContent, {
899
837
  xmlMode: true,
900
- decodeEntities: false,
901
- _useHtmlParser2: true,
902
- withStartIndices: true,
903
- withEndIndices: true
838
+ decodeEntities: false
904
839
  });
905
840
  transTagTemplate(
906
841
  $includeContent,
907
842
  templateModule,
908
843
  includePath,
909
844
  components,
910
- componentPlaceholder,
911
- { path: includeDiagnosticSource, content: includeContent },
912
- path2
845
+ componentPlaceholder
913
846
  );
914
847
  transTagWxs(
915
848
  $includeContent,
916
849
  scriptModule,
917
- includePath,
918
- path2
850
+ includePath
919
851
  );
920
852
  processIncludedFileWxsDependencies(includeContent, includePath, scriptModule, components, processedPaths);
921
853
  $includeContent("template").remove();
@@ -929,73 +861,54 @@ function toCompileTemplate(isComponent, path2, components, componentPlaceholder,
929
861
  $(elem).remove();
930
862
  }
931
863
  });
932
- transTagTemplate(
933
- $,
934
- templateModule,
935
- sourcePath,
936
- components,
937
- componentPlaceholder,
938
- { path: diagnosticSource, content: originalContent },
939
- path2
940
- );
941
- transTagWxs($, scriptModule, sourcePath, path2);
864
+ transTagTemplate($, templateModule, path2, components, componentPlaceholder);
865
+ transTagWxs($, scriptModule, path2);
942
866
  const importNodes = $("import");
943
867
  importNodes.each((_, elem) => {
944
868
  const src = $(elem).attr("src");
945
869
  if (src) {
946
- const importFullPath = resolveTemplateDependencyPath(workPath, sourcePath, src);
947
- getDependencyGraph().addFile(path2, importFullPath, "view");
870
+ const importFullPath = getAbsolutePath(workPath, path2, src);
948
871
  let importPath = importFullPath.replace(workPath, "").replace(buildExtStripRegex(getTemplateExts()), "");
949
872
  const importDiagnosticSource = importFullPath.startsWith(workPath) ? importFullPath.slice(workPath.length) : importPath;
950
873
  if (!importPath.startsWith("/")) {
951
874
  importPath = "/" + importPath;
952
875
  }
953
- const importContent = getContentByPath(importFullPath);
954
- if (importContent.trim()) {
876
+ const importContent = getContentByPath(importFullPath).trim();
877
+ if (importContent) {
955
878
  checkTemplateCompatibility(importContent, importDiagnosticSource, components);
956
879
  const $$ = cheerio.load(importContent, {
957
880
  xmlMode: true,
958
- decodeEntities: false,
959
- _useHtmlParser2: true,
960
- withStartIndices: true,
961
- withEndIndices: true
881
+ decodeEntities: false
962
882
  });
963
883
  transTagTemplate(
964
884
  $$,
965
885
  templateModule,
966
- importPath,
886
+ path2,
967
887
  components,
968
- componentPlaceholder,
969
- { path: importDiagnosticSource, content: importContent },
970
- path2
888
+ componentPlaceholder
971
889
  );
972
890
  transTagWxs(
973
891
  $$,
974
892
  scriptModule,
975
- importPath,
976
- path2
893
+ importPath
977
894
  );
978
895
  processIncludedFileWxsDependencies(importContent, importPath, scriptModule, components, processedPaths);
979
896
  }
980
897
  }
981
898
  });
982
899
  importNodes.remove();
983
- transAsses($, $("image"), sourcePath, path2);
900
+ transAsses($, $("image"), path2);
984
901
  const res = [];
985
902
  transHtmlTag($.html(), res, components, componentPlaceholder);
986
903
  return {
987
904
  tpl: res.join(""),
988
- sourceInfo: {
989
- path: diagnosticSource,
990
- content: originalContent
991
- },
992
905
  instruction: {
993
906
  templateModule,
994
907
  scriptModule
995
908
  }
996
909
  };
997
910
  }
998
- function transTagTemplate($, templateModule, path2, components, componentPlaceholder, sourceInfo, graphOwnerPath = path2) {
911
+ function transTagTemplate($, templateModule, path2, components, componentPlaceholder) {
999
912
  const templateNodes = $("template[name]");
1000
913
  templateNodes.each((_, elem) => {
1001
914
  const name = $(elem).attr("name");
@@ -1003,109 +916,24 @@ function transTagTemplate($, templateModule, path2, components, componentPlaceho
1003
916
  templateContent.find("import").remove();
1004
917
  templateContent.find("include").remove();
1005
918
  templateContent.find(getViewScriptTags().join(",")).remove();
1006
- transAsses($, templateContent.find("image"), path2, graphOwnerPath);
919
+ transAsses($, templateContent.find("image"), path2);
1007
920
  const res = [];
1008
921
  transHtmlTag(templateContent.html(), res, components, componentPlaceholder);
1009
922
  templateModule.push({
1010
923
  path: `tpl-${name}`,
1011
- tpl: res.join(""),
1012
- sourceInfo: sourceInfo ? {
1013
- ...sourceInfo,
1014
- startLine: getSourceLine(sourceInfo.content, elem.children?.[0]?.startIndex ?? elem.startIndex)
1015
- } : null
924
+ tpl: res.join("")
1016
925
  });
1017
926
  });
1018
927
  templateNodes.remove();
1019
928
  }
1020
- function getSourceLine(source, index = 0) {
1021
- return source.slice(0, Math.max(0, index)).split("\n").length;
1022
- }
1023
- function transAsses($, imageNodes, path2, graphOwnerPath = path2) {
929
+ function transAsses($, imageNodes, path2) {
1024
930
  imageNodes.each((_, elem) => {
1025
931
  const imgSrc = $(elem).attr("src").trim();
1026
932
  if (!imgSrc.startsWith("{{")) {
1027
- if (!imgSrc.startsWith("http") && !imgSrc.startsWith("//") && /\.(?:png|jpe?g|gif|svg)(?:\?.*)?$/.test(imgSrc)) {
1028
- getDependencyGraph().addFile(
1029
- graphOwnerPath,
1030
- resolveAssetSourcePath(getWorkPath(), path2, imgSrc),
1031
- "view"
1032
- );
1033
- }
1034
933
  $(elem).attr("src", collectAssets(getWorkPath(), path2, imgSrc, getTargetPath(), getAppId()));
1035
934
  }
1036
935
  });
1037
936
  }
1038
- var DIMINA_SLOT_GROUP_TAG = "dimina-slot-group";
1039
- var DIMINA_FOR_SCOPE_TAG = "dimina-for-scope";
1040
- function getDirectiveAttributeNames(attrs, suffixes) {
1041
- const directiveNames = new Set(suffixes.map((suffix) => suffix.replace(/^:/, "")));
1042
- return Object.keys(attrs || {}).filter((name) => directiveNames.has(getTemplateDirectiveName(name)));
1043
- }
1044
- function hasForAndIf(attrs) {
1045
- return getDirectiveAttributeNames(attrs, [":for", ":for-items"]).length > 0 && getDirectiveAttributeNames(attrs, [":if"]).length > 0;
1046
- }
1047
- function groupDuplicateNamedSlots($, components) {
1048
- const slotHosts = $("*").toArray().filter((element) => {
1049
- const tag = element.tagName;
1050
- return tag === "component" || Boolean(components?.[tag]);
1051
- });
1052
- for (const host of slotHosts) {
1053
- const groups = /* @__PURE__ */ new Map();
1054
- for (const child of $(host).children().toArray()) {
1055
- const slotName = child.attribs?.slot;
1056
- if (!slotName) continue;
1057
- const group = groups.get(slotName) || [];
1058
- group.push(child);
1059
- groups.set(slotName, group);
1060
- }
1061
- for (const [slotName, nodes] of groups) {
1062
- if (nodes.length === 1 && !hasForAndIf(nodes[0].attribs)) {
1063
- continue;
1064
- }
1065
- const wrapper = $(`<${DIMINA_SLOT_GROUP_TAG}></${DIMINA_SLOT_GROUP_TAG}>`);
1066
- wrapper.attr("name", slotName);
1067
- $(nodes[0]).before(wrapper);
1068
- for (const node of nodes) {
1069
- $(node).removeAttr("slot");
1070
- wrapper.append(node);
1071
- }
1072
- }
1073
- }
1074
- }
1075
- function wrapForIfScopes($) {
1076
- const nodes = $("*").toArray();
1077
- for (const node of nodes) {
1078
- if (node.tagName === DIMINA_FOR_SCOPE_TAG || !hasForAndIf(node.attribs)) {
1079
- continue;
1080
- }
1081
- const attrsToMove = getDirectiveAttributeNames(node.attribs, [
1082
- ":for",
1083
- ":for-items",
1084
- ":for-item",
1085
- ":for-index",
1086
- ":key"
1087
- ]);
1088
- const wrapper = $(`<${DIMINA_FOR_SCOPE_TAG}></${DIMINA_FOR_SCOPE_TAG}>`);
1089
- for (const name of attrsToMove) {
1090
- wrapper.attr(name, node.attribs[name]);
1091
- $(node).removeAttr(name);
1092
- }
1093
- $(node).before(wrapper);
1094
- wrapper.append(node);
1095
- }
1096
- }
1097
- function normalizeTemplateSyntax(html, components) {
1098
- const $ = cheerio.load(html, {
1099
- xmlMode: true,
1100
- decodeEntities: false,
1101
- _useHtmlParser2: true,
1102
- lowerCaseTags: false,
1103
- lowerCaseAttributeNames: false
1104
- });
1105
- groupDuplicateNamedSlots($, components);
1106
- wrapForIfScopes($);
1107
- return $.html();
1108
- }
1109
937
  function transHtmlTag(html, res, components, componentPlaceholder) {
1110
938
  const attrsList = [];
1111
939
  const parser = new htmlparser2.Parser(
@@ -1126,29 +954,22 @@ function transHtmlTag(html, res, components, componentPlaceholder) {
1126
954
  },
1127
955
  { xmlMode: true }
1128
956
  );
1129
- parser.write(normalizeTemplateSyntax(html, components));
957
+ parser.write(html);
1130
958
  parser.end();
1131
959
  }
1132
960
  function transTag(opts) {
1133
961
  const { isStart, tag, attrs, components } = opts;
1134
962
  let res;
1135
- if (tag === DIMINA_SLOT_GROUP_TAG) {
1136
- if (isStart) {
1137
- return `<template ${generateSlotDirective(attrs.name)}>`;
1138
- }
1139
- return "</template>";
1140
- } else if (tag === DIMINA_FOR_SCOPE_TAG) {
1141
- res = "template";
1142
- } else if (tag === "slot") {
963
+ if (tag === "slot") {
1143
964
  res = tag;
1144
965
  } else if (components && components[tag]) {
1145
966
  res = `dd-${tag}`;
1146
967
  } else if (tag === "component" || tag === "canvas") {
1147
968
  res = tag;
1148
- } else if (tagWhiteList.includes(tag)) {
1149
- res = `dd-${tag}`;
969
+ } else if (!tagWhiteList.includes(tag)) {
970
+ res = "dd-text";
1150
971
  } else {
1151
- res = tag;
972
+ res = `dd-${tag}`;
1152
973
  }
1153
974
  let tagRes;
1154
975
  const propsAry = isStart ? getProps(attrs, tag, components) : [];
@@ -1201,65 +1022,40 @@ function generateSlotDirective(slotValue) {
1201
1022
  }
1202
1023
  function getProps(attrs, tag, components) {
1203
1024
  const attrsList = [];
1204
- const isCustomComponent = Boolean(components && components[tag]);
1205
1025
  const propBindings = {};
1206
- const hasEventBindings = Object.keys(attrs).some((name) => /^(?:capture-)?(?:bind|catch)(?::)?.+/.test(name));
1207
- if (tag === "page-meta") {
1208
- attrsList.push({
1209
- name: "dimina-rpx-unit",
1210
- value: "vw"
1211
- });
1212
- }
1213
- if (hasEventBindings) {
1214
- attrsList.push({
1215
- name: "v-c-event-node",
1216
- value: components && components[tag] ? "'component'" : "'node'"
1217
- });
1218
- }
1219
1026
  Object.entries(attrs).forEach(([name, value]) => {
1220
- const templateDirective = getTemplateDirectiveName(name);
1221
- if (templateDirective === "if") {
1027
+ if (name.endsWith(":if")) {
1222
1028
  attrsList.push({
1223
1029
  name: "v-if",
1224
1030
  value: parseSafeBraceExp(value)
1225
1031
  });
1226
- } else if (templateDirective === "elif") {
1032
+ } else if (name.endsWith(":elif")) {
1227
1033
  attrsList.push({
1228
1034
  name: "v-else-if",
1229
1035
  value: parseSafeBraceExp(value)
1230
1036
  });
1231
- } else if (templateDirective === "else") {
1037
+ } else if (name.endsWith(":else")) {
1232
1038
  attrsList.push({
1233
1039
  name: "v-else",
1234
1040
  value: ""
1235
1041
  });
1236
- } else if (templateDirective === "for" || templateDirective === "for-items") {
1042
+ } else if (name.endsWith(":for") || name.endsWith(":for-items")) {
1237
1043
  attrsList.push({
1238
1044
  name: "v-for",
1239
1045
  value: parseForExp(value, attrs)
1240
1046
  });
1241
- } else if (templateDirective === "for-item" || templateDirective === "for-index") {
1242
- } else if (templateDirective === "key") {
1047
+ } else if (name.endsWith(":for-item") || name.endsWith(":for-index")) {
1048
+ } else if (name.endsWith(":key")) {
1243
1049
  const tranValue = parseKeyExpression(value, getForItemName(attrs), getForIndexName(attrs));
1244
1050
  attrsList.push({
1245
1051
  name: ":key",
1246
1052
  value: tranValue
1247
1053
  });
1248
1054
  } else if (name === "style") {
1249
- const parsedStyle = parseSafeBraceExp(value);
1250
1055
  attrsList.push({
1251
1056
  name: "v-c-style",
1252
- value: transformRpx(parsedStyle)
1057
+ value: transformRpx(parseSafeBraceExp(value))
1253
1058
  });
1254
- if (isCustomComponent) {
1255
- attrsList.push({
1256
- name: ":dimina-wxml-style",
1257
- value: parsedStyle
1258
- });
1259
- if (isWrappedByBraces(value) && parsedStyle) {
1260
- propBindings.style = parsedStyle;
1261
- }
1262
- }
1263
1059
  } else if (name === "class") {
1264
1060
  if (isWrappedByBraces(value)) {
1265
1061
  attrsList.push({
@@ -1322,7 +1118,7 @@ function getProps(attrs, tag, components) {
1322
1118
  }
1323
1119
  } else if (isWrappedByBraces(value)) {
1324
1120
  const pVal = tag === "template" && name === "data" ? parseTemplateDataExp(value) : parseSafeBraceExp(value);
1325
- if (isCustomComponent) {
1121
+ if (components && components[tag]) {
1326
1122
  if (pVal && typeof pVal === "string") {
1327
1123
  propBindings[name] = pVal;
1328
1124
  }
@@ -1349,7 +1145,7 @@ function getProps(attrs, tag, components) {
1349
1145
  propsRes.push(`${name}="${escapeQuotes(value)}"`);
1350
1146
  }
1351
1147
  });
1352
- if (isCustomComponent && Object.keys(propBindings).length > 0) {
1148
+ if (components && components[tag] && Object.keys(propBindings).length > 0) {
1353
1149
  try {
1354
1150
  const validBindings = {};
1355
1151
  for (const [key, value] of Object.entries(propBindings)) {
@@ -1437,22 +1233,6 @@ function getViewPath(workPath, src) {
1437
1233
  }
1438
1234
  }
1439
1235
  }
1440
- function resolveTemplateDependencyPath(workPath, ownerPath, src) {
1441
- const resolvedPath = getAbsolutePath(workPath, ownerPath, src);
1442
- if (fs_default.existsSync(resolvedPath) && fs_default.statSync(resolvedPath).isFile()) {
1443
- return resolvedPath;
1444
- }
1445
- if (path.extname(resolvedPath)) {
1446
- return resolvedPath;
1447
- }
1448
- for (const ext of getTemplateExts()) {
1449
- const candidate = `${resolvedPath}${ext}`;
1450
- if (fs_default.existsSync(candidate) && fs_default.statSync(candidate).isFile()) {
1451
- return candidate;
1452
- }
1453
- }
1454
- return resolvedPath;
1455
- }
1456
1236
  function escapeQuotes(input) {
1457
1237
  return input.replace(/"/g, "'");
1458
1238
  }
@@ -1490,7 +1270,7 @@ function splitWithBraces(str) {
1490
1270
  function parseClassRules(cssRule) {
1491
1271
  let list = splitWithBraces(cssRule);
1492
1272
  list = list.map((item) => {
1493
- return parseSafeBraceExp(item);
1273
+ return parseBraceExp(item);
1494
1274
  });
1495
1275
  if (list.length === 1) {
1496
1276
  return list.pop();
@@ -1499,7 +1279,7 @@ function parseClassRules(cssRule) {
1499
1279
  }
1500
1280
  function getForItemName(attrs) {
1501
1281
  for (const key in attrs) {
1502
- if (getTemplateDirectiveName(key) === "for-item") {
1282
+ if (key.endsWith(":for-item")) {
1503
1283
  return attrs[key];
1504
1284
  }
1505
1285
  }
@@ -1507,7 +1287,7 @@ function getForItemName(attrs) {
1507
1287
  }
1508
1288
  function getForIndexName(attrs) {
1509
1289
  for (const key in attrs) {
1510
- if (getTemplateDirectiveName(key) === "for-index") {
1290
+ if (key.endsWith(":for-index")) {
1511
1291
  return attrs[key];
1512
1292
  }
1513
1293
  }
@@ -1516,21 +1296,12 @@ function getForIndexName(attrs) {
1516
1296
  function parseForExp(exp, attrs) {
1517
1297
  const item = getForItemName(attrs);
1518
1298
  const index = getForIndexName(attrs);
1519
- const listVariableName = parseSafeBraceExp(exp);
1299
+ const listVariableName = parseBraceExp(exp);
1520
1300
  return `(${item}, ${index}) in ${listVariableName}`;
1521
1301
  }
1522
1302
  var braceRegex = /(\{\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}\})|([^{}]+)/g;
1523
1303
  var noBraceRegex = /\{\{((?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*)\}\}/;
1524
1304
  var ternaryRegex = /[^?]+\?.+:.+/;
1525
- var RESERVED_TEMPLATE_CONTEXT_ALIASES = /* @__PURE__ */ new Map([
1526
- ["class", "__dimina_reserved_class"]
1527
- ]);
1528
- var RESERVED_TEMPLATE_CONTEXT_NAMES = new Map(
1529
- [...RESERVED_TEMPLATE_CONTEXT_ALIASES].map(([name, alias]) => [alias, name])
1530
- );
1531
- function encodeReservedTemplateContextIdentifier(expression) {
1532
- return RESERVED_TEMPLATE_CONTEXT_ALIASES.get(expression) || expression;
1533
- }
1534
1305
  function parseBraceExp(exp) {
1535
1306
  let result;
1536
1307
  const group = [];
@@ -1538,7 +1309,7 @@ function parseBraceExp(exp) {
1538
1309
  if (result[1]) {
1539
1310
  const matchResult = result[1].match(noBraceRegex);
1540
1311
  if (matchResult) {
1541
- const statement = encodeReservedTemplateContextIdentifier(matchResult[1].trim());
1312
+ const statement = matchResult[1].trim();
1542
1313
  if (ternaryRegex.test(statement)) {
1543
1314
  group.push(`(${statement})`);
1544
1315
  } else {
@@ -1555,11 +1326,11 @@ function parseBraceExp(exp) {
1555
1326
  function parseTemplateDataExp(exp) {
1556
1327
  const matchResult = exp.trim().match(/^\{\{([\s\S]*)\}\}$/);
1557
1328
  if (matchResult) {
1558
- return addOptionalChaining(`{${matchResult[1].trim()}}`);
1329
+ return `{${matchResult[1].trim()}}`;
1559
1330
  }
1560
- return `{${parseSafeBraceExp(exp)}}`;
1331
+ return `{${parseBraceExp(exp)}}`;
1561
1332
  }
1562
- function transTagWxs($, scriptModule, filePath, graphOwnerPath = filePath) {
1333
+ function transTagWxs($, scriptModule, filePath) {
1563
1334
  const wxsNodes = $(getViewScriptTags().join(","));
1564
1335
  wxsNodes.each((_, elem) => {
1565
1336
  const smName = $(elem).attr("module");
@@ -1579,7 +1350,6 @@ function transTagWxs($, scriptModule, filePath, graphOwnerPath = filePath) {
1579
1350
  wxsFilePath = getAbsolutePath(workPath, filePath, src);
1580
1351
  }
1581
1352
  if (wxsFilePath) {
1582
- getDependencyGraph().addFile(graphOwnerPath, wxsFilePath, "view");
1583
1353
  const relativePath = stripViewScriptExt(wxsFilePath.replace(workPath, ""));
1584
1354
  uniqueModuleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
1585
1355
  cacheKey = wxsFilePath;
@@ -1601,7 +1371,7 @@ function transTagWxs($, scriptModule, filePath, graphOwnerPath = filePath) {
1601
1371
  if (!wxsContent) {
1602
1372
  return;
1603
1373
  }
1604
- wxsContent = processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, filePath, graphOwnerPath);
1374
+ wxsContent = processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, filePath);
1605
1375
  compileResCache.set(cacheKey, wxsContent);
1606
1376
  }
1607
1377
  if (wxsContent) {
@@ -1685,7 +1455,7 @@ function extractWxsDependencies(moduleCode) {
1685
1455
  }
1686
1456
  return dependencies;
1687
1457
  }
1688
- function insertWxsToRenderResult(code, scriptModule, scriptRes, filename = "render.js", inputMap = null) {
1458
+ function insertWxsToRenderCode(code, scriptModule, scriptRes, filename = "render.js") {
1689
1459
  const wxsBindings = [];
1690
1460
  const codeReplacements = [];
1691
1461
  const ast = parseJs(code, filename);
@@ -1706,7 +1476,10 @@ function insertWxsToRenderResult(code, scriptModule, scriptRes, filename = "rend
1706
1476
  });
1707
1477
  declarations.push(`const ${localIdentifier} = require(${JSON.stringify(requireModuleName)});`);
1708
1478
  }
1709
- if (wxsBindings.length > 0 && renderBody?.type === "BlockStatement") {
1479
+ if (wxsBindings.length === 0) {
1480
+ return getProgramCode(code, ast);
1481
+ }
1482
+ if (renderBody?.type === "BlockStatement") {
1710
1483
  codeReplacements.push({
1711
1484
  type: "insert",
1712
1485
  start: renderBody.start + 1,
@@ -1718,15 +1491,6 @@ ${declarations.join("\n")}`
1718
1491
  walk(ast, {
1719
1492
  enter(node) {
1720
1493
  if (node.type === "MemberExpression" && node.object?.type === "Identifier" && node.object.name === "_ctx" && !node.computed && node.property?.type === "Identifier") {
1721
- const reservedName = RESERVED_TEMPLATE_CONTEXT_NAMES.get(node.property.name);
1722
- if (reservedName) {
1723
- codeReplacements.push({
1724
- start: node.property.start,
1725
- end: node.property.end,
1726
- value: reservedName
1727
- });
1728
- return;
1729
- }
1730
1494
  const replacement = wxsBindings.find((item) => item.templatePropertyName === node.property.name);
1731
1495
  if (replacement) {
1732
1496
  codeReplacements.push({
@@ -1738,36 +1502,9 @@ ${declarations.join("\n")}`
1738
1502
  }
1739
1503
  }
1740
1504
  });
1741
- if (codeReplacements.length === 0) {
1742
- return { code: getProgramCode(code, ast), map: inputMap };
1743
- }
1744
1505
  const transformed = applyCodeReplacements(code, codeReplacements);
1745
- let map = inputMap;
1746
- if (enableSourcemap) {
1747
- const generatedMap = new MagicString(code);
1748
- const selected = [];
1749
- for (const replacement of [...codeReplacements].sort((a, b) => b.end - b.start - (a.end - a.start))) {
1750
- if (!selected.some((item) => replacement.start < item.end && item.start < replacement.end)) {
1751
- selected.push(replacement);
1752
- }
1753
- }
1754
- for (const replacement of selected.sort((a, b) => b.start - a.start)) {
1755
- if (replacement.type === "insert") {
1756
- generatedMap.appendLeft(replacement.start, replacement.value);
1757
- } else {
1758
- generatedMap.overwrite(replacement.start, replacement.end, replacement.value);
1759
- }
1760
- }
1761
- const wxsTransformMap = generatedMap.generateMap({
1762
- file: filename,
1763
- source: filename,
1764
- includeContent: true,
1765
- hires: true
1766
- }).toString();
1767
- map = inputMap ? remapSourcemap(wxsTransformMap, inputMap) : wxsTransformMap;
1768
- }
1769
1506
  const transformedAst = parseJs(transformed, filename);
1770
- return { code: getProgramCode(transformed, transformedAst), map };
1507
+ return getProgramCode(transformed, transformedAst);
1771
1508
  }
1772
1509
  function __resetViewState() {
1773
1510
  compileResCache.clear();
@@ -1781,7 +1518,6 @@ export {
1781
1518
  generateVModelTemplate,
1782
1519
  initWxsFilePathMap,
1783
1520
  loadWxsModule,
1784
- normalizeTemplateSyntax,
1785
1521
  parseBraceExp,
1786
1522
  parseClassRules,
1787
1523
  parseKeyExpression,