( s: MagicString, sourceCodeLocation: Token.Location, newValue: string, )
| 255 | const attrValueStartRE = /=\s*(.)/ |
| 256 | |
| 257 | export function overwriteAttrValue( |
| 258 | s: MagicString, |
| 259 | sourceCodeLocation: Token.Location, |
| 260 | newValue: string, |
| 261 | ): MagicString { |
| 262 | const srcString = s.slice( |
| 263 | sourceCodeLocation.startOffset, |
| 264 | sourceCodeLocation.endOffset, |
| 265 | ) |
| 266 | const valueStart = attrValueStartRE.exec(srcString) |
| 267 | if (!valueStart) { |
| 268 | // overwrite attr value can only be called for a well-defined value |
| 269 | throw new Error( |
| 270 | `[vite:html] internal error, failed to overwrite attribute value`, |
| 271 | ) |
| 272 | } |
| 273 | const wrapOffset = valueStart[1] === '"' || valueStart[1] === "'" ? 1 : 0 |
| 274 | const valueOffset = valueStart.index! + valueStart[0].length - 1 |
| 275 | s.update( |
| 276 | sourceCodeLocation.startOffset + valueOffset + wrapOffset, |
| 277 | sourceCodeLocation.endOffset - wrapOffset, |
| 278 | newValue, |
| 279 | ) |
| 280 | return s |
| 281 | } |
| 282 | |
| 283 | export function removeViteIgnoreAttr( |
| 284 | s: MagicString, |
no outgoing calls
no test coverage detected