From f43e2bf4ef85ddc810c20cbf42d1b2f72452388f Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Wed, 13 Dec 2023 17:54:59 +0800 Subject: [PATCH] feat: Add ParseFilesConfig.resolveParseFiles to handle the include/exclude config --- cxx-parser/__tests__/unit_test/cxx_parser_configs.test.ts | 7 +++++-- cxx-parser/src/cxx_parser.ts | 6 ++++-- cxx-parser/src/cxx_parser_configs.ts | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cxx-parser/__tests__/unit_test/cxx_parser_configs.test.ts b/cxx-parser/__tests__/unit_test/cxx_parser_configs.test.ts index 2cf36fa..5d227dd 100644 --- a/cxx-parser/__tests__/unit_test/cxx_parser_configs.test.ts +++ b/cxx-parser/__tests__/unit_test/cxx_parser_configs.test.ts @@ -2,7 +2,10 @@ import fs from 'fs'; import os from 'os'; import path from 'path'; -import { CXXParserConfigs } from '../../src/cxx_parser_configs'; +import { + CXXParserConfigs, + ParseFilesConfig, +} from '../../src/cxx_parser_configs'; describe('CXXParserConfigs', () => { let tmpDir: string = ''; @@ -72,7 +75,7 @@ describe('ParseFilesConfig', () => { args as unknown as CXXParserConfigs ); - let finalParseFiles = config.parseFiles.resolveParseFiles(); + let finalParseFiles = ParseFilesConfig.resolveParseFiles(config.parseFiles); expect(finalParseFiles.length).toBe(1); expect(finalParseFiles[0]).toEqual(path1); // file1.h diff --git a/cxx-parser/src/cxx_parser.ts b/cxx-parser/src/cxx_parser.ts index 090985a..c46406a 100644 --- a/cxx-parser/src/cxx_parser.ts +++ b/cxx-parser/src/cxx_parser.ts @@ -6,7 +6,7 @@ import path from 'path'; import { ParseResult, TerraContext } from '@agoraio-extensions/terra-core'; import { ClangASTStructConstructorParser } from './constructor_initializer_parser'; -import { CXXParserConfigs } from './cxx_parser_configs'; +import { CXXParserConfigs, ParseFilesConfig } from './cxx_parser_configs'; import { CXXFile, CXXTYPE, cast } from './cxx_terra_node'; export function generateChecksum(files: string[]) { @@ -117,7 +117,9 @@ export function CXXParser( ): ParseResult | undefined { let cxxParserConfigs = CXXParserConfigs.resolve(terraContext.configDir, args); - let parseFiles = cxxParserConfigs.parseFiles.resolveParseFiles(); + let parseFiles = ParseFilesConfig.resolveParseFiles( + cxxParserConfigs.parseFiles + ); let jsonContent = dumpCXXAstJson( terraContext, cxxParserConfigs.includeHeaderDirs, diff --git a/cxx-parser/src/cxx_parser_configs.ts b/cxx-parser/src/cxx_parser_configs.ts index c3e5f42..9e3113c 100644 --- a/cxx-parser/src/cxx_parser_configs.ts +++ b/cxx-parser/src/cxx_parser_configs.ts @@ -25,9 +25,9 @@ export class ParseFilesConfig { * * @returns An array of strings representing the files to be parsed. */ - resolveParseFiles(): string[] { - return this.include.filter((it) => { - return !this.exclude.includes(it); + static resolveParseFiles(config: ParseFilesConfig): string[] { + return config.include.filter((it) => { + return !config.exclude.includes(it); }); } }