-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Incorrect bundle behavior when IIFE #1837
Comments
|
As far as I can tell, the problem is caused by strict mode vs. sloppy mode, which is caused by the function notStrict() { return this }
function strict() { 'use strict'; return this }
console.log(notStrict.apply('foo'), strict.apply('foo')) Sloppy mode requires the value for You can get this code to work even with the It may not be straightforward to automatically solve this in esbuild's case because strict mode infects all scopes inside it by design, and not all code that esbuild bundles can be run in strict mode. And esbuild's scope-flattening bundling approach combines scopes from different files with potentially different strict mode settings. I suppose I could potentially insert |
This is due to a statement incorrectly inserted before strict mode directive: // node_modules/.pnpm/@[email protected]/node_modules/@babel/types/lib/utils/shallowEqual.js
var require_shallowEqual = __commonJS({
"node_modules/.pnpm/@[email protected]/node_modules/@babel/types/lib/utils/shallowEqual.js"(exports) {
init_shims();
"use strict"; // directives must appear before any other statements in the block |
Reproduce
esm.html
andiife.html
Source
Expected
ESM context output
Unexpected
iife context output
The text was updated successfully, but these errors were encountered: