Skip to content

Commit

Permalink
Serialize the AST for all file extensions (#4739)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia-kebets-sonarsource authored Jun 14, 2024
1 parent ad002df commit fd2dcd0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ void test() {
assertThat(buildResult.getLogsLines(l -> l.matches(logMatch))).hasSize(1);

// TS file is not processed yet.
assertThat(buildResult.getLogsLines(l -> l.matches(".*Processing file src/dir.*"))).hasSize(1);
assertThat(buildResult.getLogsLines(l -> l.matches(".*Processing file src/dir.*"))).hasSize(2);
}
}
4 changes: 2 additions & 2 deletions packages/bridge/tests/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('router', () => {
const filePath = path.join(fixtures, 'file.ts');
const fileType = 'MAIN';
const tsConfig = path.join(fixtures, 'tsconfig.json');
const data = { filePath, fileType, tsConfigs: [tsConfig] };
const data = { filePath, fileType, tsConfigs: [tsConfig], skipAst: true };
const response = (await request(server, '/analyze-ts', 'POST', data)) as string;
const {
issues: [issue],
Expand All @@ -176,7 +176,7 @@ describe('router', () => {
const { programId } = JSON.parse(
(await request(server, '/create-program', 'POST', { tsConfig })) as string,
);
const data = { filePath, fileType, programId };
const data = { filePath, fileType, programId, skipAst: true };
const response = (await request(server, '/analyze-with-program', 'POST', data)) as string;
const {
issues: [issue],
Expand Down
11 changes: 0 additions & 11 deletions packages/jsts/src/analysis/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,12 @@ function analyzeFile(
}

function serializeAst(sourceCode: SourceCode, filePath: string) {
if (!isSupported(filePath)) {
return null;
}

try {
return serializeInProtobuf(sourceCode.ast);
} catch (e) {
info(`Failed to serialize AST for file "${filePath}"`);
return null;
}

/**
* Remove this when we figure out how to serialize the TypeScript AST
*/
function isSupported(filePath: string) {
return filePath.endsWith('.js');
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/jsts/src/parsers/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as protobuf from 'protobufjs';
import * as path from 'node:path';
import * as estree from 'estree';
import { AST } from 'eslint';
import { debug } from '@sonar/shared';

const PATH_TO_PROTOFILE = path.join(__dirname, 'estree.proto');
const PROTO_ROOT = protobuf.loadSync(PATH_TO_PROTOFILE);
Expand Down Expand Up @@ -214,7 +215,7 @@ export function visitNode(node: estree.BaseNodeWithoutComments | undefined | nul
case 'FunctionExpression':
return visitFunctionExpression(node as estree.FunctionExpression);
default:
console.log(`Unknown node type: ${node.type}`);
debug(`Unknown node type: ${node.type}`);
}
}

Expand Down

0 comments on commit fd2dcd0

Please sign in to comment.