ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
61 lines (59 loc) • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const testHelpers_1 = require("./../testHelpers");
describe("UnwrappableNode", () => {
describe("unwrap", () => {
function doTest(startCode, expectedCode) {
const { firstChild, sourceFile } = testHelpers_1.getInfoFromText(startCode);
const nodeInBody = firstChild.getChildSyntaxListOrThrow().getChildren()[0];
firstChild.unwrap();
chai_1.expect(() => firstChild.compilerNode).to.throw(); // should be disposed
chai_1.expect(() => nodeInBody.compilerNode).to.not.throw();
chai_1.expect(sourceFile.getFullText()).to.equal(expectedCode);
}
it("should unwrap a namespace", () => {
doTest(`namespace Test {
var t: string;
var u: string;
var v: string;
}`, `var t: string;\nvar u: string;\nvar v: string;`);
});
it("should unwrap a namespace with periods in name", () => {
doTest(`namespace Test.This.Out {
var t: string;
}`, `var t: string;`);
});
it("should unwrap a with the correct indentation", () => {
doTest(`
namespace Test {
var t: string;
}`, ` var t: string;`);
});
it("should not unindent any string literals", () => {
doTest(`namespace Test {
var t = "some text \\
goes here";
var u = \`some text
goes here\`;
var v = \`some text
goes here $\{test
}more
and $\{more}\`;
}`, `var t = "some text \\
goes here";
var u = \`some text
goes here\`;
var v = \`some text
goes here $\{test
}more
and $\{more}\`;`);
});
it("should unwrap a function", () => {
doTest(`function myFunction(param: string) {
var t: string;
}`, `var t: string;`);
});
});
});
//# sourceMappingURL=unwrappableNodeTests.js.map