@tsrx/prettier-plugin 0.3.109 → 0.3.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsrx/prettier-plugin",
3
- "version": "0.3.109",
3
+ "version": "0.3.110",
4
4
  "description": "Ripple plugin for Prettier",
5
5
  "type": "module",
6
6
  "module": "src/index.js",
@@ -27,7 +27,7 @@
27
27
  "prettier": "^3.8.4"
28
28
  },
29
29
  "dependencies": {
30
- "@tsrx/core": "0.1.47"
30
+ "@tsrx/core": "0.1.48"
31
31
  },
32
32
  "files": [
33
33
  "src/"
package/src/index.js CHANGED
@@ -1623,10 +1623,19 @@ function printRippleNode(node, path, options, print, args) {
1623
1623
  break;
1624
1624
 
1625
1625
  case 'ImportExpression': {
1626
+ const importExpression =
1627
+ /** @type {AST.ImportExpression & { phase?: 'defer' | null, arguments?: AST.Expression[] }} */ (
1628
+ node
1629
+ );
1626
1630
  /** @type {Doc[]} */
1627
- const parts = ['import(', path.call(print, 'source')];
1631
+ const parts = [
1632
+ importExpression.phase === 'defer' ? 'import.defer(' : 'import(',
1633
+ path.call(print, 'source'),
1634
+ ];
1628
1635
  if (node.options) {
1629
1636
  parts.push(', ', path.call(print, 'options'));
1637
+ } else if (importExpression.arguments?.length) {
1638
+ parts.push(', ', path.call(print, 'arguments', 0));
1630
1639
  }
1631
1640
  parts.push(')');
1632
1641
  nodeContent = parts;
@@ -2580,8 +2589,8 @@ function printRippleNode(node, path, options, print, args) {
2580
2589
 
2581
2590
  /**
2582
2591
  * Print an import declaration
2583
- * @param {AST.ImportDeclaration} node - The import declaration node
2584
- * @param {AstPath<AST.ImportDeclaration>} path - The AST path
2592
+ * @param {AST.TSRXImportDeclaration} node - The import declaration node
2593
+ * @param {AstPath<AST.TSRXImportDeclaration>} path - The AST path
2585
2594
  * @param {RippleFormatOptions} options - Prettier options
2586
2595
  * @param {PrintFn} _print - Print callback (unused)
2587
2596
  * @returns {Doc[]}
@@ -2589,9 +2598,9 @@ function printRippleNode(node, path, options, print, args) {
2589
2598
  function printImportDeclaration(node, path, options, _print) {
2590
2599
  /** @type {Doc[]} */
2591
2600
  const parts = ['import'];
2592
-
2593
- // Handle type imports
2594
- if (node.importKind === 'type') {
2601
+ if (node.phase === 'defer') {
2602
+ parts.push(' defer');
2603
+ } else if (node.importKind === 'type') {
2595
2604
  parts.push(' type');
2596
2605
  }
2597
2606
 
@@ -2659,7 +2668,25 @@ function printImportDeclaration(node, path, options, _print) {
2659
2668
  ? source.name
2660
2669
  : formatStringLiteral(/** @type {string} */ (source.value), options);
2661
2670
 
2662
- parts.push(' ', sourceDoc, semi(options));
2671
+ parts.push(' ', sourceDoc);
2672
+
2673
+ const attributes =
2674
+ /** @type {Array<{ key: AST.Identifier | AST.Literal, value: AST.Literal }>} */ (
2675
+ /** @type {any} */ (node).attributes ?? /** @type {any} */ (node).assertions ?? []
2676
+ );
2677
+ if (attributes.length > 0) {
2678
+ const attributeDocs = attributes.map((attribute) => {
2679
+ const key =
2680
+ attribute.key.type === 'Identifier'
2681
+ ? attribute.key.name
2682
+ : formatStringLiteral(/** @type {string} */ (attribute.key.value), options);
2683
+ const value = formatStringLiteral(/** @type {string} */ (attribute.value.value), options);
2684
+ return [key, ': ', value];
2685
+ });
2686
+ parts.push(' with { ', join(', ', attributeDocs), ' }');
2687
+ }
2688
+
2689
+ parts.push(semi(options));
2663
2690
 
2664
2691
  return parts;
2665
2692
  }
package/src/index.test.js CHANGED
@@ -1324,6 +1324,20 @@ const items=[1,2,3];
1324
1324
  expect(result).toBeWithNewline(expected);
1325
1325
  });
1326
1326
 
1327
+ it('should preserve and format dynamic deferred imports', async () => {
1328
+ const input = `const feature=import.defer("./feature.js")`;
1329
+ const expected = `const feature = import.defer('./feature.js');`;
1330
+ const result = await format(input, { singleQuote: true });
1331
+ expect(result).toBeWithNewline(expected);
1332
+ });
1333
+
1334
+ it('should preserve dynamic deferred import options', async () => {
1335
+ const input = `const data=import.defer("./feature.json",{with:{type:"json"}})`;
1336
+ const expected = `const data = import.defer('./feature.json', { with: { type: 'json' } });`;
1337
+ const result = await format(input, { singleQuote: true });
1338
+ expect(result).toBeWithNewline(expected);
1339
+ });
1340
+
1327
1341
  it('should format destructured dynamic import() in Promise.all', async () => {
1328
1342
  const input = `const [{ EditorState }, { oneDark }] = await Promise.all([import('@codemirror/state'), import('@codemirror/theme-one-dark')]);`;
1329
1343
  const expected = `const [{ EditorState }, { oneDark }] = await Promise.all([
@@ -1712,6 +1726,13 @@ import { Something, type Props, track } from 'ripple';`;
1712
1726
  expect(result).toBeWithNewline(expected);
1713
1727
  });
1714
1728
 
1729
+ it('should preserve and format static deferred imports', async () => {
1730
+ const input = `import defer*as feature from "./feature.json" with{type:"json"};`;
1731
+ const expected = `import defer * as feature from './feature.json' with { type: 'json' };`;
1732
+ const result = await format(input, { singleQuote: true });
1733
+ expect(result).toBeWithNewline(expected);
1734
+ });
1735
+
1715
1736
  // Regressed in 0.3.97: the printer dropped the `type` keyword from
1716
1737
  // type-only re-exports and inline export specifiers, turning them into
1717
1738
  // runtime re-exports of bindings that only exist as types (a module-load