@formatjs/unplugin 1.1.0 → 1.1.4
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 +5 -5
- package/transform.js +12 -11
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.1.
|
|
4
|
+
"version": "1.1.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Long Ho <holevietlong@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"magic-string": "^0.30.0",
|
|
20
|
-
"oxc-parser": "^0.
|
|
21
|
-
"unplugin": "^
|
|
22
|
-
"@formatjs/
|
|
23
|
-
"@formatjs/
|
|
20
|
+
"oxc-parser": "^0.120.0",
|
|
21
|
+
"unplugin": "^3.0.0",
|
|
22
|
+
"@formatjs/icu-messageformat-parser": "3.5.3",
|
|
23
|
+
"@formatjs/ts-transformer": "4.4.2"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@rspack/core": ">=1",
|
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
|
-
//
|
|
87
|
-
//
|
|
88
|
-
|
|
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
|
-
|
|
233
|
-
//
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
}
|