|
"use strict"; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.isParserObject = isParserObject; |
|
exports.isEnhancedParserObject = isEnhancedParserObject; |
|
exports.isBasicParserObject = isBasicParserObject; |
|
exports.maybeTSESLintParserObject = maybeTSESLintParserObject; |
|
exports.isTSESLintParserObject = isTSESLintParserObject; |
|
|
|
function isParserObject(value) { |
|
return isEnhancedParserObject(value) || isBasicParserObject(value); |
|
} |
|
|
|
function isEnhancedParserObject(value) { |
|
return Boolean(value && typeof value.parseForESLint === "function"); |
|
} |
|
|
|
function isBasicParserObject(value) { |
|
return Boolean(value && typeof value.parse === "function"); |
|
} |
|
|
|
function maybeTSESLintParserObject(value) { |
|
return (isEnhancedParserObject(value) && |
|
isBasicParserObject(value) && |
|
typeof value.createProgram === "function" && |
|
typeof value.clearCaches === "function" && |
|
typeof value.version === "string"); |
|
} |
|
|
|
function isTSESLintParserObject(value) { |
|
if (!isEnhancedParserObject(value)) |
|
return false; |
|
try { |
|
const result = value.parseForESLint("", {}); |
|
const services = result.services; |
|
return Boolean(services && |
|
services.esTreeNodeToTSNodeMap && |
|
services.tsNodeToESTreeNodeMap); |
|
} |
|
catch (_a) { |
|
return false; |
|
} |
|
} |
|
|