Skip to content

Conversation

@tgriesser
Copy link
Contributor

@tgriesser tgriesser commented Oct 31, 2025

Ran into a situation recently where code was working in development, but then exhibited different behavior after the code was run through a minifier. Narrowed it down to the is.class check, which incorrectly assumes there is always trailing whitespace after the class keyword. In a class expression with an anonymous class, class{... is valid syntax.

I initially tried adding the failing test case to test/test.ts but it seems the tsimp is somehow modifying the source and that the whitespace is re-added after the class keyword. I didn't dig into it, and instead added a test/test-node.js with a note about why it was needed.

Edit: Thought of another way to keep the whitespace from being mangled in transpilation, returning the class from a Function constructor. This way there's no .js / separate files for the tests.

@sindresorhus sindresorhus merged commit e7c84fc into sindresorhus:main Oct 31, 2025
1 check passed
@tgriesser tgriesser deleted the tgriesser/fix/is-class-minified branch November 1, 2025 19:33
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.

2 participants