baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript
https://baconjs.github.io
MIT License
6.47k stars 330 forks source link

Fully asserted build #569

Open phadej opened 9 years ago

phadej commented 9 years ago

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: https://github.com/baconjs/bacon.js/issues/568

lautis commented 9 years ago

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.

phadej commented 9 years ago

@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.

lautis commented 9 years ago

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.