question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error getting Hyperclick suggestion: TypeError: Cannot read property 'file' of undefined, coming from babel-core traversal internals

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
AsaAyerscommented, Oct 2, 2016

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.

0reactions
sompylasarcommented, Oct 13, 2016

Cool 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

sitemap-questions-86.xml - Stack Overflow
... 2020-12-03 https://stackoverflow.com/questions/1116397/suggested-reading- ... -bulk-load-because-the-file-could-not-be-opened-operating-system-error-co ...
Read more >
Bug List - Bugs - Eclipse
MESSAGE Cannot invoke "org.eclipse.ui.internal.Workbench.getThemeManager()" because the return value of "org.eclipse.ui.internal.Workbench.
Read more >
MathJax Documentation - Read the Docs
MathJax is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all.
Read more >
Beginning ReactJS Foundations Building User Interfaces with ...
this.secretNumber = 100; return this.secretNumber;. } console.log(getSecretNumber()); // error: cannot set property. 'secretNumber' of undefined.
Read more >
Jspdf background color black code examples free online - Weebly
Varying Data Types¶ Arrays ERROR TypeError: undefined is not an object ... in jquery enzyme TypeError: Cannot read property 'child' of undefined how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found