Skip to content

Commit

Permalink
Export assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Oct 10, 2018
1 parent ae1c132 commit fbf31c0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/compiler/ast/module/ExportAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ExportAssignment extends ExportAssignmentBase<ts.ExportAssignment>
* @param textOrWriterFunction - Text or writer function to set as the export assignment expression.
*/
setExpression(textOrWriterFunction: string | WriterFunction) {
this.getExpression().replaceWithText(textOrWriterFunction);
this.getExpression().replaceWithText(textOrWriterFunction, this.getWriterWithQueuedChildIndentation());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CodeBlockWriter } from "../../codeBlockWriter";
import { IndexSignatureDeclarationStructure } from "../../structures";
import { printTextFromStringOrWriter } from "../../utils";
import { FactoryStructurePrinter } from "../FactoryStructurePrinter";
import { NewLineFormattingStructuresPrinter } from "../formatting";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export class ExportAssignmentStructurePrinter extends FactoryStructurePrinter<Ex
else
writer.write(" default ");

this.printTextOrWriterFunc(writer, structure.expression);

writer.write(";");
writer.write(this.getTextWithQueuedChildIndentation(writer, structure.expression)).write(";");
}
}
4 changes: 4 additions & 0 deletions src/tests/compiler/module/exportAssignmentTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ describe(nameof(ExportAssignment), () => {
doTest("export = 5;", "6", "export = 6;");
});

it("should set with writer and using queued child indentation", () => {
doTest("export = 5;", writer => writer.writeLine("4 +").write("7"), "export = 4 +\n 7;");
});

it("should set for an export default", () => {
doTest("export default 5;", writer => writer.write("6"), "export default 6;");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from "chai";
import { FormatCodeSettings } from "../../../compiler";
import { ExportAssignmentStructurePrinter } from "../../../structurePrinters";
import { ExportAssignmentStructure } from "../../../structures";
import { getStructureFactoryAndWriter } from "../../testHelpers";

describe(nameof(ExportAssignmentStructurePrinter), () => {
interface Options {
formatCodeSettings?: FormatCodeSettings;
}

function doTest(structure: ExportAssignmentStructure, expectedOutput: string, options: Options = {}) {
const { writer, factory } = getStructureFactoryAndWriter(options.formatCodeSettings);
factory.forExportAssignment().printText(writer, structure);
expect(writer.toString()).to.equal(expectedOutput);
}

// todo: more tests

describe(nameof<ExportAssignmentStructurePrinter>(p => p.printText), () => {
describe("expression", () => {
it("should write with a string", () => {
doTest({ expression: "testing" }, `export = testing;`);
});

it("should write with a writer and use queued child indentation", () => {
doTest({ expression: writer => writer.writeLine("testing |").write("this") }, `export = testing |\n this;`);
});
});
});
});

0 comments on commit fbf31c0

Please sign in to comment.