@@ -1905,72 +1905,68 @@ exports.attribsAttributeValue = (attribs, key, pool) => {
19051905
19061906/**
19071907 * Incrementally builds a Changeset.
1908- *
1909- * @typedef {object } Builder
1910- * @property {Function } insert -
1911- * @property {Function } keep -
1912- * @property {Function } keepText -
1913- * @property {Function } remove -
1914- * @property {Function } toString -
19151908 */
1909+ exports . Builder = class {
1910+ /**
1911+ * @param {number } oldLen - Old length
1912+ */
1913+ constructor ( oldLen ) {
1914+ this . _oldLen = oldLen ;
1915+ this . _ops = [ ] ;
1916+ this . _charBank = exports . stringAssembler ( ) ;
1917+ }
1918+
1919+ /**
1920+ * @param attribs - Either [[key1,value1],[key2,value2],...] or '*0*1...' (no pool needed in
1921+ * latter case).
1922+ */
1923+ keep ( N , L , attribs , pool ) {
1924+ const o = new exports . Op ( '=' ) ;
1925+ o . attribs = ( attribs && exports . makeAttribsString ( '=' , attribs , pool ) ) || '' ;
1926+ o . chars = N ;
1927+ o . lines = ( L || 0 ) ;
1928+ this . _ops . push ( o ) ;
1929+ return this ;
1930+ }
1931+
1932+ keepText ( text , attribs , pool ) {
1933+ this . _ops . push ( ...opsFromText ( '=' , text , attribs , pool ) ) ;
1934+ return this ;
1935+ }
1936+
1937+ insert ( text , attribs , pool ) {
1938+ this . _ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1939+ this . _charBank . append ( text ) ;
1940+ return this ;
1941+ }
1942+
1943+ remove ( N , L ) {
1944+ const o = new exports . Op ( '-' ) ;
1945+ o . attribs = '' ;
1946+ o . chars = N ;
1947+ o . lines = ( L || 0 ) ;
1948+ this . _ops . push ( o ) ;
1949+ return this ;
1950+ }
1951+
1952+ toString ( ) {
1953+ let lengthChange ;
1954+ const serializedOps = exports . serializeOps ( ( function * ( ) {
1955+ lengthChange = yield * exports . canonicalizeOps ( this . _ops , true ) ;
1956+ } ) . call ( this ) ) ;
1957+ const newLen = this . _oldLen + lengthChange ;
1958+ return exports . pack ( this . _oldLen , newLen , serializedOps , this . _charBank . toString ( ) ) ;
1959+ }
1960+ } ;
19161961
19171962/**
1963+ * @deprecated Use the `Builder` class instead.
19181964 * @param {number } oldLen - Old length
19191965 * @returns {Builder }
19201966 */
19211967exports . builder = ( oldLen ) => {
1922- const ops = [ ] ;
1923- let packed = null ;
1924- const charBank = exports . stringAssembler ( ) ;
1925-
1926- const self = {
1927- /**
1928- * @param attribs - Either [[key1,value1],[key2,value2],...] or '*0*1...' (no pool needed in
1929- * latter case).
1930- */
1931- keep : ( N , L , attribs , pool ) => {
1932- const o = new exports . Op ( '=' ) ;
1933- o . attribs = ( attribs && exports . makeAttribsString ( '=' , attribs , pool ) ) || '' ;
1934- o . chars = N ;
1935- o . lines = ( L || 0 ) ;
1936- packed = null ;
1937- ops . push ( o ) ;
1938- return self ;
1939- } ,
1940- keepText : ( text , attribs , pool ) => {
1941- packed = null ;
1942- ops . push ( ...opsFromText ( '=' , text , attribs , pool ) ) ;
1943- return self ;
1944- } ,
1945- insert : ( text , attribs , pool ) => {
1946- packed = null ;
1947- ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1948- charBank . append ( text ) ;
1949- return self ;
1950- } ,
1951- remove : ( N , L ) => {
1952- const o = new exports . Op ( '-' ) ;
1953- o . attribs = '' ;
1954- o . chars = N ;
1955- o . lines = ( L || 0 ) ;
1956- packed = null ;
1957- ops . push ( o ) ;
1958- return self ;
1959- } ,
1960- toString : ( ) => {
1961- if ( packed == null ) {
1962- let lengthChange ;
1963- const serializedOps = exports . serializeOps ( ( function * ( ) {
1964- lengthChange = yield * exports . canonicalizeOps ( ops , true ) ;
1965- } ) ( ) ) ;
1966- const newLen = oldLen + lengthChange ;
1967- packed = exports . pack ( oldLen , newLen , serializedOps , charBank . toString ( ) ) ;
1968- }
1969- return packed ;
1970- } ,
1971- } ;
1972-
1973- return self ;
1968+ warnDeprecated ( 'Changeset.builder() is deprecated; use the Changeset.Builder class instead' ) ;
1969+ return new exports . Builder ( oldLen ) ;
19741970} ;
19751971
19761972exports . makeAttribsString = ( opcode , attribs , pool ) => {
@@ -2062,7 +2058,7 @@ exports.inverse = (cs, lines, alines, pool) => {
20622058 let curLineNextOp = new exports . Op ( '+' ) ;
20632059
20642060 const unpacked = exports . unpack ( cs ) ;
2065- const builder = exports . builder ( unpacked . newLen ) ;
2061+ const builder = new exports . Builder ( unpacked . newLen ) ;
20662062
20672063 const consumeAttribRuns = ( numChars , func /* (len, attribs, endsLine)*/ ) => {
20682064 if ( ( ! curLineOpIter ) || ( curLineOpIterLine !== curLine ) ) {
0 commit comments