From 323e450b8afad21993deb79162d6b84533269edf Mon Sep 17 00:00:00 2001 From: Luke Thomas Date: Sat, 12 Jan 2019 14:47:47 -0600 Subject: [PATCH] Build changes --- build/lib/format/partial/FieldTypesFormatter.js | 11 +++++++++++ build/lib/format/partial/MessageFormatter.js | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/build/lib/format/partial/FieldTypesFormatter.js b/build/lib/format/partial/FieldTypesFormatter.js index e295d59..cc87fac 100644 --- a/build/lib/format/partial/FieldTypesFormatter.js +++ b/build/lib/format/partial/FieldTypesFormatter.js @@ -4,6 +4,9 @@ const Utility_1 = require("../../Utility"); exports.MESSAGE_TYPE = 11; exports.BYTES_TYPE = 12; exports.ENUM_TYPE = 14; +exports.JS_NORMAL = 0; +exports.JS_STRING = 1; +exports.JS_NUMBER = 2; const TypeNumToTypeString = {}; TypeNumToTypeString[1] = "number"; // TYPE_DOUBLE TypeNumToTypeString[2] = "number"; // TYPE_FLOAT @@ -23,12 +26,20 @@ TypeNumToTypeString[15] = "number"; // TYPE_SFIXED32 TypeNumToTypeString[16] = "number"; // TYPE_SFIXED64 TypeNumToTypeString[17] = "number"; // TYPE_SINT32 - Uses ZigZag encoding. TypeNumToTypeString[18] = "number"; // TYPE_SINT64 - Uses ZigZag encoding. +const JsTypeNumToTypeString = {}; +JsTypeNumToTypeString[exports.JS_NORMAL] = null; // [jstype = JS_NORMAL] +JsTypeNumToTypeString[exports.JS_STRING] = "string"; // [jstype = JS_STRING] +JsTypeNumToTypeString[exports.JS_NUMBER] = "number"; // [jstype = JS_NUMBER] var FieldTypesFormatter; (function (FieldTypesFormatter) { function getTypeName(fieldTypeNum) { return TypeNumToTypeString[fieldTypeNum]; } FieldTypesFormatter.getTypeName = getTypeName; + function getJsTypeName(fieldTypeNum) { + return fieldTypeNum === exports.JS_NORMAL ? null : JsTypeNumToTypeString[fieldTypeNum]; + } + FieldTypesFormatter.getJsTypeName = getJsTypeName; function getFieldType(type, typeName, currentFileName, exportMap) { let fieldType; let fromExport; diff --git a/build/lib/format/partial/MessageFormatter.js b/build/lib/format/partial/MessageFormatter.js index 8087b9b..6dc4bde 100644 --- a/build/lib/format/partial/MessageFormatter.js +++ b/build/lib/format/partial/MessageFormatter.js @@ -131,7 +131,13 @@ var MessageFormatter; fieldData.exportType = exportType; } else { - exportType = fieldData.exportType = FieldTypesFormatter_1.FieldTypesFormatter.getTypeName(fieldData.type); + let type = FieldTypesFormatter_1.FieldTypesFormatter.getTypeName(fieldData.type); + // Check for [jstype = JS_STRING] overrides + const options = field.getOptions(); + if (options && options.hasJstype()) { + type = FieldTypesFormatter_1.FieldTypesFormatter.getJsTypeName(options.getJstype()); + } + exportType = fieldData.exportType = type; } fieldData.isOptionalValue = field.getType() === FieldTypesFormatter_1.MESSAGE_TYPE; fieldData.isRepeatField = field.getLabel() === descriptor_pb_1.FieldDescriptorProto.Label.LABEL_REPEATED;