How to use the addComment function from @babel/types
Find comprehensive JavaScript @babel/types.addComment code examples handpicked from public code repositorys.
GitHub: jackromo888/octicons
47 48 49 50 51 52 53 54 55 56
// const {code} = generate( t.variableDeclaration('const', [ t.variableDeclarator( t.identifier(name), t.addComment( t.callExpression(t.identifier('createIconComponent'), [ // The name of the generated icon t.stringLiteral(name), // The className used on the underlying <svg> element
915
0
0
GitHub: benjycui/bisheng
118 119 120 121 122 123 124 125 126 127
&& pathNode.left.object.name === 'exports' && pathNode.left.property && pathNode.left.property.value === 'default' ) { renderReturn = types.returnStatement( types.addComment( types.callExpression( types.memberExpression(types.identifier('React'), types.identifier('createElement')), [types.identifier('_default')], ),
430
0
64
75 76 77 78 79 80 81 82 83 84
} }, }); if (options.tsNoCheck) { t.addComment(ast.program.body[0], 'leading', '@ts-nocheck', true); } const { code } = generate(ast, generateOptions); return code;
23
115
4
+ 7 other calls in file
17 18 19 20 21 22 23 24 25 26
// only traverse children ast of `with(this) {...}` part, // just like the `identifier.program.inWith` of bubble's logic path.scope.addGlobal(t.identifier(vueModelName)); path.traverse(nestedVisitor); const withStatementReturnBody = path.node.body.body[0] t.addComment(withStatementReturnBody, "leading", WithStatementReplaceComment) path.replaceWithMultiple([withStatementReturnBody]) } }, };
9
110
5
+ 3 other calls in file
125 126 127 128 129 130 131 132 133 134
path.node.body.forEach(node => { hasExport = hasExport || t.isExportDeclaration(node); }); if (!hasExport) { const exportNode = t.exportNamedDeclaration(); t.addComment(exportNode, 'trailing', 'The above line is generated by conditional compilation, when no export detected after CC.'); path.node.body.push(exportNode); } } },
37
93
129
+ 6 other calls in file
GitHub: Kode/Krom
376 377 378 379 380 381 382 383 384 385
/** * Annotate code with original file path. */ function annotateWithOriginalPath(ast, relPath) { if (ast.program && ast.program.body && ast.program.body.length > 0) { babelTypes.addComment( ast.program.body[0], 'leading', ' Original: ' + relPath, true); } }
22
89
0
22 23 24 25 26 27 28 29 30 31 32 33
if (parent.type === 'root') { return null; } const expression = t.jsxEmptyExpression(); t.addComment(expression, 'inner', node.value); return t.jsxExpressionContainer(expression); }; exports.comment = comment;
0
1
0
88 89 90 91 92 93 94 95 96
const body = isOverloading ? createOverloadedMethodBody(classJson, json) : createMethodBody(classJson, json); const m = t.classMethod('method', t.identifier(methodNameToSnakeCase(json.name)), args, body, false, true); if (json.comment) { t.addComment(m, 'leading', json.comment); } return m; }
0
0
0
+ 11 other calls in file
34 35 36 37 38 39 40 41 42 43
}) if(content) { const contentNode = t.variableDeclaration('const', [ t.variableDeclarator(t.identifier('nls'), content) ]) t.addComment(contentNode, 'leading', 'NLS内容') return contentNode } } }
0
0
0
100 101 102 103 104 105 106 107 108 109 110
// List of string literals of failed tests. function getLiteralsForFailed(leadingComment, failedList) { const result = failedList.map(path => babelTypes.stringLiteral(path)); if (result.length) { babelTypes.addComment(result[0], 'leading', leadingComment); } return result; }
0
0
0
+ 8 other calls in file
174 175 176 177 178 179 180 181 182 183
!leadingComments || !leadingComments.some( comment => comment.value === OUT_OF_SYNC_TOKEN, ) ) { types.addComment(property, 'leading', OUT_OF_SYNC_TOKEN, true); } newProperties.push(property); } else if (!deletedIds.has(id)) { // Keep property as-is if it has not been deleted.
0
0
0
@babel/types.identifier is the most popular function in @babel/types (20936 examples)