A Guarded Namespace Is Refused

Status: refused by design

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

Object is a namespace, not a value: the language reads Object.is and Object.entries as the static functions they name. A guard asks whether a value is null or undefined, and a namespace is never either, so Object?.is and Object?.["is"] are refused at the word. Guarding the function is a call of a value, and stays: Object.is?.(a, b) (static functions).

The row acc.guarded-namespace of refused constructs registers the refusal, and built-in static functions gives its reason.

Examples

export default Object?.is(1, 1);

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

What to Write Instead

Read the static function without the guard, as alternative.f.js does:

export default Object.is(1, 1);

It answers true.

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:16 - error: reserved word
1 | export default Object?.is(1, 1);
  |                ^

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

sample.mjs:1:16 - error: `Object` is a namespace, not a value: there is nothing to guard
1 | export default Object?.is(1, 1);
  |                ^^^^^^ JavaScript checks the global `Object` for `null` here
  = help: read the static function without the guard:
          export default Object.is(1, 1);
  = note: refused by design, see spec/built-ins/static-functions/guarded/README.md

JavaScript source, sample.mjs:

export default Object?.is(1, 1);

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

true

What to write instead

The FunctionalScript spelling, alternative.f.js:

/**
 * The FunctionalScript spelling of [`sample.mjs`](./sample.mjs): the static function, read without a guard
 * ([`README.md`](./README.md)).
 *
 * @module
 */

export default Object.is(1, 1);

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

const $0=Object.is;export default $0(1,1);

What it answers, its default export:

true

Emergent Testing

Idle. Press Run to start the suite.

  • ./proof.f.mjs