How to use the program function from @babel/types
Find comprehensive JavaScript @babel/types.program code examples handpicked from public code repositorys.
GitHub: groupon/swagql
188 189 190 191 192 193 194 195 196 197
...[].concat(prefix), ...this.inputTypes.astNodes, ...this.outputTypes.astNodes, ...[].concat(postfix), ]; const program = t.program(body); program.leadingComments = [ { type: 'CommentLine', value: ' Generated by SwagQL. Do not edit by hand.',
3
46
11
288 289 290 291 292 293 294 295 296 297 298 299
return Array.from(flags.values()); } function concatPrograms(inputs) { // Concatentate programs. const resultProgram = babelTypes.program([]); const result = babelTypes.file(resultProgram, [], null); for (const input of inputs) { const ast = input.ast.program;
46
35
0
GitHub: ats1999/next.js
31 32 33 34 35 36 37 38 39 40
), ]), t.exportDefaultDeclaration(t.identifier(componentName)), ] return t.program(body, [], 'module') } const generateJSXElement = (componentName, children = null) => t.JSXElement(
0
3
1
+ 3 other calls in file
GitHub: ruleenginejs/ruleengine
56 57 58 59 60 61 62 63 64 65 66 67
const exportFn = options.esModule ? generateDefaultExport : generateModuleExport; statements.push(exportFn(PIPELINE_VAR)); const program = t.program(statements); const ast = t.file(program); return ast; }
1
2
1
+ 57 other calls in file
GitHub: Airkro/road-to-rome
65 66 67 68 69 70 71 72 73
path, to: pascalCase(to), })); const ast = t.file( t.program([...statement(items), variable(items), logger(items)]), ); const { code } = generator.default(ast, {}, '');
0
2
0
+ 4 other calls in file
GitHub: hakanatabas/parcel
123 124 125 126 127 128 129 130 131 132
if (asset.cacheData.isES6Module) { path.unshiftContainer('body', [ESMODULE_TEMPLATE()]); } path.replaceWith( t.program([ WRAPPER_TEMPLATE({ NAME: getExportsIdentifier(asset), BODY: path.node.body, }),
0
2
1
+ 7 other calls in file
44 45 46 47 48 49 50 51 52 53
} else { inner.push(node); } }); const program = t.program([ ...nodes, t.expressionStatement( t.callExpression( t.memberExpression(
0
1
1
+ 58 other calls in file
254 255 256 257 258 259 260 261 262
getBlockStatement(children = []) { return t.blockStatement(children); } visitFile_input(ctx) { return t.program( flatten(ctx.children.map(child => this.visitChildren(child))) ); }
0
1
0
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } const root = (h, node) => t.program((0, _all.default)(h, node)); exports.root = root; const comment = (h, node, parent) => {
0
1
0
GitHub: dfreeman/declgen
42 43 44 45 46 47 48 49 50 51
if (this.hasBuilt) return; this.hasBuilt = true; let fullDestination = `${this.outputPath}/${this.destination}`; let declaration = t.program([ Object.assign( t.variableDeclaration('const', [ t.variableDeclarator( Object.assign(t.identifier('config'), {
0
1
0
+ 11 other calls in file
GitHub: HandsomeWalker/v2r
26 27 28 29 30 31 32 33 34 35
vueParseObj.descriptor.template.content ); jsAst = initState(jsAst, store); templateAst = initTemplate(templateAst, null, new Set()); const { code: jsCode } = generator( t.program( [ ...jsAst.program.body.filter((item) => t.isImportDeclaration(item)), t.functionDeclaration( t.identifier("VueTest"),
0
0
1
+ 213 other calls in file
305 306 307 308 309 310 311 312 313 314
operationTypes.push(t.objectTypeProperty(t.identifier('rawResponse'), t.genericTypeAnnotation(t.identifier("".concat(node.name, "RawResponse"))))); babelNodes.push(rawResponseType); } babelNodes.push(exportType(node.name, exactObjectTypeAnnotation(operationTypes))); return t.program(babelNodes); }, Fragment: function Fragment(node) { var selections = flattenArray( /* $FlowFixMe: selections have already been transformed */
0
0
2
440 441 442 443 444 445 446 447 448 449
const type = isPluralFragment ? readOnlyArrayOfType(baseType) : baseType; state.runtimeImports.add('FragmentReference'); return t.program([ ...getFragmentImports(state), ...getEnumDefinitions(schema, state), importTypes(Array.from(state.runtimeImports).sort(), 'relay-runtime'), ...fragmentTypes,
0
0
1
270 271 272 273 274 275 276 277 278
// set default name const pathFragments = outputFile.split('/'); if (!json.name) { json.name = pathFragments[pathFragments.length - 1].replace('.js', ''); } const ast = t.program([createClass(json), createExport(json)]); const output = generate(ast); const commentBefore = '/**\n\n\tThis code is generated.\n\tFor more information see generation/README.md.\n*/\n\n';
0
0
0
+ 11 other calls in file
184 185 186 187 188 189 190 191 192 193 194
SKIPPED: skippedArray, SOFTSKIPPED: softSkippedArray, SLOPPY: sloppyArray, }); const resultProgram = babelTypes.program(statements); const code = babelGenerator(resultProgram, { comments: true }).code; const prettyCode = prettier.format(code, { parser: "babel" }); fs.writeFileSync('generated/exceptions.js', prettyCode); }
0
0
0
+ 2 other calls in file
56 57 58 59 60 61 62 63 64 65
} else { throw "No declaration for node"; } } if (imports.length) { let p = types.program(imports); let f = types.file(p); ex_path.replaceWith(f); } }
0
0
1
@babel/types.identifier is the most popular function in @babel/types (20936 examples)