\' in a Double-Quoted String Is Refused

Status: refused by design

"\'" is not FunctionalScript. "\'" is valid JavaScript, and fjs compile refuses it by design: the demo below shows what it prints.

A double-quoted string is a JSON string in FunctionalScript, so that a JSON document is a module's value as it stands, and JSON has no \' escape. JavaScript reads "\'" as "'"; FunctionalScript refuses the escape, and the apostrophe is written as itself, or escaped in a single-quoted string (strings).

The row lit.double-quoted-apostrophe of refused constructs registers the refusal, and strings gives its reason.

Examples

export default "\'";

The demo on this page compiles sample.mjs, the module above, with this build's fjs compile, and shows the line it prints and the token it refuses. Below that it shows what JavaScript answers for the same module: '.

What to Write Instead

Write the apostrophe as itself, as alternative.f.js does:

export default "'";

It answers '.

A Better Message

Today fjs compile prints unexpected token at the refused token. The demo proposes what it should print instead: the reason at the same token, what JavaScript does there, and the allowed spelling, the line alternative.f.js writes, as help. The page compiles the alternative too, so the suggestion is one the compiler accepts.

Reference

Demo

Not allowed in FunctionalScript

This is valid JavaScript, and fjs compile refuses it, by design: it is not a FunctionalScript module.

What fjs compile sample.mjs output.js prints:

sample.mjs:1:16-2:1 - error: unexpected token
1 | export default "\'";
  |                ^

What it should print instead, pointing to what FunctionalScript allows (proposed):

sample.mjs:1:16 - error: `\'` is not an escape of a double-quoted string: FunctionalScript keeps those JSON strings
1 | export default "\'";
  |                ^^^^ JavaScript reads this as `"'"`
  = help: write the apostrophe as itself:
          export default "'";
  = note: refused by design, see spec/values/strings/apostrophe-escape/README.md

JavaScript source, sample.mjs:

export default "\'";

What JavaScript answers for the same module, its default export:

'

What to write instead

The FunctionalScript spelling, alternative.f.js:

/**
 * The FunctionalScript spelling of [`sample.mjs`](./sample.mjs): the apostrophe, written as itself
 * ([`README.md`](./README.md)).
 *
 * @module
 */

export default "'";

What fjs compile alternative.f.js output.js writes:

export default "'";

What it answers, its default export:

'

Emergent Testing

Idle. Press Run to start the suite.

  • ./proof.f.mjs