diff --git a/src/parseExpensiMark.ts b/src/parseExpensiMark.ts index 4162eb6c..673734af 100644 --- a/src/parseExpensiMark.ts +++ b/src/parseExpensiMark.ts @@ -1,9 +1,27 @@ 'worklet'; +import {Platform} from 'react-native'; import {ExpensiMark} from 'expensify-common'; import {unescapeText} from 'expensify-common/dist/utils'; +import {decode} from 'html-entities'; +import type {WorkletFunction} from 'react-native-reanimated/lib/typescript/commonTypes'; import type {MarkdownType, MarkdownRange} from './commonTypes'; +function isWeb() { + return Platform.OS === 'web'; +} + +function isJest() { + return !!global.process.env.JEST_WORKER_ID; +} + +// eslint-disable-next-line no-underscore-dangle +if (__DEV__ && !isWeb() && !isJest() && (decode as WorkletFunction).__workletHash === undefined) { + throw new Error( + "[react-native-live-markdown] `parseExpensiMark` requires `html-entities` package to be workletized. Please add `'worklet';` directive at the top of `node_modules/html-entities/lib/index.js` using patch-package.", + ); +} + const MAX_PARSABLE_LENGTH = 4000; type Token = ['TEXT' | 'HTML', string];