Giter Club home page Giter Club logo

Comments (7)

JoeStanton avatar JoeStanton commented on August 16, 2024

@paulroper you had a possible solution for this? Want to PR it?

from babel-transform-js-to-jsx.

paulroper avatar paulroper commented on August 16, 2024

I didn't hit a solution for multi-line declarations unfortunately, only single line. 😞

from babel-transform-js-to-jsx.

JoeStanton avatar JoeStanton commented on August 16, 2024

Can you share the AST explorer sample you had? We can adapt it for multi-line and deal with scoping.

from babel-transform-js-to-jsx.

paulroper avatar paulroper commented on August 16, 2024

...I didn't save it because I dumb am 👍

from babel-transform-js-to-jsx.

paulroper avatar paulroper commented on August 16, 2024

I had a mess around in the AST Explorer again and came up with this:

export default function ({types: t}) {
  return {
    visitor: {      
      ExpressionStatement(path) {
        if (path.node.expression.type !== "AssignmentExpression") { return; }

        const left = path.node.expression.left;
        const binding = path.scope.bindings[left.name];

        if (binding && !binding.path.shouldSkip) {
          path.replaceWith(
            t.variableDeclaration("var", [t.VariableDeclarator(left, path.node.expression.right)])
          );

          binding.path.remove(); 
        }
      }
    }
  };
}

It'll turn:

var a, b, c;
a = 1;
b = 3;
c = 4;

Into:

var a = 1;
var b = 3;
var c = 4;

from babel-transform-js-to-jsx.

JoeStanton avatar JoeStanton commented on August 16, 2024

Great! Can you look into a good way to check the scope?

from babel-transform-js-to-jsx.

paulroper avatar paulroper commented on August 16, 2024

Check the scope of the transformed variable assignments?

from babel-transform-js-to-jsx.

Related Issues (13)

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.