Skip to content

Commit

Permalink
fix: unsupported regex eval in Safari error #34
Browse files Browse the repository at this point in the history
  • Loading branch information
openscript committed Jul 2, 2022
1 parent 14cbcfe commit 4e4f2b7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export const parsePathPrefix = (path: string, defaultPrefix: string) => {
return defaultPrefix;
}

const splittedPath = path.match(/(?<=^\/)\w{2}(-\w{2})?(?=\/)/g);
// Regex literals are evaluated when the script is loaded, whereas the RegExp instantiation is done when it's reached during execution. Safari doesn't support look behinds, which causes an error when the script is loaded. This is only needed in SSG.
// eslint-disable-next-line prefer-regex-literals
const splitPathExpression = new RegExp('(?<=^/)\\w{2}(-\\w{2})?(?=/)', 'g');
const splittedPath = path.match(splitPathExpression);
return splittedPath && splittedPath[0] ? splittedPath[0] : defaultPrefix;
};

Expand Down

0 comments on commit 4e4f2b7

Please sign in to comment.