-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
tools: improve heading type detection in json.js #20074
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -553,15 +553,54 @@ function cloneValue(src) { | |||
} | ||||
|
||||
|
||||
// These parse out the contents of an H# tag. | ||||
// This section parse out the contents of an H# tag. | ||||
|
||||
// To reduse escape slashes in RegExp string components. | ||||
const r = String.raw; | ||||
|
||||
const eventPrefix = r`^Event:\s+`; | ||||
const classPrefix = r`^[Cc]lass:\s+`; | ||||
const ctorPrefix = r`^(?:[Cc]onstructor:\s+)?new\s+`; | ||||
const classMethodPrefix = r`^Class Method:\s+`; | ||||
const maybeClassPropertyPrefix = r`(?:Class Property:\s+)?`; | ||||
|
||||
const maybeQuote = '[\'"]?'; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried, but ESLint throws. It seems this rule does not suffice for this: Line 217 in 2060787
We need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I thought such PR would be a small one) #20214 |
||||
const notQuotes = '[^\'"]+'; | ||||
|
||||
// To include constructs like `readable\[Symbol.asyncIterator\]()` | ||||
// or `readable.\_read(size)` (with Markdown escapes). | ||||
const simpleId = r`(?:(?:\\?_)+|\b)\w+\b`; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have |
||||
const computedId = r`\\?\[[\w\.]+\\?\]`; | ||||
const id = `(?:${simpleId}|${computedId})`; | ||||
const classId = r`[A-Z]\w+`; | ||||
|
||||
const ancestors = r`(?:${id}\.?)+`; | ||||
const maybeAncestors = r`(?:${id}\.?)*`; | ||||
|
||||
const callWithParams = r`\([^)]*\)`; | ||||
|
||||
const noCallOrProp = '(?![.[(])'; | ||||
|
||||
const maybeExtends = r`(?:\s+extends\s+${maybeAncestors}${classId})?`; | ||||
|
||||
const headingExpressions = [ | ||||
{ type: 'event', re: /^Event(?::|\s)+['"]?([^"']+).*$/i }, | ||||
{ type: 'class', re: /^Class:\s*([^ ]+).*$/i }, | ||||
{ type: 'property', re: /^[^.[]+(\[[^\]]+\])\s*$/ }, | ||||
{ type: 'property', re: /^[^.]+\.([^ .()]+)\s*$/ }, | ||||
{ type: 'classMethod', re: /^class\s*method\s*:?[^.]+\.([^ .()]+)\([^)]*\)\s*$/i }, | ||||
{ type: 'method', re: /^(?:[^.]+\.)?([^ .()]+)\([^)]*\)\s*$/ }, | ||||
{ type: 'ctor', re: /^new ([A-Z][a-zA-Z]+)\([^)]*\)\s*$/ }, | ||||
{ type: 'event', re: RegExp( | ||||
`${eventPrefix}${maybeQuote}(${notQuotes})${maybeQuote}$`, 'i') }, | ||||
|
||||
{ type: 'class', re: RegExp( | ||||
`${classPrefix}(${maybeAncestors}${classId})${maybeExtends}$`, '') }, | ||||
|
||||
{ type: 'ctor', re: RegExp( | ||||
`${ctorPrefix}(${maybeAncestors}${classId})${callWithParams}$`, '') }, | ||||
|
||||
{ type: 'classMethod', re: RegExp( | ||||
`${classMethodPrefix}${maybeAncestors}(${id})${callWithParams}$`, 'i') }, | ||||
|
||||
{ type: 'method', re: RegExp( | ||||
`^${maybeAncestors}(${id})${callWithParams}$`, 'i') }, | ||||
|
||||
{ type: 'property', re: RegExp( | ||||
`^${maybeClassPropertyPrefix}${ancestors}(${id})${noCallOrProp}$`, 'i') }, | ||||
]; | ||||
|
||||
function newSection({ text }) { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for
\s
? I mean, can there be tabs or new lines?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I do not think there can be. Do you mean it would be better to use
'^Event: +'
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in the fixup commit.