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