Conversation
sandersn
approved these changes
Apr 25, 2017
Member
sandersn
left a comment
There was a problem hiding this comment.
One nit, otherwise looks good.
| return false; | ||
| } | ||
| const blockScope = getEnclosingBlockScopeContainer(declaration); | ||
| while (currentNode) { |
Member
There was a problem hiding this comment.
you can use findAncestor in core.ts to replace this loop. It's fairly new, about a week or so old.
Contributor
Author
There was a problem hiding this comment.
findAncestor doesn't do much to improve this. It's the same number of lines, introduces a new environment record for the closure each time it's called, and doesn't improve readability of the function. There's no apparent performance difference between the two, as far as I can tell.
function isPartOfClassBody(declaration: ClassLikeDeclaration, node: Identifier) {
node = getParseTreeNode(node, isIdentifier);
if (!node || node.end <= declaration.pos || node.pos >= declaration.end) {
// if the node has no correlation to a parse tree node, its definitely not
// part of the body.
// if the node is outside of the document range of the declaration, its
// definitely not part of the body.
return false;
}
const blockScope = getEnclosingBlockScopeContainer(declaration);
return !!findAncestor(node, current => {
if (current === blockScope || current === declaration) {
return "quit";
}
if (isClassElement(current) && current.parent === declaration) {
// we are in the class body, but we treat static fields as outside of the class body
return current.kind !== SyntaxKind.PropertyDeclaration
|| (getModifierFlags(current) & ModifierFlags.Static) === 0 ? true : "quit";
}
return false;
});
}
Member
There was a problem hiding this comment.
Fair enough. If there's no readability benefit then there's no point introducing it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes the emit for class names when emitting classes for ES5.
Fixes #14945