react-icons-sprite 0.9.0 → 0.9.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.
|
@@ -35,8 +35,46 @@ const getRange = (node) => {
|
|
|
35
35
|
if (typeof node.start === "number" && typeof node.end === "number") return [node.start, node.end];
|
|
36
36
|
return null;
|
|
37
37
|
};
|
|
38
|
+
const getParseLangCandidates = (filename) => {
|
|
39
|
+
const lower = (filename.split("?", 1)[0] ?? filename).toLowerCase();
|
|
40
|
+
if (lower.endsWith(".tsx")) return [
|
|
41
|
+
"tsx",
|
|
42
|
+
"ts",
|
|
43
|
+
"jsx",
|
|
44
|
+
"js"
|
|
45
|
+
];
|
|
46
|
+
if (lower.endsWith(".ts")) return [
|
|
47
|
+
"ts",
|
|
48
|
+
"tsx",
|
|
49
|
+
"js",
|
|
50
|
+
"jsx"
|
|
51
|
+
];
|
|
52
|
+
if (lower.endsWith(".jsx")) return [
|
|
53
|
+
"jsx",
|
|
54
|
+
"js",
|
|
55
|
+
"tsx",
|
|
56
|
+
"ts"
|
|
57
|
+
];
|
|
58
|
+
return [
|
|
59
|
+
"js",
|
|
60
|
+
"jsx",
|
|
61
|
+
"ts",
|
|
62
|
+
"tsx"
|
|
63
|
+
];
|
|
64
|
+
};
|
|
38
65
|
const parseAst = (code, filename) => {
|
|
39
|
-
|
|
66
|
+
const languages = getParseLangCandidates(filename);
|
|
67
|
+
let firstResult;
|
|
68
|
+
for (const lang of languages) {
|
|
69
|
+
const result = parseSync(filename, code, {
|
|
70
|
+
lang,
|
|
71
|
+
sourceType: "module",
|
|
72
|
+
range: true
|
|
73
|
+
});
|
|
74
|
+
firstResult ??= result;
|
|
75
|
+
if (result.errors.length === 0) return result;
|
|
76
|
+
}
|
|
77
|
+
return firstResult ?? parseSync(filename, code, {
|
|
40
78
|
lang: "tsx",
|
|
41
79
|
sourceType: "module",
|
|
42
80
|
range: true
|
|
@@ -213,20 +251,36 @@ const transformModule = (code, id, register, sources = DEFAULT_ICON_SOURCES, opt
|
|
|
213
251
|
map: null,
|
|
214
252
|
anyReplacements: false
|
|
215
253
|
};
|
|
216
|
-
const
|
|
254
|
+
const declToAllSpecs = /* @__PURE__ */ new Map();
|
|
255
|
+
const declToUsedSpecs = /* @__PURE__ */ new Map();
|
|
217
256
|
for (const { decl, spec } of localNameToImport.values()) {
|
|
218
|
-
const localName = spec.local;
|
|
219
|
-
if (!localName?.name || !usedLocalNames.has(localName.name)) continue;
|
|
220
257
|
const declNode = decl;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
258
|
+
const specNode = spec;
|
|
259
|
+
const all = declToAllSpecs.get(declNode) ?? [];
|
|
260
|
+
if (all.length === 0) {
|
|
224
261
|
const specifiers = declNode.specifiers ?? [];
|
|
225
|
-
for (const oneSpec of specifiers) if (oneSpec.type === "ImportSpecifier" || oneSpec.type === "ImportDefaultSpecifier")
|
|
226
|
-
|
|
262
|
+
for (const oneSpec of specifiers) if (oneSpec.type === "ImportSpecifier" || oneSpec.type === "ImportDefaultSpecifier") all.push(oneSpec);
|
|
263
|
+
declToAllSpecs.set(declNode, all);
|
|
264
|
+
}
|
|
265
|
+
const localName = specNode.local;
|
|
266
|
+
if (!localName?.name || !usedLocalNames.has(localName.name)) continue;
|
|
267
|
+
const used = declToUsedSpecs.get(declNode) ?? [];
|
|
268
|
+
used.push(specNode);
|
|
269
|
+
declToUsedSpecs.set(declNode, used);
|
|
270
|
+
}
|
|
271
|
+
for (const [declNode, usedSpecs] of declToUsedSpecs.entries()) {
|
|
272
|
+
const allSpecs = declToAllSpecs.get(declNode) ?? [];
|
|
273
|
+
if (allSpecs.length > 0 && usedSpecs.length >= allSpecs.length) {
|
|
274
|
+
removeEntireImport(ms, code, declNode);
|
|
275
|
+
continue;
|
|
227
276
|
}
|
|
228
|
-
|
|
229
|
-
|
|
277
|
+
const byStartDesc = [...usedSpecs].sort((a, b) => {
|
|
278
|
+
const aRange = getRange(a);
|
|
279
|
+
const bRange = getRange(b);
|
|
280
|
+
if (!aRange || !bRange) return 0;
|
|
281
|
+
return bRange[0] - aRange[0];
|
|
282
|
+
});
|
|
283
|
+
for (const usedSpec of byStartDesc) removeImportSpecifier(ms, code, usedSpec);
|
|
230
284
|
}
|
|
231
285
|
if (!hasIconImport) ms.prepend(`import { ${iconLocalName} } from "${ICON_SOURCE}";\n`);
|
|
232
286
|
const transformedCode = ms.toString();
|
package/dist/vite/plugin.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { REACT_ICONS_SPRITE_URL_PLACEHOLDER } from "../index.mjs";
|
|
2
|
-
import { i as transformModule, n as buildSprite, r as createCollector, t as DEFAULT_ICON_SOURCES } from "../core-
|
|
2
|
+
import { i as transformModule, n as buildSprite, r as createCollector, t as DEFAULT_ICON_SOURCES } from "../core-B0kAb7AT.mjs";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
//#region src/vite/plugin.ts
|
|
5
5
|
const reactIconsSprite = (options = {}) => {
|
package/dist/webpack/loader.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as transformModule } from "../core-
|
|
2
|
-
import { t as collector } from "../collector-
|
|
1
|
+
import { i as transformModule } from "../core-B0kAb7AT.mjs";
|
|
2
|
+
import { t as collector } from "../collector-BvJbH8Da.mjs";
|
|
3
3
|
//#region src/webpack/loader.ts
|
|
4
4
|
const reactIconsSpriteLoader = async function(source) {
|
|
5
5
|
if (this.mode === "development") return source;
|
package/dist/webpack/plugin.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { REACT_ICONS_SPRITE_URL_PLACEHOLDER } from "../index.mjs";
|
|
2
|
-
import { n as buildSprite } from "../core-
|
|
3
|
-
import { t as collector } from "../collector-
|
|
2
|
+
import { n as buildSprite } from "../core-B0kAb7AT.mjs";
|
|
3
|
+
import { t as collector } from "../collector-BvJbH8Da.mjs";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
//#region src/webpack/plugin.ts
|
|
6
6
|
var ReactIconsSpriteWebpackPlugin = class {
|
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": "0.9.
|
|
4
|
+
"version": "0.9.1",
|
|
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>",
|
|
@@ -50,7 +50,6 @@
|
|
|
50
50
|
],
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsdown",
|
|
53
|
-
"bench:transform": "vitest bench tests/transform.bench.ts",
|
|
54
53
|
"dev": "tsdown --watch",
|
|
55
54
|
"format": "biome format --write --no-errors-on-unmatched",
|
|
56
55
|
"format:check": "biome format --no-errors-on-unmatched",
|