tc39 / proposal-export-default-from

Proposal to add `export v from "mod";` to ECMAScript.
https://tc39.github.io/proposal-export-default-from/
306 stars 12 forks source link

[Q] Breaking change? #2

Open nicolo-ribaudo opened 6 years ago

nicolo-ribaudo commented 6 years ago

This proposal disallows export default from; (which is valid ES2017 code). Is it intentional? Ref: https://github.com/babel/babel/pull/7309

jdalton commented 6 years ago

With from being a binding. That's a super cool find! \cc @benjamn

benjamn commented 6 years ago

I think the decision to forbid export default from is a bug in the spec text, and in general I am opposed to introducing syntax gotchas like this one. Both of the other forbidden tokens are reserved words: function and class, so forbidding them has no drawback.

The only argument I can imagine for disallowing this production, despite the breaking change that it represents, is that the following syntaxes still work:

export { from as default }
export default (0, from)

Of course, that still leaves the objection that export default from was legal before/without this proposal.

Disambiguating export default from <any token other than a string literal> from export default from "module" just requires more lookahead, right?

Do newlines create a problem?

export default from
"just a string literal expression statement?"

This ambiguity is not fatal; we just need to decide what it means. My preference would be to avoid making newlines meaningful, so the above code would be a single export default from "module" declaration, rather than export default from followed by a string literal expression statement.

hax commented 5 years ago

This ambiguity is not fatal; we just need to decide what it means. My preference would be to avoid making newlines meaningful, so the above code would be a single export default from "module" declaration, rather than export default from followed by a string literal expression statement.

No, you can't do that because it will change the semantic of current valid code, aka. breaking change.

The only option is keep treating it as

export default from // <-- ASI
"just a string literal expression statement?"
ExE-Boss commented 5 years ago

I wish JavaScript required semicolons, as that would’ve made many things unambiguous.

hax commented 5 years ago

@ExE-Boss

var exp; do exp; // do expression proposal? while (0) console.log('ok'); // ASI without line break!!


- The problems are historical design decisions which cause ASI hazards or potential ASI hazards, not the design of optional semicolon itself. There are many other languages also use optional semicolon, but works fine.
- (Controversially, but many programmers, include me, believe that) leading-semicolon coding style is easier and less error than semicolon-always coding style, especially in the situation that u do not have linter on the hand.