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

Fails on class member methods #3

Open
kmannislands opened this issue Dec 14, 2017 · 5 comments
Open

Fails on class member methods #3

kmannislands opened this issue Dec 14, 2017 · 5 comments

Comments

@kmannislands
Copy link

Bug

  • babel-plugin-console version: v0.2.0
  • node version: tried v6.11.4 and v8.4.0
  • npm (or yarn) version: v1.1.0 and v1.3.2, respectively

What you did:
Added a console.scope to a class member method.

What happened (please provide anything you think will help):
Babel failed to build.

Relevant code or config:

To demonstrate using the babel REPL, run babel-node --plugins console and then do something like:

> class myClass { memberMethod() { console.log('foo'); } }
undefined
> new myClass().memberMethod()
foo
undefined
> class anotherClass { memberMethod() { console.scope('inside member') } }
undefined
> new anotherClass().memberMethod()
undefined

if you try and build something like the above example with webpack and babel-loader you get something like:

./foo/src/components/file-containing-class.js
Module build failed: TypeError: /abs/path/to/foo/src/module-editor/components/module-editor-page.js: Cannot read property 'start' of undefined
    at getFunctionSignature (/abs/path/to/foo/node_modules/babel-plugin-console/dist/scope/signatures/index.js:60:51)
    at exports.default (/abs/path/to/foo/node_modules/babel-plugin-console/dist/scope/signatures/index.js:13:10)
    at traverseFunctions (/abs/path/to/foo/node_modules/babel-plugin-console/dist/scope/index.js:115:41)
    at exports.default (/abs/path/to/foo/node_modules/babel-plugin-console/dist/scope/index.js:28:17)
    at PluginPass.CallExpression (/abs/path/to/foo/node_modules/babel-plugin-console/dist/index.js:37:43)
    at newFn (/abs/path/to/foo/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/abs/path/to/foo/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/abs/path/to/foo/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/abs/path/to/foo/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/abs/path/to/foo/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/abs/path/to/foo/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/abs/path/to/foo/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/abs/path/to/foo/node_modules/babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/abs/path/to/foo/node_modules/babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/abs/path/to/foo/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/abs/path/to/foo/node_modules/babel-traverse/lib/context.js:103:17)
 @ ./src/baz/index.js 38:24-66
 @ ./src/app/app-router.js
 @ ./src/app/index.js
 @ multi (webpack)-dev-server/client?https://0.0.0.0:9090 webpack/hot/dev-server ./src/app/index.js

I would really like to use this babel-plugin (looks cool), but I can't introduce it if it kills the webpack build when a dev puts a console.scope in a wrong place.

Interested in helping to see this through if this package is still maintained.

@mattphillips
Copy link
Owner

Hey @kmannislands I’ve not had the time lately to spend working on this. Originally I built this to only be used inside of functions, but there are so many other usages of the plugin like your example :)

I’d definitely be open to help with supporting class methods if you’ve got the time? Otherwise I can try to put some time to the side next week to take a look for you.

@kwelch
Copy link

kwelch commented Dec 15, 2017

I highly recommend @kentcdodds course on egghead about ASTs or his frontend masters course.

This repo has tests so you could add your test case in to the suite and update the plugin until it passes. I also recommend astexplorer which Kent explains how to use in his videos.

If you have any questions feel free to drop a line.

@kmannislands
Copy link
Author

@mattphillips I'm interested in helping out, I'll take a look at the code this weekend.
I think supporting member methods would widen the appeal of this plugin quite a bit as classes are used pretty heavily by react these days.

I am also having some trouble getting babel to build inside of arrow functions or decorated functions, haven't had time to isolate the problem yet. May open another ticket or two once I do.

@dmitriyK1
Copy link

Would be nice to see this fixed

@kmannislands
Copy link
Author

Not planning on pursuing this personally in favor of VS Code's debug mode.

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

4 participants