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

Report all the js file errors and skip only the nodes that are not allowed in JS file #11978

Merged
merged 5 commits into from
Nov 10, 2016

Conversation

sheetalkamat
Copy link
Member

Fixes #11800

// Return directly from the case if the given node doesnt want to visit each child
// Otherwise break to visit each child

switch (parent.kind) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we using parent instead of node?

Copy link
Member Author

Choose a reason for hiding this comment

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

Here we are checking if the node is 'questiontoken' or 'type' of parent and hence the check.

Copy link
Contributor

Choose a reason for hiding this comment

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

but what was wrong with the previous pattern where we check parameter node, and then check it has a questiontoken set?

Copy link
Member Author

Choose a reason for hiding this comment

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

There was no control over what to skip.. With this we visit all nodes except the nodes that aren't supported. (Eg. checkout how we use to return true when we found ? token, which would mean we wouldn't look into parameter children.. While that might be ok there it isn't if say for example we want to report error say on decorator of the class declaration and also verify say methods of class..) With this if we have say found typeNode of the variable declaration/function return type we don't go it that type node. But still visit other nodes of the variable declaration/function declaration which means we would be reporting other errors.

case SyntaxKind.ExportKeyword:
case SyntaxKind.ConstKeyword:
case SyntaxKind.DefaultKeyword:
case SyntaxKind.AbstractKeyword:
Copy link
Contributor

Choose a reason for hiding this comment

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

why is abstract and const legal modifiers?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, I just copied from earlier implementation.. const should be valid when variable statement to handle const a = 10 and abstract shouldn't be valid. I will update this

case SyntaxKind.VariableStatement:
// Check modifiers
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration | VariableStatement>parent).modifiers) {
return checkModifiers(<NodeArray<Modifier>>nodes);
return checkModifiers(<NodeArray<Modifier>>nodes, isConstValid);
Copy link
Contributor

Choose a reason for hiding this comment

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

is not this always false?

Copy link
Member Author

Choose a reason for hiding this comment

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

forgot to amend the changes before pushing it out. Updated it.

@sheetalkamat sheetalkamat force-pushed the errorReportingInJsFile branch from 0208345 to 6456325 Compare November 9, 2016 18:40
return true;
// Check modifiers
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration | VariableStatement>parent).modifiers) {
return checkModifiers(<NodeArray<Modifier>>nodes, !isConstInvalid);
Copy link
Contributor

Choose a reason for hiding this comment

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

return checkModifiers(<NodeArray<Modifier>>nodes, parent.kind === SyntaxKind.VariableStatement)

Copy link
Member Author

Choose a reason for hiding this comment

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

Just want to avoid doing that check again as its already done as part of case statement?

Copy link
Contributor

Choose a reason for hiding this comment

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

it much more readable and better than accessing an undefined variable to be frank.

@sheetalkamat sheetalkamat merged commit c87bce1 into master Nov 10, 2016
@sheetalkamat sheetalkamat deleted the errorReportingInJsFile branch November 10, 2016 18:37
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants