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

Switch to Babel parser & Change JSHint to ESLint & Drop Support for Node 6 #61

Merged
merged 2 commits into from
Jul 1, 2019

Conversation

tomdale
Copy link
Contributor

@tomdale tomdale commented Jul 1, 2019

This PR changes the parser from Esprima (the default) to Babel. It uses a pre-configured parser shipped with recast (recast/parsers/babel) so that the AST returned by Babel is compatible.

The goal of this change is to support newer JavaScript syntax that is not yet supported by Esprima, so this PR also includes a new test where the input source includes a class, class fields, and a decorator.

I also replaced jshint with eslint, based on the current ember-cli configuration, but adjusted the rules to be looser to avoid noise in the diff. We can tighten up the rules and update the source in a separate change.

This also adds a prettier config pulled from ember-cli, but does not enforce the rules in the test suite at this time (again, to avoid a noisy diff making it hard to understand the Babel/Esprima parser change).

@tomdale tomdale requested review from Turbo87 and rwjblue July 1, 2019 20:56
@@ -0,0 +1,7 @@
class AppRouter extends Router {
@tracked location = config.locationType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to confirm decorators don’t blow up parsing (which I assume is the point), but just wanted to confirm that we are on the same page: it’s super unlikely that we’d allow this specific field as tracked, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, making this tracked would have no effect. I'd be happy to change the test if you can recommend an example that would be less confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just @someDecorator makes it clear that we're testing for abstract decorator support, not a specific expected feature?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, probably but its fine either way to me.

@@ -1,6 +1,5 @@
language: node_js
node_js:
- '6'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be considered a breaking change and will require a new major version release

"eslint": "^6.0.1",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-mocha": "^5.3.0",
"eslint-plugin-node": "^9.1.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's not too much work, could you extract the JSHint->ESLint change to a separate PR? that would make the parser changes here significantly easier to review 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to separate it completely but it was non-trivial because some of the code in this PR was incompatible with the old version of jshint. I tried to make the code changes as minimal as possible. If it makes it easier, almost all parser-related changes are in the code, not configuration files (other than the new Babel deps in package.json).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like an ordering problem to me. if switching to ESLint is necessary for the code in this PR then why not switch to ESLint first, before modifying any code? I assume the ESLint change does not depend on the new parser code in this PR.

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update engines in package.json to: ”8.* || 10.* || >= 12”?

This commit changes the parser from esprima (the default parser that comes with recast) to @babel/parser. It uses the pre-configured Babel parser shipped with recast (recast/parsers/babel) that ensures the AST returned by Babel is compatible with recast.

The goal of this change is to support newer JavaScript syntax that is not yet supported by Esprima, so this commit also includes a new test where the input source includes class syntax, class fields, and a decorator.

I also replaced jshint with eslint, based on the current ember-cli configuration, but adjusted the rules to be looser to avoid noise in the diff. We can tighten up the rules and update the source in a separate change.

This also adds a prettier config pulled from ember-cli, but does not enforce the rules in the test suite at this time (again, to avoid a noisy diff making it hard to understand the Babel/Esprima parser change).
@tomdale
Copy link
Contributor Author

tomdale commented Jul 1, 2019

Updated engines to drop 6.x support and changed the decorator name in the fixtures to look less like a real (but misleading) example someone could inadvertently try to copy.

@rwjblue rwjblue merged commit 966afeb into master Jul 1, 2019
@delete-merged-branch delete-merged-branch bot deleted the babel-parser branch July 1, 2019 21:22
@Turbo87 Turbo87 changed the title Switch to Babel parser Switch to Babel parser & Change JSHint to ESLint & Drop Support for Node 6 Jul 2, 2019
@chancancode
Copy link

We should confirm that export default class Router extends EmberRouter { ... } works (the export default part). I have no reason to think it doesn't, but seems important to test it.

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

Successfully merging this pull request may close these issues.

4 participants