Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// const printAST = require('ast-pretty-print')
const {createMacro} = require('babel-plugin-macros')
const getReplacers = require('./replace')
module.exports = createMacro(codegenMacros)
function codegenMacros({references, state, babel}) {
const {asIdentifier} = getReplacers(babel)
const fileOpts = state.file.opts
references.default.forEach(referencePath => {
if (asIdentifier(referencePath, fileOpts) === false) {
throw referencePath.buildCodeFrameError(
'codegen macro must be used as a tagged template literal, function, jsx, or .require call',
Error,
)
}
})
}
const path = require('path')
// const printAST = require('ast-pretty-print')
const {createMacro} = require('babel-plugin-macros')
const glob = require('glob')
module.exports = createMacro(prevalMacros)
function prevalMacros({references, state, babel}) {
references.default.forEach(referencePath => {
if (referencePath.parentPath.type === 'CallExpression') {
asyncVersion({referencePath, state, babel})
} else if (
referencePath.parentPath.type === 'MemberExpression' &&
referencePath.parentPath.node.property.name === 'sync'
) {
syncVersion({referencePath, state, babel})
} else if (
referencePath.parentPath.type === 'MemberExpression' &&
referencePath.parentPath.node.property.name === 'deferred'
) {
deferredVersion({referencePath, state, babel})
} else {
import path from 'path'
import {createMacro} from 'babel-plugin-macros'
const pkgName = 'react-broker'
export default createMacro(evaluateMacros)
// cycles through each call to the macro and determines an output for each
function evaluateMacros({references, state, babel}) {
references.default.forEach(referencePath =>
makeLegacyEnsure({
state,
babel,
referencePath,
})
)
}
// if Broker is defined in the scope then it will use that Broker, otherwise
// it requires the module.
function makeLegacyEnsure({state, babel, referencePath}) {
const brokerTemplate = babel.template.smart(
stylesArgument,
marcoConfig.warning
? t.booleanLiteral(true)
: t.booleanLiteral(false),
]),
),
]);
firstImportDeclarationNode.insertBefore(helperImportDeclaration);
firstNonImportDeclarationNode.insertBefore(bindedStylesDeclaration);
programPath.traverse(visitor(t, getStyleNameIdentifier, marcoConfig));
});
};
export default createMacro(myMacro, { configName: "reactCssModulesMacro" });
throw new Error(
'you have used `react-imported-component/macro` without `babel-plugin-macro` or `react-hot-loader/babel` installed'
);
};
const lazy: typeof import('./HOC').lazy = neverCallMe;
const imported: typeof import('./HOC').default = neverCallMe;
const importedModule: typeof import('./Module').importedModule = neverCallMe;
const useImported: typeof import('./useImported').useImported = neverCallMe;
const ImportedModule: typeof import('./Module').ImportedModule = neverCallMe;
const ImportedComponent: typeof import('./Component').ImportedComponent = neverCallMe;
export { lazy, imported, importedModule, ImportedModule, ImportedComponent, useImported, assignImportedComponents };
export default createMacro(macro);
const arrowFunctionExpression =
ast.program.body[1].declarations[0].init;
return t.objectProperty(
t.stringLiteral(componentName),
arrowFunctionExpression,
);
});
referencePath.parentPath.replaceWith(
t.objectExpression(objectProperties),
);
}
});
}
export default createMacro(svgrMacro);
path: NodePath,
) {
if (!t.isIdentifier(path.node.callee)) {
return;
}
const name = path.node.callee.name;
const importDecl = findImportDeclaration(t, name, path);
if (importDecl) {
importDecl.source.value = RUNTIME_IMPORT;
}
}
export default createMacro(function tsOptChainMacro(macro: Macro) {
const t = macro.babel.types;
for (const key of Object.keys(macro.references)) {
const paths = macro.references[key];
for (const path of paths) {
if (t.isCallExpression(path.parent)) {
const callPath = path.parentPath as NodePath<
BabelTypes.CallExpression
>;
transfromMacroImport(t, callPath);
transformOptchainCall(t, callPath);
}
}
}
return {
const flags = regExpConstructor.get('arguments.1')
regExpConstructor.replaceWith(
t.regExpLiteral(concatenated, flags && flags.node.value),
)
return
}
regexgenCall.replaceWith(t.stringLiteral(compiledRegExp))
return
}
regexgenCall.replaceWith(t.regExpLiteral(compiledRegExp))
})
}
export default createMacro(regexgenMacro)
import { createMacro } from 'babel-plugin-macros';
import generateScopeLog from '../scope';
module.exports = createMacro(({ babel: { template, types }, references }) =>
references.default.forEach(({ parentPath }) =>
parentPath.replaceWithMultiple(generateScopeLog(parentPath, template, types))
)
);
};
}
allMethods.forEach(({
method, path, sourceMethod, type,
}) => {
const isDecrementing = type === 'decrementing';
const isObject = type === 'object';
const handler = createTransformer(method, handlers[sourceMethod], isDecrementing, isObject);
handler(path);
});
}
module.exports = createMacro(inlineLoops);