UNPKG

@cosmology/ast

Version:
52 lines (51 loc) 2.64 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.fromProtoMsgMethod = void 0; const t = __importStar(require("@babel/types")); const utils_1 = require("../../../utils"); const types_1 = require("../../types"); const fromProtoMsgMethod = (context, name, proto) => { const varName = 'message'; const ReturnType = types_1.SymbolNames.Msg(name); const ProtoMsgName = types_1.SymbolNames.ProtoMsg(name); const TypeName = types_1.SymbolNames.Msg(name); const body = []; // body body.push(t.returnStatement(t.callExpression(t.memberExpression(t.identifier(TypeName), t.identifier('decode')), [ t.memberExpression(t.identifier(varName), t.identifier('value')), ...(context.options.interfaces.enabled && context.options.interfaces.useUseInterfacesParams ? [ t.identifier('undefined'), t.identifier('useInterfaces') ] : []), ]))); return (0, utils_1.objectMethod)('method', t.identifier('fromProtoMsg'), [ (0, utils_1.identifier)(varName, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(ProtoMsgName)))), ...(context.options.interfaces.enabled && context.options.interfaces.useUseInterfacesParams ? [ t.assignmentPattern((0, utils_1.identifier)('useInterfaces', t.tsTypeAnnotation(t.tsBooleanKeyword())), t.identifier((context.pluginValue('interfaces.useByDefault') ?? true).toString())) ] : []), ], t.blockStatement(body), false, false, false, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(ReturnType)))); }; exports.fromProtoMsgMethod = fromProtoMsgMethod;