MCPcopy
hub / github.com/sveltejs/svelte / get_global_keypath

Function get_global_keypath

packages/svelte/src/compiler/phases/scope.js:1448–1471  ·  view source on GitHub ↗

* Returns the name of the rune if the given expression is a `CallExpression` using a rune. * @param {Expression | Super} node * @param {Scope} scope

(node, scope)

Source from the content-addressed store, hash-verified

1446 * @param {Scope} scope
1447 */
1448function get_global_keypath(node, scope) {
1449 let n = node;
1450
1451 let joined = '';
1452
1453 while (n.type === 'MemberExpression') {
1454 if (n.computed) return null;
1455 if (n.property.type !== 'Identifier') return null;
1456 joined = '.' + n.property.name + joined;
1457 n = n.object;
1458 }
1459
1460 if (n.type === 'CallExpression' && n.callee.type === 'Identifier') {
1461 joined = '()' + joined;
1462 n = n.callee;
1463 }
1464
1465 if (n.type !== 'Identifier') return null;
1466
1467 const binding = scope.get(n.name);
1468 if (binding !== null) return null; // rune name, but references a variable or store
1469
1470 return n.name + joined;
1471}

Callers 2

constructorMethod · 0.85
get_runeFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected