Skip to content

Commit d2a41d3

Browse files
committed
Add module guard so the script still works in browsers. Attempt to keep the old closure reference code as well.
1 parent 2b6ac1f commit d2a41d3

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

javascript/diff_match_patch_uncompressed.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -2410,10 +2410,24 @@ diff_match_patch.patch_obj.prototype.toString = function() {
24102410
return text.join('').replace(/%20/g, ' ');
24112411
};
24122412

2413-
2414-
// The following export code was added by @ForbesLindesay
2415-
module.exports = diff_match_patch;
2416-
module.exports['diff_match_patch'] = diff_match_patch;
2417-
module.exports['DIFF_DELETE'] = DIFF_DELETE;
2418-
module.exports['DIFF_INSERT'] = DIFF_INSERT;
2419-
module.exports['DIFF_EQUAL'] = DIFF_EQUAL;
2413+
// CLOSURE:begin_strip
2414+
// Lines below here will not be included in the Closure-compatible library.
2415+
if (typeof module === 'object') {
2416+
// The following export code was added by @ForbesLindesay
2417+
module.exports = diff_match_patch;
2418+
module.exports['diff_match_patch'] = diff_match_patch;
2419+
module.exports['DIFF_DELETE'] = DIFF_DELETE;
2420+
module.exports['DIFF_INSERT'] = DIFF_INSERT;
2421+
module.exports['DIFF_EQUAL'] = DIFF_EQUAL;
2422+
} else {
2423+
// Export these global variables so that they survive Google's JS compiler.
2424+
// In a browser, 'this' will be 'window'.
2425+
/** @suppress {globalThis} */
2426+
this['diff_match_patch'] = diff_match_patch;
2427+
/** @suppress {globalThis} */
2428+
this['DIFF_DELETE'] = DIFF_DELETE;
2429+
/** @suppress {globalThis} */
2430+
this['DIFF_INSERT'] = DIFF_INSERT;
2431+
/** @suppress {globalThis} */
2432+
this['DIFF_EQUAL'] = DIFF_EQUAL;
2433+
}

0 commit comments

Comments
 (0)