Skip to content

Different lexer behavior when creating lexer class object without options #3854

@t4cmyk

Description

@t4cmyk

Marked version: 16.4.2

Describe the bug

import { marked } from "marked";

const lexer = new marked.Lexer();
const tokensA = marked.Lexer.lex("Test");
const tokensB = lexer.lex("Test");

The values of tokensA and tokensB should be the same instead tokensA is

[
    {
        "type": "paragraph",
        "raw": "Test",
        "text": "Test",
        "tokens": [
            {
                "type": "text",
                "raw": "Test",
                "text": "Test",
                "escaped": false
            }
        ]
    }
]

as expected but tokensB is

[
    {
        "type": "paragraph",
        "raw": "Test",
        "text": "Test",
        "tokens": []
    }
]

The problem is probably related to the shared _defaults option object.

To Reproduce
Steps to reproduce the behavior: Run the code above

Expected behavior
I would expect both options to give the same result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions