Skip to content

Commit 3513e1f

Browse files
committed
fix(compiler): handle OptionalCallExpression and OptionalMemberExpression in data contract site matching
The visit function in data-contracts.js only matched CallExpression and MemberExpression node types. When the parser emits the Babel-style OptionalCallExpression or OptionalMemberExpression (e.g. for store?.write(…) or write?.(…)), those sites were not recognized as contract uses and were incorrectly reported as OCTANE_DATA_CONTRACT_ESCAPE. Add the optional node type checks to all four locations: - visit: CallExpression → also OptionalCallExpression - visit: callee MemberExpression → also OptionalMemberExpression - visit: standalone MemberExpression checks → also OptionalMemberExpression - contractsOf: namespace MemberExpression → also OptionalMemberExpression This is consistent with the rest of the compiler, which handles both shapes throughout (descriptor-lowering, signal-declarations, dom-bindings, etc.).
1 parent b1dd2c1 commit 3513e1f

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎packages/octane/src/compiler/data-contracts.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export function analyzeDataContracts(source, filename) {
197197
return (scope && aliases.get(scope)?.get(node.name)) ?? null;
198198
}
199199
if (
200-
node?.type === 'MemberExpression' &&
200+
(node?.type === 'MemberExpression' || node?.type === 'OptionalMemberExpression') &&
201201
!node.computed &&
202202
node.object.type === 'Identifier' &&
203203
namespaces.has(node.object.name) &&
@@ -269,7 +269,7 @@ export function analyzeDataContracts(source, filename) {
269269
};
270270

271271
const visit = (node, parent, key) => {
272-
if (node.type === 'CallExpression') {
272+
if (node.type === 'CallExpression' || node.type === 'OptionalCallExpression') {
273273
const kind = factoryOf(node);
274274
if (kind !== null && !declared.has(node)) {
275275
report(
@@ -281,7 +281,10 @@ export function analyzeDataContracts(source, filename) {
281281
const callee = unwrapTsExpr(node.callee);
282282
let index;
283283
let name;
284-
if (callee.type === 'MemberExpression' && !callee.computed) {
284+
if (
285+
(callee.type === 'MemberExpression' || callee.type === 'OptionalMemberExpression') &&
286+
!callee.computed
287+
) {
285288
name = callee.property.name;
286289
index = METHOD_SITES.get(name);
287290
// The bounded loop form: `[a, b].map((contract) => …)`.
@@ -315,8 +318,9 @@ export function analyzeDataContracts(source, filename) {
315318
return false;
316319
}
317320
}
318-
const named = node.type === 'MemberExpression' ? contractsOf(node) : null;
319-
if (node.type === 'MemberExpression' && named === null && contractsOf(node.object) !== null) {
321+
const isMember = node.type === 'MemberExpression' || node.type === 'OptionalMemberExpression';
322+
const named = isMember ? contractsOf(node) : null;
323+
if (isMember && named === null && contractsOf(node.object) !== null) {
320324
// A property read off a contract, such as `books.view.compare`.
321325
if (node.computed) walk(node.property, node, 'property', visit);
322326
return false;

0 commit comments

Comments
 (0)