Skip to content

Commit

Permalink
Change parse() to not reuse static field for parsed result
Browse files Browse the repository at this point in the history
Fixes bug where parse() will return the same object for every
call if called inside an arrow function passed to
Array.prototype.map()
  • Loading branch information
argonaut0 committed Jul 8, 2021
1 parent 2a437b2 commit 21484d7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/marked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ export class Marked {
*/
static parse(src: string, options: MarkedOptions = this.options): Parsed {
try {
const result = {content: "", meta: {}};
const { tokens, links, meta } = this.callBlockLexer(src, options);
this.parsed.content = this.callParser(tokens, links, options);
this.parsed.meta = meta;
return this.parsed;
result.content = this.callParser(tokens, links, options);
result.meta = meta;
return result;
} catch (e) {
this.parsed.content = this.callMe(e);
return this.parsed;
result.content = this.callMe(e);
return result;
}
}

Expand Down

0 comments on commit 21484d7

Please sign in to comment.