@knighted/module 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -580,7 +580,10 @@ const format = async (src, ast, opts) => {
580
580
  seen.add(propName);
581
581
  if (rhs.type === 'Identifier') {
582
582
  const rhsId = rhsSourceFor(rhs);
583
- if (rhsId === rhs.name) {
583
+ const rhsName = rhs.name;
584
+ if (rhsId === rhsName && rhsName === propName) {
585
+ exportsOut.push(`export { ${propName} };`);
586
+ } else if (rhsId === rhsName) {
584
587
  exportsOut.push(`export { ${rhsId} as ${propName} };`);
585
588
  } else {
586
589
  exportsOut.push(`export const ${propName} = ${rhsId};`);
@@ -589,9 +592,15 @@ const format = async (src, ast, opts) => {
589
592
  exportsOut.push(`export const ${propName} = ${rhsSrc};`);
590
593
  }
591
594
  }
595
+
596
+ // Trim trailing whitespace and one optional semicolon so the idiomatic export
597
+ // replacement does not leave the original `;` behind (avoids emitting `;;`).
598
+ let end = write.end;
599
+ while (end < src.length && (src[end] === ' ' || src[end] === '\t')) end++;
600
+ if (end < src.length && src[end] === ';') end++;
592
601
  replacements.push({
593
602
  start: write.start,
594
- end: write.end
603
+ end
595
604
  });
596
605
  }
597
606
  if (!seen.size) return {
package/dist/format.js CHANGED
@@ -573,7 +573,10 @@ const format = async (src, ast, opts) => {
573
573
  seen.add(propName);
574
574
  if (rhs.type === 'Identifier') {
575
575
  const rhsId = rhsSourceFor(rhs);
576
- if (rhsId === rhs.name) {
576
+ const rhsName = rhs.name;
577
+ if (rhsId === rhsName && rhsName === propName) {
578
+ exportsOut.push(`export { ${propName} };`);
579
+ } else if (rhsId === rhsName) {
577
580
  exportsOut.push(`export { ${rhsId} as ${propName} };`);
578
581
  } else {
579
582
  exportsOut.push(`export const ${propName} = ${rhsId};`);
@@ -582,9 +585,15 @@ const format = async (src, ast, opts) => {
582
585
  exportsOut.push(`export const ${propName} = ${rhsSrc};`);
583
586
  }
584
587
  }
588
+
589
+ // Trim trailing whitespace and one optional semicolon so the idiomatic export
590
+ // replacement does not leave the original `;` behind (avoids emitting `;;`).
591
+ let end = write.end;
592
+ while (end < src.length && (src[end] === ' ' || src[end] === '\t')) end++;
593
+ if (end < src.length && src[end] === ';') end++;
585
594
  replacements.push({
586
595
  start: write.start,
587
- end: write.end
596
+ end
588
597
  });
589
598
  }
590
599
  if (!seen.size) return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knighted/module",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Bidirectional transform for ES modules and CommonJS.",
5
5
  "type": "module",
6
6
  "main": "dist/module.js",