Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken hoisted variable #103

Open
ccorcos opened this issue Jun 26, 2017 · 3 comments
Open

Broken hoisted variable #103

ccorcos opened this issue Jun 26, 2017 · 3 comments

Comments

@ccorcos
Copy link

ccorcos commented Jun 26, 2017

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
	}
@motiz88
Copy link
Owner

motiz88 commented Jun 26, 2017

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.

@ccorcos
Copy link
Author

ccorcos commented Jun 26, 2017

		"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
Copy link
Author

ccorcos commented Jun 26, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants