Skip to content

Commit 44122eb

Browse files
committed
chore: switch RuleType back to an enum
1 parent f665b00 commit 44122eb

File tree

3 files changed

+79
-77
lines changed

3 files changed

+79
-77
lines changed

index.compiler.spec.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -3799,7 +3799,7 @@ describe('options.slugify', () => {
37993799

38003800
describe('overrides', () => {
38013801
it('should substitute the appropriate JSX tag if given a component', () => {
3802-
class FakeParagraph extends React.Component {
3802+
class FakeParagraph extends React.Component<React.PropsWithChildren<{}>> {
38033803
render() {
38043804
return <p className="foo">{this.props.children}</p>
38053805
}
@@ -3837,7 +3837,7 @@ describe('overrides', () => {
38373837
})
38383838

38393839
it('should accept an override shorthand if props do not need to be overidden', () => {
3840-
class FakeParagraph extends React.Component {
3840+
class FakeParagraph extends React.Component<React.PropsWithChildren<{}>> {
38413841
render() {
38423842
return <p className="foo">{this.props.children}</p>
38433843
}
@@ -3865,7 +3865,9 @@ describe('overrides', () => {
38653865
})
38663866

38673867
it('should override the title property when parsing a link', () => {
3868-
class FakeLink extends React.Component<{ title: string }> {
3868+
class FakeLink extends React.Component<
3869+
React.PropsWithChildren<{ title: string }>
3870+
> {
38693871
render() {
38703872
const { title, children } = this.props
38713873
return <a title={title}>{children}</a>
@@ -3910,7 +3912,7 @@ describe('overrides', () => {
39103912
})
39113913

39123914
it('should substitute pre & code tags if supplied with an override component', () => {
3913-
class OverridenPre extends React.Component {
3915+
class OverridenPre extends React.Component<React.PropsWithChildren<{}>> {
39143916
render() {
39153917
const { children, ...props } = this.props
39163918

@@ -3922,7 +3924,7 @@ describe('overrides', () => {
39223924
}
39233925
}
39243926

3925-
class OverridenCode extends React.Component {
3927+
class OverridenCode extends React.Component<React.PropsWithChildren<{}>> {
39263928
render() {
39273929
const { children, ...props } = this.props
39283930

index.component.spec.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ it('handles a no-children scenario', () => {
3030
})
3131

3232
it('accepts options', () => {
33-
class FakeParagraph extends React.Component {
33+
class FakeParagraph extends React.Component<React.PropsWithChildren<{}>> {
3434
render() {
3535
return <p className="foo">{this.props.children}</p>
3636
}

index.tsx

+71-71
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,47 @@ import * as React from 'react'
1212
* Analogous to `node.type`. Please note that the values here may change at any time,
1313
* so do not hard code against the value directly.
1414
*/
15-
export const RuleType = {
16-
blockQuote: '0',
17-
breakLine: '1',
18-
breakThematic: '2',
19-
codeBlock: '3',
20-
codeFenced: '4',
21-
codeInline: '5',
22-
footnote: '6',
23-
footnoteReference: '7',
24-
gfmTask: '8',
25-
heading: '9',
26-
headingSetext: '10',
15+
export const enum RuleType {
16+
blockQuote = '0',
17+
breakLine = '1',
18+
breakThematic = '2',
19+
codeBlock = '3',
20+
codeFenced = '4',
21+
codeInline = '5',
22+
footnote = '6',
23+
footnoteReference = '7',
24+
gfmTask = '8',
25+
heading = '9',
26+
headingSetext = '10',
2727
/** only available if not `disableHTMLParsing` */
28-
htmlBlock: '11',
29-
htmlComment: '12',
28+
htmlBlock = '11',
29+
htmlComment = '12',
3030
/** only available if not `disableHTMLParsing` */
31-
htmlSelfClosing: '13',
32-
image: '14',
33-
link: '15',
31+
htmlSelfClosing = '13',
32+
image = '14',
33+
link = '15',
3434
/** emits a `link` 'node', does not render directly */
35-
linkAngleBraceStyleDetector: '16',
35+
linkAngleBraceStyleDetector = '16',
3636
/** emits a `link` 'node', does not render directly */
37-
linkBareUrlDetector: '17',
37+
linkBareUrlDetector = '17',
3838
/** emits a `link` 'node', does not render directly */
39-
linkMailtoDetector: '18',
40-
newlineCoalescer: '19',
41-
orderedList: '20',
42-
paragraph: '21',
43-
ref: '22',
44-
refImage: '23',
45-
refLink: '24',
46-
table: '25',
47-
tableSeparator: '26',
48-
text: '27',
49-
textBolded: '28',
50-
textEmphasized: '29',
51-
textEscaped: '30',
52-
textMarked: '31',
53-
textStrikethroughed: '32',
54-
unorderedList: '33',
55-
} as const
39+
linkMailtoDetector = '18',
40+
newlineCoalescer = '19',
41+
orderedList = '20',
42+
paragraph = '21',
43+
ref = '22',
44+
refImage = '23',
45+
refLink = '24',
46+
table = '25',
47+
tableSeparator = '26',
48+
text = '27',
49+
textBolded = '28',
50+
textEmphasized = '29',
51+
textEscaped = '30',
52+
textMarked = '31',
53+
textStrikethroughed = '32',
54+
unorderedList = '33',
55+
}
5656

5757
const enum Priority {
5858
/**
@@ -768,7 +768,7 @@ function parserFor(
768768
// there can be a single output function for all links,
769769
// even if there are several rules to parse them.
770770
if (parsed.type == null) {
771-
parsed.type = ruleType as unknown as keyof typeof RuleType
771+
parsed.type = ruleType as unknown as RuleType
772772
}
773773

774774
result.push(parsed)
@@ -1925,130 +1925,130 @@ export namespace MarkdownToJSX {
19251925

19261926
export interface BlockQuoteNode {
19271927
children: MarkdownToJSX.ParserResult[]
1928-
type: (typeof RuleType)['blockQuote']
1928+
type: RuleType.blockQuote
19291929
}
19301930

19311931
export interface BreakLineNode {
1932-
type: (typeof RuleType)['breakLine']
1932+
type: RuleType.breakLine
19331933
}
19341934

19351935
export interface BreakThematicNode {
1936-
type: (typeof RuleType)['breakThematic']
1936+
type: RuleType.breakThematic
19371937
}
19381938

19391939
export interface CodeBlockNode {
1940-
type: (typeof RuleType)['codeBlock']
1940+
type: RuleType.codeBlock
19411941
attrs?: JSX.IntrinsicAttributes
19421942
lang?: string
19431943
text: string
19441944
}
19451945

19461946
export interface CodeFencedNode {
1947-
type: (typeof RuleType)['codeFenced']
1947+
type: RuleType.codeFenced
19481948
}
19491949

19501950
export interface CodeInlineNode {
1951-
type: (typeof RuleType)['codeInline']
1951+
type: RuleType.codeInline
19521952
text: string
19531953
}
19541954

19551955
export interface FootnoteNode {
1956-
type: (typeof RuleType)['footnote']
1956+
type: RuleType.footnote
19571957
}
19581958

19591959
export interface FootnoteReferenceNode {
1960-
type: (typeof RuleType)['footnoteReference']
1960+
type: RuleType.footnoteReference
19611961
target: string
19621962
text: string
19631963
}
19641964

19651965
export interface GFMTaskNode {
1966-
type: (typeof RuleType)['gfmTask']
1966+
type: RuleType.gfmTask
19671967
completed: boolean
19681968
}
19691969

19701970
export interface HeadingNode {
1971-
type: (typeof RuleType)['heading']
1971+
type: RuleType.heading
19721972
children: MarkdownToJSX.ParserResult[]
19731973
id: string
19741974
level: 1 | 2 | 3 | 4 | 5 | 6
19751975
}
19761976

19771977
export interface HeadingSetextNode {
1978-
type: (typeof RuleType)['headingSetext']
1978+
type: RuleType.headingSetext
19791979
}
19801980

19811981
export interface HTMLCommentNode {
1982-
type: (typeof RuleType)['htmlComment']
1982+
type: RuleType.htmlComment
19831983
}
19841984

19851985
export interface ImageNode {
1986-
type: (typeof RuleType)['image']
1986+
type: RuleType.image
19871987
alt?: string
19881988
target: string
19891989
title?: string
19901990
}
19911991

19921992
export interface LinkNode {
1993-
type: (typeof RuleType)['link']
1993+
type: RuleType.link
19941994
children: MarkdownToJSX.ParserResult[]
19951995
target: string
19961996
title?: string
19971997
}
19981998

19991999
export interface LinkAngleBraceNode {
2000-
type: (typeof RuleType)['linkAngleBraceStyleDetector']
2000+
type: RuleType.linkAngleBraceStyleDetector
20012001
}
20022002

20032003
export interface LinkBareURLNode {
2004-
type: (typeof RuleType)['linkBareUrlDetector']
2004+
type: RuleType.linkBareUrlDetector
20052005
}
20062006

20072007
export interface LinkMailtoNode {
2008-
type: (typeof RuleType)['linkMailtoDetector']
2008+
type: RuleType.linkMailtoDetector
20092009
}
20102010

20112011
export interface OrderedListNode {
2012-
type: (typeof RuleType)['orderedList']
2012+
type: RuleType.orderedList
20132013
items: MarkdownToJSX.ParserResult[][]
20142014
ordered: true
20152015
start?: number
20162016
}
20172017

20182018
export interface UnorderedListNode {
2019-
type: (typeof RuleType)['unorderedList']
2019+
type: RuleType.unorderedList
20202020
items: MarkdownToJSX.ParserResult[][]
20212021
ordered: false
20222022
}
20232023

20242024
export interface NewlineNode {
2025-
type: (typeof RuleType)['newlineCoalescer']
2025+
type: RuleType.newlineCoalescer
20262026
}
20272027

20282028
export interface ParagraphNode {
2029-
type: (typeof RuleType)['paragraph']
2029+
type: RuleType.paragraph
20302030
children: MarkdownToJSX.ParserResult[]
20312031
}
20322032

20332033
export interface ReferenceNode {
2034-
type: (typeof RuleType)['ref']
2034+
type: RuleType.ref
20352035
}
20362036

20372037
export interface ReferenceImageNode {
2038-
type: (typeof RuleType)['refImage']
2038+
type: RuleType.refImage
20392039
alt?: string
20402040
ref: string
20412041
}
20422042

20432043
export interface ReferenceLinkNode {
2044-
type: (typeof RuleType)['refLink']
2044+
type: RuleType.refLink
20452045
children: MarkdownToJSX.ParserResult[]
20462046
fallbackChildren: MarkdownToJSX.ParserResult[]
20472047
ref: string
20482048
}
20492049

20502050
export interface TableNode {
2051-
type: (typeof RuleType)['table']
2051+
type: RuleType.table
20522052
/**
20532053
* alignment for each table column
20542054
*/
@@ -2058,40 +2058,40 @@ export namespace MarkdownToJSX {
20582058
}
20592059

20602060
export interface TableSeparatorNode {
2061-
type: (typeof RuleType)['tableSeparator']
2061+
type: RuleType.tableSeparator
20622062
}
20632063

20642064
export interface TextNode {
2065-
type: (typeof RuleType)['text']
2065+
type: RuleType.text
20662066
text: string
20672067
}
20682068

20692069
export interface BoldTextNode {
2070-
type: (typeof RuleType)['textBolded']
2070+
type: RuleType.textBolded
20712071
children: MarkdownToJSX.ParserResult[]
20722072
}
20732073

20742074
export interface ItalicTextNode {
2075-
type: (typeof RuleType)['textEmphasized']
2075+
type: RuleType.textEmphasized
20762076
children: MarkdownToJSX.ParserResult[]
20772077
}
20782078

20792079
export interface EscapedTextNode {
2080-
type: (typeof RuleType)['textEscaped']
2080+
type: RuleType.textEscaped
20812081
}
20822082

20832083
export interface MarkedTextNode {
2084-
type: (typeof RuleType)['textMarked']
2084+
type: RuleType.textMarked
20852085
children: MarkdownToJSX.ParserResult[]
20862086
}
20872087

20882088
export interface StrikethroughTextNode {
2089-
type: (typeof RuleType)['textStrikethroughed']
2089+
type: RuleType.textStrikethroughed
20902090
children: MarkdownToJSX.ParserResult[]
20912091
}
20922092

20932093
export interface HTMLNode {
2094-
type: (typeof RuleType)['htmlBlock']
2094+
type: RuleType.htmlBlock
20952095
attrs: JSX.IntrinsicAttributes
20962096
children?: ReturnType<MarkdownToJSX.NestedParser> | undefined
20972097
noInnerParse: Boolean
@@ -2100,7 +2100,7 @@ export namespace MarkdownToJSX {
21002100
}
21012101

21022102
export interface HTMLSelfClosingNode {
2103-
type: (typeof RuleType)['htmlSelfClosing']
2103+
type: RuleType.htmlSelfClosing
21042104
attrs: JSX.IntrinsicAttributes
21052105
tag: string
21062106
}

0 commit comments

Comments
 (0)