dts-jest
Version:
A preprocessor for Jest to snapshot test TypeScript declaration (.d.ts) files
52 lines (51 loc) • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.find_trigger_footers = void 0;
var definitions_1 = require("../definitions");
var create_message_1 = require("./create-message");
var for_each_comment_1 = require("./for-each-comment");
var get_comment_content_1 = require("./get-comment-content");
var get_display_line_1 = require("./get-display-line");
var get_trigger_line_1 = require("./get-trigger-line");
var normalize_expected_value_1 = require("./normalize-expected-value");
var find_trigger_footers = function (source_file, bodies, ts) {
var footers = [];
var body_end_line_set = new Set(bodies.map(function (body) { return source_file.getLineAndCharacterOfPosition(body.end).line; }));
var unattachable_lines = [];
(0, for_each_comment_1.for_each_comment)(source_file, function (comment, scanner) {
var match = (0, get_comment_content_1.get_comment_content)(comment).match(definitions_1.trigger_footer_regex);
if (match === null) {
return;
}
var start = scanner.getTokenPos();
var footer_line = source_file.getLineAndCharacterOfPosition(start).line;
var body_end_line = (0, get_trigger_line_1.get_trigger_body_end_line)(footer_line);
if (!body_end_line_set.has(body_end_line)) {
unattachable_lines.push(footer_line);
return;
}
body_end_line_set.delete(body_end_line);
var value = match[definitions_1.TriggerFooterMatchIndex.Value];
switch (value) {
case definitions_1.TriggerFooterFlag.Show:
case definitions_1.TriggerFooterFlag.Error:
case definitions_1.TriggerFooterFlag.NoError:
footers.push({
line: footer_line,
flag: value,
});
break;
default:
footers.push({
line: footer_line,
expected: (0, normalize_expected_value_1.normalize_expected_value)(value, source_file.fileName, footer_line, ts),
});
break;
}
}, ts);
if (unattachable_lines.length !== 0) {
throw new Error((0, create_message_1.create_message)('Unattachable trigger-footer(s) detected:', unattachable_lines.map(function (line) { return "".concat(source_file.fileName, ":").concat((0, get_display_line_1.get_display_line)(line)); })));
}
return footers;
};
exports.find_trigger_footers = find_trigger_footers;