Closed
Description
The goal of the task is to be able to provide a custom SourceParser to the runASTAnalysis function (if not provided it will take the default JsSourceParser for example).
The idea behind that is to allow anyone to extend/add a new Parsing mechanism (to support TypeScript source for example).
In my mind I see two build-in class:
- SourceParser (with the current constructor code)
Lines 18 to 36 in d26eafc
- JsSourceParser extending SourceParser (with the current parseScript code). The default parser for JS-X-Ray.
https://github.com/NodeSecure/js-x-ray/blob/master/src/SourceParser.js#L50
If someone want to re-implement his own, it would look like this;
import { SourceParser, runASTAnalysis } from "@nodesecure/js-x-ray";
import { parse } from '@typescript-eslint/typescript-estree';
export class TsSourceParser extends SourceParser {
parseScript() {
const ast = parse(this.source, {});
return ast;
}
}
const { warnings, dependencies } = runASTAnalysis(
readFileSync("./file.ts", "utf-8"),
{
sourceParser: TsSourceParser
}
);
Metadata
Metadata
Assignees
Labels
No labels