@formatjs/unplugin 1.0.0 → 1.1.3

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/LICENSE.md CHANGED
File without changes
package/README.md CHANGED
File without changes
package/esbuild.d.ts CHANGED
File without changes
package/esbuild.js CHANGED
File without changes
package/index.d.ts CHANGED
File without changes
package/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formatjs/unplugin",
3
3
  "description": "Universal build plugin for FormatJS — supports Vite, Webpack, Rollup, esbuild, and Rspack",
4
- "version": "1.0.0",
4
+ "version": "1.1.3",
5
5
  "license": "MIT",
6
6
  "author": "Long Ho <holevietlong@gmail.com>",
7
7
  "type": "module",
@@ -16,11 +16,11 @@
16
16
  "./transform": "./transform.js"
17
17
  },
18
18
  "dependencies": {
19
- "@formatjs/icu-messageformat-parser": "workspace:*",
20
- "@formatjs/ts-transformer": "workspace:*",
21
19
  "magic-string": "^0.30.0",
22
- "oxc-parser": "^0.114.0",
23
- "unplugin": "^2.3.0"
20
+ "oxc-parser": "^0.120.0",
21
+ "unplugin": "^3.0.0",
22
+ "@formatjs/ts-transformer": "4.4.2",
23
+ "@formatjs/icu-messageformat-parser": "3.5.3"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@rspack/core": ">=1",
@@ -62,4 +62,4 @@
62
62
  }
63
63
  },
64
64
  "repository": "formatjs/formatjs.git"
65
- }
65
+ }
package/rollup.d.ts CHANGED
File without changes
package/rollup.js CHANGED
File without changes
package/rspack.d.ts CHANGED
File without changes
package/rspack.js CHANGED
File without changes
package/transform.d.ts CHANGED
File without changes
package/transform.js CHANGED
@@ -83,10 +83,9 @@ export function transform(code, id, options) {
83
83
  const attributes = elementNode.attributes || [];
84
84
  const descriptor = {};
85
85
  const locations = {};
86
- // Use the position right after the element name as the insertion point
87
- // Find the first attribute start, or use the end of the element name
88
- const firstAttr = attributes[0];
89
- locations.insertionPoint = firstAttr ? firstAttr.start : elementNode.name.end;
86
+ // Always insert after the element name so the id survives even when the
87
+ // first attribute (e.g. description) is removed.
88
+ locations.insertionPoint = elementNode.name.end;
90
89
  for (const attr of attributes) {
91
90
  if (attr.type !== "JSXAttribute") continue;
92
91
  const attrName = attr.name;
@@ -140,7 +139,7 @@ export function transform(code, id, options) {
140
139
  } else if (locations.insertionPoint != null) {
141
140
  // Insert id at a stable position (after `{` for objects, before first attr for JSX)
142
141
  if (isJSX) {
143
- s.appendLeft(locations.insertionPoint, `id=${JSON.stringify(newId)} `);
142
+ s.appendLeft(locations.insertionPoint, ` id=${JSON.stringify(newId)}`);
144
143
  } else {
145
144
  s.appendRight(locations.insertionPoint, `id: ${JSON.stringify(newId)}, `);
146
145
  }
@@ -229,14 +228,16 @@ export function transform(code, id, options) {
229
228
  // Walk backward through attribute name
230
229
  while (i >= 0 && /[a-zA-Z0-9_$]/.test(code[i])) i--;
231
230
  const attrStart = i + 1;
232
- let attrEnd = loc.end;
233
- // Skip trailing whitespace
234
- let j = attrEnd;
235
- while (j < code.length && (code[j] === " " || code[j] === " ")) j++;
236
- attrEnd = j;
237
- // Also remove leading whitespace
231
+ const attrEnd = loc.end;
232
+ // Remove leading whitespace/newline before attribute name.
233
+ // We intentionally do NOT consume trailing whitespace so that when attributes
234
+ // are on the same line the space before the next attribute is preserved.
235
+ // e.g. `<FM description="x" defaultMessage="y" />` → `<FM defaultMessage="y" />`
238
236
  let k = attrStart - 1;
239
237
  while (k >= 0 && (code[k] === " " || code[k] === " ")) k--;
238
+ // Also include the preceding newline for multi-line JSX so the whole line is removed.
239
+ if (k >= 0 && code[k] === "\n") k--;
240
+ if (k >= 0 && code[k] === "\r") k--;
240
241
  const removeStart = k + 1;
241
242
  s.remove(removeStart, attrEnd);
242
243
  }
package/vite.d.ts CHANGED
File without changes
package/vite.js CHANGED
File without changes
package/webpack.d.ts CHANGED
File without changes
package/webpack.js CHANGED
File without changes