babel-plugin-transform-hoist-nested-functions icon indicating copy to clipboard operation
babel-plugin-transform-hoist-nested-functions copied to clipboard

Broken hoisted variable

Open ccorcos opened this issue 7 years ago • 3 comments

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
	}

ccorcos avatar Jun 26 '17 20:06 ccorcos

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.

motiz88 avatar Jun 26 '17 20:06 motiz88

		"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.

ccorcos avatar Jun 26 '17 20:06 ccorcos

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.

ccorcos avatar Jun 26 '17 20:06 ccorcos