Skip to content

Commit

Permalink
Rename toJson to toJSON to for native serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinovantes committed Jun 25, 2024
1 parent 9be3a49 commit 1deee7d
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 59 deletions.
2 changes: 1 addition & 1 deletion demo/components/CodePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ watch(editorText, async(editorText) => {
try {
const parserOutput = htmlCompiler.parse(editorText, { disableWarnings: true })
outputAst.value = JSON.stringify(parserOutput.root.toJson(), undefined, 4)
outputAst.value = JSON.stringify(parserOutput.root.toJSON(), undefined, 4)
const outputHtml = htmlCompiler.compile(parserOutput)
renderedHtmlPre.value = await codeToHtml(outputHtml.body, {
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/Block/DoctestBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class RstDoctestBlock extends RstNode {
super(registrar, source)
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstDoctestBlockData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstDoctestBlockData>

root.data = {
rawText: this._rawText,
Expand Down
6 changes: 3 additions & 3 deletions src/RstNode/Block/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class RstDocument extends RstNode {
super(registrar, source, children)
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstDocumentData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstDocumentData>

root.data = {
docMeta: this.docMeta?.toJson() ?? null,
docMeta: this.docMeta?.toJSON() ?? null,
}

return root
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/Block/LiteralBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class RstLiteralBlock extends RstNode {
super(registrar, source)
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstLiteralBlockData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstLiteralBlockData>

root.data = {
rawText: this._rawText,
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/Block/Section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class RstSection extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstSectionData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstSectionData>

root.data = {
level: this.level,
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/ExplicitMarkup/CitationDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class RstCitationDef extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstCitationDefData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstCitationDefData>

root.data = {
rawLabel: this._rawLabel,
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/ExplicitMarkup/Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class RstComment extends RstNode {
super(registrar, source)
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstCommentData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstCommentData>

root.data = {
rawText: this._rawText,
Expand Down
8 changes: 4 additions & 4 deletions src/RstNode/ExplicitMarkup/Directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export class RstDirective extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstDirectiveData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstDirectiveData>

root.data = {
rawDirective: this._rawDirective,
initContent: this.initContent.map((node) => node.toJson()),
config: this.config?.toJson() ?? null,
initContent: this.initContent.map((node) => node.toJSON()),
config: this.config?.toJSON() ?? null,
rawBodyText: this.rawBodyText,
}

Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/ExplicitMarkup/FootnoteDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class RstFootnoteDef extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstFootnoteDefData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstFootnoteDefData>

root.data = {
rawLabel: this._rawLabel,
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/ExplicitMarkup/HyperlinkTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export class RstHyperlinkTarget extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstHyperlinkTargetData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstHyperlinkTargetData>

root.data = {
rawLabel: this._rawLabel,
Expand Down
8 changes: 4 additions & 4 deletions src/RstNode/ExplicitMarkup/SubstitutionDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export class RstSubstitutionDef extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstSubstitutionDefData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstSubstitutionDefData>

root.data = {
rawNeedle: this._rawNeedle,
rawDirective: this._rawDirective,
initContent: this.initContent.map((node) => node.toJson()),
config: this.config?.toJson() ?? null,
initContent: this.initContent.map((node) => node.toJSON()),
config: this.config?.toJSON() ?? null,
}

return root
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/Inline/HyperlinkRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class RstHyperlinkRef extends RstText {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstHyperlinkRefData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstHyperlinkRefData>

root.data = {
rawText: this.rawText,
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/Inline/InterpretedText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class RstInterpretedText extends RstText {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstInterpretedTextData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstInterpretedTextData>

root.data = {
rawText: this.rawText,
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/Inline/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class RstText extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstTextData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstTextData>

root.data = {
rawText: this.rawText,
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/List/BulletListItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class RstBulletListItem extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstBulletListItemData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstBulletListItemData>

root.data = {
bullet: this.bullet,
Expand Down
10 changes: 5 additions & 5 deletions src/RstNode/List/DefinitionListItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class RstDefinitionListItem extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstDefinitionListItemData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstDefinitionListItemData>

root.data = {
term: this.term.map((node) => node.toJson()),
classifiers: this.classifiers.map((classifier) => classifier.map((node) => node.toJson())),
definition: this.definition.map((bodyNode) => bodyNode.toJson()),
term: this.term.map((node) => node.toJSON()),
classifiers: this.classifiers.map((classifier) => classifier.map((node) => node.toJSON())),
definition: this.definition.map((bodyNode) => bodyNode.toJSON()),
}

return root
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/List/EnumeratedList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class RstEnumeratedList extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstEnumeratedListData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstEnumeratedListData>

root.data = {
listType: this.listType,
Expand Down
8 changes: 4 additions & 4 deletions src/RstNode/List/FieldListItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export class RstFieldListItem extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstFieldListItemData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstFieldListItemData>

root.data = {
name: this.name.map((node) => node.toJson()),
body: this.body.map((node) => node.toJson()),
name: this.name.map((node) => node.toJSON()),
body: this.body.map((node) => node.toJSON()),
}

return root
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/List/OptionListItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class RstOptionListItem extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<OptionListItemData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<OptionListItemData>

root.data = {
options: this.options,
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/RstNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ export abstract class RstNode {
return root
}

toJson(): RstNodeJson {
toJSON(): RstNodeJson {
return {
type: this.nodeType,
data: {},
source: this.source,
children: this.children.map((child) => child.toJson()),
children: this.children.map((child) => child.toJSON()),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/RstNode/Table/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export class RstTable extends RstNode {
this.isComplexTable = !hasHeaderRow || hasSpanningCells || hasNonParagraphCellContent
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstTableData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstTableData>

root.data = {
headRows: this.headRows.map((child) => child.toJson()),
bodyRows: this.bodyRows.map((child) => child.toJson()),
headRows: this.headRows.map((child) => child.toJSON()),
bodyRows: this.bodyRows.map((child) => child.toJSON()),
}

return root
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/Table/TableCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class RstTableCell extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstTableCellData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstTableCellData>

root.data = {
rowSpan: this.rowSpan,
Expand Down
4 changes: 2 additions & 2 deletions src/RstNode/Table/TableRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class RstTableRow extends RstNode {
return root
}

override toJson(): RstNodeJson {
const root = super.toJson() as RstNodeJson<RstTableRowData>
override toJSON(): RstNodeJson {
const root = super.toJSON() as RstNodeJson<RstTableRowData>

root.data = {
isHeadRow: this.isHeadRow,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/RstNode/RstNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ Oh yes, the _\`Norwegian Blue\`. What's, um, what's wrong with it?
See https://www.python.org.
`

describe('toJson', () => {
describe('toJSON', () => {
const { root } = parseTestInput(input)
const rootClone = new RstNodeRegistrar().reviveRstNodeFromJson(root.toJson())
const rootClone = new RstNodeRegistrar().reviveRstNodeFromJson(root.toJSON())

test('node can be converted to json and revived into equivalent node', () => {
expect(rootClone.toObject()).toStrictEqual(root.toObject())
Expand Down

0 comments on commit 1deee7d

Please sign in to comment.