Skip to content
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

Potential hazard #10

Open
MadProbe opened this issue Mar 22, 2021 · 4 comments
Open

Potential hazard #10

MadProbe opened this issue Mar 22, 2021 · 4 comments

Comments

@MadProbe
Copy link

MadProbe commented Mar 22, 2021

const ::example = { get() { console.log(1); } }
const get = function () { console.log(2); }
const cond = Math.random() > 0.5;

cond ? null::example:get(); // How will this be parsed?
cond ? null::example:get() : get(); // and this?

(To avoid this hazard i think we can change ':' ext name operator to '.:', which seems to have no hazard at all)

cond ? null::example.:get() : get();
@ljharb
Copy link
Member

ljharb commented Mar 22, 2021

This doesn't seem ambiguous to me. The first ternary is cond ? (null::example) : get(), the second is a syntax error.

As to your suggestion, remember that 1. is legal syntax:

const ? 1.:get()

@MadProbe
Copy link
Author

MadProbe commented Mar 22, 2021

I think we could parse .: only when <value>::<symbol> pattern is encountered and your example functions as it is now, and

1 ? 1..:1

is a syntax error

@justinmchase
Copy link

Is null::example:get() a valid expression at all? Seems like it would have to be a valid expression all by itself for it to be a problem with ternaries.

@hax
Copy link
Member

hax commented Sep 4, 2021

@MadProbe This issue already be listed in the docs (https://github.com/tc39/proposal-extensions/blob/master/docs/syntax.md#syntax-ambiguity-of-abc) though I'm sorry it not listed in the repo readme page.

There are many possible solutions, .: may work, but as the author of this proposal I insist that, if we really want change token, it should be only one character. The doc I mentioned list all possible chars, and consider other factors, the alternatives are:

  • o::Ext~method()
  • o::Ext#method()
  • o::Ext'method() (to be honest, I slightly prefer this 😅)

Is null::example:get() a valid expression at all? Seems like it would have to be a valid expression all by itself for it to be a problem with ternaries.

@justinmchase Yes, it's valid. It just use null as receiver and send to example. Basically null::example:get(...args) is just the syntax sugar of Extension.from(example).invoke(null, 'get', args).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants