Giter Site home page Giter Site logo

codemod's Introduction

codemod

Code rewriting tools for automated refactors.

Why Codemods?

Sometimes big changes to your source code are required, and making such changes by hand is dangerous. For example, codemods can:

  • rename across a codebase safely
  • upgrade your uses of outdated APIs
  • perform complex automated refactors
  • much more!

Since codemods are typically just code themselves, you can write one to do whatever you want.

Getting Started

Check out the docs for @codemod/cli for instructions on installing and using the codemod CLI tool.

Repository Structure

This repository is a monorepo, or multi-package repository. See the READMEs for the packages here:

License

Copyright 2017 Brian Donovan

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

codemod's People

Contributors

alex-dixon avatar alexhancock avatar dependabot-preview[bot] avatar dependabot[bot] avatar eventualbuddha avatar greenkeeper[bot] avatar greenkeeperio-bot avatar lgtm-migrator avatar macklinu avatar mcmickjuice avatar sarupbanskota avatar seaoftea avatar yacinehmito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

codemod's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


The push permission to the Git repository is required.

semantic-release cannot push the version tag to the branch master on remote Git repository.

Please refer to the authentication configuration documentation to configure the Git credentials on your CI environment.


Good luck with your project ✨

Your semantic-release bot 📦🚀

ASTExplorer latest revision link does not work with `--remote-plugin`

Steps to reproduce

$ npx @codemod/cli --remote-plugin https://astexplorer.net/#/gist/5a4cf1d9e15657695ae270f5c7819b2c/latest docs/pages

Current behavior

SyntaxError: /tmp/tmp-6662825TjJR4bHrVJn.js: Unexpected token (1:0)

> 1 | <!DOCTYPE html>
    | ^
  2 | <html>
  3 | <head>
  4 | <title>AST explorer</title>

Expected behavior

Same as with the current revision e.g.

$ npx @codemod/cli --remote-plugin https://astexplorer.net/#/gist/5a4cf1d9e15657695ae270f5c7819b2c/2f5034e0efd549fa9fd99cecce91e19c15c2e9f7 docs/pages

Alternatives

Document that latest revisions do not work.

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepo:

    • The dependency @babel/core was updated from 7.1.1 to 7.1.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Import declarations not transforming properly

Summary:

  • The codemod fails to transform the import declarations properly when operating on lots of files.
  • It works just fine when the code mod is run only one file at a time.
  • I'm using version 2.0.6

Details

I'm writing a series of babel code mod transformations to get rid of depreciated jQuery methods in our Ember app. When the code is transformed somewhere in the file, we need to make sure to import the proper methods at the top of the file. Here's an example of the transformation I built:

import { click } from 'ember-native-dom-helpers'

becomes:

import { click, findAll } from 'ember-native-dom-helpers'

This transformation works just fine in AST explorer, such as in this link:

https://astexplorer.net/#/gist/f910710bddc949b00b5c3a062943a79f/b5c8398618a0ea6df8f027661575206509d36c5f

When I try to run the code-mod locally, however, many of the import declarations don't get converted properly. Here's the script that I ran in our internal ember application.

codemod tests/acceptance/ --remote-plugin "https://astexplorer.net/#/gist/f910710bddc949b00b5c3a062943a79f/b5c8398618a0ea6df8f027661575206509d36c5f"

Once I run a diff on the code, it shows the import statements unaltered.

+++ b/facesheet/tests/acceptance/scheduling/admin-locations-schedule-test.js
@@ -64,9 +64,7 @@ describe('Acceptance \| hello world page', function() {
   it('lists location displayName', async function() {
     await visit('some_internal_url');

-    const locationNames = find('.our-selector-name')
-      .map((i, el) => el.text)
-      .get();
+    const locationNames = findAll('.eng-location-schedule-link').map(el => el.textContent);
     expect(locationNames).to.include.members(['Nest', 'Dartmouth']);
   });

But, when I run the codemod on that single file alone, everything works fine, everything works as expected.

codemod tests/acceptance/hello-world-test.js --remote-plugin "https://astexplorer.net/#/gist/f910710bddc949b00b5c3a062943a79f/b5c8398618a0ea6df8f027661575206509d36c5f"

Here's the git diff when the codemod is run one file at a time:

-import { find as findNativeDOM, waitUntil } from 'ember-native-dom-helpers';
+import { find as findNativeDOM, waitUntil, findAll } from 'ember-native-dom-helpers';

 describe('Acceptance | hello world page', function() {
   let application;
@@ -64,9 +64,7 @@ describe('Acceptance | hello world page', function() {
   it('lists location displayName', async function() {
     await visit('some_internal_url');

-    const locationNames = find('.our-selector-name')
-      .map((i, el) => el.text)
-      .get();
+    const locationNames = findAll('.our-selector-name').map(el => el.textContent);
     expect(locationNames).to.include.members(['Nest', 'Dartmouth']);
   });

Let me know if you need any more details from me. Despite this issue, this babel code-mod tool has been immensely useful, to thank you a thousand times for making it open source!

  • Steve Z.

Adding an onComplete function

After running my codemod I need to do a set of find and replaces across all text in all of the files that were passed in. Is there any sort of onComplete property in this package? That way I could run the find and replace and reuse the path parameter I passed in

`and` matches

It looks like there's a start on first-order logic with or.

I'm wondering if there's any interest or past attempts at and. I have something sort of working but I'm not completely happy with it. It seems to recognize something like the following should not compile (very disorganized playground and pseudoish-code):

declare function isNumber = (x:unknown)  => x  is number
declare function isString = (x:unknown)  => x  is string
and(isNumber,isString)(42)

So maybe that's as far as we can go.

What I'd really think was cool is if we could inform the compiler the resultant type is the "intersection" of all the predicate arguments to and.

e.g.

const fooBarBaz: Foo & Bar & Baz = and(isFoo, isBar, isBaz)({a:1,b:2,c:3)

I've made a couple passes at implementing that. I'm guessing there's something I'm not understanding fully about x is Foo return types/existential predicates. It looks like the compiler infers them as booleans sometimes.

Further there might need to be an H list or equivalent to deal with the polymorphism of the predicate arguments.

Options are not passed into the plugin

I created dummy plugin that does nothing but console.log of options.
And if I run it like that

codemod -p ./index.js -o [email protected] --printer prettier /src

with config like that

{ "test": true }

Or like that

codemod -p ./index.js -o index='{"test":true}' --printer prettier /src

It outputs {} into the console.

I tried to run it with name in the plugin like -o [email protected] with no result

That makes any codemod that requires options to be unusable.

[Question] How to list changed files?

Specifically the use case for this is to implement a replacement for the removal of --printer=prettier

I don't want to lint out entire project after each codemod, but I'm not sure what a less drastic option might be unless the files can be listed out?

Error: Requires Babel "^7.0.0-beta.41", but was loaded with "7.9.0"

I'm getting this error:

❯ codemod --plugin @babel/plugin-proposal-function-bind src/resources/assets/scripts
Error: Requires Babel "^7.0.0-beta.41", but was loaded with "7.9.0". You'll need to update your @babel/core version.

I suspect this is a quirk of npm global bins trying to use local packages (why on earth it would try to do that, I don't know), but maybe you should upgrade codemod out of babel 7 beta?


Or maybe it's not codemod that has this dependency...? Here's the rest of the stack:

    at throwVersionError (/path/to/my/project/node_modules/@babel/helper-plugin-utils/lib/index.js:63:11)
    at Object.assertVersion (/path/to/my/project/node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
    at /path/to/my/project/node_modules/@babel/plugin-proposal-function-bind/lib/index.js:17:7
    at /path/to/my/project/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
    at new Plugin (/path/to/my/project/node_modules/@codemod/cli/src/Config.ts:23:22)
    at Config.<anonymous> (/path/to/my/project/node_modules/@codemod/cli/src/Config.ts:82:18)
    at Generator.next (<anonymous>)
    at fulfilled (/path/to/my/project/node_modules/@codemod/cli/src/Config.js:5:58)

I don't know who wants what :(


FWIW, it does the same thing if I run everything locally:

node_modules/.bin/codemod --find-babel-config --plugin node_modules/@babel/plugin-proposal-function-bind/lib/index.js src/r
esources/assets/scripts
Error: Requires Babel "^7.0.0-beta.41", but was loaded with "7.9.0". You'll need to update your @babel/core version.

Process hangs when using --stdio

Hello, thanks for writing this piece of software!

Everything's working great for me from a file transformation perspective however I am unable to get the --stdio switch feature to work. The process hangs when this switch is provided.

Below is a link to a repo that repros this issue. I've included an actual codemod as well as a noop one. All scenarios are enumerated out in package.json scripts section.

https://github.com/mcMickJuice/babel-codemod-stdio-issue

Comments are removed when path is replaced

This might be related to #168

I have a very simple example transform here

The ast-explorer example above is set to babylon6 and babel6, which has exactly the same behavior as running this transform via @codemod/cli

If I set it to babylon7 and babel7, it doesn't remove the comment.

It's a bug regardless, but I'm curious why it's happening, given that @codemod/cli uses @babel/[email protected]

Is there a way to disable rewriting a file?

I'm using codemods to do searches across files for complicated things which a regular grep can't fulfill (such as: does any file have a component which has these two particular attributes). When my codemod finds files matching the said properties, I output the list to another file. I don't mutate the AST in any way (these search transforms are just a bunch of if-else checks and a console.error() to write the filename to another file).

One issue while doing this is that codemod modifies all the files which it touches. It forcefully transforms line endings, adds or removes some braces here and there, etc. Then I have to do a git checkout -- . always after running the codemod.

Is there a way to disable the codemod from writing the file it touches? I'd like it to just read the file, run the non-mutating transform and just let the file be.

Add support of syntaxes?

I have a plugin which depends on many syntaxes, and if I use babel-cli or babel.transform through the code, everything is working perfectly.
When I use my plugin with codemod it's arguing, saying that I need to add react/jsx/spread etc plugins, but why should I when I just need babel to understand syntax and output code and when I have all required syntaxes already described in the plugin.

Thanks.

Specify babylon syntaxes to parse files?

First of all thanks for the awesome codemod cli tool with ts support!

I'm terribly sorry if this was covered before, but I couldn't find an answer in examples and other issues. I've got a babel-plugin that I want to use to perform some changes on .ts and .tsx files. So my plugin already inherits @babel/plugin-syntax-typescript to make proper type checks as per Babel Handbook guidelines. How do I enable other Babylon syntaxes (jsx) to parse (not transform) files when running babel-codemod? Am I missing something here?

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Allow prettier(-eslint) for the output

Based on this. Specifically, I think that both prettier and prettier-eslint should be supported. Many folks would benefit from the eslint integration even if they're not using prettier at all.

Support globs?

Globs (using glob) are really common for packages like this one. It would be very nice to be able to specify a glob for the transformation.

[Question] How to create npx compatible codemod runners

I'm trying to create a simple codemod and I want to make it possible for end users to simply run that codemod once, without having to install it as a dependency first. Something like this would be optimal:

npx my-codemod-package-name file-paths

I think that should be possible by creating a bin setup in my package which runs codemod-cli behind the scenes, but I'm not sure how to set that up. Is there a public API that I can import and use in my bin script? Or should I execute the cli command from node code?

Any guidance is appreciated.

PS. I'm new to node / tooling development so sorry if this is a silly question.

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Missing name property in package.json.

The package.json's name property is required in order to publish a package to the npm registry.

Please make sure to add a valid name for your package in your package.json.


Good luck with your project ✨

Your semantic-release bot 📦🚀

support working with .ts files

So there's word on the web that babel7 now supports parsing typescript and recast has been modified to work with it. Apparently, jscodemod --parser babylon will now apply transforms on .ts files (facebook/jscodeshift#180 (comment)). It would be cool for babel-codemod to be able to handle .ts files as well. because it's my goto tool for running codemods now 😸. This is especially handy for cases where you have codebases in transition, with lots of old legacy in .js and newer legacy in .ts 😁
I am not sure how much work would be necessary to enable this or how feasible it is. As always though, I greatly appreciate your time.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Debug mode?

Does anyone have a good debugger workflow for working with babel-codemod?

ASTExplorer is great, but somewhat tedious- i wish I can work more in my IDE and iterate plugin development without ASTExplorer

Ability to step through the plugin or log output would be helpful

Suggestion: replace custom file path resolver with globby

I see that the current file path resolver manually traverses directories, and hardcodes to exclude some directories, like node_modules.

I suggest using a third-party solution like globby instead. This automatically gives functionality like more sophisticated patterns, or pattern exclusions. And it reduces the amount of code in this project.

And, instead of hardcoding directories to ignore, I'd recommend reading the user's gitignore and just ignoring everything there.

All-or-nothing matches

First, this library is awesome.

I noticed captures can return undefined:

export class CapturedMatcher<C, M = C> extends Matcher<M> {

I'm guessing this is to support partial matches, but sometimes I want matcher.match to fail if one of its captures fails.

export const matchRamdaExpr = (node:unknown, ramdaIdent = "R"): [t.MemberExpression, t.Identifier] | null => {
  let $methodName = m.capture(m.identifier())
  const matcher =
    m.memberExpression(
      m.identifier(ramdaIdent),
      $methodName,
    )

  return matcher.match(node)
   // need this guard if the capture can fail but the rest of the match can succeed
  // can remove it if capture.current returns `T` instead of `T` | undefined
   && $methodName.current
    ? [node, $methodName.current] : null
}

Babel-core: make it a peerDep

So that you can use a different version (v7)

I guess the only issue is how that would work with npx or a global install..

How to use proposal plugins?

We're using babel-plugin-proposal-optional-chaining in one of our projects. When running a codemode we get the error

Support for the experimental syntax 'optionalChaining' isn't currently enabled

along with a message from babel:

Add @babel/plugin-proposal-optional-chaining (https://git.io/vb4Sk) to the 'plugins' section of your Babel config to enable transformation.

However, we have a local .babelrc with the plugin defined. Adding --find-babel-config didn't help.

Any hints to how to solve this issue? Thanks in advance!

Add option to transpile TypeScript plugins directly

Probably should use ts-node the same way #31 uses babel-register, but will require some research since the options are obviously different. What should the option be called? --ts-transpile? Should we just put both --babel-transpile and this one under a single --transpile-plugins flag? Maybe it should even be on by default, as long as we’re already shipping the dependencies with the package.

cc @mcMickJuice

Is there any way to ignore certain paths?

Hi, I'm wondering if there is some way to let say in monorepo tell codemod ./packages
But tell it to ignore node_modules that are, surely nested.
Right now it starts to match all the stuff.
I assume I can do that with glob pattern, but I had no success build one that is doing that :)
Suggestion what pattern will work will be greatly appreciated :) Or smth like .codemodignore with node_modules in it :)

path.addComment() does not seem to work

Hi,

I am trying to use path.addComment() to insert a comment into the code. The issue is that I don't see any result with ast explorer or babel-codemod. I've asked around on the babeljs slack channel and was told ast explorer has one customization that might interfere with comments. I am wondering if babel-codemod has the same customization. Here's the snippet I was playing with:
https://astexplorer.net/#/gist/3773ea0b4c55ee68e6b6d9929f3ecab7/2a6fa8635ac12a1fcd35d3e078fe41e3b58821ec

Much appreciate any help :)

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepoundefined

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

CLI Tests failing on Windows

The cli tests are failing on my windows machine:

version of node: 8.0.0
windows 10 pro

  • ENOENT errors related to this call in runCodemodCLI:
    let child = execFile(join(__dirname, '../bin/codemod'), args);
  • infinite loop occurring in tests where createTemporaryFile is called

The former is probably related to spawn issues with execFile on windows...the latter, i have no idea.

Tests are passing in CI env based on my recent PR though, that's why I think this is windows specific...or just my machine?

[Proposal] programmatic use

How about separating the CLI part so babel-codemod can be easily used via programmatic interface?
That would ease creating tools based on this fantastic project

Bug? (babelrc options not work) + Use case (need to pass fn to plugin options)

Use case: I need to pass function to plugin options (replacer for babel-plugin-replace-imports).

There is no way to do it using --plugin-options (only json supported)

So I have to use .babelrc.js

setup:
node -v: v12.18.0
"@codemod/cli": "^2.2.1"
my .babelrc.js content:

console.log(111111)

module.exports = {
  // "extends": "@babel/preset-env",
  "plugins": [
    [
      "babel-plugin-replace-imports",
      {
        "test": /\/?regexp\//i,
        "replacer": () => {console.log(2222)}
      }
    ]
  ]
}

1. Just babelrc

npm run codemod -- --find-babel-config -p babel-plugin-replace-imports js/libs/navi.js
result:

111111
Encountered an error while processing js/libs/navi.js:
Error: /Users/arestov/dkt/js/libs/navi.js: 
babel-plugin-replace-imports: options are required.

options are required.
expected result: 🙅‍♂️ no error
(looks like options was not passed to plugin by cli)

2. babelrc + --plugin-options

npm run codemod -- --find-babel-config --plugin-options babel-plugin-replace-imports='{"ff": 55}' -p babel-plugin-replace-imports js/libs/navi.js
result:

111111
Encountered an error while processing js/libs/navi.js:
Error: /Users/arestov/dkt/js/libs/navi.js: 
babel-plugin-replace-imports: «test» option is required.

«test» option is required.
expected result: ❓
(shouldn't cli prefer babelrc?)
(--plugin-options was used, looks like options was not passed to plugin by cli)

3. alt babelrc (short/compact plugins) + --plugin-options

.babelrc.js

console.log(111111)

module.exports = {
  // "extends": "@babel/preset-env",
  "plugins": [
    [
      "babel-plugin-replace-imports",
    ]
  ]
}

npm run codemod -- --find-babel-config --plugin-options babel-plugin-replace-imports='{"ff": 55}' -p babel-plugin-replace-imports js/libs/navi.js

111111
Encountered an error while processing js/libs/navi.js:
Error: /Users/arestov/dkt/js/libs/navi.js: 
babel-plugin-replace-imports: options are required.

options are required.
expected result: 🙅‍♂️ no error
(--plugin-options was not used, looks like empty options in plugins list was selected by cli)

4. @codemod/core

tt.js

var { transform } = require('@codemod/core')


const result = transform('import k from "nothing";import j from "something";', {
  'plugins': [
    [
      'babel-plugin-replace-imports',
      {
        'test': /nothing/i,
        'replacer': () => {
          console.log('replacing!')
          return 11
        }
      }
    ]
  ]
})

console.log(result.code)

node tt.js
result:

replacing!
import k from "11";import j from "something";

Result code contains unnecessary semicolon

After transforming, the generate code contains unnecessary semicolon, here is my code.

source code:

function square (n) {
  return n * n
}

plugin:

module.exports = function () {
  return {
    visitor: {
      FunctionDeclaration (path) {
        path.scope.rename('n', 'x')
      }
    }
  }
}

result:

function square (x) {
  return x * x;
}

the result code is what I want, but in return statement contains an unnecessary semicolon, can we
rewrite source code without semicolons.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.