Skip to content

suppressErrors + withPositions is causing Exception on wrong expressions #1185

@mkslanc

Description

@mkslanc

Hi! I am trying to replace underlying library for php diagnostics for ace-linters, and meet this bug.
Minimal reproducible example:

<?php
fu1nction nfact($n) {
    if ($n == 0) {
        return 1;
    }
    else {
        return $n * nfact($n - 1);
    }
}
?>

on

{
            parser: {
                extractDoc: false,
                suppressErrors: true,
            },
            ast: {
                withPositions: true,
                withSource: false,
            },
            lexer: {
                all_tokens: false,
                comment_tokens: false,
                mode_eval: false,
                asp_tags: false,
                short_tags: true, // allow `<?` if needed
            },
        }

will cause

TypeError: Cannot read properties of undefined (reading 'loc')
    at AST.swapLocations (php-parser.js:189:30)
    at AST.resolvePrecedence (php-parser.js:323:10)
    at result (php-parser.js:381:17)
    at Parser$1.read_statement (php-parser.js:10206:18)
    at Parser$1.read_top_statement (php-parser.js:9896:21)
    at Parser$1.read_start (php-parser.js:9175:19)
    at Parser.parse (php-parser.js:6566:22)
    at Engine.parseCode (php-parser.js:4349:22)
    at PhpService.doValidation (php-service.ts:61:38)
    at service-manager.ts:57:31

on my service using your lib as an engine.

Setting withPositions to false or suppressErrors to false would lead to normal behaviour, though without precise positions of course.

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