@godxjp/ui 23.4.0 → 23.4.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.
- package/package.json +2 -2
- package/scripts/ui-audit.mjs +66 -2
package/package.json
CHANGED
package/scripts/ui-audit.mjs
CHANGED
|
@@ -797,12 +797,76 @@ function walk(dir, acc = []) {
|
|
|
797
797
|
return acc;
|
|
798
798
|
}
|
|
799
799
|
|
|
800
|
+
/** True when `index` sits inside an unclosed backtick template starting at or after `from`. */
|
|
801
|
+
function insideTemplateLiteral(source, from, index) {
|
|
802
|
+
let ticks = 0;
|
|
803
|
+
for (let i = from; i < index; i++) {
|
|
804
|
+
if (source[i] === "\\") {
|
|
805
|
+
i++;
|
|
806
|
+
continue;
|
|
807
|
+
}
|
|
808
|
+
if (source[i] === "`") ticks++;
|
|
809
|
+
}
|
|
810
|
+
return ticks % 2 === 1;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/** `<TurnResult>(` is a generic call, not JSX — scanning after its `>` hits `` `/path/${id}` ``. */
|
|
814
|
+
function isGenericTypeBeforeCall(source, openStart, closeIndex) {
|
|
815
|
+
const name = source.slice(openStart + 1, closeIndex);
|
|
816
|
+
if (!/^[A-Z][\w]*$/.test(name)) return false;
|
|
817
|
+
return /^\s*\(/.test(source.slice(closeIndex + 1));
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Hand currency in JSX text after `>`: `>¥{amount}`, `>${price}`, `$1,200` — not `` `/chat/${id}` ``.
|
|
822
|
+
* `$` immediately before `{` inside a template literal is interpolation, never a price sigil.
|
|
823
|
+
*/
|
|
824
|
+
function findHandCurrencyInJsxText(source, from) {
|
|
825
|
+
for (let i = from; i < source.length; i++) {
|
|
826
|
+
const char = source[i];
|
|
827
|
+
if (char === "<") break;
|
|
828
|
+
if (char === "{") break;
|
|
829
|
+
if (char === "`") {
|
|
830
|
+
i++;
|
|
831
|
+
while (i < source.length) {
|
|
832
|
+
if (source[i] === "\\") {
|
|
833
|
+
i += 2;
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
if (source[i] === "`") break;
|
|
837
|
+
i++;
|
|
838
|
+
}
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
if (char === "$") {
|
|
842
|
+
if (insideTemplateLiteral(source, from, i)) continue;
|
|
843
|
+
const digits = source.slice(i).match(/^\$(?:\d[\d,]*(?:\.\d+)?|\d)/);
|
|
844
|
+
if (digits) return { end: i + digits[0].length };
|
|
845
|
+
const brace = source.slice(i).match(/^\$\s*\{/);
|
|
846
|
+
if (brace && !insideTemplateLiteral(source, from, i)) {
|
|
847
|
+
return { end: i + brace[0].length };
|
|
848
|
+
}
|
|
849
|
+
continue;
|
|
850
|
+
}
|
|
851
|
+
if (/[¥€£₫]/.test(char)) {
|
|
852
|
+
if (insideTemplateLiteral(source, from, i)) continue;
|
|
853
|
+
const brace = source.slice(i).match(/^[¥€£₫]\s*\{/);
|
|
854
|
+
if (brace) return { end: i + brace[0].length };
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
return null;
|
|
858
|
+
}
|
|
859
|
+
|
|
800
860
|
/** Match real JSX text after a balanced opening tag, including props with comparisons. */
|
|
801
861
|
function* currencyMatches(source) {
|
|
802
862
|
for (const opening of source.matchAll(/<(?:[A-Za-z][\w.:]*\b|(?=>))/g)) {
|
|
803
863
|
const end = jsxOpeningEnd(source, opening.index);
|
|
804
|
-
|
|
805
|
-
if (
|
|
864
|
+
if (end >= source.length) continue;
|
|
865
|
+
if (isGenericTypeBeforeCall(source, opening.index, end)) continue;
|
|
866
|
+
const hit = findHandCurrencyInJsxText(source, end + 1);
|
|
867
|
+
if (hit) {
|
|
868
|
+
yield { 0: source.slice(opening.index, hit.end), index: opening.index };
|
|
869
|
+
}
|
|
806
870
|
}
|
|
807
871
|
yield* source.matchAll(/\}\s*円\s*</g);
|
|
808
872
|
}
|