* Extract and blocks from the Vue source
()
| 189 | * Extract <script> and <script setup> blocks from the Vue source |
| 190 | */ |
| 191 | private extractScriptBlocks(): Array<{ |
| 192 | content: string; |
| 193 | startLine: number; |
| 194 | isSetup: boolean; |
| 195 | language: Language; |
| 196 | }> { |
| 197 | const blocks: Array<{ |
| 198 | content: string; |
| 199 | startLine: number; |
| 200 | isSetup: boolean; |
| 201 | language: Language; |
| 202 | }> = []; |
| 203 | |
| 204 | // A self-closing `<script src="./legacy.js" />` has no body; match it on |
| 205 | // its own so it cannot run on to the next block's `</script>`. |
| 206 | const scriptRegex = new RegExp(SFC_SCRIPT_ELEMENT); |
| 207 | let match; |
| 208 | |
| 209 | while ((match = scriptRegex.exec(this.source)) !== null) { |
| 210 | if (match.groups?.content === undefined) continue; |
| 211 | const attrs = match[1] || ''; |
| 212 | const content = match.groups.content; |
| 213 | |
| 214 | // TypeScript, TSX or JavaScript, from the lang attribute |
| 215 | const language = sfcScriptLanguage(attrs, 'vue'); |
| 216 | |
| 217 | // Detect <script setup> |
| 218 | const isSetup = /\bsetup\b/.test(attrs); |
| 219 | |
| 220 | // Calculate the 0-indexed line where the content begins. The content |
| 221 | // starts right after the opening tag's `>` — its leading `\n` is part |
| 222 | // of the content, so relative line 1 sits ON the tag's closing line |
| 223 | // (adding 1 here double-counted the embedded newline and shifted every |
| 224 | // script-block symbol down a line). |
| 225 | const beforeScript = this.source.substring(0, match.index); |
| 226 | const scriptTagLine = (beforeScript.match(/\n/g) || []).length; |
| 227 | const openingTag = match[0].substring(0, match[0].indexOf('>') + 1); |
| 228 | const openingTagLines = (openingTag.match(/\n/g) || []).length; |
| 229 | const contentStartLine = scriptTagLine + openingTagLines; // 0-indexed line |
| 230 | |
| 231 | blocks.push({ |
| 232 | content, |
| 233 | startLine: contentStartLine, |
| 234 | isSetup, |
| 235 | language, |
| 236 | }); |
| 237 | } |
| 238 | |
| 239 | return blocks; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Process a script block by delegating to TreeSitterExtractor |
no test coverage detected