Comments (8)
@fkling What are your thoughts on adding a recipes
section to the documentation (similar to this). I've found a few examples of use-cases in the past digging through the issues on this repo that would have been great to have documented.
I know there are already links to the codemod repos in the bottom of the readme, but specific recipes could be an added bonus.
from jscodeshift.
Mmh. I assume the comment is attached to the VarableDeclaration, so when you remove the node, the comment is removed as well. You could save the comment first and reattach it to the file node: http://felix-kling.de/esprima_ast_explorer/#/kGspd21ZnD/1.
Maybe we can do something to make this easier, but not sure yet what.
We should definitely provide an API that makes it easy to get, add and remove comments on nodes.
from jscodeshift.
Yeah, I figured as much. Maybe we could just special-case the first comment? It seems rare that you'd ever want to move or drop it (especially at FB).
from jscodeshift.
I can work on it to detach the first comment a file from the first statement and add as a node. Is this desirable?
from jscodeshift.
@DrewML: Sounds like an excellent idea to me!
from jscodeshift.
Hey,
By chance could someone take a look at this issue?
The problem here for me is that sometimes the codemod does try to restore the leading comment, but that leading comment was not removed in the first place, leading to a duplicate leading comment.
I'm not a JSCodeShift/Recast expert but couldn't we make sure the actual leading comment gets removed before restoring it, or restoring it only when necessary?
from jscodeshift.
@slorber Yes it seems that if the first node was not modified, the first comment would be duplicated.
The solution is to check if the first node has changed : http://astexplorer.net/#/hb6iLO9hTe/48
Modify "underscore"
to anything else (like "lodash"
) in the original source code so that the node is not removed and you will see that the comment is not duplicated.
from jscodeshift.
What is the rationale to attach comments to other nodes? Why can't they live as independent nodes?
from jscodeshift.
Related Issues (20)
- URL transform doesn't work with TypeScript HOT 2
- Can't see file in current working directory - "Skipping path which does not exist." HOT 2
- Ignore pattern doesn't work with relative paths starting with two dots (../) HOT 1
- Automatically publish latest dev version to npm HOT 1
- Declaration has "null" loc field when inside export HOT 1
- missing semicolon how to fix this HOT 9
- how can I add @babel/plugin-proposal-private-methods to jscodeshift ? HOT 5
- extensions cli option not respected when passing individual file paths
- cannot replace JSX nodes within render props
- Added parenthesis around await expression in if statement HOT 4
- Updating setter function's parameter cause invalid output HOT 4
- Easiest way to insert a comment at the beginning of a file? HOT 3
- Generics are being removed from JSX Elements HOT 2
- Unit Tests Broken? HOT 1
- Last npm release (0.15) is ~6 months old HOT 2
- how to remove empty line using jscodeshift? HOT 1
- WSL2 - Can't install project with jscodeshift in dependencies HOT 1
- Enable parsing of `accessor` keyword HOT 6
- testOptions aren't propagated through some of the test methods
- [Bug] [email protected] ignores the files not starting with `.js` extension by default HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jscodeshift.