WIP - add extractor, generate snippet_data
This commit is contained in:
6
node_modules/babel-plugin-macros/dist/__tests__/fixtures/config/babel-plugin-macros.config.js
generated
vendored
Normal file
6
node_modules/babel-plugin-macros/dist/__tests__/fixtures/config/babel-plugin-macros.config.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
configurableMacro: {
|
||||
fileConfig: true,
|
||||
someConfig: true,
|
||||
},
|
||||
}
|
||||
4
node_modules/babel-plugin-macros/dist/__tests__/fixtures/config/cjs-code.js
generated
vendored
Normal file
4
node_modules/babel-plugin-macros/dist/__tests__/fixtures/config/cjs-code.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
const configured = require('./configurable.macro')
|
||||
|
||||
// eslint-disable-next-line babel/no-unused-expressions
|
||||
configured`stuff`
|
||||
4
node_modules/babel-plugin-macros/dist/__tests__/fixtures/config/code.js
generated
vendored
Normal file
4
node_modules/babel-plugin-macros/dist/__tests__/fixtures/config/code.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import configured from './configurable.macro'
|
||||
|
||||
// eslint-disable-next-line babel/no-unused-expressions
|
||||
configured`stuff`
|
||||
10
node_modules/babel-plugin-macros/dist/__tests__/fixtures/config/configurable.macro.js
generated
vendored
Normal file
10
node_modules/babel-plugin-macros/dist/__tests__/fixtures/config/configurable.macro.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
const {createMacro} = require('../../../../')
|
||||
|
||||
const configName = 'configurableMacro'
|
||||
const realMacro = jest.fn()
|
||||
module.exports = createMacro(realMacro, {configName})
|
||||
// for testing purposes only
|
||||
Object.assign(module.exports, {
|
||||
realMacro,
|
||||
configName,
|
||||
})
|
||||
8
node_modules/babel-plugin-macros/dist/__tests__/fixtures/emotion-esm.macro.js
generated
vendored
Normal file
8
node_modules/babel-plugin-macros/dist/__tests__/fixtures/emotion-esm.macro.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
const {createMacro} = require('../../')
|
||||
|
||||
export default createMacro(evalMacro)
|
||||
|
||||
function evalMacro() {
|
||||
// we're lazy right now
|
||||
// we don't want to eval
|
||||
}
|
||||
29
node_modules/babel-plugin-macros/dist/__tests__/fixtures/emotion.macro.js
generated
vendored
Normal file
29
node_modules/babel-plugin-macros/dist/__tests__/fixtures/emotion.macro.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// this is a fake version of emotion
|
||||
// const printAST = require('ast-pretty-print')
|
||||
const {createMacro} = require('../../')
|
||||
|
||||
module.exports = createMacro(emotionMacro)
|
||||
|
||||
function emotionMacro({references, babel}) {
|
||||
const {types: t} = babel
|
||||
references.css.forEach(cssRef => {
|
||||
if (cssRef.parentPath.type === 'TaggedTemplateExpression') {
|
||||
cssRef.parentPath.replaceWith(
|
||||
t.stringLiteral(
|
||||
cssRef.parentPath
|
||||
.get('quasi')
|
||||
.evaluate()
|
||||
.value.trim(),
|
||||
),
|
||||
)
|
||||
}
|
||||
})
|
||||
references.styled.forEach(styledRef => {
|
||||
if (styledRef.parentPath.parentPath.type === 'TaggedTemplateExpression') {
|
||||
const quasi = styledRef.parentPath.parentPath.get('quasi')
|
||||
const val = quasi.evaluate().value.trim()
|
||||
const replacement = t.templateLiteral([t.templateElement(val)], [])
|
||||
quasi.replaceWith(replacement)
|
||||
}
|
||||
})
|
||||
}
|
||||
8
node_modules/babel-plugin-macros/dist/__tests__/fixtures/error-thrower.macro.js
generated
vendored
Normal file
8
node_modules/babel-plugin-macros/dist/__tests__/fixtures/error-thrower.macro.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
// const printAST = require('ast-pretty-print')
|
||||
const {createMacro} = require('../../')
|
||||
|
||||
module.exports = createMacro(evalMacro)
|
||||
|
||||
function evalMacro() {
|
||||
throw new Error('very unhelpful')
|
||||
}
|
||||
54
node_modules/babel-plugin-macros/dist/__tests__/fixtures/eval.macro.js
generated
vendored
Normal file
54
node_modules/babel-plugin-macros/dist/__tests__/fixtures/eval.macro.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
const {parse} = require('@babel/parser')
|
||||
// const printAST = require('ast-pretty-print')
|
||||
const {createMacro} = require('../../')
|
||||
|
||||
module.exports = createMacro(evalMacro)
|
||||
|
||||
function evalMacro({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) {
|
||||
const value = quasiPath.parentPath.get('quasi').evaluate().value
|
||||
quasiPath.parentPath.replaceWith(evalToAST(value))
|
||||
}
|
||||
|
||||
function asFunction(argumentsPaths) {
|
||||
const value = argumentsPaths[0].evaluate().value
|
||||
argumentsPaths[0].parentPath.replaceWith(evalToAST(value))
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function asJSX({attributes, children}) {
|
||||
// It's a shame you cannot use evaluate() with JSX
|
||||
const value = children[0].node.value
|
||||
children[0].parentPath.replaceWith(evalToAST(value))
|
||||
}
|
||||
|
||||
function evalToAST(value) {
|
||||
let x
|
||||
// eslint-disable-next-line
|
||||
eval(`x = ${value}`)
|
||||
return thingToAST(x)
|
||||
}
|
||||
|
||||
function thingToAST(object) {
|
||||
const fileNode = parse(`var x = ${JSON.stringify(object)}`)
|
||||
return fileNode.program.body[0].declarations[0].init
|
||||
}
|
||||
20
node_modules/babel-plugin-macros/dist/__tests__/fixtures/jsx-id-prefix.macro.js
generated
vendored
Normal file
20
node_modules/babel-plugin-macros/dist/__tests__/fixtures/jsx-id-prefix.macro.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// adds "prefix-" to each `id` attribute
|
||||
const {createMacro} = require('../../')
|
||||
|
||||
module.exports = createMacro(wrapWidget)
|
||||
|
||||
function wrapWidget({references, babel}) {
|
||||
const {types: t} = babel
|
||||
references.default.forEach(wrap => {
|
||||
wrap.parentPath.traverse({
|
||||
JSXAttribute(path) {
|
||||
const name = path.get('name')
|
||||
if (t.isJSXIdentifier(name) && name.node.name === 'id') {
|
||||
const value = path.get('value')
|
||||
if (t.isStringLiteral(value))
|
||||
value.replaceWith(t.stringLiteral(`macro-${value.node.value}`))
|
||||
}
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
23
node_modules/babel-plugin-macros/dist/__tests__/fixtures/jsx-id-prefix.plugin.js
generated
vendored
Normal file
23
node_modules/babel-plugin-macros/dist/__tests__/fixtures/jsx-id-prefix.plugin.js
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
// babel-plugin adding `plugin-` prefix to each "id" JSX attribute
|
||||
module.exports = main
|
||||
|
||||
function main({types: t}) {
|
||||
return {
|
||||
visitor: {
|
||||
// intentionally traversing from Program,
|
||||
// if it matches JSXAttribute here the issue won't be reproduced
|
||||
Program(progPath) {
|
||||
progPath.traverse({
|
||||
JSXAttribute(path) {
|
||||
const name = path.get('name')
|
||||
if (t.isJSXIdentifier(name) && name.node.name === 'id') {
|
||||
const value = path.get('value')
|
||||
if (t.isStringLiteral(value))
|
||||
value.replaceWith(t.stringLiteral(`plugin-${value.node.value}`))
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
7
node_modules/babel-plugin-macros/dist/__tests__/fixtures/keep-imports.macro.js
generated
vendored
Normal file
7
node_modules/babel-plugin-macros/dist/__tests__/fixtures/keep-imports.macro.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
const {createMacro} = require('../../')
|
||||
|
||||
module.exports = createMacro(keepImportMacro)
|
||||
|
||||
function keepImportMacro() {
|
||||
return {keepImports: true}
|
||||
}
|
||||
8
node_modules/babel-plugin-macros/dist/__tests__/fixtures/macro-error-thrower.macro.js
generated
vendored
Normal file
8
node_modules/babel-plugin-macros/dist/__tests__/fixtures/macro-error-thrower.macro.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
// const printAST = require('ast-pretty-print')
|
||||
const {createMacro, MacroError} = require('../../')
|
||||
|
||||
module.exports = createMacro(evalMacro)
|
||||
|
||||
function evalMacro() {
|
||||
throw new MacroError('very helpful')
|
||||
}
|
||||
1
node_modules/babel-plugin-macros/dist/__tests__/fixtures/non-wrapped.macro.js
generated
vendored
Normal file
1
node_modules/babel-plugin-macros/dist/__tests__/fixtures/non-wrapped.macro.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = () => {}
|
||||
5
node_modules/babel-plugin-macros/dist/__tests__/fixtures/path-replace-issue/variable-assignment.js
generated
vendored
Normal file
5
node_modules/babel-plugin-macros/dist/__tests__/fixtures/path-replace-issue/variable-assignment.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import myEval from '../eval.macro'
|
||||
|
||||
const result = myEval`+('4' + '2')`
|
||||
|
||||
global.result = result
|
||||
3
node_modules/babel-plugin-macros/dist/__tests__/fixtures/primitive-config/babel-plugin-macros.config.js
generated
vendored
Normal file
3
node_modules/babel-plugin-macros/dist/__tests__/fixtures/primitive-config/babel-plugin-macros.config.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
configurableMacro: 4,
|
||||
}
|
||||
4
node_modules/babel-plugin-macros/dist/__tests__/fixtures/primitive-config/code.js
generated
vendored
Normal file
4
node_modules/babel-plugin-macros/dist/__tests__/fixtures/primitive-config/code.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import configured from './configurable.macro'
|
||||
|
||||
// eslint-disable-next-line babel/no-unused-expressions
|
||||
configured`stuff`
|
||||
10
node_modules/babel-plugin-macros/dist/__tests__/fixtures/primitive-config/configurable.macro.js
generated
vendored
Normal file
10
node_modules/babel-plugin-macros/dist/__tests__/fixtures/primitive-config/configurable.macro.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
const {createMacro} = require('../../../../')
|
||||
|
||||
const configName = 'configurableMacro'
|
||||
const realMacro = jest.fn()
|
||||
module.exports = createMacro(realMacro, {configName})
|
||||
// for testing purposes only
|
||||
Object.assign(module.exports, {
|
||||
realMacro,
|
||||
configName,
|
||||
})
|
||||
Reference in New Issue
Block a user