@@ -12,7 +12,9 @@ export function compileRaw(proto, options = {}) {
1212
1313 let output = options . dev ? '' : `// code generated by pbf v${ version } \n` ;
1414 if ( options . jsDoc ) {
15- output += typeDef ( `import("${ options . dev ? '../../index.js' : 'pbf' } ").default` , 'Pbf' ) ;
15+ output += options . dev ?
16+ typeDef ( 'import("../../index.js").default' , 'Pbf' ) :
17+ typeDef ( 'import("pbf")' , 'Pbf' ) ;
1618 }
1719 output += writeContext ( context , options ) ;
1820 return output ;
@@ -42,7 +44,13 @@ function writeMessage(ctx, options) {
4244 if ( ! options . noRead ) {
4345 const readName = `read${ name } ` ;
4446 if ( options . jsDoc ) {
45- code += [ '\n/**' , ' * @param {Pbf} pbf' , ' * @param {number} [end]' , ` * @returns {${ name } }` , ' */' ] . join ( '\n' ) . concat ( '\n' ) ;
47+ code += `
48+ /**
49+ * @param {Pbf} pbf
50+ * @param {number} [end]
51+ * @returns {${ name } }
52+ */
53+ ` ;
4654 }
4755 code +=
4856`${ writeFunctionExport ( options , readName ) } function ${ readName } (pbf, end) {
@@ -55,7 +63,13 @@ function writeMessage(ctx, options) {
5563 const { key, value} = getMapTsType ( fields ) ;
5664 param = `{key: ${ key } ; value: ${ value } }` ;
5765 }
58- code += [ '\n/**' , ' * @param {number} tag' , ` * @param {${ param } } obj` , ' * @param {Pbf} pbf' , ' */' ] . join ( '\n' ) . concat ( '\n' ) ;
66+ code += `
67+ /**
68+ * @param {number} tag
69+ * @param {${ param } } obj
70+ * @param {Pbf} pbf
71+ */
72+ ` ;
5973 }
6074 code +=
6175`function ${ readName } Field(tag, obj, pbf) {
@@ -93,7 +107,12 @@ function writeMessage(ctx, options) {
93107 param = `{key: ${ key } ; value: ${ value } }` ;
94108 }
95109
96- code += [ '\n/**' , ` * @param {${ param } } obj` , ' * @param {Pbf} pbf' , ' */' ] . join ( '\n' ) . concat ( '\n' ) ;
110+ code += `
111+ /**
112+ * @param {${ param } } obj
113+ * @param {Pbf} pbf
114+ */
115+ ` ;
97116 }
98117
99118 code += `${ writeFunctionExport ( options , writeName ) } function ${ writeName } (obj, pbf) {\n` ;
@@ -480,12 +499,6 @@ function getMapTsType(fields) {
480499 return { key, value} ;
481500}
482501
483- /**
484- * @param {string } type
485- * @param {string } name
486- * @param {{name: string; type: string; required: boolean} } [fields]
487- * @returns {string }
488- */
489502function typeDef ( type , name , fields = [ ] ) {
490503 const unionProperties = { } ;
491504 const properties = fields . map ( ( field ) => {
@@ -512,16 +525,10 @@ function typeDef(type, name, fields = []) {
512525 . concat ( '\n' ) ;
513526}
514527
515- /**
516- * @param {object } ctx
517- * @param {string } name
518- * @param {{name: string; type: string; required: boolean} } [fields]
519- * @returns {string }
520- */
521528function compileType ( ctx , name , fields = [ ] ) {
522529 if ( ctx . _proto . map ) {
523530 const { key, value} = getMapTsType ( fields ) ;
524- return typeDef ( `Object <${ key } , ${ value } >` , name , [ ] ) ;
531+ return typeDef ( `Record <${ key } , ${ value } >` , name , [ ] ) ;
525532 }
526533
527534 const typedFields = fields . map ( ( field ) => {
0 commit comments