Giter Club home page Giter Club logo

preval.macro's Introduction

preval.macro

This is a babel-plugin-macros macro for babel-plugin-preval.

Please see those projects for more information.

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev preval.macro

You'll also need to install and configure babel-plugin-macros if you haven't already.

Usage

Once you've configured babel-plugin-macros you can import/require preval.macro. For example:

import preval from 'preval.macro'

const one = preval`module.exports = 1 + 2 - 1 - 1`

Note:

babel-plugin-preval allows you to have a few more APIs than you have with this macro, but this macro comes with all the benefits of using babel-plugin-macros (which you can read about in the babel-plugin-macros docs).

preval.macro's People

Contributors

allcontributors[bot] avatar andrewmcodes avatar dependabot[bot] avatar jdorfman avatar kentcdodds avatar michaeldeboey 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

preval.macro's Issues

Is not work for wrapped function

Hi! Thanks for this project.

I try to reuse preval.macro for injecting some additional logic, but precompile is not work in that case. Check the example

function test(...a) {
  // some computation...
  return preval(...a);
}

const oneByPreval = preval`module.exports = 1 + ${2} - 1 - 1`; // `1`
const oneByPrevalWrapper = test`module.exports = 1 + ${2} - 1 - 1`; // `{}`

Support @babel/register

I had some trouble reusing code between the frontend and in a macro. I tried requiring @babel/register before require'ing the file I needed. That did not work.

Another solution to this would be to allow exporting a promise. If that were the case, I could have used the import function. This would however not work if the code contained JSX.

Otherwise, I love this macro!

Link to repo from npmjs.com

Hey there! I was looking into this project and noticed there wasn't a link from npmjs.com to the Github repo.

Would it be beneficial to add something like this to the package.json?

"repository": {
  "type" : "git",
  "url" : "https://github.com/kentcdodds/preval.macro"
}

I'm sure there's a more sophisticated way, this was just recommended in the npm docs.

Would be glad to submit a PR to that effect if there's interest.

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.