proposal-export-default-from icon indicating copy to clipboard operation
proposal-export-default-from copied to clipboard

[Q] Breaking change?

Open nicolo-ribaudo opened this issue 7 years ago • 5 comments

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

nicolo-ribaudo avatar Feb 09 '18 08:02 nicolo-ribaudo

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

jdalton avatar Feb 09 '18 08:02 jdalton

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.

benjamn avatar Feb 10 '18 15:02 benjamn

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?"

hax avatar Oct 04 '19 06:10 hax

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

ExE-Boss avatar Oct 04 '19 08:10 ExE-Boss

@ExE-Boss

  • We can't change the rules now. (Theoretically we could change some rules if no one rely on that, for example maybe there is no real code like
export default from
"string literal"

exist in the world...but who knows?

  • Even enforce semicolons there are still ambiguous in the language, for example:
return 
  {a: 1};

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.

hax avatar Oct 12 '19 03:10 hax