question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question babel-plugin-flow-runtime: overwrite assert: false

See original GitHub issue

According to the documentation assert: true should be turned off during production builds.

For an UMD library with an public API it would be beneficial if assertions could be scoped to specific public methods. That would allow getting the the benefits of run time type checking for the library consumer without getting the overall performance penalty.

Here’s an example, where I’d like to get assertions for the public filter method (taken from a tcomb babel-plugin-transform-flow-strip-types implementation).

...
const FilterLogic = enums.of(['or', 'and'], 'FilterLogic')

type FilterExpression = {
  field: string,
  operator: string,
  value: any
}

type FilterGroup = {
  logic: FilterLogic,
  filters: Array<FilterExpression | FilterGroup>
}

export default class Collections {
...

// Would it be possible to turn on assertion for .filter?
// maybe by using a decorator like @guarded?
  filter (options?: FilterGroup) {
    if (!options) {
      return toJS(this.$filter)
    }
    this.$filter = options
    this.data = []

    return this.read()
  }
...
}


Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
phpnodecommented, Jan 12, 2017

Added pragma like // @flow-runtime assert, decorate and suppression types / comments in v0.0.7, docs here - https://codemix.github.io/flow-runtime/#/docs/pragmas

0reactions
RainerAtSpiritcommented, Jan 12, 2017

This looks excellent. Thanks for adding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Better alternatives to assert(false) in C/C++ - Stack Overflow
My compiler recognizes that the program finishes once assert(false) has been reached. However, whenever I compile with -DNDEBUG for ...
Read more >
Python's assert: Debug and Test Your Code Like a Pro
In this tutorial, you'll learn how to use Python's assert statement to document, debug, and test code in development.
Read more >
Programming With Assertions - Oracle Help Center
An assertion is a statement in the Java programming language that enables ... Another problem with using assertions for argument checking is that...
Read more >
console.assert() - Web APIs | MDN
The console.assert() method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.
Read more >
Throw error if condition false - MATLAB assert - MathWorks
Error using assert Assertion failed. The expression evaluates as false. The assertion fails and MATLAB throws an error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found