@@ -717,24 +717,21 @@ exports.stringIterator = (str) => {
717717
718718/**
719719 * A custom made StringBuffer
720- *
721- * @typedef {object } StringAssembler
722- * @property {Function } append -
723- * @property {Function } toString -
724720 */
721+ class StringAssembler {
722+ constructor ( ) { this . clear ( ) ; }
723+ clear ( ) { this . _str = '' ; }
724+ /**
725+ * @param {string } x -
726+ */
727+ append ( x ) { this . _str += String ( x ) ; }
728+ toString ( ) { return this . _str ; }
729+ }
725730
726731/**
727732 * @returns {StringAssembler }
728733 */
729- exports . stringAssembler = ( ) => ( {
730- _str : '' ,
731- clear ( ) { this . _str = '' ; } ,
732- /**
733- * @param {string } x -
734- */
735- append ( x ) { this . _str += String ( x ) ; } ,
736- toString ( ) { return this . _str ; } ,
737- } ) ;
734+ exports . stringAssembler = ( ) => new StringAssembler ( ) ;
738735
739736/**
740737 * @typedef {object } StringArrayLike
@@ -1161,7 +1158,7 @@ exports.applyToText = (cs, str) => {
11611158 assert ( str . length === unpacked . oldLen , `mismatched apply: ${ str . length } / ${ unpacked . oldLen } ` ) ;
11621159 const bankIter = exports . stringIterator ( unpacked . charBank ) ;
11631160 const strIter = exports . stringIterator ( str ) ;
1164- const assem = exports . stringAssembler ( ) ;
1161+ const assem = new StringAssembler ( ) ;
11651162 for ( const op of exports . deserializeOps ( unpacked . ops ) ) {
11661163 switch ( op . opcode ) {
11671164 case '+' :
@@ -1480,7 +1477,7 @@ exports.compose = (cs1, cs2, pool) => {
14801477 const len3 = unpacked2 . newLen ;
14811478 const bankIter1 = exports . stringIterator ( unpacked1 . charBank ) ;
14821479 const bankIter2 = exports . stringIterator ( unpacked2 . charBank ) ;
1483- const bankAssem = exports . stringAssembler ( ) ;
1480+ const bankAssem = new StringAssembler ( ) ;
14841481
14851482 const newOps = applyZip ( unpacked1 . ops , unpacked2 . ops , ( op1 , op2 ) => {
14861483 const op1code = op1 . opcode ;
@@ -1923,7 +1920,7 @@ class Builder {
19231920 constructor ( oldLen ) {
19241921 this . _oldLen = oldLen ;
19251922 this . _ops = [ ] ;
1926- this . _charBank = exports . stringAssembler ( ) ;
1923+ this . _charBank = new StringAssembler ( ) ;
19271924 }
19281925
19291926 /**
@@ -2184,7 +2181,7 @@ exports.inverse = (cs, lines, alines, pool) => {
21842181
21852182 const nextText = ( numChars ) => {
21862183 let len = 0 ;
2187- const assem = exports . stringAssembler ( ) ;
2184+ const assem = new StringAssembler ( ) ;
21882185 const firstString = linesGet ( curLine ) . substring ( curChar ) ;
21892186 len += firstString . length ;
21902187 assem . append ( firstString ) ;
@@ -2410,7 +2407,7 @@ const followAttributes = (att1, att2, pool) => {
24102407 return '' ;
24112408 } ) ;
24122409 // we've only removed attributes, so they're already sorted
2413- const buf = exports . stringAssembler ( ) ;
2410+ const buf = new StringAssembler ( ) ;
24142411 for ( const att of atts ) {
24152412 buf . append ( '*' ) ;
24162413 buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
0 commit comments