GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Fix `insertNodeAtClassStart` for empty class with comment · Pull Request #23342 · microsoft/TypeScript Conversation
|
| export function addToSeen(seen: Map<true>, key: string | number): boolean { | ||
| export function addToSeen(seen: Map<true>, key: string | number): boolean; | ||
| export function addToSeen<T>(seen: Map<T>, key: string | number, value: T): boolean; | ||
| export function addToSeen<T>(seen: Map<T>, key: string | number, value: T = true as any): boolean { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
For my own edification, why not use {} as the default value?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've been using Map<true> everywhere for sets; to me Map<{}> would imply actually being a map from string to something, where we didn't specify that something.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (addToSeen(this.classesWithNodesInsertedAtStart, getNodeId(cls), cls)) { | ||
| prefix = this.newLineCharacter; | ||
| // For `class C {\n}`, don't add the trailing "\n" | ||
| if (cls.members.length === 0 && !(positionsAreOnSameLine as any)(...getClassBraceEnds(cls, sourceFile), sourceFile)) { // TODO: GH#4130 remove 'as any' |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Does the number of members matter? It seems like you want to omit the linebreak as long as the class is on a single line.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's the opposite -- if the class is on a single line I want to add line breaks on both sides to get {\n member\n}; if the class is already multiline I only want the first line break.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| this.insertNodeBefore(sourceFile, firstMember, newElement); | ||
| } | ||
|
|
||
| const indentation = formatting.SmartIndenter.findFirstNonWhitespaceColumn(getLineStartPositionForPosition(clsStart, sourceFile), clsStart, sourceFile, this.formatContext.options) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should the indentation be omitted if the class is on a single line?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's about to be multiline since we're adding a member, and that new member should be indented.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| this.classesWithNodesInsertedAtStart.forEach(cls => { | ||
| const sourceFile = cls.getSourceFile(); | ||
| const [openBraceEnd, closeBraceEnd] = getClassBraceEnds(cls, sourceFile); | ||
| // For `class C { }` remove the whitespace inside the braces. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Leaving the space would result in the class ending in \n } instead of just \n} The formatter won't handle this since it only formats the new nodes we're adding, not the existing whitespace surrounding them.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Andrew Casey (@amcasey) Could you update your review? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.