Skip to content

Commit 818a557

Browse files
committed
fix(extractor): add string-type guard and anchored regex for defineProperty key extraction (#1328)
- defineProperty path: guard arg1.type !== 'string' before extraction, matching the Rust seed_define_property_entries behaviour (which returns None for non-string AST nodes) - defineProperties path: use anchored /^['"]|['"]$/ to strip only boundary quotes, not quotes within the key value, with string-type guard - seedProtoProperties: same anchored regex fix for pair keys Closes the TS/Rust engine parity gap flagged in Greptile review. (docs check acknowledged)
1 parent f8b727b commit 818a557

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/extractors/javascript.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,8 @@ function handleDefinePropertyTypeMap(
16341634
arg1 = args[1]!,
16351635
arg2 = args[2]!;
16361636
if (arg0.type !== 'identifier') return;
1637-
const key = arg1.text.replace(/['"]/g, '');
1637+
if (arg1.type !== 'string') return;
1638+
const key = arg1.text.replace(/^['"]|['"]$/g, '');
16381639
if (!key) return;
16391640
const target = findDescriptorValue(arg2);
16401641
if (!target) return;
@@ -1652,7 +1653,7 @@ function handleDefinePropertyTypeMap(
16521653
const keyN = pair.childForFieldName('key');
16531654
const valN = pair.childForFieldName('value');
16541655
if (!keyN || !valN) continue;
1655-
const key = keyN.text.replace(/['"]/g, '');
1656+
const key = keyN.type === 'string' ? keyN.text.replace(/^['"]|['"]$/g, '') : keyN.text;
16561657
const target = findDescriptorValue(valN);
16571658
if (!target) continue;
16581659
setTypeMapEntry(typeMap, `${arg0.text}.${key}`, target, 0.85);
@@ -1688,7 +1689,7 @@ function seedProtoProperties(
16881689
const keyN = child.childForFieldName('key');
16891690
const valN = child.childForFieldName('value');
16901691
if (!keyN || !valN || valN.type !== 'identifier') continue;
1691-
const key = keyN.type === 'string' ? keyN.text.replace(/['"]/g, '') : keyN.text;
1692+
const key = keyN.type === 'string' ? keyN.text.replace(/^['"]|['"]$/g, '') : keyN.text;
16921693
setTypeMapEntry(typeMap, `${varName}.${key}`, valN.text, 0.85);
16931694
}
16941695
}

0 commit comments

Comments
 (0)