Skip to content

Commit

Permalink
Add module guard so the script still works in browsers. Attempt to ke…
Browse files Browse the repository at this point in the history
…ep the old closure reference code as well.
  • Loading branch information
TheSpyder committed Feb 19, 2024
1 parent a4ab9b0 commit f651143
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions javascript/diff_match_patch_uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) {

/**
* Rearrange diff boundaries that split Unicode surrogate pairs.
*
*
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
*/
diff_match_patch.prototype.diff_cleanupSplitSurrogates = function(diffs) {
Expand Down Expand Up @@ -1264,17 +1264,17 @@ diff_match_patch.prototype.digit16 = function(c) {

/**
* Decode URI-encoded string but allow for encoded surrogate halves
*
*
* diff_match_patch needs this relaxation of the requirements because
* not all libraries and versions produce valid URI strings in toDelta
* and we don't want to crash this code when the input is valid input
* but at the same time invalid utf-8
*
*
* @example: decodeURI( 'abcd%3A %F0%9F%85%B0' ) = 'abcd: \ud83c\udd70'
* @example: decodeURI( 'abcd%3A %ED%A0%BC' ) = 'abcd: \ud83c'
*
*
* @cite: @mathiasbynens utf8.js at https://github.com/mathiasbynens/utf8.js
*
*
* @param {String} text input string encoded by encodeURI() or equivalent
* @return {String}
*/
Expand Down Expand Up @@ -2384,10 +2384,24 @@ diff_match_patch.patch_obj.prototype.toString = function() {
return text.join('').replace(/%20/g, ' ');
};


// The following export code was added by @ForbesLindesay
module.exports = diff_match_patch;
module.exports['diff_match_patch'] = diff_match_patch;
module.exports['DIFF_DELETE'] = DIFF_DELETE;
module.exports['DIFF_INSERT'] = DIFF_INSERT;
module.exports['DIFF_EQUAL'] = DIFF_EQUAL;
// CLOSURE:begin_strip
// Lines below here will not be included in the Closure-compatible library.
if (typeof module === 'object') {
// The following export code was added by @ForbesLindesay
module.exports = diff_match_patch;
module.exports['diff_match_patch'] = diff_match_patch;
module.exports['DIFF_DELETE'] = DIFF_DELETE;
module.exports['DIFF_INSERT'] = DIFF_INSERT;
module.exports['DIFF_EQUAL'] = DIFF_EQUAL;
} else {
// Export these global variables so that they survive Google's JS compiler.
// In a browser, 'this' will be 'window'.
/** @suppress {globalThis} */
this['diff_match_patch'] = diff_match_patch;
/** @suppress {globalThis} */
this['DIFF_DELETE'] = DIFF_DELETE;
/** @suppress {globalThis} */
this['DIFF_INSERT'] = DIFF_INSERT;
/** @suppress {globalThis} */
this['DIFF_EQUAL'] = DIFF_EQUAL;
}

0 comments on commit f651143

Please sign in to comment.