diff --git a/src/file/numbering/numbering.spec.ts b/src/file/numbering/numbering.spec.ts index 0142335c26..211c4e5543 100644 --- a/src/file/numbering/numbering.spec.ts +++ b/src/file/numbering/numbering.spec.ts @@ -216,7 +216,7 @@ describe("AbstractNumbering", () => { const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepLines(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [{ "w:keepLines": null }], + "w:pPr": [{ "w:keepLines": {} }], }); }); @@ -225,7 +225,7 @@ describe("AbstractNumbering", () => { const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepNext(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [{ "w:keepNext": null }], + "w:pPr": [{ "w:keepNext": {} }], }); }); }); diff --git a/src/file/paragraph/image.spec.ts b/src/file/paragraph/image.spec.ts index d69eda845b..ca00bfbabc 100644 --- a/src/file/paragraph/image.spec.ts +++ b/src/file/paragraph/image.spec.ts @@ -156,12 +156,12 @@ describe("Image", () => { }, }, { - "a:srcRect": null, + "a:srcRect": {}, }, { "a:stretch": [ { - "a:fillRect": null, + "a:fillRect": {}, }, ], }, @@ -202,7 +202,7 @@ describe("Image", () => { }, }, { - "a:avLst": null, + "a:avLst": {}, }, ], }, diff --git a/src/file/paragraph/paragraph.spec.ts b/src/file/paragraph/paragraph.spec.ts index 382095b268..cebba6554e 100644 --- a/src/file/paragraph/paragraph.spec.ts +++ b/src/file/paragraph/paragraph.spec.ts @@ -471,7 +471,7 @@ describe("Paragraph", () => { { "w:pPr": [ { - "w:pageBreakBefore": null, + "w:pageBreakBefore": {}, }, ], }, @@ -625,7 +625,7 @@ describe("Paragraph", () => { paragraph.keepLines(); const tree = new Formatter().format(paragraph); expect(tree).to.deep.equal({ - "w:p": [{ "w:pPr": [{ "w:keepLines": null }] }], + "w:p": [{ "w:pPr": [{ "w:keepLines": {} }] }], }); }); }); @@ -635,7 +635,7 @@ describe("Paragraph", () => { paragraph.keepNext(); const tree = new Formatter().format(paragraph); expect(tree).to.deep.equal({ - "w:p": [{ "w:pPr": [{ "w:keepNext": null }] }], + "w:p": [{ "w:pPr": [{ "w:keepNext": {} }] }], }); }); }); @@ -645,7 +645,7 @@ describe("Paragraph", () => { paragraph.bidirectional(); const tree = new Formatter().format(paragraph); expect(tree).to.deep.equal({ - "w:p": [{ "w:pPr": [{ "w:bidi": null }] }], + "w:p": [{ "w:pPr": [{ "w:bidi": {} }] }], }); }); }); diff --git a/src/file/settings/compatibility.spec.ts b/src/file/settings/compatibility.spec.ts index 2c94b2a84c..0d6099b133 100644 --- a/src/file/settings/compatibility.spec.ts +++ b/src/file/settings/compatibility.spec.ts @@ -8,7 +8,7 @@ describe("Compatibility", () => { const compatibility = new Compatibility(); const tree = new Formatter().format(compatibility); - expect(tree).to.deep.equal({ "w:compat": null }); + expect(tree).to.deep.equal({ "w:compat": {} }); }); }); @@ -18,7 +18,7 @@ describe("Compatibility", () => { compatibility.doNotExpandShiftReturn(); const tree = new Formatter().format(compatibility); - expect(tree).to.deep.equal({ "w:compat": [{ "w:doNotExpandShiftReturn": null }] }); + expect(tree).to.deep.equal({ "w:compat": [{ "w:doNotExpandShiftReturn": {} }] }); }); }); }); diff --git a/src/file/styles/style/character-style.spec.ts b/src/file/styles/style/character-style.spec.ts index 362bee3241..019230ea4d 100644 --- a/src/file/styles/style/character-style.spec.ts +++ b/src/file/styles/style/character-style.spec.ts @@ -20,7 +20,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -41,7 +41,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -63,7 +63,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, { "w:basedOn": { _attr: { "w:val": "otherId" } } }, ], @@ -89,7 +89,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -113,7 +113,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -136,7 +136,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -159,7 +159,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -191,7 +191,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -214,7 +214,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -237,7 +237,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -260,7 +260,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -280,7 +280,7 @@ describe("CharacterStyle", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, { "w:link": { _attr: { "w:val": "MyLink" } } }, ], @@ -300,8 +300,8 @@ describe("CharacterStyle", () => { }, }, }, - { "w:unhideWhenUsed": null }, - { "w:semiHidden": null }, + { "w:unhideWhenUsed": {} }, + { "w:semiHidden": {} }, ], }); }); diff --git a/src/file/styles/style/components.spec.ts b/src/file/styles/style/components.spec.ts index b12f1e8838..8982f402dd 100644 --- a/src/file/styles/style/components.spec.ts +++ b/src/file/styles/style/components.spec.ts @@ -36,18 +36,18 @@ describe("Style components", () => { it("UnhideWhenUsed#constructor", () => { const style = new components.UnhideWhenUsed(); const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ "w:unhideWhenUsed": null }); + expect(tree).to.deep.equal({ "w:unhideWhenUsed": {} }); }); it("QuickFormat#constructor", () => { const style = new components.QuickFormat(); const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ "w:qFormat": null }); + expect(tree).to.deep.equal({ "w:qFormat": {} }); }); it("SemiHidden#constructor", () => { const style = new components.SemiHidden(); const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ "w:semiHidden": null }); + expect(tree).to.deep.equal({ "w:semiHidden": {} }); }); }); diff --git a/src/file/styles/style/default-styles.spec.ts b/src/file/styles/style/default-styles.spec.ts index 3888983c56..580e2bee2b 100644 --- a/src/file/styles/style/default-styles.spec.ts +++ b/src/file/styles/style/default-styles.spec.ts @@ -12,7 +12,7 @@ describe("Default Styles", () => { { "w:name": { _attr: { "w:val": "Heading 1" } } }, { "w:basedOn": { _attr: { "w:val": "Normal" } } }, { "w:next": { _attr: { "w:val": "Normal" } } }, - { "w:qFormat": null }, + { "w:qFormat": {} }, ], }); }); @@ -26,7 +26,7 @@ describe("Default Styles", () => { { "w:name": { _attr: { "w:val": "Title" } } }, { "w:basedOn": { _attr: { "w:val": "Normal" } } }, { "w:next": { _attr: { "w:val": "Normal" } } }, - { "w:qFormat": null }, + { "w:qFormat": {} }, ], }); }); @@ -40,7 +40,7 @@ describe("Default Styles", () => { { "w:name": { _attr: { "w:val": "Heading 1" } } }, { "w:basedOn": { _attr: { "w:val": "Normal" } } }, { "w:next": { _attr: { "w:val": "Normal" } } }, - { "w:qFormat": null }, + { "w:qFormat": {} }, ], }); }); @@ -54,7 +54,7 @@ describe("Default Styles", () => { { "w:name": { _attr: { "w:val": "Heading 2" } } }, { "w:basedOn": { _attr: { "w:val": "Normal" } } }, { "w:next": { _attr: { "w:val": "Normal" } } }, - { "w:qFormat": null }, + { "w:qFormat": {} }, ], }); }); @@ -68,7 +68,7 @@ describe("Default Styles", () => { { "w:name": { _attr: { "w:val": "Heading 3" } } }, { "w:basedOn": { _attr: { "w:val": "Normal" } } }, { "w:next": { _attr: { "w:val": "Normal" } } }, - { "w:qFormat": null }, + { "w:qFormat": {} }, ], }); }); @@ -82,7 +82,7 @@ describe("Default Styles", () => { { "w:name": { _attr: { "w:val": "Heading 4" } } }, { "w:basedOn": { _attr: { "w:val": "Normal" } } }, { "w:next": { _attr: { "w:val": "Normal" } } }, - { "w:qFormat": null }, + { "w:qFormat": {} }, ], }); }); @@ -96,7 +96,7 @@ describe("Default Styles", () => { { "w:name": { _attr: { "w:val": "Heading 5" } } }, { "w:basedOn": { _attr: { "w:val": "Normal" } } }, { "w:next": { _attr: { "w:val": "Normal" } } }, - { "w:qFormat": null }, + { "w:qFormat": {} }, ], }); }); @@ -110,7 +110,7 @@ describe("Default Styles", () => { { "w:name": { _attr: { "w:val": "Heading 6" } } }, { "w:basedOn": { _attr: { "w:val": "Normal" } } }, { "w:next": { _attr: { "w:val": "Normal" } } }, - { "w:qFormat": null }, + { "w:qFormat": {} }, ], }); }); @@ -123,7 +123,7 @@ describe("Default Styles", () => { { _attr: { "w:type": "paragraph", "w:styleId": "ListParagraph" } }, { "w:name": { _attr: { "w:val": "List Paragraph" } } }, { "w:basedOn": { _attr: { "w:val": "Normal" } } }, - { "w:qFormat": null }, + { "w:qFormat": {} }, ], }); }); @@ -176,10 +176,10 @@ describe("Default Styles", () => { }, }, { - "w:semiHidden": null, + "w:semiHidden": {}, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }); @@ -211,12 +211,12 @@ describe("Default Styles", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, { "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } }, { - "w:semiHidden": null, + "w:semiHidden": {}, }, ], }); @@ -255,12 +255,12 @@ describe("Default Styles", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, { "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } }, { "w:link": { _attr: { "w:val": "FootnoteText" } } }, { - "w:semiHidden": null, + "w:semiHidden": {}, }, ], }); @@ -284,7 +284,7 @@ describe("Default Styles", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, { "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } }, ], diff --git a/src/file/styles/style/paragraph-style.spec.ts b/src/file/styles/style/paragraph-style.spec.ts index cf529c8773..3d9f7e73bc 100644 --- a/src/file/styles/style/paragraph-style.spec.ts +++ b/src/file/styles/style/paragraph-style.spec.ts @@ -42,7 +42,7 @@ describe("ParagraphStyle", () => { const style = new ParagraphStyle("myStyleId").quickFormat(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:qFormat": null }], + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:qFormat": {} }], }); }); @@ -216,7 +216,7 @@ describe("ParagraphStyle", () => { const style = new ParagraphStyle("myStyleId").keepLines(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepLines": null }] }], + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepLines": {} }] }], }); }); @@ -224,7 +224,7 @@ describe("ParagraphStyle", () => { const style = new ParagraphStyle("myStyleId").keepNext(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepNext": null }] }], + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepNext": {} }] }], }); }); @@ -439,7 +439,7 @@ describe("ParagraphStyle", () => { const style = new ParagraphStyle("myStyleId").semiHidden(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:semiHidden": null }], + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:semiHidden": {} }], }); }); @@ -464,7 +464,7 @@ describe("ParagraphStyle", () => { const style = new ParagraphStyle("myStyleId").unhideWhenUsed(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:unhideWhenUsed": null }], + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:unhideWhenUsed": {} }], }); }); }); diff --git a/src/file/styles/styles.spec.ts b/src/file/styles/styles.spec.ts index 09e986d5cb..cbce96de94 100644 --- a/src/file/styles/styles.spec.ts +++ b/src/file/styles/styles.spec.ts @@ -64,7 +64,7 @@ describe("Styles", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }, @@ -88,7 +88,7 @@ describe("Styles", () => { }, }, { - "w:unhideWhenUsed": null, + "w:unhideWhenUsed": {}, }, ], }, diff --git a/src/file/table/grid.spec.ts b/src/file/table/grid.spec.ts index cbef732f95..b5c0586743 100644 --- a/src/file/table/grid.spec.ts +++ b/src/file/table/grid.spec.ts @@ -17,7 +17,7 @@ describe("GridCol", () => { it("does not set a width attribute if not given", () => { const grid = new GridCol(); const tree = new Formatter().format(grid); - expect(tree).to.deep.equal({ "w:gridCol": null }); + expect(tree).to.deep.equal({ "w:gridCol": {} }); }); }); }); diff --git a/src/file/table/table-column.spec.ts b/src/file/table/table-column.spec.ts index bff98500f1..72a1fb4b67 100644 --- a/src/file/table/table-column.spec.ts +++ b/src/file/table/table-column.spec.ts @@ -37,15 +37,15 @@ describe("TableColumn", () => { const tree = new Formatter().format(cells[0]); expect(tree).to.deep.equal({ - "w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "restart" } } }] }, { "w:p": null }], + "w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "restart" } } }] }, { "w:p": {} }], }); const tree2 = new Formatter().format(cells[1]); - expect(tree2).to.deep.equal({ "w:tc": [{ "w:p": null }] }); + expect(tree2).to.deep.equal({ "w:tc": [{ "w:p": {} }] }); const tree3 = new Formatter().format(cells[2]); expect(tree3).to.deep.equal({ - "w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] }, { "w:p": null }], + "w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] }, { "w:p": {} }], }); }); }); diff --git a/src/file/table/table-row/table-row.spec.ts b/src/file/table/table-row/table-row.spec.ts index 2af955eb6d..f279c81e96 100644 --- a/src/file/table/table-row/table-row.spec.ts +++ b/src/file/table/table-row/table-row.spec.ts @@ -11,7 +11,7 @@ describe("TableRow", () => { const tableRow = new TableRow([]); const tree = new Formatter().format(tableRow); expect(tree).to.deep.equal({ - "w:tr": null, + "w:tr": {}, }); }); @@ -23,7 +23,7 @@ describe("TableRow", () => { { "w:tc": [ { - "w:p": null, + "w:p": {}, }, ], }, diff --git a/src/file/table/table.spec.ts b/src/file/table/table.spec.ts index 513524d863..b51f303bda 100644 --- a/src/file/table/table.spec.ts +++ b/src/file/table/table.spec.ts @@ -107,7 +107,7 @@ const WIDTHS = { // ], // }, // { "w:tblGrid": [{ "w:gridCol": { _attr: { "w:w": 100 } } }] }, -// { "w:tr": [{ "w:tc": [{ "w:p": null }] }] }, +// { "w:tr": [{ "w:tc": [{ "w:p": {} }] }] }, // ], // }; @@ -119,7 +119,7 @@ describe("Table", () => { columns: 2, }); const tree = new Formatter().format(table); - const cell = { "w:tc": [{ "w:p": null }] }; + const cell = { "w:tc": [{ "w:p": {} }] }; expect(tree).to.deep.equal({ "w:tbl": [ { "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS] }, @@ -284,7 +284,7 @@ describe("Table", () => { .to.be.an("array") .which.has.length.at.least(1); expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({ - "w:tc": [{ "w:p": null }], + "w:tc": [{ "w:p": {} }], }); }); @@ -311,7 +311,7 @@ describe("Table", () => { const cell = row["w:tr"].find((x) => x["w:tc"]); expect(cell).not.to.be.undefined; expect(cell["w:tc"][cell["w:tc"].length - 1]).to.deep.equal({ - "w:p": null, + "w:p": {}, }); }); diff --git a/src/file/xml-components/imported-xml-component.spec.ts b/src/file/xml-components/imported-xml-component.spec.ts index 72caf44bb4..2f17e9b37d 100644 --- a/src/file/xml-components/imported-xml-component.spec.ts +++ b/src/file/xml-components/imported-xml-component.spec.ts @@ -73,7 +73,7 @@ describe("ImportedXmlComponent", () => { }, }, { - "w:child": null, + "w:child": {}, }, ], }); diff --git a/src/file/xml-components/xml-component.spec.ts b/src/file/xml-components/xml-component.spec.ts index 38a0b12711..503129ef47 100644 --- a/src/file/xml-components/xml-component.spec.ts +++ b/src/file/xml-components/xml-component.spec.ts @@ -1,4 +1,4 @@ -import { assert } from "chai"; +import { expect } from "chai"; import { Utility } from "tests/utility"; import { XmlComponent } from "./"; @@ -15,7 +15,7 @@ describe("XmlComponent", () => { describe("#constructor()", () => { it("should create an Xml Component which has the correct rootKey", () => { const newJson = Utility.jsonify(xmlComponent); - assert.equal(newJson.rootKey, "w:test"); + expect(newJson.rootKey).to.equal("w:test"); }); }); @@ -31,7 +31,7 @@ describe("XmlComponent", () => { return; } - assert.isNull(xml["w:test"]); + expect(xml["w:test"]).to.deep.equal({}); }); }); }); diff --git a/src/file/xml-components/xml-component.ts b/src/file/xml-components/xml-component.ts index 56a10bc323..feb1d1092e 100644 --- a/src/file/xml-components/xml-component.ts +++ b/src/file/xml-components/xml-component.ts @@ -30,11 +30,11 @@ export abstract class XmlComponent extends BaseXmlComponent { // represents our attributes, use the object itself as our children to // avoid an unneeded XML close element. (Note: We have to use this // function to get typescript to allow our check.) - // Additionally, if the array is empty, use null as our children to - // get an empty XML element generated. + // Additionally, if the array is empty, use an empty object as our + // children in order to get an empty XML element generated. const onlyAttrs = (c) => typeof c === "object" && c._attr; return { - [this.rootKey]: children.length ? (children.length === 1 && onlyAttrs(children[0]) ? children[0] : children) : null, + [this.rootKey]: children.length ? (children.length === 1 && onlyAttrs(children[0]) ? children[0] : children) : {}, }; } @@ -52,7 +52,9 @@ export abstract class XmlComponent extends BaseXmlComponent { export abstract class IgnoreIfEmptyXmlComponent extends XmlComponent { public prepForXml(): IXmlableObject | undefined { const result = super.prepForXml(); - if (result && result[this.rootKey]) { + // Ignore the object if its falsey or is an empty object (would produce + // an empty XML element if allowed to be included in the output). + if (result && (typeof result[this.rootKey] !== "object" || Object.keys(result[this.rootKey]).length)) { return result; } } diff --git a/tslint.json b/tslint.json index 6c498e2957..d6eb606eba 100644 --- a/tslint.json +++ b/tslint.json @@ -15,8 +15,7 @@ "max-classes-per-file": [false], "no-implicit-dependencies": false, "no-submodule-imports": false, - // We need null in order to get empty elements from the xml library - "no-null-keyword": false, + "no-null-keyword": true, "return-undefined": true, "prefer-readonly": true, "no-duplicate-imports": true,