How to use the isValidIdentifier function from @babel/types
Find comprehensive JavaScript @babel/types.isValidIdentifier code examples handpicked from public code repositorys.
3 4 5 6 7 8 9 10 11
const generateExpression = require('./generate-expression'); function objectToAST(object) { const properties = Object.entries(object).map(([name, value]) => { const isObject = typeof value === 'object'; const isIdentifier = t.isValidIdentifier(name); const astValue = isObject ? objectToAST(value) : t.stringLiteral(value); const key = isIdentifier ? t.identifier(name) : t.stringLiteral(name);
25
523
6
7 8 9 10 11 12 13 14 15 16
for (const name in obj) { const astValue = typeof obj[name] === 'object' ? astFromObject(obj[name]) : t.stringLiteral(obj[name]); const key = t.isValidIdentifier(name, false) ? t.identifier(name) : t.stringLiteral(name); ast.push(t.objectProperty(key, astValue));
18
195
7
+ 3 other calls in file
126 127 128 129 130 131 132 133 134 135
}); // Add incoming translations that did not already exist in this locale Object.keys(translationsLeftToWrite).forEach(id => { const value = translationsLeftToWrite[id]; const keyNode = types.isValidIdentifier(id) ? types.identifier(id) : types.stringLiteral(id); const valueNode = typeof value === 'string'
1
1
7
@babel/types.identifier is the most popular function in @babel/types (20936 examples)