Work around unsupported RegExp lookbehind in WebKit. (#85)
* Work around unsupported RegExp lookbehind in WebKit. * Update static/find/find.js Co-authored-by: Mario Carneiro <di.gama@gmail.com> Co-authored-by: Mario Carneiro <di.gama@gmail.com>main
parent
d7fe046e94
commit
153982f982
|
@ -17,14 +17,27 @@
|
|||
|
||||
import { DeclarationDataCenter } from "../declaration-data.js";
|
||||
|
||||
function leanFriendlyRegExp(c) {
|
||||
try {
|
||||
return new RegExp("(?<!«[^»]*)" + c);
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
// Lookbehind is not implemented yet in WebKit: https://bugs.webkit.org/show_bug.cgi?id=174931
|
||||
// Fall back to less friendly regex.
|
||||
return new RegExp(c);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We don't use browser's default hash and searchParams in case Lean declaration name
|
||||
* can be like `«#»`, rather we manually handle the `window.location.href` with regex.
|
||||
*/
|
||||
const LEAN_FRIENDLY_URL_REGEX = /^[^?#]+(?:\?((?:[^«#»]|«.*»)*))?(?:#(.*))?$/;
|
||||
const LEAN_FRIENDLY_AND_SEPARATOR = /(?<!«[^»]*)&/;
|
||||
const LEAN_FRIENDLY_EQUAL_SEPARATOR = /(?<!«[^»]*)=/;
|
||||
const LEAN_FRIENDLY_SLASH_SEPARATOR = /(?<!«[^»]*)\//;
|
||||
const LEAN_FRIENDLY_AND_SEPARATOR = leanFriendlyRegExp("&");
|
||||
const LEAN_FRIENDLY_EQUAL_SEPARATOR = leanFriendlyRegExp("=");
|
||||
const LEAN_FRIENDLY_SLASH_SEPARATOR = leanFriendlyRegExp("/");
|
||||
|
||||
const [_, query, fragment] = LEAN_FRIENDLY_URL_REGEX.exec(window.location.href);
|
||||
const queryParams = new Map(
|
||||
|
|
Loading…
Reference in New Issue