babel: [Bug] plugin-transform-block-scoping: Cannot read property 'bindings' of null
Choose one: is this a bug report or feature request?
Log:
james@LAPTOP-UP0DKQSC ~/code/winescan/Stopwatch
$ yarn test
yarn run v1.5.1
$ jest
FAIL __tests__\App.js
● Test suite failed to run
TypeError: Cannot read property 'bindings' of null
at Scope.moveBindingTo (node_modules/@babel/traverse/lib/scope/index.js:923:13)
at BlockScoping.updateScopeInfo (node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:364:17)
at BlockScoping.run (node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:330:12)
at PluginPass.BlockStatementSwitchStatementProgram (node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:70:24)
at newFn (node_modules/@babel/traverse/lib/visitors.js:223:21)
at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:64:19)
at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:38:17)
at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:99:12)
at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:135:18)
at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:94:19)
Input Code
import 'react-native';
import React from 'react';
import App from '../App';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(<App />).toJSON();
expect(tree).toMatchSnapshot();
});
Babel/Babylon Configuration (.babelrc, package.json, cli command)
{
"presets": ["react-native"]
}
Possible Solution
I did a bit of manual digging through the code. The problem is that here, parentScope
is null. parentScope
is initialized here. Over here, where updateScopeInfo
was called, we make some checks before calling the method to ensure that the parent is a function/program node.
It seems like the code in the last URL should be changed:
// this is a block within a `Function/Program` so we can safely leave it be
- if (t.isFunction(this.parent) || t.isProgram(this.block)) {
+ if (t.isFunction(this.parent) || t.isProgram(this.parent)) {
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 28 (14 by maintainers)
Hey @jamesqo! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we’re a limited number of volunteers, so it’s possible this won’t be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.
@Tauka you’ll want to use
@babel/preset-env
(env, which is babel-preset-env will load the old v6 versions)Here’s a one liner to reproduce the issue.
Running with
7.0.0-beta.44
:produces:
@ArtemGovorov your stack trace also hints at mixing v7 and v6:
and
(Note the things in bold)
@existentialism Problem solved, thank you!
@existentialism Thanks for your help! I have solved this issue a few days ago, and I can finally link to github today…… this is my suggestions: