Open sazzer opened 7 years ago
As a workaround, if I user the individual plugins instead of the preset I can make it work. I have to have a configuration of:
{
"sourceMap": true,
"presets": [
"latest"
],
"plugins": [
"babel-plugin-empower-assert",
"babel-plugin-espower",
"rewire",
"transform-runtime"
]
}
And now that same line is converted into:
_get__('assert')(_rec._expr(_rec._capt(_rec._capt(adder(_rec._capt(a, 'arguments/0/left/arguments/0'), _rec._capt(b, 'arguments/0/left/arguments/1')), 'arguments/0/left') === 5, 'arguments/0'), {
content: 'assert(adder(a, b) === 5)',
filepath: 'src/server/demo.test.js',
line: 12
}));
I assume that what is happening is babel-plugin-rewire is being applied before the babel-preset-power-assert, and so the plugins from the preset aren't finding the code they expect - because it's already been re-written - and so they are failing to do the conversion.
@sazzer Thanks for your report and sorry for the late reply. I think the problem is not very easy to resolve, as it might seem to be a an ordering issue.
babel plugin rewire replaces assert with get('assert') which itself returns the assert variable with a function returning the assert variable. I think this destroys your logic to detect, whether to use the power assert conversion.
The workaround with explicitly specifying the execution order is therefore a viable solution. An alternative approach is to specifiy assert in the list of ignoredIdentifiers. This should prevent assert from being rewired at all.
An alternative approach would be to trace the assert variable, but imho I think this is impossible.
I've no idea if this is a problem in babel-plugin-rewire or babel-preset-power-assert, but if I have both in my build at the same time then babel-plugin-rewire works and babel-preset-power-assert doesn't do anything.
With my Babel configuration looking like:
Then the following transformation happens:
into
But when I add babel-plugin-rewire in to the build, as such:
Then the exact same line is transformed into