Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// import generate from "@babel/generator";
// console.log(template,t)
// const buildRequire = template(`
// var %%importName%% = require(%%source%%);
// `);
// const ast = buildRequire({
// importName: t.identifier("myModule"),
// source: t.stringLiteral("my-module"),
// });
// https://astexplorer.net/
const source = "my-module";
const ast = template.ast(`
// JS
var a = 'abcd'
`);
ast.kind = 'let'
console.log(ast);
console.log(generate(ast).code);
function astTernary(platform, valueTrue, valueFalse) {
// Omit the var assignment when specifier is empty (global import case, executing for the side-effects only).
const assignee = specifier ? `var ${specifier.local.name} = ` : "";
const platformStr = `import { Platform } from "react-native";`;
const platformImport = !isPlatformImportInserted ? platformStr : "";
if (platformImport) {
isPlatformImportInserted = true;
}
return babelTemplate.ast(
platformImport +
assignee +
`Platform.OS === "${platform}" ? require("${valueTrue}") : require("${valueFalse}");`
);
}
const buildShortcodeFunction = () =>
template.ast(
`
const mdxMakeShortcode = name => props => {
console.warn("Component " + name + " was not imported, exported, or provided by MDXProvider as global scope")
return <div>
}
`,
{
plugins: ['jsx']
}
)
</div>
module.exports.generate = memo((value) => {
const result = template.ast(value, {
allowAwaitOutsideFunction: true,
});
return result.expression || result;
});
function generateVariableDeclaration (name, tokens, css, componentId) {
return template.ast(`const ${name} = ${transformCSSRequire(tokens, css, componentId)}`)
}
module.exports.ast = memo((value, options) => {
const result = template.ast(value, {
...defaults,
...options,
});
return result.expression || result;
});