@@ -4,19 +4,20 @@ const getReplacement = require('./get-replacement')
44
55module . 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