UNPKG

@creditkarma/thrift-parser

Version:

A parser for Thrift written in TypeScript

67 lines 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function organize(raw) { const namespaces = []; const includes = []; const constants = []; const enums = []; const typedefs = []; const structs = []; const unions = []; const exceptions = []; const services = []; for (const next of raw.body) { switch (next.type) { case "NamespaceDefinition" /* NamespaceDefinition */: namespaces.push(next); break; case "IncludeDefinition" /* IncludeDefinition */: includes.push(next); break; case "CppIncludeDefinition" /* CppIncludeDefinition */: // We're not generating C++ break; case "ConstDefinition" /* ConstDefinition */: constants.push(next); break; case "EnumDefinition" /* EnumDefinition */: enums.push(next); break; case "StructDefinition" /* StructDefinition */: structs.push(next); break; case "UnionDefinition" /* UnionDefinition */: unions.push(next); break; case "ExceptionDefinition" /* ExceptionDefinition */: exceptions.push(next); break; case "TypedefDefinition" /* TypedefDefinition */: typedefs.push(next); break; case "ServiceDefinition" /* ServiceDefinition */: services.push(next); break; default: const msg = next; throw new Error(`Unexpected statement type found: ${msg}`); } } return { type: "ThriftDocument" /* ThriftDocument */, body: [ ...namespaces, ...includes, ...enums, ...typedefs, ...constants, ...structs, ...unions, ...exceptions, ...services, ], tokens: raw.tokens, }; } exports.organize = organize; //# sourceMappingURL=organizer.js.map