Skip to content

Commit

Permalink
fix(macros): update macros to the latest API
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed Jul 8, 2017
1 parent 635a162 commit 600beb8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
23 changes: 18 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
"commitmsg": "opt --in commit-msg --exec \"validate-commit-msg\"",
"precommit": "lint-staged && opt --in pre-commit --exec \"npm start validate\""
},
"files": ["dist"],
"keywords": ["babel", "babel-plugin", "eval", "precompile"],
"files": [
"dist"
],
"keywords": [
"babel",
"babel-plugin",
"eval",
"precompile"
],
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
"license": "MIT",
"dependencies": {
Expand All @@ -23,7 +30,7 @@
"ast-pretty-print": "^2.0.0",
"babel-cli": "^6.24.1",
"babel-jest": "^20.0.3",
"babel-macros": "0.3.0",
"babel-macros": "0.4.0",
"babel-plugin-tester": "^3.2.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-inline-environment-variables": "0.1.1",
Expand All @@ -44,11 +51,17 @@
"validate-commit-msg": "^2.12.1"
},
"lint-staged": {
"*.js": ["prettier-eslint --write --print-width=80", "git add"]
"*.js": [
"prettier-eslint --write --print-width=80",
"git add"
]
},
"jest": {
"testEnvironment": "node",
"testPathIgnorePatterns": ["/node_modules/", "/fixtures/"],
"testPathIgnorePatterns": [
"/node_modules/",
"/fixtures/"
],
"coverageThreshold": {
"global": {
"branches": 100,
Expand Down
24 changes: 22 additions & 2 deletions src/macros.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
// const printAST = require('ast-pretty-print')
const getReplacement = require('./get-replacement')

// this implements the babel-macros v0.2.0 API
module.exports = {asTag, asFunction, asJSX}
// this implements the babel-macros v0.4.0 API
module.exports = prevalMacros

function prevalMacros({references, state}) {
references.default.forEach(referencePath => {
if (referencePath.parentPath.type === 'TaggedTemplateExpression') {
asTag(referencePath.parentPath.get('quasi'), state)
} else if (referencePath.parentPath.type === 'CallExpression') {
asFunction(referencePath.parentPath.get('arguments'), state)
} else if (referencePath.parentPath.type === 'JSXOpeningElement') {
asJSX(
{
attributes: referencePath.parentPath.get('attributes'),
children: referencePath.parentPath.parentPath.get('children'),
},
state,
)
} else {
// TODO: throw a helpful error message
}
})
}

function asTag(quasiPath, {file: {opts: {filename}}}) {
const string = quasiPath.parentPath.get('quasi').evaluate().value
Expand Down

0 comments on commit 600beb8

Please sign in to comment.