Pre-evaluate code at build-time with babel-macros

Overview

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).

Comments
  • Is not work for wrapped function

    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`; // `{}`
    
    opened by artalar 1
  • docs: remove CodeFund sponsor

    docs: remove CodeFund sponsor

    CodeFund is not allowed to place ads on README's anymore according to GitHub.

    Please reach out to our team if you have any questions :slightly_smiling_face:

    opened by andrewmcodes 0
  • Bump js-yaml from 3.12.0 to 3.13.1

    Bump js-yaml from 3.12.0 to 3.13.1

    Bumps js-yaml from 3.12.0 to 3.13.1.

    Changelog

    Sourced from js-yaml's changelog.

    3.13.1 / 2019-04-05

    • Fix possible code execution in (already unsafe) .load(), #480.

    3.13.0 / 2019-03-20

    • Security fix: safeLoad() can hang when arrays with nested refs used as key. Now throws exception for nested arrays. #475.

    3.12.2 / 2019-02-26

    • Fix noArrayIndent option for root level, #468.

    3.12.1 / 2019-01-05

    • Added noArrayIndent option, #432.
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Support @babel/register

    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!

    opened by adrianhelvik 0
  • Link to repo from npmjs.com

    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.

    opened by handeyeco 1
Owner
Kent C. Dodds
Improving the world w/ quality software · Husband, Father, Latter-day Saint, Teacher, OSS · http://TestingJavaScript.com · http://EpicReact.Dev · Be Kind
Kent C. Dodds
JSHint is a tool that helps to detect errors and potential problems in your JavaScript code

JSHint, A Static Code Analysis Tool for JavaScript [ Use it online • Docs • FAQ • Install • Contribute • Blog • Twitter ] JSHint is a community-driven

JSHint 8.8k Jan 2, 2023
Detect copy-pasted and structurally similar code

Detect copy-pasted and structurally similar JavaScript code. Requires Node.js 6.0+, and supports ES6, JSX as well as Flow. Note: the project has been

Daniel St. Jules 3.5k Dec 26, 2022
Find and fix problems in your JavaScript code.

ESLint Website | Configuring | Rules | Contributing | Reporting Bugs | Code of Conduct | Twitter | Mailing List | Chat Room ESLint is a tool for ident

ESLint 21.9k Dec 31, 2022
The JavaScript Code Quality Tool

JSLint, The JavaScript Code Quality Tool Douglas Crockford [email protected] 2019-03-15 jslint.js contains the jslint function. It parses and a

Douglas Crockford 3.5k Jan 6, 2023
🌟 JavaScript Style Guide, with linter & automatic code fixer

JavaScript Standard Style Sponsored by English • Español (Latinoamérica) • Français • Bahasa Indonesia • Italiano (Italian) • 日本語 (Japanese) • 한국어 (Ko

Standard JS 27.8k Dec 31, 2022
Babel-plugin-amd-checker - Module format checking plugin for Babel usable in both Node.js the web browser environments.

babel-plugin-amd-checker A Babel plugin to check the format of your modules when compiling your code using Babel. This plugin allows you to abort the

Ferdinand Prantl 1 Jan 6, 2022
Babel plugin and helper functions for interoperation between Node.js native ESM and Babel ESM

babel-plugin-node-cjs-interop and node-cjs-interop: fix the default import interoperability issue in Node.js The problem to solve Consider the followi

Masaki Hara 15 Nov 6, 2022
Evaluate JavaScript on a URL through headless Chrome browser.

jseval Evaluate JavaScript on a URL through headless Chrome browser. build docker build -t jseval -f jseval.dockerfile . usage docker run --rm jseval

Fumiya A 22 Nov 29, 2022
An experimental transpiler to bring tailwind macros to SWC 🚀

stailwc (speedy tailwind compiler) This is an experimental SWC transpiler to bring compile time tailwind macros to SWC (and nextjs) a-la twin macro. T

Alexander Lyon 140 Jan 3, 2023
This is time-saving pre-built Webpack-initialization template

This is time-saving pre-built Webpack-initialization template. Users can take advantage of the power of Webpack to dynamically load CSS, Html, and js files complete with server. Built with JavaScript/WEBPACK/HTML/CSS.

Steve 14 Jun 27, 2022
Turn your ES5 code into readable ES6. Lebab does the opposite of what Babel does.

Lebab Lebab transpiles your ES5 code to ES6/ES7. It does exactly the opposite of what Babel does. If you want to understand what Lebab exactly does, t

Lebab 5.5k Dec 31, 2022
A complete set up of the React application with Typescript, Webpack 5, Babel v7, SSR, Code Splitting and HMR.

Getting Started with react-final-boilerplate Clone the code npm install You are good to go with React Application. Open http://localhost:3000/ and you

null 24 Dec 22, 2022
Example code for MFE routing, shared state, build-time & runtime deploy video

Turborepo starter with pnpm This is an official starter turborepo. What's inside? This turborepo uses pnpm as a packages manager. It includes the foll

Jack Herrington 42 Nov 2, 2022
A jQuery plugin that recreates the Material Design pre-loader (as seen on inbox).

Material Design Preloader!s A jQuery plugin that recreates the Material Design preloader (as seen on inbox). I was fascinated when I first saw the pre

Aaron Lumsden 376 Dec 29, 2022
Serverless Pre-Rendering Landing Page

Serverless Pre-Rendering Demo Read the blog post Checkout the demo Developing By default, the content on the site is based off our public Notion page.

Vercel 389 Dec 21, 2022
O objetivo dessa aplicação era criar um frontend feito totalmente em Javascript, sem nenhum arquivo HTML ou CSS pré-criado. Além disso, esse projeto também é o frontend da minha API 100% NodeJS.

Projeto HTML 100% Javascript Front-end feito "sem HTML" Conteúdos ➜ Sobre o projeto ➜ O que aprendi ➜ Como usar ?? Sobre o projeto Voltar ao topo O ob

João Victor Negreiros 19 Aug 3, 2021
Pre-assignment for Reaktor Developer Trainee, which shows the current live matches of rock-scissors-paper games, and history results

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Vladislav Cherkasheninov 0 Feb 2, 2022
A CLI for generating starter files for different JS frameworks with tailwindCSS pre-installed

tailwindcsscli A CLI for generating starter files for different JS frameworks with tailwindCSS pre-installed Installation To install the CLI, run the

Kira 12 Sep 30, 2022
A plugin starter for medusa pre-configured and using typescript

Plugin starter (Typescript) Start to write your own plugin as quick as possible Getting started Installation git clone [email protected]:adrien2p/medusa-

Adrien de Peretti 12 Nov 9, 2022
My hometask for pre-basic course on OTUS

Репозиторий с домашними заданиями по подготовительному курсу JS OTUS Домашнее задание №1 «Линейные алгоритмы» В переменных a и b хранятся числа. Напис

null 1 Jan 21, 2022