Binding a Literal Word Is Refused

Status: refused by design

const undefined is not FunctionalScript. const undefined = 1 is valid JavaScript, and fjs compile refuses it by design: the demo below shows what it prints.

undefined, NaN and Infinity are names in JavaScript, not keywords, so a module may bind them: after const undefined = 1, undefined is 1. FunctionalScript reads the three as the values they spell everywhere, so binding one is refused, and a reader can trust what the word means.

The row name.literal-word of refused constructs registers the refusal, and literal words gives its reason.

Examples

const undefined = 1;
export default undefined;

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: 1.

What to Write Instead

Give the constant a name of its own, as alternative.f.js does:

const one = 1;
export default one;

It answers 1.

A Better Message

Today fjs compile prints reserved word 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:7 - error: reserved word
1 | const undefined = 1;
  |       ^

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

sample.mjs:1:7 - error: `undefined` is the value it spells: FunctionalScript does not let a module bind it
1 | const undefined = 1;
  |       ^^^^^^^^^ JavaScript binds `undefined` to `1` here
  = help: give the constant a name of its own:
          const one = 1;
  = note: refused by design, see spec/bindings/literal-words/README.md

JavaScript source, sample.mjs:

const undefined = 1;
export default undefined;

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

1

What to write instead

The FunctionalScript spelling, alternative.f.js:

/**
 * The FunctionalScript spelling of [`sample.mjs`](./sample.mjs): the same constant under a name of its own
 * ([`README.md`](./README.md)).
 *
 * @module
 */

const one = 1;
export default one;

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

export default 1;

What it answers, its default export:

1

Emergent Testing

Idle. Press Run to start the suite.

  • ./proof.f.mjs