Live data from Hacker News

ECMAScript 2016+ in Firefox

blog.mozilla.org

81–90 of 93 posts

Re: ECMAScript 2016+ in Firefox

#81
post #76
post #34

Earlier quoted context omitted.

Yep and with Babel we recommend using https://github.com/babel/babel-preset-env to compile only what's missing in the targets you support. Hopefully we have a better solution about making multiple bundles (separate one for IE) soon

I'm currently experimenting with if-no-window.Promise-then-polyfill via polyfill.io (I dont quite trust synchronous dynamic script loading yet, but we'll see if that's robust enough on old browsers). Sure, old browsers need an extra roundtrip, and it's an additional point of failure - but it simplifies dev tooling, and if your users actually cared about perf, they wouldn't be using ancient browsers. It won't fix many…

> if your users actually cared about perf, they wouldn't be using ancient browsers.

Many of them do care, but not the IT department that vets their machines.

Re: ECMAScript 2016+ in Firefox

#82
post #81
post #76

Earlier quoted context omitted.

I'm currently experimenting with if-no-window.Promise-then-polyfill via polyfill.io (I dont quite trust synchronous dynamic script loading yet, but we'll see if that's robust enough on old browsers). Sure, old browsers need an extra roundtrip, and it's an additional point of failure - but it simplifies dev tooling, and if your users actually cared about perf, they wouldn't be using ancient browsers. It won't fix many…

> if your users actually cared about perf, they wouldn't be using ancient browsers. Many of them do care, but not the IT department that vets their machines.

There are pros and cons there. The overhead isn't huge; if you use any ads whatsoever those likely swamp this effect anyhow. And dev time is limited - how much time is it worth shaving at best 100ms off for a small and shrinking group of clients? It's cacheable, so it's a not a commonly recurring delay, and it's likely to be a lot smaller on decent networks. (https://tools.keycdn.com/ping puts the worst ping as being from tokyo at 84ms; many are sub-ms as you might expect from a cdn).

I think it's (potentially) a better tradeoff than making most clients pay for larger bundle sizes even though they don't need it.

But well: tradeoffs.

Re: ECMAScript 2016+ in Firefox

#83
post #70
post #68

Earlier quoted context omitted.

ES6 modules are great because they're statically analysable, whilst CommonJS modules aren't.

just parse it like any other js code

By that do you mean you can 'just parse' CommonJS modules?

(If so) CommonJS allows you to dynamically alter module.exports anywhere within your module. You can't determine what those exports are just by parsing, you'd need to execute the code.

Re: ECMAScript 2016+ in Firefox

#84
post #83
post #70

Earlier quoted context omitted.

just parse it like any other js code

By that do you mean you can 'just parse' CommonJS modules? (If so) CommonJS allows you to dynamically alter module.exports anywhere within your module. You can't determine what those exports are just by parsing, you'd need to execute the code.

> CommonJS allows you to dynamically alter module.exports anywhere within your module

It's certainly a risk, but that isn't a common practice.

Re: ECMAScript 2016+ in Firefox

#85
post #84
post #83

Earlier quoted context omitted.

By that do you mean you can 'just parse' CommonJS modules? (If so) CommonJS allows you to dynamically alter module.exports anywhere within your module. You can't determine what those exports are just by parsing, you'd need to execute the code.

> CommonJS allows you to dynamically alter module.exports anywhere within your module It's certainly a risk, but that isn't a common practice.

There's also ...

  if(Math.round(Math.random()) === 1) {
    export let foo = bar; // have fun debugging!
  }
I think it would also be fine to execute modules to see what's in module.exports, while some modules might have side effects like writing to /etc/passwd without calling any method, it's not the norm.

Re: ECMAScript 2016+ in Firefox

#86
post #68
post #63

Earlier quoted context omitted.

Es6 modules suck because they will litter the global scope, while commonjs/nodejs modules can be required locally.

ES6 modules are great because they're statically analysable, whilst CommonJS modules aren't.

You can statically analyze CommonJS modules (and they are most often used in a statically optimizable way), they just aren't statically optimizable in the general case.

Re: ECMAScript 2016+ in Firefox

#87
post #85
post #84

Earlier quoted context omitted.

> CommonJS allows you to dynamically alter module.exports anywhere within your module It's certainly a risk, but that isn't a common practice.

There's also ... if(Math.round(Math.random()) === 1) { export let foo = bar; // have fun debugging! } I think it would also be fine to execute modules to see what's in module.exports, while some modules might have side effects like writing to /etc/passwd without calling any method, it's not the norm.

> There's also ... [...]

(I assume you meant to write your example in CommonJS style, because that's not valid a ES6 export, they must be top-level).

Doesn't your example highlight exactly why even executing the code wouldn't even help you there?

Re: ECMAScript 2016+ in Firefox

#88
post #84
post #83

Earlier quoted context omitted.

By that do you mean you can 'just parse' CommonJS modules? (If so) CommonJS allows you to dynamically alter module.exports anywhere within your module. You can't determine what those exports are just by parsing, you'd need to execute the code.

> CommonJS allows you to dynamically alter module.exports anywhere within your module It's certainly a risk, but that isn't a common practice.

The fact it's allowed at all is the problem though, and precisely why ES6 modules are superior.

Re: ECMAScript 2016+ in Firefox

#89
post #87
post #85

Earlier quoted context omitted.

There's also ... if(Math.round(Math.random()) === 1) { export let foo = bar; // have fun debugging! } I think it would also be fine to execute modules to see what's in module.exports, while some modules might have side effects like writing to /etc/passwd without calling any method, it's not the norm.

> There's also ... [...] (I assume you meant to write your example in CommonJS style, because that's not valid a ES6 export, they must be top-level). Doesn't your example highlight exactly why even executing the code wouldn't even help you there?

Didn't know you could only export at the global scope. Wanted to show that you could do stupid, hard to analyze things in ES6 modules too. But maybe you can't !? Although I don't want a committee to not only decide what is stupid or not, but also hard code it into the spec so I can't do some things even if I have very good reasons to. Like being able to require modules locally to make the code easier to reason about, and easier to delete, copy, share, reuse and manage. It's what made NodeJS so popular, because it's so easy to use, reuse and share modules.

Re: ECMAScript 2016+ in Firefox

#90
post #89
post #87

Earlier quoted context omitted.

> There's also ... [...] (I assume you meant to write your example in CommonJS style, because that's not valid a ES6 export, they must be top-level). Doesn't your example highlight exactly why even executing the code wouldn't even help you there?

Didn't know you could only export at the global scope. Wanted to show that you could do stupid, hard to analyze things in ES6 modules too. But maybe you can't !? Although I don't want a committee to not only decide what is stupid or not, but also hard code it into the spec so I can't do some things even if I have very good reasons to. Like being able to require modules locally to make the code easier to reason about,…

> Wanted to show that you could do stupid, hard to analyze things in ES6 modules too. But maybe you can't !?

You can't, at least not in this way. A module's imported and exported names are statically determined. Of course, you can just export a single object, and then make that object arbitrarily complex depending on runtime behavior.

> Like being able to require modules locally

Not sure what this means.

Post reply on HN