Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parseTypeScriptSourceFile(
fileContent: string,
filePath: string,
tsConfigs?: string[],
): SourceCode | ParsingError {
try {
checkTypeScriptVersionCompatibility(require("typescript").version);
// we load the typescript parser dynamically, so we don't need typescript dependency when analyzing pure JS project
const tsParser = require("@typescript-eslint/parser");
const result = tsParser.parseForESLint(fileContent, {
...PARSER_CONFIG_MODULE,
filePath: filePath,
project: tsConfigs,
loggerFn: console.log,
});
return new SourceCode({ ...result, parserServices: result.services, text: fileContent });
} catch (exception) {
return {
line: exception.lineNumber,
message: exception.message,
code: parseExceptionCodeOf(exception.message),
};
}
}