dts-jest
Version:
A preprocessor for Jest to snapshot test TypeScript declaration (.d.ts) files
38 lines (37 loc) • 1.5 kB
JavaScript
;
exports.__esModule = true;
var definitions_1 = require("../definitions");
var for_each_comment_1 = require("./for-each-comment");
exports.find_docblock_options = function (source_file, ts) {
var options = {};
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 '" + option_value + "'");
}
});
return false;
}, ts);
return options;
};