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

Parsing fails upon encountering optional chaining #51

Open
JonathanWilbur opened this issue Oct 11, 2020 · 8 comments
Open

Parsing fails upon encountering optional chaining #51

JonathanWilbur opened this issue Oct 11, 2020 · 8 comments

Comments

@JonathanWilbur
Copy link

JonathanWilbur commented Oct 11, 2020

Upon encountering an optional chaining operator, the parsing fails. I am using this in the Jest VS Code Extension, but I have also tried the other popular Jest VS Code Extension, both of which fail and both of which use this library. Here is an example that you can try yourself:

This parses correctly. In VS Code, I can see the "Run | Debug" floating over the tests.

describe("Normalization", () => {
    test("adds a module to every assignment", () => {
        expect(assignment.module.name).toBe("AuthenticationFramework");
    });
});

When you add the question mark (optional chaining operator), it no longer parses correctly.

This does not parse correctly. I cannot see the "Run | Debug" floating over the tests anymore.

describe("Normalization", () => {
    test("adds a module to every assignment", () => {
        expect(assignment.module?.name).toBe("AuthenticationFramework");
    });
});
@JonathanWilbur
Copy link
Author

JonathanWilbur commented Oct 11, 2020

I see now that this is because this library does not execute parse from the @babel/parser library with any plugins, so only the bare minimum "vanilla Babel" would be supported. I believe this should be easy to fix by requireing the local babel.config.js file (or making it configurable, at least) so that the required Babel plugins can be used.

In my case, I believe this plugin would fix it, but again, this library does not use any of the plugins that I indicate in babel.config.js.

@connectdotz
Copy link
Collaborator

hmmm... actually the parser should be able to parse the output from all plugins, see here. But it doesn't load the plugin for you, your project will still need to load the particular plugin so it can be transpired correctly for the parser to parse...

where did you see the error message? from the output window or developer console? Are you able to run jest in the terminal? Is vscode-jest using the same command (jest.pathToJest) above?

If you still have problems, please create a sample repo so we can quickly narrow it down.

@JonathanWilbur
Copy link
Author

@connectdotz I have installed the two related plugins just to be sure. Neither worked.

        "@babel/plugin-proposal-optional-chaining": "^7.11.0",
        "@babel/plugin-syntax-optional-chaining": "^7.8.3",

And in babel.config.js, I indicated that I want both to be used.

    plugins: [
        "@babel/plugin-syntax-optional-chaining",
        "@babel/plugin-proposal-optional-chaining",
    ],

But still, the problem persists.

where did you see the error message? from the output window or developer console? Are you able to run jest in the terminal? Is vscode-jest using the same command (jest.pathToJest) above?

All of my tests run fine when I run with the jest command line, either via npm run test or the jest command directly.

@JonathanWilbur
Copy link
Author

For clarity, I have tried with both plugins individually as well.

@connectdotz
Copy link
Collaborator

@JonathanWilbur this might sound silly, but you did restart the extension after adding the babel plugin, right?

If none worked, please create a sample repo. I am pretty sure the parser is able to parse optional chaining as I have used it in my projects.

@JonathanWilbur
Copy link
Author

@dinofx
Copy link

dinofx commented Oct 23, 2020

optional chaining and many other typescript language features also cause parsing to fail. For example, I moved this function out of a test file to prevent parsing from failing:

export function assert(condition: any): asserts condition {
  expect(condition).toBe(true);
}

Given the ubiquity of TypeScript (the vscode-jest extension, for example), would be nice for editor support to enable TS support for .ts[x] files.

@connectdotz
Copy link
Collaborator

connectdotz commented Oct 24, 2020

@JonathanWilbur I tried your repo and the test (in test/jest/index.test.js) showed pass, no parsing error, everything looks all right to me...

[update]
However, I am using the vscode-jest v4 alpha version... maybe you can try https://github.com/jest-community/vscode-jest/releases/tag/v4.0.0-alpha.1, to see if your problem resolved?

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

No branches or pull requests

3 participants