Error getting Hyperclick suggestion: TypeError: Cannot read property 'file' of undefined, coming from babel-core traversal internals
See original GitHub issueThe following exception is caught by the Atom hyperclick
package which serves as the base for the Atom js-hyperclick
package.
/Users/sompylasar/.atom/packages/hyperclick/lib/HyperclickForTextEditor.js:259 Error getting Hyperclick suggestion: TypeError: Cannot read property 'file' of undefined
at Scope.checkBlockScopedCollisions (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/scope/index.js:412:21)
at Scope.<anonymous> (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/scope/index.js:594:18)
at Scope.registerBinding (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/scope/index.js:608:8)
at Scope.registerDeclaration (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/scope/index.js:537:14)
at NodePath.Declaration (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/scope/index.js:83:36)
at NodePath.call (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/path/context.js:56:28)
at NodePath.visit (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/path/context.js:90:8)
at TraversalContext.visitMultiple (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/context.js:108:16)
at TraversalContext.visit (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/context.js:146:19)
at Function.traverse.node (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/index.js:76:17)
at Object.traverse [as default] (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/index.js:55:14)
at NodePath.traverse (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/path/index.js:163:23)
at Scope.crawl (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/scope/index.js:821:10)
at Scope.init (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/scope/index.js:737:32)
at NodePath.setScope (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/path/context.js:149:30)
at NodePath.setContext (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/path/context.js:168:8)
at NodePath.unshiftContext (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/path/context.js:273:8)
at TraversalContext.create (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/context.js:74:10)
at TraversalContext.visitSingle (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/context.js:131:23)
at TraversalContext.visit (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/context.js:148:19)
at Function.traverse.node (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/index.js:76:17)
at traverse (/Users/sompylasar/.atom/packages/js-hyperclick/node_modules/babel-core/lib/traversal/index.js:55:14)
at parseCode (/Users/sompylasar/.atom/packages/js-hyperclick/lib/make-cache.js:71:5)
at Object.get (/Users/sompylasar/.atom/packages/js-hyperclick/lib/make-cache.js:202:34)
at exports.default (/Users/sompylasar/.atom/packages/js-hyperclick/lib/suggestions.js:193:66)
at Object.getSuggestionForWord (/Users/sompylasar/.atom/packages/js-hyperclick/lib/js-hyperclick.js:14:24)
at _ret2.v (/Users/sompylasar/.atom/packages/hyperclick/lib/Hyperclick.js:193:24)
at /Users/sompylasar/.atom/packages/hyperclick/lib/Hyperclick.js:22:52
at undefined.next (native)
at step (/Users/sompylasar/.atom/packages/hyperclick/lib/Hyperclick.js:39:273)
at /Users/sompylasar/.atom/packages/hyperclick/lib/Hyperclick.js:39:443
at /Users/sompylasar/.atom/packages/hyperclick/lib/Hyperclick.js:39:99
at Hyperclick.getSuggestion (/Users/sompylasar/.atom/packages/hyperclick/lib/Hyperclick.js:169:14)
at HyperclickForTextEditor.<anonymous> (/Users/sompylasar/.atom/packages/hyperclick/lib/HyperclickForTextEditor.js:246:63)
at undefined.next (native)
at step (/Users/sompylasar/.atom/packages/hyperclick/lib/HyperclickForTextEditor.js:17:273)
at /Users/sompylasar/.atom/packages/hyperclick/lib/HyperclickForTextEditor.js:17:443
at HyperclickForTextEditor.<anonymous> (/Users/sompylasar/.atom/packages/hyperclick/lib/HyperclickForTextEditor.js:17:99)
at HyperclickForTextEditor._onKeyDown (/Users/sompylasar/.atom/packages/hyperclick/lib/HyperclickForTextEditor.js:198:14)
The culprit code from the babel-core
version js-hyperclick
uses which is 5.8.38
assumes that this.hub
is present at the time checkBlockScopedCollisions
is called, but in some condition (sorry, I could not find the minimal repro) this happens to be false:
Scope.prototype.checkBlockScopedCollisions = function checkBlockScopedCollisions(local, kind, name, id) {
// ignore parameters
if (kind === "param") return;
// ignore hoisted functions if there's also a local let
if (kind === "hoisted" && local.kind === "let") return;
var duplicate = false;
// don't allow duplicate bindings to exist alongside
if (!duplicate) duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module";
// don't allow a local of param with a kind of let
if (!duplicate) duplicate = local.kind === "param" && (kind === "let" || kind === "const");
if (duplicate) {
throw this.hub.file.errorWithNode(id, messages.get("scopeDuplicateDeclaration", name), TypeError);
}
};
The current version of babel-core
slightly differs, but still has this assumption.
checkBlockScopedCollisions(local, kind: string, name: string, id: Object) {
// ignore parameters
if (kind === "param") return;
// ignore hoisted functions if there's also a local let
if (kind === "hoisted" && local.kind === "let") return;
let duplicate = false;
// don't allow duplicate bindings to exist alongside
if (!duplicate) duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module";
// don't allow a local of param with a kind of let
if (!duplicate) duplicate = local.kind === "param" && (kind === "let" || kind === "const");
if (duplicate) {
throw this.hub.file.buildCodeFrameError(id, messages.get("scopeDuplicateDeclaration", name), TypeError);
}
}
The this.hub
property is assigned once, in the constructor of the Scope
, the value is taken from path.hub
.
It should come down from the parentPath
of the TraversalContext
which does not propagate from the root TraversalContext
as it should be passed into the traverse
function but in js-hyperclick
it is not passed.
I’m not sure if this is a bug in js-hyperclick
or babel
, as the documentation does not mention parentPath
, so I am asking a question on the babel
repo as well.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
Nevermind, no need to open an issue.
js-hyperclick
normally only responds to things that can be links. Visually you should see your variable underline. When there’s a parse error everything becomes a link and if you try to activate them it will show the error.Cool 👍