by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 25 08:58
    N1kto commented #316
  • Jun 15 02:16
    tjx666 commented #717
  • Jun 15 00:06
    eventualbuddha commented #717
  • Jun 14 11:33
    tjx666 edited #717
  • Jun 14 11:07
    tjx666 edited #717
  • Jun 14 11:06
    tjx666 opened #717
  • Jun 12 17:48
    Daniel15 synchronize #716
  • Jun 12 00:53
    Daniel15 commented #559
  • Jun 12 00:53
    Daniel15 opened #716
  • Jun 11 07:33
    bromagosa commented #370
  • Jun 09 15:14
    conartist6 edited #712
  • Jun 07 17:47
    conartist6 synchronize #712
  • Jun 07 17:39
    conartist6 commented #623
  • Jun 07 17:35
    conartist6 commented #706
  • Jun 07 17:34
    conartist6 commented #706
  • Jun 07 17:30
    conartist6 closed #714
  • Jun 07 17:30
    conartist6 commented #714
  • Jun 07 17:27
    conartist6 commented #715
  • Jun 07 17:22
    conartist6 opened #715
  • Jun 06 19:05
    conartist6 commented #572
Jeroen Engels
@jfmengels
(and just filtering out the lines with console.logs does the trick, so we're good there)
Ben Newman
@benjamn
yeah, that's another thing: sometimes it's a lot easier to do a dumb preprocessing step than it is to figure out how to write a smart transform
Jeroen Engels
@jfmengels
Yes, lesson learned ;) (or so I hope)
Ben Newman
@benjamn
it's all about your productivity :)
Jeroen Engels
@jfmengels
Well, I spent a few evenings on this, where I kept thinking in the "jscodeshift box", not outside the box
Ok, off to bed. Thanks a lot @benjamn, and I'll let you know how it goes ;)
Ben Newman
@benjamn
good luck & take care!
Jeroen Engels
@jfmengels
Hey!
I'm off to bed, but just wanted to let you know that my (second) PR for the lodash docs has been merged lodash/lodash#1963.
Original core docs: https://github.com/lodash/lodash/blob/4.3.0/doc/README.md
Generated fp docs: https://gist.github.com/jfmengels/6b973b69c491375117dc#_pullatindexes-array (scroll a little bit down)
Have a good one ;)
Benjamin Tan
@demoneaux
Hi @benjamn I sent in a few PRs recently, wonder if you've seen them?
demetriusnunes
@demetriusnunes
hi guys, wonder if you could help me. I'm just starting with codemods, and I wonder how could use it to instrument my code, ie, add logging statements at the beginning of each function. has anyone done that?
Brendan Annable
@BrendanAnnable
Buzzing in here!
Any thoughts on adding jsdoc/closure compiler annotations support? Or adding some plugin architecture for externally adding support?
My goal is to use recast as a general programmatic refactoring tool, but I need it to refactor the typing information along with it.
There is a parser here https://github.com/hegemonic/catharsis but it does not appear to support codegen.
jsdoc also has an internal parser that you can't really access properly, but again no codegen either.
Ben Newman
@benjamn
@BrendanAnnable is there an AST specification for that parser? And, at a minimum, does it generate AST nodes that have .loc.{start,end} information?
Brendan Annable
@BrendanAnnable
@benjamn So that parser only parses the typing information, so I doubt it would have .loc information. i.e. if you have a comment e.g. /** @type {Array<SomeFancyType>} */ it won't actually parse the entire comment, just the Array<SomeFancyType> part.
I only briefly looked into it though
jsdoc have their own "regex parser" infront of it https://github.com/jsdoc3/jsdoc/blob/master/lib/jsdoc/doclet.js#L110
Matheus Fernandes
@matheuss
Hi guys! I'm reading a file that have this array:
plugins: [],
With recast, I'm adding to elements and then saving the file. Turns out that recast does this:
plugins: ["hyperpanic", "hypercwd"],
Any change that I could print this?
plugins: [
   "hyperpanic",
   "hypercwd"
],
Brendan Annable
@BrendanAnnable
Recast doesn't have the ability to print according to a style guide.
There was a github issue requesting such a feature.
Matheus Fernandes
@matheuss
😔
Thanks!
Ari Porad
@ariporad

Hi All, quick question: Is there a way to use scope to eliminate unused variables? For example, if I have this:

function () {
  var x = 5;
  doFoo(123);
};

I want to convert it to:

function () {
  // Notice: No `x`
  doFoo(123);
}

Thanks!

Brendan Annable
@BrendanAnnable
@ariporad Maybe collect two pieces of information in a single traversal and analze after. e.g. Collect each declared Identifier and its associated scope, and also collect all used variables and their associated scope (using scope.lookup) and then compare the two for disparities.
Ari Porad
@ariporad
Ok, thanks!
Brendan Annable
@BrendanAnnable
@benjamn Is there any plans for scope.js to support defaulted function params? It currently treats them as global variables.
(ast-types)
Lucas Bento
@lucasbento
Do I have to enable something for recast to parse async/await?
I'm not finding anything about it on the repository
Ben Newman
@benjamn
@BrendanAnnable that's definitely an oversight/bug, and I'd be happy to review a pull request!
@lucasbento try recast.parse(source, { parser: <any object with a .parse method> })
Lucas Bento
@lucasbento
@benjamn: thank you, I fixed it by using babylon parser
sorry I forgot to mention that here
Ben Newman
@benjamn
np, glad you figured it out
Lucas Bento
@lucasbento
@benjamn: ;)
Brendan Annable
@BrendanAnnable
@benjamn looks like the File type does not a filename? It is somehow possible to add an optional filename to it?
maybe taking the sourceFileName from the options given to recast.parse?
Brendan Annable
@BrendanAnnable
My use case that I have no way of tracking the filename when performing AST transformations (which may include filename changes). I could track it with external state, but that would be sucky. Especially when there is a perfect File node which could store it directly within the AST itself.
Brendan Annable
@BrendanAnnable
Oh man, it was a 2 line change to ast-types and a 1 line change to recast and works perfectly for my use case. I'll create the PRs, hopefully there isn't an issue.
Brendan Annable
@BrendanAnnable
PRs in benjamn/ast-types#200 benjamn/recast#354
Saveliy Baranov
@concubicycle
Hey
Can this lib preserve comments when pretty printing?
Mitermayer Reis
@mitermayer
I am working on a project that would update/adds new comments to the AST to be printed.
  • What is the recommended way to do that ?
  • Can I achieve this using recast/lib/comments?
Ben Newman
@benjamn
@mitermayer In an AST produced by recast.parse, comments are exposed as a .comments property on nodes
each comment object has boolean .leading and .trailing properties, indicating the comment's relationship to the node
you can create new comment objects with require("recast").types.builders.block("comment text") or .line("comment text")
most nodes in the AST won't have a .comments array attached to them, because they don't have any comments
so you might have to create the array if you're adding new comments for the first time