Skip to content

Commit 8aa77c2

Browse files
committed
feat(core): improve esm/commonjs compat with emoji-regex dependency
1 parent 120e635 commit 8aa77c2

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/core/utils/common.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import * as types from './types';
22
import { dispatchToMainThread, dispatchToUIThread, isMainThread } from './mainthread-helper';
3-
import emojiRegex from 'emoji-regex';
3+
import * as emojiRegexModule from 'emoji-regex';
4+
5+
// Normalize emoji-regex CommonJS / ESM shapes into a callable function.
6+
// Some bundlers expose it as module.exports, others as module.exports.default.
7+
const emojiRegex: (input: string) => RegExp = (() => {
8+
const mod: any = emojiRegexModule;
9+
if (mod && typeof mod.default === 'function') {
10+
return mod.default;
11+
}
12+
if (typeof mod === 'function') {
13+
return mod;
14+
}
15+
// Fallback: minimal safe regex that never throws.
16+
return () => /./g;
17+
})();
418

519
export * from './mainthread-helper';
620
export * from './macrotask-scheduler';
@@ -168,5 +182,5 @@ export function mainThreadify(func: Function): (...args: any[]) => void {
168182
export function isEmoji(value: string): boolean {
169183
// TODO: In a future runtime update, we can switch to using Unicode Property Escapes:
170184
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes
171-
return emojiRegex().test(value);
185+
return emojiRegex(value).test(value);
172186
}

0 commit comments

Comments
 (0)