On Sun, Jan 13, 2019 at 6:49 PM Cyril Auburtin
<[email protected]> wrote:
>
> There's `console.assert`

The problem with that and other userland solutions is that for something
like this:

```js
assert(a !== b, `a (${a}) !== b (${b})`);
```

you have only three choices for production builds:

1. Have the asserts active in production (throwing assertion errors).

2. Have the asserts do the relevant check and process the template literal,
but not raise an error when it fails. (So `a !== b` still gets executed,
but no error is raised if it's false.)

3. Pre-process your scripts to remove the assertions

Whereas with a language-level assert, in production that entire
pseudo-function-call would be parsed but then completely ignored, including
the `a !== b` and evaluating the template. And ideally, with a
language-level feature, even when assertions are enabled, the template
would only be evaluated if the assertion failed, as though you'd written:

```js
if (a !== b) {
    throw new AssertionError(`a (${a}) !== b (${b})`);
}
```

-- T.J. Crowder
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to