babel-plugin-transform-hoist-nested-functions
babel-plugin-transform-hoist-nested-functions copied to clipboard
Broken hoisted variable
I get an error that result is not defined.
class Storage {
// lru calls this callback synchronously
public get(key: string): Value | null {
let result: Value
lru.getItem(this.makeKey(key), this.getOptions, (err, value) => {
result = value
})
return result
}
Thanks @ccorcos! I'll look into it this weekend. I'll have to jog my memory as to how this plugin even works tbh. Would appreciate a listing of Babel versions and any other plugins that are in play here.
"babel-core": "6.22.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-hoist-jsx-style": "^1.0.0",
"babel-plugin-transform-hoist-nested-functions": "^1.2.0",
"babel-plugin-transform-react-constant-elements": "6.22.0",
"babel-plugin-transform-react-inline-elements": "6.22.0",
"babel-preset-es2015": "6.22.0",
"babel-preset-react": "6.22.0",
This was my config:
plugins: [
"transform-react-inline-elements",
"transform-react-constant-elements",
[
"transform-hoist-nested-functions",
{
methods: true,
},
],
"transform-class-properties",
"transform-hoist-jsx-style",
],
And everything worked when I took out your plugin.
I get this error even without the methods option:
plugins: [
"transform-react-inline-elements",
"transform-react-constant-elements",
"transform-hoist-jsx-style",
"transform-hoist-nested-functions",
// "transform-class-properties",
],
Looks like its pulling out that callback function without realizing that it accesses a hoisted variable right there.