Permalink
Browse files

Make addUnicodeData flush the pattern cache.

  • Loading branch information...
1 parent 1d57f92 commit 0ef1f3c69d13e5be6e5a332855eafdee873cdf92 @slevithan committed Aug 21, 2012
Showing with 17 additions and 1 deletion.
  1. +4 −0 src/addons/unicode/unicode-base.js
  2. +9 −1 src/backcompat.js
  3. +4 −0 xregexp-all.js
@@ -220,6 +220,10 @@
unicode[normalize(item.alias)] = item;
}
}
+
+ // Reset the pattern cache used by the `XRegExp` constructor, since the same pattern and
+ // flags might now produce different results
+ XRegExp.cache.flush('patterns');
};
/* Add data for the Unicode `L` or `Letter` category. Separate addons are available that add other
View
@@ -56,9 +56,17 @@
* @deprecated As of XRegExp 2.0.0. No replacement.
*/
XRegExp.freezeTokens = function() {
- XRegExp.addToken = XRegExp.addUnicodeData = function() {
+ var errorFn = function() {
throw new Error('Cannot change XRegExp syntax after running freezeTokens');
};
+
+ XRegExp.addToken = errorFn;
+
+ // Don't replace `addUnicodeData` unless it exists, since it might be used to check whether
+ // XRegExp's Unicode Base addon is available
+ if (XRegExp.addUnicodeData) {
+ XRegExp.addUnicodeData = errorFn;
+ }
};
/**
View
@@ -2349,6 +2349,10 @@ var XRegExp = (function(undefined) {
unicode[normalize(item.alias)] = item;
}
}
+
+ // Reset the pattern cache used by the `XRegExp` constructor, since the same pattern and
+ // flags might now produce different results
+ XRegExp.cache.flush('patterns');
};
/* Add data for the Unicode `L` or `Letter` category. Separate addons are available that add other

0 comments on commit 0ef1f3c

Please sign in to comment.