react-icons-sprite 1.2.0-rc.1 → 1.2.0-rc.2

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.
@@ -256,12 +256,44 @@ const scanJsxReferencePropEdits = (code, symbols, componentName, usedSymbols, re
256
256
  if (symbols.items[componentLocal] || ignoredComponentLocals.has(componentLocal)) continue;
257
257
  const tagEnd = findJsxOpeningTagEnd(code, cursor);
258
258
  if (tagEnd === -1) continue;
259
- const attributes = code.slice(cursor, tagEnd);
260
- for (const match of attributes.matchAll(/(\s[A-Za-z_$][\w$.-]*(?::[A-Za-z_$][\w$.-]*)?\s*=\s*\{\s*)([A-Za-z_$][\w$]*)(\s*\})/g)) {
261
- const iconLocal = match[2];
259
+ let attributeCursor = cursor;
260
+ while (attributeCursor < tagEnd) {
261
+ while (isWhitespace(code[attributeCursor])) attributeCursor += 1;
262
+ if (attributeCursor >= tagEnd || code[attributeCursor] === "/") break;
263
+ if (code[attributeCursor] === "{") {
264
+ const expressionEnd = findJsxExpressionEnd(code, attributeCursor);
265
+ attributeCursor = expressionEnd === -1 ? tagEnd : expressionEnd + 1;
266
+ continue;
267
+ }
268
+ if (!isIdentifierStart(code[attributeCursor])) {
269
+ attributeCursor += 1;
270
+ continue;
271
+ }
272
+ attributeCursor += 1;
273
+ while (isJsxAttributeNamePart(code[attributeCursor])) attributeCursor += 1;
274
+ while (isWhitespace(code[attributeCursor])) attributeCursor += 1;
275
+ if (code[attributeCursor] !== "=") continue;
276
+ attributeCursor += 1;
277
+ while (isWhitespace(code[attributeCursor])) attributeCursor += 1;
278
+ const valueStart = attributeCursor;
279
+ if (code[valueStart] === "\"" || code[valueStart] === "'") {
280
+ attributeCursor = skipQuotedString(code, valueStart);
281
+ continue;
282
+ }
283
+ if (code[valueStart] !== "{") continue;
284
+ const expressionEnd = findJsxExpressionEnd(code, valueStart);
285
+ if (expressionEnd === -1 || expressionEnd > tagEnd) {
286
+ attributeCursor = tagEnd;
287
+ continue;
288
+ }
289
+ attributeCursor = expressionEnd + 1;
290
+ const expression = code.slice(valueStart + 1, expressionEnd);
291
+ const iconMatch = /^(\s*)([A-Za-z_$][\w$]*)(\s*)$/.exec(expression);
292
+ if (!iconMatch) continue;
293
+ const iconLocal = iconMatch[2];
262
294
  const symbol = symbols.items[iconLocal];
263
295
  if (!symbol || isFontAwesomeIconPack(symbol.pack) || isHugeiconsIconPack(symbol.pack)) continue;
264
- const iconLocalStart = cursor + match.index + match[1].length;
296
+ const iconLocalStart = valueStart + 1 + iconMatch[1].length;
265
297
  edits.push({
266
298
  type: "replace",
267
299
  from: iconLocalStart,
@@ -278,6 +310,50 @@ const scanJsxReferencePropEdits = (code, symbols, componentName, usedSymbols, re
278
310
  count
279
311
  };
280
312
  };
313
+ const isJsxAttributeNamePart = (char) => {
314
+ return isIdentifierPart(char) || char === "-" || char === "." || char === ":";
315
+ };
316
+ const skipQuotedString = (code, start) => {
317
+ const quote = code[start];
318
+ let cursor = start + 1;
319
+ while (cursor < code.length) {
320
+ if (code[cursor] === "\\") {
321
+ cursor += 2;
322
+ continue;
323
+ }
324
+ if (code[cursor] === quote) return cursor + 1;
325
+ cursor += 1;
326
+ }
327
+ return code.length;
328
+ };
329
+ const findJsxExpressionEnd = (code, start) => {
330
+ let quote = null;
331
+ let braceDepth = 0;
332
+ for (let index = start; index < code.length; index += 1) {
333
+ const char = code[index];
334
+ if (quote) {
335
+ if (char === "\\") {
336
+ index += 1;
337
+ continue;
338
+ }
339
+ if (char === quote) quote = null;
340
+ continue;
341
+ }
342
+ if (char === "\"" || char === "'" || char === "`") {
343
+ quote = char;
344
+ continue;
345
+ }
346
+ if (char === "{") {
347
+ braceDepth += 1;
348
+ continue;
349
+ }
350
+ if (char === "}") {
351
+ braceDepth -= 1;
352
+ if (braceDepth === 0) return index;
353
+ }
354
+ }
355
+ return -1;
356
+ };
281
357
  const hasIconIdAttribute = (code, start, end) => {
282
358
  for (let index = start; index < end; index += 1) {
283
359
  if (code.charCodeAt(index) !== 105 || code.charCodeAt(index + 1) !== 99 || code.charCodeAt(index + 2) !== 111 || code.charCodeAt(index + 3) !== 110 || code.charCodeAt(index + 4) !== 73 || code.charCodeAt(index + 5) !== 100) continue;
@@ -1,7 +1,7 @@
1
1
  import { REACT_ICONS_SPRITE_URL_PLACEHOLDER } from "../index.mjs";
2
2
  import { a as createCollector, r as DEFAULT_ICON_SOURCES } from "../compute-icon-id-Xx4G3fva.mjs";
3
3
  import { t as buildSprite } from "../build-sprite-CxqvU2LE.mjs";
4
- import { t as transformModule } from "../transform-module-Chln1wen.mjs";
4
+ import { t as transformModule } from "../transform-module-3mbTFhoj.mjs";
5
5
  import { createHash } from "node:crypto";
6
6
  //#region src/vite/plugin.ts
7
7
  const reactIconsSprite = (options = {}) => {
@@ -1,4 +1,4 @@
1
- import { t as transformModule } from "../transform-module-Chln1wen.mjs";
1
+ import { t as transformModule } from "../transform-module-3mbTFhoj.mjs";
2
2
  import { t as collector } from "../collector-CBRz9R_h.mjs";
3
3
  //#region src/webpack/loader.ts
4
4
  const reactIconsSpriteLoader = async function(source) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://www.schemastore.org/package.json",
3
3
  "name": "react-icons-sprite",
4
- "version": "1.2.0-rc.1",
4
+ "version": "1.2.0-rc.2",
5
5
  "type": "module",
6
6
  "description": "A lightweight Vite, Rsbuild and Webpack plugin for react-icons that builds a single SVG sprite and rewrites icons to <use>, reducing bundle size and runtime overhead.",
7
7
  "author": "Jure Rotar <hello@jurerotar.com>",