Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 12, 2025

The build process was incorrectly triggering warnings when comments in .svelte files mentioned export const trailingSlash or other page options. This happened because the regex pattern used to detect page option exports didn't account for JavaScript/HTML comments.

For example, this code would incorrectly trigger a warning:

<script>
  // This comment mentions export const trailingSlash = "always"
  console.log('Hello world');
</script>

The warning would show:

src/routes/+page.svelte
`export const trailingSlash` will be ignored — move it to +page(.server).js/ts instead.

This fix adds an is_within_comment() helper function in a new comment_utils.js file that robustly checks if regex matches occur within:

  • Single-line comments (//)
  • Multi-line comments (/* */)
  • HTML comments (<!-- -->)

The implementation properly handles edge cases like comment delimiters appearing within strings (e.g., "/*"; export const trailingSlash = "always"; "*/") by tracking string boundaries and escape sequences.

The solution is minimal and surgical - it preserves the existing regex but adds a validation step to exclude matches found within comments. All existing functionality remains unchanged while eliminating false positive warnings.

Fixes #13781.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Aug 12, 2025
Copy link
Contributor Author

Copilot AI commented Aug 12, 2025

@eltigerchino 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@changeset-bot
Copy link

changeset-bot bot commented Aug 12, 2025

🦋 Changeset detected

Latest commit: 1e6c0ed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

@teemingc teemingc marked this pull request as ready for review August 12, 2025 04:34
@teemingc teemingc marked this pull request as draft August 12, 2025 04:35
Copilot AI changed the title [WIP] Build warning incorrectly triggered by comment mentioning trailingSlash in +page.svelte Fix build warning incorrectly triggered by comments mentioning trailingSlash Aug 12, 2025
Copilot AI requested a review from teemingc August 12, 2025 04:46
Copilot finished work on behalf of teemingc August 12, 2025 04:46
* @param {number} matchIndex - The index where the match starts
* @returns {boolean} - True if the match is within a comment
*/
function isWithinComment(content, matchIndex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't duplicate the functions here. You should export a utility function that checks the content and re-use the function between the test and the original file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I've extracted the is_within_comment function to a new comment_utils.js file and updated both the main code and tests to use the exported utility. The function is no longer duplicated. Commit: f29b350

@teemingc teemingc changed the title Fix build warning incorrectly triggered by comments mentioning trailingSlash fix: avoid warning if they belong to a comment Aug 12, 2025
@teemingc teemingc changed the title fix: avoid warning if they belong to a comment fix: avoid warning if page options in a Svelte file belongs to a comment Aug 12, 2025
@Rich-Harris
Copy link
Member

@copilot a few things:

  • you duplicated the function between vite/index.js and vite/index.spec.js which defeats the object of a test
  • put these helpers in a new file, don't clutter up vite/index.js
  • the implementation isn't robust — it gives the wrong answer for "/*"; export const trailingSlash = 'always'; "*/"
  • use snake_case for variable/function names, not camelCase
  • run pnpm format and pnpm check inside packages/kit after making any changes

Copy link
Contributor Author

Copilot AI commented Aug 12, 2025

@copilot a few things:

  • you duplicated the function between vite/index.js and vite/index.spec.js which defeats the object of a test
    ...

All feedback addressed in commit f29b350:

✅ Extracted comment detection to new comment_utils.js file
✅ Removed function duplication between main and test files
✅ Implemented robust parsing that handles the edge case "/*"; export const trailingSlash = 'always'; "*/"
✅ Used snake_case naming (is_within_comment)
✅ Ran pnpm format and pnpm check - all passing

The new implementation properly handles strings, escape sequences, and all comment types while correctly identifying when exports are truly within comments vs. when comment delimiters appear in strings.

Copilot AI requested a review from Rich-Harris August 12, 2025 13:12
Copilot finished work on behalf of Rich-Harris August 12, 2025 13:12
@Rich-Harris Rich-Harris marked this pull request as ready for review August 12, 2025 13:52
@Rich-Harris Rich-Harris merged commit 81e4314 into main Aug 12, 2025
21 checks passed
@Rich-Harris Rich-Harris deleted the copilot/fix-13781 branch August 12, 2025 16:41
@github-actions github-actions bot mentioned this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build warning incorrectly triggered by comment mentioning trailingSlash in +page.svelte

3 participants