Skip to content

Commit 811bcc0

Browse files
chodaictclaude
andcommitted
fix(ascii-stroke): narrow SVG root via instanceof, drop unsafe cast
`doc.documentElement` is typed HTMLElement, so `as SVGSVGElement` tripped ts(2352) and was blocking the pre-push astro-check gate (pre-existing, unrelated to README). Replace the tagName string guard with `instanceof SVGSVGElement` — it narrows root properly (and rejects <parsererror>/non-SVG roots), so importNode now returns SVGSVGElement and no cast is needed. No runtime behavior lost; the gate goes green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5b2117c commit 811bcc0

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/lib/ascii-stroke-dom.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export function sampleSvgStrokes(
5858
if (typeof document === 'undefined') return null;
5959

6060
const doc = new DOMParser().parseFromString(svgText, 'image/svg+xml');
61+
// instanceof narrows root to SVGSVGElement for the rest of the function (and
62+
// rejects <parsererror>/non-SVG roots), so no downstream cast is needed.
6163
const root = doc.documentElement;
62-
if (!root || root.nodeName === 'parsererror' || root.tagName.toLowerCase() !== 'svg') return null;
64+
if (!(root instanceof SVGSVGElement)) return null;
6365

6466
// Resolve the user-space box: explicit viewBox, else width/height.
6567
const vb = root.getAttribute('viewBox');
@@ -92,7 +94,7 @@ export function sampleSvgStrokes(
9294
'style',
9395
'position:absolute;left:-99999px;top:0;width:0;height:0;overflow:hidden',
9496
);
95-
const mounted = document.importNode(root, true) as SVGSVGElement;
97+
const mounted = document.importNode(root, true);
9698
mounted.setAttribute('width', String(vbW));
9799
mounted.setAttribute('height', String(vbH));
98100
mounted.setAttribute('preserveAspectRatio', 'xMidYMid meet');

0 commit comments

Comments
 (0)