endojs / Jessie

Tiny subset of JavaScript for ocap-safe universal mobile code
Apache License 2.0
281 stars 16 forks source link

trailing commas? #38

Closed dckc closed 4 years ago

dckc commented 4 years ago

This came up while trying to parse automaticRefund.js from the Zoe docs.

The other tweaks seem to be captured in issues already...

const ast3 = jessie`
const makeContract = harden((zoe, terms) => {
  let count = 0;
  const automaticRefund = harden({
    makeOffer: escrowReceipt => {
      const { offerHandle } = zoe.burnEscrowReceipt(escrowReceipt);
      count += 1;
      zoe.complete(harden([offerHandle]));
      return "The offer was accepted";
    },
    getOffersCount: () => count
  });
  return harden({
    instance: automaticRefund,
    assays: terms.assays
  });
});
`;
Chris-Hibbert commented 4 years ago

I don't get it. What/Who is suggesting that trailing commas are an issue?

There are two trailing commas in this fragment, and one that looks like it's missing and would be required by eslint if this weren't embedded in a string.

I'm still learning javascript, but it looks like the comma following makeOffer is required, as is the one following instance. Eslint would ask for another one after assays.

So who was complaining about what here?

dckc commented 4 years ago

The automaticRefund example follows the airbnb eslint style, which is to use trailing commas in order to minimize diffs and such. I agree this is good JS style.

The version of the jessie grammar I was testing against didn't allow trailing commas; I think it was influenced by JSON, which does not allow trailing commas. For example, in my browser console:

> JSON.parse("{\"x\": 1,}")
VM129:1 Uncaught SyntaxError: Unexpected token } in JSON at position 8

I gather that grammar I was testing against is obsolete in favor of quasi-jessie.js.ts in jessica

I worked with @michaelfig to set up a sort of REPL environment for using that grammar: https://repl.it/@dckc/jessica-safe-mobile-code

So I can see that this grammar allows trailing commas. I suppose I could close this issue based on that evidence, but I'd prefer to hear from somebody like @erights . Better yet, I'd like to see a test case added to a Jessie test suite.

erights commented 4 years ago

I'd prefer to hear from somebody like @erights

Because this syntactic pattern should be encouraged, the Jessie grammar should allow trailing commas. I'm glad it does.

erights commented 4 years ago

I worked with @michaelfig to set up a sort of REPL environment for using that grammar: https://repl.it/@dckc/jessica-safe-mobile-code

I don't understand what I'm looking at there or how to interact with it. Please?

michaelfig commented 4 years ago

I resurrected my old in-browser Jessica runner, and added a Parse button to generate an AST.

You can play with it at: https://jessica.fig.org/jessie-frame/

michaelfig commented 4 years ago

Moved to: https://jessica.agoric.com/jessie-frame/