Skip to content

Conversation

@rbuckton
Copy link
Contributor

@rbuckton rbuckton commented Apr 7, 2015

Fixes #2660 and #2661

  • Added rules for spacing around decorators
  • Computing the undecorated start line of a node for use as the effectiveParentStartLine

There's still an issue with indentation in formatOnEnter.

Copy link
Contributor

Choose a reason for hiding this comment

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

i made a change to make isExpression return true for decorators.

Copy link
Contributor

Choose a reason for hiding this comment

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

can you just walk up until you find a decorator, or just use hasAncestor/getAncestor

Copy link
Contributor

Choose a reason for hiding this comment

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

here is the change i referenced earlier: #2659

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on our offline discussion, I changed the logic in isExpression in #2659. This should no longer be an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we ever add support for decorators on class expressions, function expressions, or arrow functions then hasAncestor/getAncestor is unsafe to use. Consider the following:

@class { /*A*/ } class C { }

At A above, a call to getAncestor(SyntaxKind.Decorator) would return the decorator for C, but it should have stopped at the class body. hasAncestor and getAncestor don't have a boundary. We could add a boundary check, but this is easy enough.

I may change this to the following, though:

        static NodeIsInDecoratorContext(node: Node): boolean {
            while (isExpression(node)) {
                node = node.parent;
            }
            return node.kind === SyntaxKind.Decorator;
        }

@mhegazy
Copy link
Contributor

mhegazy commented Apr 9, 2015

👍

rbuckton added a commit that referenced this pull request Apr 10, 2015
@rbuckton rbuckton merged commit f318515 into master Apr 10, 2015
@rbuckton rbuckton deleted the fixDecoratorFormatting branch April 10, 2015 00:42
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 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.

Incorrect indentation for multiple decorators

4 participants