diff --git a/src/lib/complexity/strategies/cyclomatic.ts b/src/lib/complexity/strategies/cyclomatic.ts index 3e5973a..036986b 100644 --- a/src/lib/complexity/strategies/cyclomatic.ts +++ b/src/lib/complexity/strategies/cyclomatic.ts @@ -27,6 +27,7 @@ export function calculate(path: string): number | UnsupportedExtension { function fromJavaScript(path: string): number { const content = readFileSync(path, { encoding: "utf8" }); const babelResult = transformSync(content, { + filename: path, presets: ["@babel/preset-env"], }); if (!babelResult) throw new Error(`Error while parsing file ${path}`); @@ -37,6 +38,7 @@ function fromJavaScript(path: string): number { function fromTypeScript(path: string): number { const content = readFileSync(path, { encoding: "utf8" }); const babelResult = transformSync(content, { + filename: path, plugins: ["@babel/plugin-transform-typescript"], presets: ["@babel/preset-env"], }); diff --git a/src/lib/complexity/strategies/halstead.ts b/src/lib/complexity/strategies/halstead.ts index a439f0a..4ef173d 100644 --- a/src/lib/complexity/strategies/halstead.ts +++ b/src/lib/complexity/strategies/halstead.ts @@ -26,6 +26,7 @@ export function calculate(path: string): number | UnsupportedExtension { function fromJavaScript(path: string): number { const content = readFileSync(path, { encoding: "utf8" }); const babelResult = transformSync(content, { + filename: path, presets: ["@babel/preset-env"], }); if (!babelResult) throw new Error(`Error while parsing file ${path}`); @@ -36,6 +37,7 @@ function fromJavaScript(path: string): number { function fromTypeScript(path: string): number { const content = readFileSync(path, { encoding: "utf8" }); const babelResult = transformSync(content, { + filename: path, plugins: ["@babel/plugin-transform-typescript"], presets: ["@babel/preset-env"], });