Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (locale === pseudoLocale) {
pluralRules = plurals["en"]
}
const compiledMessages = R.keys(messages).map(key => {
let translation = messages[key] || (!strict ? key : "")
if (locale === pseudoLocale) {
translation = pseudoLocalize(translation)
}
return t.objectProperty(t.stringLiteral(key), compile(translation))
})
const languageData = [
t.objectProperty(
t.stringLiteral("plurals"),
parseExpression(pluralRules.toString())
)
]
const ast = buildExportStatement(
t.objectExpression([
// language data
t.objectProperty(
t.identifier("languageData"),
t.objectExpression(languageData)
),
// messages
t.objectProperty(
t.identifier("messages"),
t.objectExpression(compiledMessages)
)
]),
}
});
let callArgs = [t.arrayExpression(args)];
if (parent.callee === node) {
callArgs.push(t.numericLiteral(1));
}
let newNode = t.callExpression(t.identifier(memberFn), callArgs);
newNode.callee.__rmlSkipped = 1;
// will process a.v of x.y[a.v]
path.replaceWith(newNode);
// path.skip();
}
}
};
let expression = parseExpression(codeStr, babylonConfig);
let start = expression.start,
end = expression.end;
let ast = {
type: 'File',
start: start,
end: end,
program: {
start: start,
end: end,
type: 'Program',
body: [{
start: start,
end: end,
type: 'ExpressionStatement',
expression: expression
}]
if (type === 'string' || type === 'boolean') {
replacementDescriptor = {
type: type,
replacement: replacementDescriptor
}
} else if (t.isNode(replacementDescriptor)) {
replacementDescriptor = {
type: 'node',
replacement: replacementDescriptor
}
} else if (type === 'object'
&& replacementDescriptor.type === 'node'
&& typeof replacementDescriptor.replacement === 'string') {
replacementDescriptor.replacement = parseMap[replacementDescriptor.replacement]
? parseMap[replacementDescriptor.replacement]
: babylon.parseExpression(replacementDescriptor.replacement)
}
const replacement = replacementDescriptor.replacement
switch (replacementDescriptor.type) {
case 'boolean':
path.replaceWith(t.booleanLiteral(replacement))
break
case 'node':
if (t.isNode(replacement)) {
path.replaceWith(replacement)
}
break
default:
// treat as string
const str = String(replacement)
path.replaceWith(t.stringLiteral(str))
function checkValidJavaScriptStr(str) {
try {
babylon.parseExpression(str, {
allowImportExportEverywhere: true,
plugins: ['objectRestSpread'],
});
} catch (err) {
return false;
}
return true;
}
function checkValidJavaScriptStr(str) {
try {
babylon.parseExpression(str, {
allowImportExportEverywhere: true,
plugins: ['objectRestSpread'],
});
} catch (err) {
return false;
}
return true;
}
const applyTransform = (templateExpressionPath, text, options) => {
const jsx = jsxtremeMarkdown.toJsx(text, options);
const ast = babylon.parseExpression(jsx, { plugins: ['jsx'] });
templateExpressionPath.replaceWith(ast);
};
function isValidJSExp(exp) {
try {
parseExpression(exp, babylonConfig);
} catch (err) {
return false;
}
return true;
}
VariableDeclarator: (nodePath, state) => {
const {kind} = nodePath.parent
if (t.isIdentifier(nodePath.node.id)) {
const replaceCode =
state.replacers[`${kind} ${nodePath.node.id.name} =`]
if (replaceCode) {
const newAst = parseExpression(replaceCode)
nodePath.get('init').replaceWith(newAst)
}
}
},
'FunctionDeclaration|ClassDeclaration': (nodePath, state) => {