Skip to content

add support for non parsable FunctionExpression node type #8

@hoschi

Description

@hoschi

Some examples:

let assignedFunction = function (a, b) {
        if (a) {
            return 'a';
        } else {
            return 'b';
        }
    };

[].map(function (a, i) {
        return i
    });

// FunctionExpression inside an ObjectExpression
let myInstance = {
    myMethod() {
        return 'foo'
    }
}

Code like this can't be parsed by Recast, because it is not valid JavaScript syntax:

function (a, i) {
    return i
}

Also other parts in the ecosystem can't handle this, like 'eslint' which would mark the first line as error and doesn't show other errors. The language server used in Oni today can handle this code btw, you still get completions.

By adding a name the code is parsable again, e.g.:

function thisIsNotPartOfYourCode (a, i) {
    return i
}

ideas:

  • wrap code temporarily around before parsing it check builder example for adding AST nodes. This would not fix problems like eslint errors.
  • wrap code around in a function buffer
    • buffer now parsable by everything
    • added code should be read only (never saw 'read only' mode on a per character basis), because user should not change this
    • Yode could probably track that a change to the added name occurred and restore it, as Yode can change through the editorApi and the editor plugin can than react to to this also like make a tooltip "you should not edit this, here are dragons"
    • a bit bad look and feel as users sees code which is not in the file, can be solved by highlighting?!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions