Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parentNode.tagName ? ` parentName="${parentNode.tagName}"` : ''
}${props ? ` {...${props}}` : ''}>${children}`
}
// Wraps text nodes inside template string, so that we don't run into escaping issues.
if (node.type === 'text') {
// Don't wrap newlines unless specifically instructed to by the flag,
// to avoid issues like React warnings caused by text nodes in tables.
const shouldPreserveNewlines =
preserveNewlines || parentNode.tagName === 'p'
if (node.value === '\n' && !shouldPreserveNewlines) {
return node.value
}
return toTemplateLiteral(node.value)
}
if (node.type === 'comment') {
return `{/*${node.value}*/}`
}
if (node.type === 'import' || node.type === 'export' || node.type === 'jsx') {
return node.value
}
}
(properties, [key, value]) =>
Object.assign({}, properties, {
[paramCaseRe.test(key) ? paramCase(key) : key]: value
}),
{}
JSXAttribute(node) {
if (node.node.name.name in TRANSLATIONS) {
node.node.name.name = TRANSLATIONS[node.node.name.name]
} else if (node.node.name.name === `props`) {
node.traverse(propsKeysVisitor)
} else if (
node.node.name.name.startsWith(`data`) ||
node.node.name.name.startsWith(`aria`)
) {
const CAMEL_CASE_REGEX = /^(aria[A-Z])|(data[A-Z])/
if (CAMEL_CASE_REGEX.test(node.node.name.name)) {
node.node.name.name = camelCase(node.node.name.name)
}
} else if (
node.node.name.name in ARRAY_TO_STRING &&
node.node.value.type === 'JSXExpressionContainer' &&
node.node.value.expression.type === 'ArrayExpression'
) {
node.node.value = t.stringLiteral(
node.node.value.expression.elements.map(el => el.value).join(' ')
)
}
if (
node.node.name.name === `style` &&
node.node.value.type === `StringLiteral`
) {
let styleArray = []
visit(tree, 'jsx', node => {
if (isComment(node.value)) {
node.type = 'comment'
node.value = getCommentContents(node.value)
}
})
visit(tree, 'jsx', node => {
if (isComment(node.value)) {
node.type = 'comment'
node.value = getCommentContents(node.value)
}
})
function tokenizeEsSyntax(eat, value) {
const index = value.indexOf(EMPTY_NEWLINE)
const subvalue = index !== -1 ? value.slice(0, index) : value
if (isImportOrExport(subvalue)) {
const nodes = extractImportsAndExports(subvalue, this.file)
nodes.map(node => eat(node.value)(node))
}
}
function tokenizeEsSyntaxLocator(value, _fromIndex) {
return isImportOrExport(value) ? -1 : 1
}
JSXOpeningElement(path) {
const jsxName = path.node.name.name
if (startsWithCapitalLetter(jsxName)) {
componentNames.push(jsxName)
path.node.attributes.push(
t.jSXAttribute(
t.jSXIdentifier(`mdxType`),
t.stringLiteral(jsxName)
)
)
}
}
}