UNPKG

dts-jest

Version:

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

40 lines (39 loc) 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.find_docblock_options = void 0; var definitions_1 = require("../definitions"); var for_each_comment_1 = require("./for-each-comment"); var find_docblock_options = function (source_file, ts) { var options = {}; (0, for_each_comment_1.for_each_comment)(source_file, function (comment) { if (!comment.startsWith('/**')) { return false; } var matched = comment.match(definitions_1.docblock_option_regex); if (matched === null) { return false; } var options_literal = matched[definitions_1.DocblockOptionMatchIndex.Options].trim(); options_literal.split(/\s+/).forEach(function (option_value) { switch (option_value) { case definitions_1.DocblockOptionValue.EnableTestType: options.test_type = true; break; case definitions_1.DocblockOptionValue.EnableTestValue: options.test_value = true; break; case definitions_1.DocblockOptionValue.DisableTestType: options.test_type = false; break; case definitions_1.DocblockOptionValue.DisableTestValue: options.test_value = false; break; default: throw new Error("Unexpected option value '".concat(option_value, "'")); } }); return false; }, ts); return options; }; exports.find_docblock_options = find_docblock_options;