From 4cfeb458fe105e0c046da5101999b0f0301a3c1a Mon Sep 17 00:00:00 2001 From: Ben Dailey Date: Sun, 22 Nov 2026 11:02:28 -0500 Subject: [PATCH] fix(tia): end the SFC script tag after quoted attributes that hold > (#2063) Co-authored-by: Ben Dailey Co-authored-by: Punyapal Shah --- bin/pest-tia-vite-deps.mjs | 2 +- tests/.snapshots/success.txt | 15 +++++- tests/Unit/Plugins/Tia/ViteDepsHelper.php | 63 +++++++++++++++++++++++ tests/Visual/Parallel.php | 2 +- 4 files changed, 79 insertions(+), 3 deletions(-) diff --git a/bin/pest-tia-vite-deps.mjs b/bin/pest-tia-vite-deps.mjs index 7ab3905b..856a6639 100644 --- a/bin/pest-tia-vite-deps.mjs +++ b/bin/pest-tia-vite-deps.mjs @@ -13,7 +13,7 @@ const PAGE_EXTENSIONS = new Set([ '.mts', '.cts', '.mjs', '.cjs', ]) const SFC_RE = /\.(vue|svelte)$/i -const SCRIPT_BLOCK_RE = /]*)>([\s\S]*?)<\/script>/gi +const SCRIPT_BLOCK_RE = /"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/script>/gi const ASSET_EXT_RE = /\.(css|scss|sass|less|styl|stylus|svg|png|jpe?g|gif|webp|avif|ico|bmp|woff2?|ttf|eot|otf|md|mdx|txt|html|mp4|webm|mp3|wav|ogg|m4a|pdf|wasm|glsl|frag|vert)$/i const PROJECT_ROOT = resolve(process.argv[2] ?? process.cwd()) const PAGE_DIR_CANDIDATES = [ diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 05fab6ae..c3021ebb 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2272,6 +2272,9 @@ ✓ it keeps every import a single file component declares with ('default-export-in-line-comment') ✓ it keeps every import a single file component declares with ('default-export-in-block-comment') ✓ it keeps every import a single file component declares with ('default-export-in-string') + ✓ it keeps every import a single file component declares with ('generic-attribute') + ✓ it keeps every import a single file component declares with ('generic-attribute-single-quoted') + ✓ it keeps every import a single file component declares with ('generic-attribute-before-lang') ✓ it reports the script block language so the parser matches it with ('script-setup') ✓ it reports the script block language so the parser matches it with ('plain-script-with-default') ✓ it reports the script block language so the parser matches it with ('typescript-lang') @@ -2286,6 +2289,9 @@ ✓ it reports the script block language so the parser matches it with ('default-export-in-line-comment') ✓ it reports the script block language so the parser matches it with ('default-export-in-block-comment') ✓ it reports the script block language so the parser matches it with ('default-export-in-string') + ✓ it reports the script block language so the parser matches it with ('generic-attribute') + ✓ it reports the script block language so the parser matches it with ('generic-attribute-single-quoted') + ✓ it reports the script block language so the parser matches it with ('generic-attribute-before-lang') ✓ it always leaves a default export for importers to resolve against with ('script-setup') ✓ it always leaves a default export for importers to resolve against with ('plain-script-with-default') ✓ it always leaves a default export for importers to resolve against with ('typescript-lang') @@ -2300,6 +2306,12 @@ ✓ it always leaves a default export for importers to resolve against with ('default-export-in-line-comment') ✓ it always leaves a default export for importers to resolve against with ('default-export-in-block-comment') ✓ it always leaves a default export for importers to resolve against with ('default-export-in-string') + ✓ it always leaves a default export for importers to resolve against with ('generic-attribute') + ✓ it always leaves a default export for importers to resolve against with ('generic-attribute-single-quoted') + ✓ it always leaves a default export for importers to resolve against with ('generic-attribute-before-lang') + ✓ it ends the opening script tag after a quoted attribute that holds a closing angle bracket with ('generic-attribute') + ✓ it ends the opening script tag after a quoted attribute that holds a closing angle bracket with ('generic-attribute-single-quoted') + ✓ it ends the opening script tag after a quoted attribute that holds a closing angle bracket with ('generic-attribute-before-lang') ✓ it does not add a second default export when the block already has one ✓ it drops template and style markup that the parser would reject ✓ it stubs assets as JS modules so rolldown does not reject them as CSS with ('/app/resources/css/app.css') @@ -2311,6 +2323,7 @@ ✓ it ignores a default export that only appears in a comment or string with ('default-export-in-block-comment') ✓ it ignores a default export that only appears in a comment or string with ('default-export-in-string') - it bundles a script setup component that mentions export default in a comment → rolldown is not resolvable. + - it bundles a generic component whose script tag holds a closing angle bracket → rolldown is not resolvable. PASS Tests\Unit\Plugins\Tia\WatchPatterns ✓ it keeps the built-in fallbacks enabled by default @@ -2647,4 +2660,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1937 passed (4405 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 1949 passed (4417 assertions) \ No newline at end of file diff --git a/tests/Unit/Plugins/Tia/ViteDepsHelper.php b/tests/Unit/Plugins/Tia/ViteDepsHelper.php index 706c11e7..49ee082d 100644 --- a/tests/Unit/Plugins/Tia/ViteDepsHelper.php +++ b/tests/Unit/Plugins/Tia/ViteDepsHelper.php @@ -473,6 +473,18 @@ function tiaSfcFixtures(): array "", ['imports' => ['@/A.vue'], 'moduleType' => 'js'], ], + 'generic-attribute' => [ + "", + ['imports' => ['@/E.vue'], 'moduleType' => 'ts'], + ], + 'generic-attribute-single-quoted' => [ + "", + ['imports' => ['@/F.vue'], 'moduleType' => 'ts'], + ], + 'generic-attribute-before-lang' => [ + "", + ['imports' => ['@/G.vue'], 'moduleType' => 'ts'], + ], ]; } @@ -630,6 +642,10 @@ it('always leaves a default export for importers to resolve against', function ( expect(tiaSfcResults()[$name]['code'])->toMatch('/export\s+default\b/'); })->with(array_keys(tiaSfcFixtures())); +it('ends the opening script tag after a quoted attribute that holds a closing angle bracket', function (string $name): void { + expect(tiaSfcResults()[$name]['code'])->toStartWith("\nimport "); +})->with(['generic-attribute', 'generic-attribute-single-quoted', 'generic-attribute-before-lang']); + it('does not add a second default export when the block already has one', function (): void { preg_match_all('/export\s+default\b/', tiaSfcResults()['plain-script-with-default']['code'], $matches); @@ -711,3 +727,50 @@ it('bundles a script setup component that mentions export default in a comment', 'resources/js/components/format.js' => ['Dashboard'], ]); }); + +it('bundles a generic component whose script tag holds a closing angle bracket', function (): void { + $rolldown = tiaRolldownPackageDir(); + if ($rolldown === null) { + $this->markTestSkipped('rolldown is not resolvable.'); + } + + $root = sys_get_temp_dir().'/pest-tia-rolldown-generic-'.bin2hex(random_bytes(6)); + mkdir($root.'/resources/js/pages', 0755, true); + mkdir($root.'/resources/js/components', 0755, true); + mkdir($root.'/node_modules', 0755, true); + $root = realpath($root); + + symlink($rolldown, $root.'/node_modules/rolldown'); + file_put_contents($root.'/package.json', '{}'); + file_put_contents($root.'/resources/js/pages/Items.vue', <<<'VUE' + + + VUE); + file_put_contents($root.'/resources/js/components/SortableList.vue', <<<'VUE' + + + VUE); + file_put_contents($root.'/resources/js/components/label.ts', "export const label = (v: unknown): string => String(v)\n"); + + $process = new Process(['node', tiaViteHelperPath(), $root]); + $process->run(); + + unlink($root.'/node_modules/rolldown'); + foreach (['resources/js/pages/Items.vue', 'resources/js/components/SortableList.vue', 'resources/js/components/label.ts', 'package.json'] as $file) { + @unlink($root.'/'.$file); + } + foreach (['node_modules', 'resources/js/pages', 'resources/js/components', 'resources/js', 'resources', ''] as $dir) { + @rmdir($root.'/'.$dir); + } + + expect($process->getExitCode())->toBe(0, $process->getErrorOutput()) + ->and(json_decode($process->getOutput(), true, flags: JSON_THROW_ON_ERROR))->toMatchArray([ + 'resources/js/components/SortableList.vue' => ['Items'], + 'resources/js/components/label.ts' => ['Items'], + ]); +}); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index d97a8025..92dcb586 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -21,7 +21,7 @@ test('parallel', function () use ($run): void { $output = implode("\n", array_slice(explode("\n", (string) $output), -10)); $profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile'); - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 30 skipped, 1810 passed (3880 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 31 skipped, 1822 passed (3892 assertions)'; expect($output) ->toContain("Tests: {$expected}")