Hirse / brackets-outline-list

Extension for Brackets and Phoenix to display a list of the functions or definitions in the currently opened document.
MIT License
79 stars 30 forks source link

Support JS with-statements #110

Open ArielBookraft opened 5 years ago

ArielBookraft commented 5 years ago

It keeps say, "fix the syntax errors in the file to show the Outline." This is a .js file. There are no syntax errors in it. It runs fine. Nothing is flagged in Chrome. And ideas? Thanks!

Hirse commented 5 years ago

This is very hard to diagnose or solve without the actual input.

Does this happen for all JS files or just one?

This extension is using Espree to parse the JavaScript code. The message you cite is shown when the file cannot be parsed. You can use https://astexplorer.net to test the parsing of your file, it might show some more detailed error information.

ArielBookraft commented 5 years ago

Thanks for that link. I ran the script through it, and it flagged 2 types of errors in the code: I was using the "with" keyword in several places, and also the "delete" keyword (to delete an element from an associative array -- is there any other way of doing it?) in local mode. When I got rid of all lines containing "with" and "delete", the function list indeed appeared nicely in Brackets. But neither of these are actually errors. Is there any way of allowing them through -- I think in both cases astexplorer mentioned that they were only flagged because it was in "strict" mode. Any chance of being more lenient?

Thanks, great extension, working nicely with the CSS... Ariel

Hirse commented 5 years ago

According to MDN ...

using with is not recommended, and is forbidden in ECMAScript 5 strict mode.

In order to support parsing with, the parser's ES-version target has to be set to 3 which means newer features (=>, import, ...) would cause syntax errors. If you are targeting that version and don't use any of the ES5+ features, I would consider adding an option to the extension. Please test on AST explorer if that would actually fix the issue for you.

Regarding delete, removing properties from an object is fine, but removing a variable itself is not. See MDN reference.

ArielBookraft commented 5 years ago

Thanks for following up with this.

Actually, what seems to make the difference on AST is not changing the script version, but rather changing the "Source Type" (there's that little dropdown there in the options). If I change it to "script" instead of "module", it parses everything correctly (tried it with my script in question). OTOH, just change the version down to 3 still throws the "with" error.

If the extension could have an option to choose "script" rather than "module", that would be great!