Skip to content

Commit 99ea71a

Browse files
xjlimKent C. Dodds
authored andcommitted
fix: remove babel-core dependency (#44)
* Remove babel-core dependency * Update .all-contributorsrc * Update .all-contributorsrc * Update README.md
1 parent ec3df93 commit 99ea71a

6 files changed

Lines changed: 48 additions & 14 deletions

File tree

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@
103103
"code",
104104
"test"
105105
]
106+
},
107+
{
108+
"login": "xjlim",
109+
"name": "Joe Lim",
110+
"avatar_url": "https://avatars1.githubusercontent.com/u/10875678?v=4",
111+
"profile": "https://joelim.me",
112+
"contributions": [
113+
"code"
114+
]
106115
}
107116
]
108117
}

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Pre-evaluate code at build-time
1212
[![downloads][downloads-badge]][npm-stat]
1313
[![MIT License][license-badge]][LICENSE]
1414

15-
[![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors)
15+
[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors)
1616
[![PRs Welcome][prs-badge]][prs]
1717
[![Donate][donate-badge]][donate]
1818
[![Code of Conduct][coc-badge]][coc]
@@ -74,6 +74,27 @@ or add `// @preval` comment at the top of a file.
7474

7575
See more below.
7676

77+
## Table of Contents
78+
79+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
80+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
81+
82+
- [Installation](#installation)
83+
- [Usage](#usage)
84+
- [Configure with Babel](#configure-with-babel)
85+
- [Use with [`babel-macros`][babel-macros]](#use-with-babel-macrosbabel-macros)
86+
- [Examples](#examples)
87+
- [Notes](#notes)
88+
- [FAQ](#faq)
89+
- [Inspiration](#inspiration)
90+
- [Related Projects](#related-projects)
91+
- [Other Solutions](#other-solutions)
92+
- [Contributors](#contributors)
93+
- [LICENSE](#license)
94+
95+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
96+
97+
7798
## Installation
7899

79100
This module is distributed via [npm][npm] which is bundled with [node][node] and
@@ -341,7 +362,7 @@ Thanks goes to these people ([emoji key][emojis]):
341362
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
342363
| [<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") |
343364
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
344-
| [<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 /> |
365+
| [<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 /> |
345366
<!-- ALL-CONTRIBUTORS-LIST:END -->
346367

347368
This project follows the [all-contributors][all-contributors] specification.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
2222
"license": "MIT",
2323
"dependencies": {
24-
"babel-core": "^6.26.0",
2524
"babel-macros": "^1.1.1",
2625
"babel-register": "^6.26.0",
2726
"babylon": "^6.18.0",

src/get-replacement.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
const babel = require('babel-core')
21
const requireFromString = require('require-from-string')
32
const objectToAST = require('./object-to-ast')
43

54
module.exports = getReplacement
65

7-
function getReplacement({string: stringToPreval, filename}) {
6+
function getReplacement({string: stringToPreval, filename, babel}) {
87
const {code: transpiled} = babel.transform(stringToPreval, {
98
filename,
109
})

src/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const objectToAST = require('./object-to-ast')
55

66
module.exports = prevalPlugin
77

8-
function prevalPlugin({types: t, template, transformFromAst}) {
8+
function prevalPlugin(babel) {
9+
const {types: t, template, transformFromAst} = babel
910
const assignmentBuilder = template('const NAME = VALUE')
1011
return {
1112
name: 'preval',
@@ -22,7 +23,7 @@ function prevalPlugin({types: t, template, transformFromAst}) {
2223
comments.find(isPrevalComment).value = ' this file was prevaled'
2324

2425
const {code: string} = transformFromAst(path.node)
25-
const replacement = getReplacement({string, filename})
26+
const replacement = getReplacement({string, filename, babel})
2627

2728
const moduleExports = Object.assign(
2829
{},
@@ -50,7 +51,7 @@ function prevalPlugin({types: t, template, transformFromAst}) {
5051
if (!string) {
5152
throw new Error('Unable to determine the value of your preval string')
5253
}
53-
const replacement = getReplacement({string, filename})
54+
const replacement = getReplacement({string, filename, babel})
5455
path.replaceWith(replacement)
5556
},
5657
ImportDeclaration(path, {file: {opts: {filename}}}) {
@@ -88,6 +89,7 @@ function prevalPlugin({types: t, template, transformFromAst}) {
8889
module.exports = mod
8990
`,
9091
filename,
92+
babel,
9193
})
9294
path.replaceWith(
9395
assignmentBuilder({

src/macro.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ const getReplacement = require('./get-replacement')
44

55
module.exports = createMacro(prevalMacros)
66

7-
function prevalMacros({references, state}) {
7+
function prevalMacros({references, state, babel}) {
88
references.default.forEach(referencePath => {
99
if (referencePath.parentPath.type === 'TaggedTemplateExpression') {
10-
asTag(referencePath.parentPath.get('quasi'), state)
10+
asTag(referencePath.parentPath.get('quasi'), state, babel)
1111
} else if (referencePath.parentPath.type === 'CallExpression') {
12-
asFunction(referencePath.parentPath.get('arguments'), state)
12+
asFunction(referencePath.parentPath.get('arguments'), state, babel)
1313
} else if (referencePath.parentPath.type === 'JSXOpeningElement') {
1414
asJSX(
1515
{
1616
attributes: referencePath.parentPath.get('attributes'),
1717
children: referencePath.parentPath.parentPath.get('children'),
1818
},
1919
state,
20+
babel,
2021
)
2122
} else if (referencePath.parentPath.type === 'JSXClosingElement') {
2223
// That's okay, we already prevaled this one on its opening element.
@@ -29,34 +30,37 @@ function prevalMacros({references, state}) {
2930
})
3031
}
3132

32-
function asTag(quasiPath, {file: {opts: {filename}}}) {
33+
function asTag(quasiPath, {file: {opts: {filename}}}, babel) {
3334
const string = quasiPath.parentPath.get('quasi').evaluate().value
3435
quasiPath.parentPath.replaceWith(
3536
getReplacement({
3637
string,
3738
filename,
39+
babel,
3840
}),
3941
)
4042
}
4143

42-
function asFunction(argumentsPaths, {file: {opts: {filename}}}) {
44+
function asFunction(argumentsPaths, {file: {opts: {filename}}}, babel) {
4345
const string = argumentsPaths[0].evaluate().value
4446
argumentsPaths[0].parentPath.replaceWith(
4547
getReplacement({
4648
string,
4749
filename,
50+
babel,
4851
}),
4952
)
5053
}
5154

5255
// eslint-disable-next-line no-unused-vars
53-
function asJSX({attributes, children}, {file: {opts: {filename}}}) {
56+
function asJSX({attributes, children}, {file: {opts: {filename}}}, babel) {
5457
// It's a shame you cannot use evaluate() with JSX
5558
const string = children[0].node.value
5659
children[0].replaceWith(
5760
getReplacement({
5861
string,
5962
filename,
63+
babel,
6064
}),
6165
)
6266
const {parentPath: {node: {openingElement, closingElement}}} = children[0]

0 commit comments

Comments
 (0)