loadable-transformer-ts5
Version:
TypeScript custom transformer for lodable-components SSR
43 lines (42 loc) • 2.15 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var typescript_1 = __importDefault(require("typescript"));
var util_1 = require("./util");
describe(util_1.getLeadingComments, function () {
it('should extracts comment body with multiline comment', function () {
var source = typescript_1.default.createSourceFile('test', "\n/**\n* hoge\n* bar\n**/ 'foo'\n ", typescript_1.default.ScriptTarget.ESNext, true);
var target = source.statements[0];
var actual = (0, util_1.getLeadingComments)(target);
expect(actual).toStrictEqual(['*\n* hoge\n* bar\n*']);
});
it('should extracts comment body with single line comment', function () {
var source = typescript_1.default.createSourceFile('test', "\n// hoge\n// bar\nfoo;\n ", typescript_1.default.ScriptTarget.ESNext, true);
var target = source.statements[0];
var actual = (0, util_1.getLeadingComments)(target);
expect(actual).toStrictEqual([' hoge', ' bar']);
});
});
describe(util_1.removeMatchingLeadingComments, function () {
it("should remove leading comments if condition matches the comment's body", function () {
var actual = typescript_1.default.transpileModule('() =>/* hoge */ /* fuga */ x(y);', {
compilerOptions: {
target: typescript_1.default.ScriptTarget.ESNext,
},
transformers: {
before: [
function (ctx) { return function (source) {
var visitor = function (node) {
(0, util_1.removeMatchingLeadingComments)(node, ctx, /fuga/);
return typescript_1.default.visitEachChild(node, visitor, ctx);
};
return typescript_1.default.visitEachChild(source, visitor, ctx);
}; },
],
},
}).outputText;
expect(actual.trim()).toBe('() => x(y);');
});
});