Add FLOW_RUNTIME=namespace configuration
See original GitHub issueThis is a:
- Bug Report
- Feature Request
- Question
- Other
Which concerns:
- flow-runtime
- babel-plugin-flow-runtime
- flow-runtime-validators
- flow-runtime-mobx
- flow-config-parser
- The documentation website
What is the current behaviour?
The current implementation of babel-plugin-flow-runtime
allows configuration that either inlines the assertions or skips them at a compile them. This is good enough for developing a library that uses flow-runtime.
const add = (a: number, b: number): number => a + b;
is transformed to:
import t from 'flow-runtime';
const add = (a, b) => {
let _aType = t.number();
let _bType = t.number();
const _returnType = t.return(t.number());
t.param('a', _aType).assert(a);
t.param('b', _bType).assert(b);
return _returnType.assert(a + b);
};
However, it limits library author’s ability to distribute code with flow-runtime assertions. I do not want to use dependencies in production that have inlined flow-runtime assertions (for performance reasons).
What is the expected behaviour?
I’d like babel-plugin-flow-runtime
to accept a configuration that inlines a conditional runtime assertion, e.g.
{
"plugins": [["flow-runtime", {
"assert": "applaudience:showtime-api"
}]]
}
would produce code:
import t from 'flow-runtime';
const add = (a, b) => {
if (process.env.FLOW_RUNTIME && process.env.FLOW_RUNTIME.startsWith('applaudience:showtime-api')) {
let _aType = t.number();
let _bType = t.number();
const _returnType = t.return(t.number());
t.param('a', _aType).assert(a);
t.param('b', _bType).assert(b);
return _returnType.assert(a + b);
} else {
return a + b;
}
};
This is a mock implementation. A real-life implementation would follow the
debug
conventions.
This way, I could distribute all my codes with inlined flow-runtime
assertions that users could enable when debugging issues the same way that debug
is being used, e.g.
FLOW_RUNTIME=applaudience:* node ./index.js
would enable runtime type assertions for all dependencies under the “applaudience” namespace.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
here we go: https://github.com/codemix/babel-plugin-conditional
@phpnode Have you seen this article? It pretty much resolves the conditional plugin issues.