@wevu/compiler 6.6.12 → 6.6.13

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 (2) hide show
  1. package/dist/index.mjs +16 -5
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -3455,6 +3455,16 @@ async function compileJsxFile(source, filename, options) {
3455
3455
  };
3456
3456
  }
3457
3457
 
3458
+ //#endregion
3459
+ //#region src/utils/text.ts
3460
+ /**
3461
+ * 统一文本换行符为 LF,消除不同系统(CRLF/CR/LF)差异。
3462
+ */
3463
+ function normalizeLineEndings(source) {
3464
+ if (!source.includes("\r")) return source;
3465
+ return source.replace(/\r\n?/g, "\n");
3466
+ }
3467
+
3458
3468
  //#endregion
3459
3469
  //#region src/plugins/utils/cache.ts
3460
3470
  const mtimeCache = /* @__PURE__ */ new Map();
@@ -3492,7 +3502,7 @@ async function readFile(id, options) {
3492
3502
  if (!checkMtime) {
3493
3503
  const cached = loadCache.get(id);
3494
3504
  if (cached !== void 0) return cached;
3495
- const content = await fs.readFile(id, encoding);
3505
+ const content = normalizeLineEndings(await fs.readFile(id, encoding));
3496
3506
  loadCache.set(id, content);
3497
3507
  return content;
3498
3508
  }
@@ -3500,7 +3510,7 @@ async function readFile(id, options) {
3500
3510
  const cached = loadCache.get(id);
3501
3511
  if (cached !== void 0) return cached;
3502
3512
  }
3503
- const content = await fs.readFile(id, encoding);
3513
+ const content = normalizeLineEndings(await fs.readFile(id, encoding));
3504
3514
  loadCache.set(id, content);
3505
3515
  return content;
3506
3516
  }
@@ -3736,7 +3746,7 @@ async function resolveSfcBlockSrc(descriptor, filename, options) {
3736
3746
  */
3737
3747
  async function readAndParseSfc(filename, options) {
3738
3748
  const checkMtime = options?.checkMtime ?? true;
3739
- const source = options?.source ?? await readFile(filename, { checkMtime });
3749
+ const source = normalizeLineEndings(options?.source ?? await readFile(filename, { checkMtime }));
3740
3750
  const normalizedSource = preprocessScriptSrc(preprocessScriptSetupSrc(source));
3741
3751
  const signature = checkMtime ? (() => {
3742
3752
  const cached = mtimeCache.get(filename);
@@ -6331,10 +6341,11 @@ function extractDefineOptionsHash(content) {
6331
6341
  return createHash("sha256").update(macroSources.join("\n")).digest("hex").slice(0, 12);
6332
6342
  }
6333
6343
  async function parseVueFile(source, filename, options) {
6334
- const normalizedSource = preprocessScriptSrc(preprocessScriptSetupSrc(source));
6344
+ const normalizedInputSource = normalizeLineEndings(source);
6345
+ const normalizedSource = preprocessScriptSrc(preprocessScriptSetupSrc(normalizedInputSource));
6335
6346
  const { descriptor, errors } = parse(normalizedSource, {
6336
6347
  filename,
6337
- ignoreEmpty: normalizedSource === source
6348
+ ignoreEmpty: normalizedSource === normalizedInputSource
6338
6349
  });
6339
6350
  restoreScriptSetupSrc(descriptor);
6340
6351
  restoreScriptSrc(descriptor);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.6.12",
4
+ "version": "6.6.13",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",