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

Object access dot operator #47

Merged
merged 6 commits into from
Jan 28, 2018
Merged

Conversation

baransu
Copy link
Contributor

@baransu baransu commented Dec 26, 2017

Second attempt to resolve #28. New PR because I've started work from scratch and I want to keep clean git history.

This solution leverages parser rather than tokenizer so no new tokens were added to syntax. One not so nice part is checking if last operator and last operand in the parser/expressions are like we would like them. This probably can be improved but I'm counting on some feedback first.
I've also added error when we're trying to access object field that doesn't exist. New error inside Context: TypeError was introduced because it was more suitable for this type of error.

There are some formatting changes and they are not related to my PR but I was forced by prettier to add them because of wrong formatting on some files that were on master branch.

@baransu
Copy link
Contributor Author

baransu commented Dec 26, 2017

Linting is failing because of the eslint rules conflicting with prettier output. Maybe it's a good idea to disable code formatting rules at all because we're forcing prettier formatting so after all there is no need to check them by eslint.

@ballercat
Copy link
Owner

The eslint + prettier setup is there to ensure properly formatted code is committed to master. Looking at the eslint errors they are legit. Strings must use double quotes, this is default prettier setup. The project uses mostly default prettier style + trailing commas.

@iddan
Copy link

iddan commented Dec 26, 2017

Wasn't it agreed that no string access and declaration would be allowed to avoid confusion?

@baransu
Copy link
Contributor Author

baransu commented Dec 26, 2017

But prettier soubleQuote is not always double quote but prefer double quote. https://prettier.io/docs/en/options.html#quotes

Using prettier in validation step ensures us that code formatting is correct so having eslint for that is unneccessary. In situations like this there is no way to have eslint and prettier pass because code is properly formated after prettier pass.

@ballercat
Copy link
Owner

I see what you mean now. Yeah, our eslint-rule for quotes is misconfigured https://eslint.org/docs/rules/quotes#avoidescape we should have had an avoidEscape option enabled.

My primary concern was that it would be difficult to track down what is wrong with the source if there is only prettier validation as it'll simply point a file should be prettified but not which line/why it's failing. We could discuss disabling formatting rules, even though wouldn't really buy us anything.

For the errors you're getting, just edit the quote rule as it's misconfigured.

@coveralls
Copy link

coveralls commented Dec 26, 2017

Coverage Status

Coverage decreased (-0.2%) to 95.684% when pulling 8cf9fef on Baransu:dot-operator into ded8c9a on ballercat:master.

@baransu
Copy link
Contributor Author

baransu commented Dec 26, 2017

Waiting for review and initial feedback so I can improve things and convert examples/documentation.

@ballercat
Copy link
Owner

My initial feedback is similar to the original PR.

Since the . dot operator is already a binary operator handled by the parser. Generating a node with two params for us for pretty much free:

[
  targetNode,
  parameterNode
]

All we should need to do is to map the params to something array subscript can consume. Which is a identifierNode.stringLiternalNode. Check this part of the operator parser logic

} else if (node.value === "[") {

I don't really see a reason for us to keep track of the tokens in expression to figure out if it's an access operator or not.

@ballercat
Copy link
Owner

ballercat commented Jan 28, 2018

I gave updating this branch a shot, but it's way out of date by this point. It's been a while since any updates, so I think I'm going to consider this PR abandoned and implement the dot operator a bit differently. At this point it's a bit of a blocker for some other features.

@ballercat
Copy link
Owner

Fantastic. I was able to necromance the branch!

I hope you see why I went in a different direction. The changes to AST generators and validation made this feature a 3 line change.

Thanks for the help!

@ballercat ballercat changed the title [WIP] Object access dot operator Object access dot operator Jan 28, 2018
@ballercat ballercat merged commit 7fe1fac into ballercat:master Jan 28, 2018
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

Successfully merging this pull request may close these issues.

Dot operator and Identifiers for Object properties.
4 participants