Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for non parsable FunctionExpression node type #8

Open
hoschi opened this issue Nov 11, 2017 · 1 comment
Open

add support for non parsable FunctionExpression node type #8

hoschi opened this issue Nov 11, 2017 · 1 comment

Comments

@hoschi
Copy link
Owner

hoschi commented Nov 11, 2017

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?!
@hoschi
Copy link
Owner Author

hoschi commented Nov 11, 2017

never saw 'read only' mode on a per character basis

@bryphe or is it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant