fix: ignore async: false when async: true is set by an extension (#2920)

This commit is contained in:
Tony Brix
2023-08-19 16:58:32 -06:00
committed by GitHub
parent a990c54e0c
commit b6ee877d58
2 changed files with 24 additions and 0 deletions
+10
View File
@@ -244,6 +244,16 @@ export class Marked {
const origOpt = { ...optOrCallback };
const opt = { ...this.defaults, ...origOpt };
// Show warning if an extension set async to true but the parse was called with async: false
if (this.defaults.async === true && origOpt.async === false) {
if (!opt.silent) {
console.warn('marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.');
}
opt.async = true;
}
const throwError = this.#onError(!!opt.silent, !!opt.async, callback);
// throw error in case of non string input
+14
View File
@@ -577,6 +577,20 @@ used extension2 walked</p>
expect(defaults.async).toBeFalse();
});
it('should return Promise if async', () => {
expect(marked('test', { async: true })).toBeInstanceOf(Promise);
});
it('should return string if not async', () => {
expect(typeof marked('test', { async: false })).toBe('string');
});
it('should return Promise if async is set by extension', () => {
use({ async: true });
expect(marked('test', { async: false })).toBeInstanceOf(Promise);
});
it('should allow deleting/editing tokens', () => {
const styleTags = {
extensions: [{