mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
fix(tia): end the SFC script tag after quoted attributes that hold > (#2063)
Co-authored-by: Ben Dailey <ben@dev-deb12> Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
@@ -13,7 +13,7 @@ const PAGE_EXTENSIONS = new Set([
|
||||
'.mts', '.cts', '.mjs', '.cjs',
|
||||
])
|
||||
const SFC_RE = /\.(vue|svelte)$/i
|
||||
const SCRIPT_BLOCK_RE = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi
|
||||
const SCRIPT_BLOCK_RE = /<script\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\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 = [
|
||||
|
||||
@@ -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)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 1949 passed (4417 assertions)
|
||||
@@ -473,6 +473,18 @@ function tiaSfcFixtures(): array
|
||||
"<script setup>\nimport A from '@/A.vue'\nconst hint = 'export default'\n</script>",
|
||||
['imports' => ['@/A.vue'], 'moduleType' => 'js'],
|
||||
],
|
||||
'generic-attribute' => [
|
||||
"<script setup lang=\"ts\" generic=\"T extends Record<string, unknown>\">\nimport E from '@/E.vue'\n</script>",
|
||||
['imports' => ['@/E.vue'], 'moduleType' => 'ts'],
|
||||
],
|
||||
'generic-attribute-single-quoted' => [
|
||||
"<script setup lang='ts' generic='T extends Array<string>'>\nimport F from '@/F.vue'\n</script>",
|
||||
['imports' => ['@/F.vue'], 'moduleType' => 'ts'],
|
||||
],
|
||||
'generic-attribute-before-lang' => [
|
||||
"<script setup generic=\"K extends string, V extends Map<K, number>\" lang=\"ts\">\nimport G from '@/G.vue'\n</script>",
|
||||
['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'
|
||||
<script setup lang="ts">
|
||||
import SortableList from '../components/SortableList.vue'
|
||||
</script>
|
||||
<template><SortableList :items="[]" /></template>
|
||||
VUE);
|
||||
file_put_contents($root.'/resources/js/components/SortableList.vue', <<<'VUE'
|
||||
<script setup lang="ts" generic="T extends Record<string, unknown>">
|
||||
import { label } from './label.ts'
|
||||
defineProps<{ items: T[] }>()
|
||||
</script>
|
||||
<template><li v-for="item in items">{{ label(item) }}</li></template>
|
||||
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'],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user