Skip to content

Commit

Permalink
Workaround reference error when using async arrow functions in code (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wkwiatek authored and calesce committed Feb 22, 2017
1 parent c2d94eb commit c327cd3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ module.exports = function plugin(args) {
// class property node value is nullable
if (node.value && node.value.type === 'ArrowFunctionExpression') {
const isAsync = node.value.async;

// TODO:
// Remove this check when babel issue is resolved: https://github.com/babel/babel/issues/5078
// RHL Issue: https://github.com/gaearon/react-hot-loader/issues/391
// This code makes async arrow functions not reloadable,
// but doesn't break code any more when using 'this' inside AAF
if (isAsync) {
return;
}

const params = node.value.params;
const newIdentifier = t.identifier(`__${node.key.name}__REACT_HOT_LOADER__`);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
class Foo {
constructor() {
this.bar = async (...params) => await this.__bar__REACT_HOT_LOADER__(...params);
}

async __bar__REACT_HOT_LOADER__(a, b) {
return await b(a);
this.bar = async (a, b) => await b(a);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
class Foo {
constructor() {
this.bar = async (...params) => await this.__bar__REACT_HOT_LOADER__(...params);
}

async __bar__REACT_HOT_LOADER__(a, b) {
return await a(b);
this.bar = async (a, b) => {
return await a(b);
};
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Foo {
}

__bar__REACT_HOT_LOADER__(a = "foo") {
return `${ a }bar`;
return `${a}bar`;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Foo {
}

__bar__REACT_HOT_LOADER__({ a }, { b }) {
return `${ a }${ b }`;
return `${a}${b}`;
}

}
Expand Down

0 comments on commit c327cd3

Please sign in to comment.