Skip to content

Commit 36de84a

Browse files
author
Kent C. Dodds
committed
fix: upgrade to babel-plugin-macros
1 parent f3ea21d commit 36de84a

10 files changed

Lines changed: 90 additions & 76 deletions

File tree

.github/ISSUE_TEMPLATE.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,17 @@ never done that before, that's great! Check this free short video tutorial to
1111
learn how: http://kcd.im/pull-request
1212
-->
1313

14-
- `babel-plugin-preval` version:
15-
- `node` version:
16-
- `npm` (or `yarn`) version:
14+
* `babel-plugin-preval` version:
15+
* `node` version:
16+
* `npm` (or `yarn`) version:
1717

1818
Relevant code or config
1919

2020
```javascript
21-
2221
```
2322

2423
What you did:
2524

26-
27-
2825
What happened:
2926

3027
<!-- Please provide the full error message/screenshots/anything -->
@@ -38,6 +35,4 @@ minimal amount of code possible.
3835

3936
Problem description:
4037

41-
42-
4338
Suggested solution:

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ merge of your pull request!
1515
-->
1616

1717
<!-- What changes are being made? (What feature/bug is being fixed here?) -->
18+
1819
**What**:
1920

2021
<!-- Why are these changes necessary? -->
22+
2123
**Why**:
2224

2325
<!-- How were these changes implemented? -->
24-
**How**:
2526

27+
**How**:
2628

2729
<!-- feel free to add additional comments -->

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Thanks for being willing to contribute!
44

5-
**Working on your first Pull Request?** You can learn how from this *free* series
5+
**Working on your first Pull Request?** You can learn how from this _free_ series
66
[How to Contribute to an Open Source Project on GitHub][egghead]
77

88
## Project setup

README.md

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<h1>babel-plugin-preval</h1>
33

44
Pre-evaluate code at build-time
5+
56
</div>
67

78
<hr />
@@ -10,21 +11,19 @@ Pre-evaluate code at build-time
1011
[![Code Coverage][coverage-badge]][coverage]
1112
[![version][version-badge]][package]
1213
[![downloads][downloads-badge]][npm-stat]
13-
[![MIT License][license-badge]][LICENSE]
14+
[![MIT License][license-badge]][license]
1415

1516
[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors)
1617
[![PRs Welcome][prs-badge]][prs]
1718
[![Donate][donate-badge]][donate]
1819
[![Code of Conduct][coc-badge]][coc]
19-
[![Babel Macro][macros-badge]][babel-macros]
20+
[![Babel Macro][macros-badge]][babel-plugin-macros]
2021
[![Examples][examples-badge]][examples]
2122

2223
[![Watch on GitHub][github-watch-badge]][github-watch]
2324
[![Star on GitHub][github-star-badge]][github-star]
2425
[![Tweet][twitter-badge]][twitter]
2526

26-
<a href="https://app.codesponsor.io/link/PKGFLnhDiFvsUA5P4kAXfiPs/kentcdodds/babel-plugin-preval" rel="nofollow"><img src="https://app.codesponsor.io/embed/PKGFLnhDiFvsUA5P4kAXfiPs/kentcdodds/babel-plugin-preval.svg" style="width: 888px; height: 68px;" alt="Sponsor" /></a>
27-
2827
## The problem
2928

3029
You need to do some dynamic stuff, but don't want to do it at runtime. Or maybe
@@ -37,11 +36,11 @@ This allows you to specify some code that runs in Node and whatever you
3736
`module.exports` in there will be swapped. For example:
3837

3938
```js
40-
const x = preval`module.exports = 1`;
39+
const x = preval`module.exports = 1`
4140

4241
// ↓ ↓ ↓ ↓ ↓ ↓
4342

44-
const x = 1;
43+
const x = 1
4544
```
4645

4746
Or, more interestingly:
@@ -77,25 +76,33 @@ See more below.
7776
## Table of Contents
7877

7978
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
80-
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
8179

80+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
8281

