Anber / wyw-in-js

MIT License
191 stars 8 forks source link

support `replacement` as a function #76

Closed siriwatknp closed 2 months ago

siriwatknp commented 2 months ago

Motivation

closes #75

Summary

Author can modify the AST at the end of the process by providing the replacement argument as a function:

For example, move the prop to last

this.replacer((tagPath) => {

  const jsxElement = tagPath.parentPath.parentPath.parentPath; // this is a simple implementation

  let sxAttribute;
  jsxElement.get('attributes').forEach(attr => {
    if (attr.node?.name?.name === 'sx') {
      sxAttribute = attr;
      attr.remove();
    }
  })

  jsxElement.node.attributes.push(sxAttribute.node);

  return transformedExpression;
}, false)
changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: 62b320bac836d9649452501f1fe73d91e7676200

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR