-
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
With target=chrome99, code with var is generated #2267
Comments
One reason I’m using Another reason is because sometimes bundling needs to lazily-initialize a module and, when that module is in ESM format, the top-level symbols are separated from their initializers. This means Note that when esbuild turns |
First of all thanks for the detailed reply! I actually thought that was because of a config issue on my end. (Maybe something to add as a sidenote in the docs). Its pretty surprising to hear // esbuild
(()=>{var e=(s,o)=>()=>(o||s((o={exports:{}}).exports,o),o.exports);var h=e((r,t)=>{t.hot&&t.hot.accept();document.title="Hello World";setTimeout(()=>{document.title="Hello World 3"},1e3);var i=1,l=2,n=i+l;console.log(n);var c=[{title:"Post One",body:"This is post one"},{title:"Post Two",body:"This is post two"}],d=[...c,{title:"Post Three",body:"This is post three"}];document.body.innerHTML=d});h();})();
// looking at the unminified version of this above, seems that it's converting it to a CJS module? did I get this right? // parcel
document.title="Hello World",setTimeout((()=>{document.title="Hello World 3"}),1e3);console.log(3);const o=[{title:"Post One",body:"This is post one"},{title:"Post Two",body:"This is post two"},{title:"Post Three",body:"This is post three"}];document.body.innerHTML=o;
//# sourceMappingURL=index.cee23c50.js.map Follow-up question: any other features that are 'transpiled' on purpose? @evanw consider my initial question answered but would love a follow-up reply :) |
More info regarding your initial question: Another reason is minification. Changing
Yes. I mentioned class declarations briefly above already but they are another case that's very similar to // Before
class Foo {}
// After
var Foo = class {}; As a side effect of this transformation of class declarations, static fields may also be lowered. This is a known esbuild limitation, and is described in more detail in this comment. This is mostly irrelevant for normal static fields but it can result in lower performance of There are also some other more obscure cases. One I can think of is that esbuild automatically escapes // Before
console.log(String.raw`</script>`);
// After
var __freeze = Object.freeze;
var __defProp = Object.defineProperty;
var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
var _a;
console.log(String.raw(_a || (_a = __template(["<\/script>"])))); There may be other cases, although I can't think of any more right now. |
I'm closing this issue because there is nothing to do here, and this behavior is intentional. |
Check it out: Why shouldn't we use var in JavaScript |
That article is talking about authoring code using |
This article is terrible, how terrible? Enough for me to write the following: In the first example under "Lack of Encapsulation," he mentions that variables declared with var are accessible from anywhere within the function, but the code demonstrates accessing the variable outside the function. It would be more accurate to say that var variables are accessible from anywhere within the enclosing function scope. In the second example about hoisting, the code tries to access The fourth example about variable overriding correctly demonstrates redeclaring a variable within the same scope. However, he states that redeclaring a variable with the same name within the same scope "simply reassigns its value, without throwing an error." While reassignment occurs, it does not technically "redeclare" the variable. The fifth example about no block-level declaration shows a loop where the variable i is declared with var. The code correctly demonstrates that i is accessible outside the loop. However, he states that var lacks block-level scoping, making it harder to manage variables within specific blocks. While this is true, the example itself does not showcase the problem. |
- fix an incompatibility-issue due to esbuild's output with `String.raw` when a `"</script>"` substring is present in it. - esbuild would create a runtime function that specifically escapes the said substring. however, if multiple entrypoints are used with code-splitting enabled, then this function is imported from a common file. but as we know, our virtual javascript-code inside of the `unparseFromJs` method cannot perform an import. - the workaround is to escape any `"</script>"` substring ourselved, so that esbuild will not generate that runtime code. - see the following esbuild issue comment for more details: evanw/esbuild#2267 (comment)
I'm pretty sure this is 'expected behavior' but I don't get it, as the documentation clearly states:
The text was updated successfully, but these errors were encountered: