MCPcopy
hub / github.com/webpack/webpack / adjustForeignAttrs

Function adjustForeignAttrs

lib/html/syntax.js:5243–5274  ·  view source on GitHub ↗
(
		/** @type {HtmlAttribute[]} */ attrs,
		/** @type {number} */ ns
	)

Source from the content-addressed store, hash-verified

5241 const adjustSvgTag = (/** @type {string} */ name) =>
5242 /** @type {Record<string, string>} */ (SVG_TAG_ADJUST)[name] || name;
5243 const adjustForeignAttrs = (
5244 /** @type {HtmlAttribute[]} */ attrs,
5245 /** @type {number} */ ns
5246 ) => {
5247 // Reuse the original array/objects until an attribute actually needs
5248 // adjusting; unchanged attributes keep serializedName === undefined and
5249 // the serializer falls back to `name`. Avoids a new array + object per
5250 // attribute on every foreign element.
5251 let out = attrs;
5252 for (let i = 0; i < attrs.length; i++) {
5253 const a = attrs[i];
5254 let name = a.name;
5255 /** @type {string | undefined} */
5256 let serializedName;
5257 if (
5258 ns === NS_SVG &&
5259 /** @type {Record<string, string>} */ (SVG_ATTR_ADJUST)[name]
5260 ) {
5261 name = /** @type {Record<string, string>} */ (SVG_ATTR_ADJUST)[name];
5262 serializedName = name;
5263 }
5264 if (/** @type {Record<string, string>} */ (FOREIGN_ATTR_NS)[a.name]) {
5265 serializedName = /** @type {Record<string, string>} */ (
5266 FOREIGN_ATTR_NS
5267 )[a.name];
5268 }
5269 if (name === a.name && serializedName === undefined) continue;
5270 if (out === attrs) out = [...attrs];
5271 out[i] = { ...a, name, serializedName };
5272 }
5273 return out;
5274 };
5275
5276 const foreignContent = (/** @type {Token} */ t) => {
5277 if (t.type === TOKEN_CHAR) {

Callers 2

foreignContentFunction · 0.85
startTagInBodyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected