Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/cfg.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,17 @@ export function buildFunctionCFG(functionNode, langId) {
export async function buildCFGData(db, fileSymbols, rootDir, _engineOpts) {
// Lazily init WASM parsers if needed
let parsers = null;
let extToLang = null;
let needsFallback = false;

// Always build ext→langId map so native-only builds (where _langId is unset)
// can still derive the language from the file extension.
const extToLang = new Map();
for (const entry of LANGUAGE_REGISTRY) {
for (const ext of entry.extensions) {
extToLang.set(ext, entry.id);
}
}

for (const [relPath, symbols] of fileSymbols) {
if (!symbols._tree) {
const ext = path.extname(relPath).toLowerCase();
Expand All @@ -1068,12 +1076,6 @@ export async function buildCFGData(db, fileSymbols, rootDir, _engineOpts) {
if (needsFallback) {
const { createParsers } = await import('./parser.js');
parsers = await createParsers();
extToLang = new Map();
for (const entry of LANGUAGE_REGISTRY) {
for (const ext of entry.extensions) {
extToLang.set(ext, entry.id);
}
}
}

let getParserFn = null;
Expand Down Expand Up @@ -1115,7 +1117,7 @@ export async function buildCFGData(db, fileSymbols, rootDir, _engineOpts) {

// WASM fallback if no cached tree and not all native
if (!tree && !allNative) {
if (!extToLang || !getParserFn) continue;
if (!getParserFn) continue;
langId = extToLang.get(ext);
if (!langId || !CFG_LANG_IDS.has(langId)) continue;

Expand All @@ -1138,7 +1140,7 @@ export async function buildCFGData(db, fileSymbols, rootDir, _engineOpts) {
}

if (!langId) {
langId = extToLang ? extToLang.get(ext) : null;
langId = extToLang.get(ext);
if (!langId) continue;
}

Expand Down
20 changes: 11 additions & 9 deletions src/dataflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,17 @@ function collectIdentifiers(node, out, rules) {
export async function buildDataflowEdges(db, fileSymbols, rootDir, _engineOpts) {
// Lazily init WASM parsers if needed
let parsers = null;
let extToLang = null;
let needsFallback = false;

// Always build ext→langId map so native-only builds (where _langId is unset)
// can still derive the language from the file extension.
const extToLang = new Map();
for (const entry of LANGUAGE_REGISTRY) {
for (const ext of entry.extensions) {
extToLang.set(ext, entry.id);
}
}

for (const [relPath, symbols] of fileSymbols) {
if (!symbols._tree && !symbols.dataflow) {
const ext = path.extname(relPath).toLowerCase();
Expand All @@ -1021,12 +1029,6 @@ export async function buildDataflowEdges(db, fileSymbols, rootDir, _engineOpts)
if (needsFallback) {
const { createParsers } = await import('./parser.js');
parsers = await createParsers();
extToLang = new Map();
for (const entry of LANGUAGE_REGISTRY) {
for (const ext of entry.extensions) {
extToLang.set(ext, entry.id);
}
}
}

let getParserFn = null;
Expand Down Expand Up @@ -1069,7 +1071,7 @@ export async function buildDataflowEdges(db, fileSymbols, rootDir, _engineOpts)

// WASM fallback if no cached tree
if (!tree) {
if (!extToLang || !getParserFn) continue;
if (!getParserFn) continue;
langId = extToLang.get(ext);
if (!langId || !DATAFLOW_LANG_IDS.has(langId)) continue;

Expand All @@ -1092,7 +1094,7 @@ export async function buildDataflowEdges(db, fileSymbols, rootDir, _engineOpts)
}

if (!langId) {
langId = extToLang ? extToLang.get(ext) : null;
langId = extToLang.get(ext);
if (!langId) continue;
}

Expand Down