Skip to content

Commit

Permalink
fix: ignore async: false when async: true is set by an extension (#2920)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech authored Aug 19, 2023
1 parent a990c54 commit b6ee877
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/unit/marked-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down

1 comment on commit b6ee877

@vercel
Copy link

@vercel vercel bot commented on b6ee877 Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.