baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript

Home Page:https://baconjs.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fully asserted build

phadej opened this issue · comments

We could have the Bacon.js build with all runtime-checkable preconditions (e.g. parameter should be a function or a stream) asserted. We already have assert* we strip for production build. But we can assert more.

Related: #568

Could the asserts use environment variables like React does? This would make it easier to have asserts in your development build, but strip them away in production with envify.

@lautis I'd rather write:

function foo(stream) {
  assertStream(stream);
  // ...
}

function assertStream(stream) {
  if (process.env.NODE_ENV === "development") {
    assert(stream instanceof EventStream):
  }
}
function foo(stream) {
  if (process.env.NODE_ENV === "development") {
    assertStream(stream):
  }
}

function assertStream(stream) {
  assert(stream instanceof EventStream);
}

If envify + uglify can minify the former version, than why so not. Actually if one could mark functions to be inlined by uglify (or something else), that would be awesome.

Sorry, to lazy to try myself.

UglifyJS isn't able to remove calls to empty functions nor does it have inlining. To remove all traces of asserts with envify/uglifyjs, the latter form would have to be used. However, we could add guards to assert calls in assemble.js or let JS compilers optimise away empty functions.