83-
- [Installation](#installation)
84-
- [Usage](#usage)
85-
- [Configure with Babel](#configure-with-babel)
86-
- [Use with `babel-macros`](#use-with-babel-macros)
87-
- [Examples](#examples)
88-
- [Notes](#notes)
89-
- [FAQ](#faq)
90-
- [Inspiration](#inspiration)
91-
- [Related Projects](#related-projects)
92-
- [Other Solutions](#other-solutions)
93-
- [Contributors](#contributors)
94-
- [LICENSE](#license)
82+
* [Installation](#installation)
83+
* [Usage](#usage)
84+
* [Template Tag](#template-tag)
85+
* [import comment](#import-comment)
86+
* [preval.require](#prevalrequire)
87+
* [preval file comment (`// @preval`)](#preval-file-comment--preval)
88+
* [Configure with Babel](#configure-with-babel)
89+
* [Via `.babelrc` (Recommended)](#via-babelrc-recommended)
90+
* [Via CLI](#via-cli)
91+
* [Via Node API](#via-node-api)
92+
* [Use with `babel-plugin-macros`](#use-with-babel-plugin-macros)
93+
* [Examples](#examples)
94+
* [Notes](#notes)
95+
* [FAQ](#faq)
96+
* [How is this different from [prepack][prepack]?](#how-is-this-different-from-prepackprepack)
97+
* [How is this different from [webpack][webpack] [loaders][webpack-loaders]?](#how-is-this-different-from-webpackwebpack-loaderswebpack-loaders)
98+
* [Inspiration](#inspiration)
99+
* [Related Projects](#related-projects)
100+
* [Other Solutions](#other-solutions)
101+
* [Contributors](#contributors)
102+
* [LICENSE](#license)
95103

96104
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
97105

98-
99106
## Installation
100107

101108
This module is distributed via [npm][npm] which is bundled with [node][node] and
@@ -131,7 +138,7 @@ const greeting = preval`
131138
**After** (assuming `greeting.txt` contains the text: `"Hello world!"`):
132139

133140
```javascript
134-
const greeting = "Hello world!"
141+
const greeting = 'Hello world!'
135142
```
136143

137144
`preval` can also handle _some_ simple dynamic values as well:
@@ -149,8 +156,8 @@ const person = preval`
149156
**After** (assuming `./name-splitter` is a function that splits a name into first/last):
150157

151158
```javascript
152-
const name = 'Bob Hope';
153-
const person = { "first": "Bob", "last": "Hope" };
159+
const name = 'Bob Hope'
160+
const person = {first: 'Bob', last: 'Hope'}
154161
```
155162

156163
### import comment
@@ -200,7 +207,10 @@ And you can provide _some_ simple dynamic arguments as well:
200207
**Before**:
201208

202209
```javascript
203-
const fileLastModifiedDate = preval.require('./get-last-modified-date', '../../some-other-file.js')
210+
const fileLastModifiedDate = preval.require(
211+
'./get-last-modified-date',
212+
'../../some-other-file.js',
213+
)
204214
```
205215

206216
**After**:
@@ -220,8 +230,8 @@ Whereas the above usages (assignment/import/require) will only preval the scope
220230
```javascript
221231
// @preval
222232

223-
const id = require("./path/identity")
224-
const one = require("./path/one")
233+
const id = require('./path/identity')
234+
const one = require('./path/one')
225235

226236
const compose = (...fns) => fns.reduce((f, g) => a => f(g(a)))
227237
const double = a => a * 2
@@ -262,9 +272,9 @@ require('babel-core').transform('code', {
262272
})
263273
```
264274

265-
## Use with `babel-macros`
275+
## Use with `babel-plugin-macros`
266276

267-
Once you've [configured `babel-macros`](https://github.com/kentcdodds/babel-macros/blob/master/other/docs/user.md)
277+
Once you've [configured `babel-plugin-macros`](https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md)
268278
you can import/require the preval macro at `babel-plugin-preval/macro`.
269279
For example:
270280

@@ -278,37 +288,33 @@ const one = preval`module.exports = 1 + 2 - 1 - 1`
278288
279289
## Examples
280290

281-
- [Mastodon](https://github.com/tootsuite/mastodon/pull/4202) saved 40kb
291+
* [Mastodon](https://github.com/tootsuite/mastodon/pull/4202) saved 40kb
282292
(gzipped) using `babel-plugin-preval`
283-
- [glamorous-website](https://github.com/kentcdodds/glamorous-website/pull/235)
293+
* [glamorous-website](https://github.com/kentcdodds/glamorous-website/pull/235)
284294
uses [`preval.macro`][preval.macro] to determine Algolia options based on
285295
`process.env.LOCALE`. It also uses [`preval.macro`][preval.macro] to load an
286296
`svg` file as a string, `base64` encode it, and use it as a `background-url`
287297
for an input element.
288-
- [Generate documentation for React components](https://gist.github.com/souporserious/575609dc5a5d52e167dd2236079eccc0)
289-
- [Serverless with webpack](https://github.com/geovanisouza92/serverless-preval) build serverless functions using webpack and Babel for development and production with preval to replace (possible sensible) content in code.
298+
* [Generate documentation for React components](https://gist.github.com/souporserious/575609dc5a5d52e167dd2236079eccc0)
299+
* [Serverless with webpack](https://github.com/geovanisouza92/serverless-preval) build serverless functions using webpack and Babel for development and production with preval to replace (possible sensible) content in code.
290300

291301
## Notes
292302

293303
If you use `babel-plugin-transform-decorators-legacy`, there is a conflict because both plugins must be placed at the top
294304

295305
Wrong:
306+
296307
```json
297308
{
298-
"plugins": [
299-
"preval",
300-
"transform-decorators-legacy"
301-
]
309+
"plugins": ["preval", "transform-decorators-legacy"]
302310
}
303311
```
304312

305313
Ok:
314+
306315
```json
307316
{
308-
"plugins": [
309-
"preval",
310-
["transform-decorators-legacy"]
311-
]
317+
"plugins": ["preval", ["transform-decorators-legacy"]]
312318
}
313319
```
314320

@@ -349,7 +355,7 @@ I was inspired by the [val-loader][val-loader] from webpack.
349355

350356
## Related Projects
351357

352-
- [`preval.macro`][preval.macro] - nicer integration with `babel-macros`
358+
* [`preval.macro`][preval.macro] - nicer integration with `babel-plugin-macros`
353359

354360
## Other Solutions
355361

@@ -361,9 +367,12 @@ here!
361367
Thanks goes to these people ([emoji key][emojis]):
362368

363369
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
364-
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/babel-plugin-preval/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=kentcdodds "Tests") | [<img src="https://avatars3.githubusercontent.com/u/5610087?v=3" width="100px;"/><br /><sub>Matt Phillips</sub>](http://mattphillips.io)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=mattphillips "Code") [📖](https://github.com/kentcdodds/babel-plugin-preval/commits?author=mattphillips "Documentation") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=mattphillips "Tests") | [<img src="https://avatars1.githubusercontent.com/u/28024000?v=3" width="100px;"/><br /><sub>Philip Oliver</sub>](https://twitter.com/philipodev)<br />[🐛](https://github.com/kentcdodds/babel-plugin-preval/issues?q=author%3Aphilipodev "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/2109702?v=3" width="100px;"/><br /><sub>Sorin Davidoi</sub>](https://toot.cafe/@sorin)<br />[🐛](https://github.com/kentcdodds/babel-plugin-preval/issues?q=author%3Asorin-davidoi "Bug reports") [💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=sorin-davidoi "Code") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=sorin-davidoi "Tests") | [<img src="https://avatars4.githubusercontent.com/u/1127238?v=4" width="100px;"/><br /><sub>Luke Herrington</sub>](https://github.com/infiniteluke)<br />[💡](#example-infiniteluke "Examples") | [<img src="https://avatars4.githubusercontent.com/u/22868432?v=4" width="100px;"/><br /><sub>Lufty Wiranda</sub>](http://instagram.com/luftywiranda13)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=luftywiranda13 "Code") | [<img src="https://avatars0.githubusercontent.com/u/3877773?v=4" width="100px;"/><br /><sub>Oscar</sub>](http://obartra.github.io)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=obartra "Code") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=obartra "Tests") |
370+
371+
<!-- prettier-ignore -->
372+
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/babel-plugin-preval/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=kentcdodds "Tests") | [<img src="https://avatars3.githubusercontent.com/u/5610087?v=3" width="100px;"/><br /><sub><b>Matt Phillips</b></sub>](http://mattphillips.io)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=mattphillips "Code") [📖](https://github.com/kentcdodds/babel-plugin-preval/commits?author=mattphillips "Documentation") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=mattphillips "Tests") | [<img src="https://avatars1.githubusercontent.com/u/28024000?v=3" width="100px;"/><br /><sub><b>Philip Oliver</b></sub>](https://twitter.com/philipodev)<br />[🐛](https://github.com/kentcdodds/babel-plugin-preval/issues?q=author%3Aphilipodev "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/2109702?v=3" width="100px;"/><br /><sub><b>Sorin Davidoi</b></sub>](https://toot.cafe/@sorin)<br />[🐛](https://github.com/kentcdodds/babel-plugin-preval/issues?q=author%3Asorin-davidoi "Bug reports") [💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=sorin-davidoi "Code") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=sorin-davidoi "Tests") | [<img src="https://avatars4.githubusercontent.com/u/1127238?v=4" width="100px;"/><br /><sub><b>Luke Herrington</b></sub>](https://github.com/infiniteluke)<br />[💡](#example-infiniteluke "Examples") | [<img src="https://avatars4.githubusercontent.com/u/22868432?v=4" width="100px;"/><br /><sub><b>Lufty Wiranda</b></sub>](http://instagram.com/luftywiranda13)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=luftywiranda13 "Code") | [<img src="https://avatars0.githubusercontent.com/u/3877773?v=4" width="100px;"/><br /><sub><b>Oscar</b></sub>](http://obartra.github.io)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=obartra "Code") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=obartra "Tests") |
365373
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
366-
| [<img src="https://avatars1.githubusercontent.com/u/14310216?v=4" width="100px;"/><br /><sub>pro-nasa</sub>](https://github.com/pro-nasa)<br />[📖](https://github.com/kentcdodds/babel-plugin-preval/commits?author=pro-nasa "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/9248479?v=4" width="100px;"/><br /><sub>Sergey Bekrin</sub>](http://bekrin.me)<br /> | [<img src="https://avatars0.githubusercontent.com/u/18613301?v=4" width="100px;"/><br /><sub>Mauro Bringolf</sub>](https://maurobringolf.ch)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=maurobringolf "Code") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=maurobringolf "Tests") | [<img src="https://avatars1.githubusercontent.com/u/10875678?v=4" width="100px;"/><br /><sub>Joe Lim</sub>](https://joelim.me)<br /> |
374+
| [<img src="https://avatars1.githubusercontent.com/u/14310216?v=4" width="100px;"/><br /><sub><b>pro-nasa</b></sub>](https://github.com/pro-nasa)<br />[📖](https://github.com/kentcdodds/babel-plugin-preval/commits?author=pro-nasa "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/9248479?v=4" width="100px;"/><br /><sub><b>Sergey Bekrin</b></sub>](http://bekrin.me)<br /> | [<img src="https://avatars0.githubusercontent.com/u/18613301?v=4" width="100px;"/><br /><sub><b>Mauro Bringolf</b></sub>](https://maurobringolf.ch)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=maurobringolf "Code") [⚠️](https://github.com/kentcdodds/babel-plugin-preval/commits?author=maurobringolf "Tests") | [<img src="https://avatars1.githubusercontent.com/u/10875678?v=4" width="100px;"/><br /><sub><b>Joe Lim</b></sub>](https://joelim.me)<br />[💻](https://github.com/kentcdodds/babel-plugin-preval/commits?author=xjlim "Code") |
375+
367376
<!-- ALL-CONTRIBUTORS-LIST:END -->
368377

369378
This project follows the [all-contributors][all-contributors] specification.
@@ -392,7 +401,7 @@ MIT
392401
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
393402
[coc]: https://github.com/kentcdodds/babel-plugin-preval/blob/master/other/CODE_OF_CONDUCT.md
394403
[macros-badge]: https://img.shields.io/badge/babel--macro-%F0%9F%8E%A3-f5da55.svg?style=flat-square
395-
[babel-macros]: https://github.com/kentcdodds/babel-macros
404+
[babel-plugin-macros]: https://github.com/kentcdodds/babel-plugin-macros
396405
[examples-badge]: https://img.shields.io/badge/%F0%9F%92%A1-examples-8C8E93.svg?style=flat-square
397406
[examples]: https://github.com/kentcdodds/babel-plugin-preval/blob/master/other/EXAMPLES.md
398407
[github-watch-badge]: https://img.shields.io/github/watchers/kentcdodds/babel-plugin-preval.svg?style=social

other/CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ include:
2323
Examples of unacceptable behavior by participants include:
2424

2525
* The use of sexualized language or imagery and unwelcome sexual attention or
26-
advances
26+
advances
2727
* Trolling, insulting/derogatory comments, and personal or political attacks
2828
* Public or private harassment
2929
* Publishing others' private information, such as a physical or electronic

other/EXAMPLES.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ const whoami = preval`
1515

1616
export default WhoAmI
1717

18-
function WhoAmI () {
18+
function WhoAmI() {
1919
return (
2020
<div style={{display: 'flex', justifyContent: 'center'}}>
2121
<h1>
22-
<pre>
23-
whoami: {whoami}
24-
</pre>
22+
<pre>whoami: {whoami}</pre>
2523
</h1>
2624
</div>
2725
)
@@ -31,24 +29,26 @@ function WhoAmI () {
3129
### Code reuse with babel-plugin-preval (Especially useful with [Next.js](https://github.com/zeit/next.js))
3230

3331
A small `getPosts.js` node module that loads in markdown files in a "posts" directory.
32+
3433
```js
35-
const frontMatter = require('yaml-front-matter');
36-
const fs = require('fs');
37-
const path = require('path');
34+
const frontMatter = require('yaml-front-matter')
35+
const fs = require('fs')
36+
const path = require('path')
3837

3938
const posts = fs
4039
.readdirSync('./posts/')
4140
.filter(file => path.extname(file) === '.md')
42-
.map(file => frontMatter.loadFront(`./posts/${file}`, 'body'));
41+
.map(file => frontMatter.loadFront(`./posts/${file}`, 'body'))
4342

44-
module.exports = posts || [];
43+
module.exports = posts || []
4544
```
4645

4746
Preval the `getPosts.js` module so that posts are loaded and exported.
47+
4848
```js
49-
import preval from 'preval.macro';
49+
import preval from 'preval.macro'
5050

51-
export default preval`module.exports = require('./getPosts')`;
51+
export default preval`module.exports = require('./getPosts')`
5252
```
5353

5454
Now you can import the above posts and use a module like [marked](https://github.com/chjj/marked) to convert your markdown into blog posts! The underlying `getPosts.js` module can also be used required in `next.config.js` to build the static list of routes for `next export`. See the full example in the [Next Static](https://github.com/infiniteluke/next-static) project.

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,25 @@
1717
"precommit": "kcd-scripts precommit"
1818
},
1919
"files": ["dist", "macro.js"],
20-
"keywords": ["babel", "babel-plugin", "eval", "precompile", "babel-macros"],
20+
"keywords": [
21+
"babel",
22+
"babel-plugin",
23+
"eval",
24+
"precompile",
25+
"babel-plugin-macros"
26+
],
2127
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
2228
"license": "MIT",
2329
"dependencies": {
24-
"babel-macros": "^1.1.1",
30+
"babel-plugin-macros": "^2.0.0",
2531
"babel-register": "^6.26.0",
2632
"babylon": "^6.18.0",
2733
"require-from-string": "^2.0.1"
2834
},
2935
"devDependencies": {
3036
"ast-pretty-print": "^2.0.1",
31-
"babel-plugin-tester": "^4.0.0",
32-
"kcd-scripts": "^0.27.0"
37+
"babel-plugin-tester": "^5.0.0",
38+
"kcd-scripts": "^0.30.4"
3339
},
3440
"eslintConfig": {
3541
"extends": "./node_modules/kcd-scripts/eslint.js"

src/__tests__/macro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path'
22
import pluginTester from 'babel-plugin-tester'
3-
import plugin from 'babel-macros'
3+
import plugin from 'babel-plugin-macros'
44

55
const projectRoot = path.join(__dirname, '../../')
66

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ function prevalPlugin(babel) {
132132
if (argValues.length) {
133133
if (typeof mod !== 'function') {
134134
throw new Error(
135-
`\`preval.require\`-ed module (${source.node
136-
.value}) cannot accept arguments because it does not export a function. You passed the arguments: ${argValues.join(
135+
`\`preval.require\`-ed module (${
136+
source.node.value
137+
}) cannot accept arguments because it does not export a function. You passed the arguments: ${argValues.join(
137138
', ',
138139
)}`,
139140
)

0 commit comments

Comments
 (0)