Skip to content

fix: emit "use strict" everywhere to thwart bad bundlers #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2025

Conversation

thejustinwalsh
Copy link
Contributor

When running vite as my bundler, koota is running under strict mode.
When using metro with expo dom components koota is not running under strict mode.

When this is evaluated in Number.prototype.add in strict mode it will be a number.
When this is evaluated in Number.prototype.add without strict mode, it is coerced into an object, and that object is then used as the lookup in the Set where that object is not in the Set, the valueOf that object is.

See: https://262.ecma-international.org/5.1/#sec-C
image

Philosophcally it is a slightly painful pr to make, however, if bundlers in 2025 are going to run esm code without strict mode enabled, we should help them to have a chance.

@thejustinwalsh thejustinwalsh changed the title fix: emit use strict everywhere to thwart bad bundlers fix: emit "use strict" everywhere to thwart bad bundlers May 2, 2025
@thejustinwalsh
Copy link
Contributor Author

thejustinwalsh commented May 2, 2025

Configuring metro to use experimentalImportSupport resolves this issue, and correctly emits "use strict"; in the final bundle. As of Expo SDK 53, this is not the default config.

Enable experimentalImportSupport to your metro.config.js:

config.transformer.getTransformOptions = () => ({
  transform: {
    experimentalImportSupport: true,
  },
});

It is worth noting that experimentalImportSupport doesn't currently support require cycles or destructuring.

@krispya
Copy link
Member

krispya commented May 2, 2025

Could you add a comment on this tsup setting explaining why it exists? It is okay for it to be long-winded, having documentation in the code will make Koota easier to maintain in the future.

@krispya krispya merged commit 5f9c84f into pmndrs:main May 5, 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.

2 participants