UNPKG

dts-jest

Version:

A preprocessor for Jest to snapshot test TypeScript declaration (.d.ts) files

50 lines (49 loc) 2.35 kB
"use strict"; exports.__esModule = true; 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"); exports.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 = []; for_each_comment_1.for_each_comment(source_file, function (comment, scanner) { var match = 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 = 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: normalize_expected_value_1.normalize_expected_value(value, source_file.fileName, footer_line, ts) }); break; } }, ts); if (unattachable_lines.length !== 0) { throw new Error(create_message_1.create_message('Unattachable trigger-footer(s) detected:', unattachable_lines.map(function (line) { return source_file.fileName + ":" + get_display_line_1.get_display_line(line); }))); } return footers; };