Skip to content

Error when parsing case statements with OR operators #2

@cetfor

Description

@cetfor

I ran into an interesting error when parsing Bash like this. Notice line 3 where we use logical OR.

while [ true ]; do
    case "$command" in
        "exit" | "quit" | "q")   # issue here
            exit
            ;;
    esac
done

This throws the following error:

ReferenceError: pattern is not defined at Object.anonymous (https://vorpaljs.github.io/bash-parser-playground/bundle.js:8177:27) at Parser.parse (https://vorpaljs.github.io/bash-parser-playground/bundle.js:8382:36) at parse (https://vorpaljs.github.io/bash-parser-playground/bundle.js:7587:22) at HTMLTextAreaElement.parseSource (https://vorpaljs.github.io/bash-parser-playground/bundle.js:3:66) at HTMLTextAreaElement.dispatch (https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:3:12444) at HTMLTextAreaElement.r.handle (https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:3:9173)

When you remove the ORs and use a single case everything works.

while [ true ]; do
    case "$command" in
        "q")    # this works fine
            exit
            ;;
    esac
done

This issue happens when using https://vorpaljs.github.io/bash-parser-playground/ but it does not occur when using node-parser. Using node-parser in my own application successfully generates an AST for the first code block shown above.

Metadata

Metadata

Assignees

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