babel-plugin-transform-async-to-promises
babel-plugin-transform-async-to-promises copied to clipboard
Breaks "this" in class expressions
Excerpt from babel-jest.config.js:
plugins: [
'@userlike/babel-plugin-joke',
[
'module-resolver',
{
root: [repositoryRoot],
alias: {
/**/
},
cwd: repositoryRoot,
},
],
['@babel/plugin-proposal-decorators', { legacy: true }],
'@babel/plugin-proposal-class-properties',
['babel-plugin-transform-async-to-promises', { inlineHelpers: true }],
'babel-plugin-macros',
],
presets: [
'@babel/preset-typescript',
'@babel/preset-react',
['@babel/preset-env', { targets: { node: 16 } }],
],
Simplified source file file: test.ts
it('is a simplified test', async () => {
customFunctionMap[identifier] = coercePartial<
ClassType<FunctionCallBase> & VelixoFunctionStatic
>(
class {
public constructor(private readonly _group: string) {}
public static readonly shouldClusterComputations = true;
public getInvocationClusterKey = (): string => this._group; // here!
}
);
const result = new classVariable("group");
Resulting file:
it('...', _async(function () {
var _class;
_customFunctionMap.customFunctionMap[identifier] = (0, _coercePartial.coercePartial)((_class = class {
constructor(_group) {
this._group = _group;
this.getInvocationClusterKey = () => _this._group; // note "_this" is renamed unnecessarily here
}
}, _class.shouldClusterComputations = true, _class));
I verified that it does not happen when I remove the plugin from the plugins list.