Skip to content

chore: remove get_callee_name #9595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 22, 2023
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
7 changes: 1 addition & 6 deletions packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as assert from '../../utils/assert.js';
import {
extract_identifiers,
extract_paths,
get_callee_name,
is_event_attribute,
is_text_attribute,
object
Expand Down Expand Up @@ -268,11 +267,7 @@ export function analyze_component(root, options) {
!Runes.includes(name) ||
(declaration !== null &&
// const state = $state(0) is valid
!Runes.includes(
/** @type {string} */ (
get_callee_name(/** @type {import('estree').Expression} */ (declaration.initial))
)
) &&
get_rune(declaration.initial, instance.scope) === null &&
// allow `import { derived } from 'svelte/store'` in the same file as `const x = $derived(..)` because one is not a subscription to the other
!(
name === '$derived' &&
Expand Down
6 changes: 1 addition & 5 deletions packages/svelte/src/compiler/phases/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { walk } from 'zimmerframe';
import { is_element_node } from './nodes.js';
import * as b from '../utils/builders.js';
import { error } from '../errors.js';
import {
extract_identifiers,
extract_identifiers_from_expression,
get_callee_name
} from '../utils/ast.js';
import { extract_identifiers, extract_identifiers_from_expression } from '../utils/ast.js';
import { Runes } from './constants.js';

export class Scope {
Expand Down
13 changes: 0 additions & 13 deletions packages/svelte/src/compiler/utils/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ export function object(expression) {
return expression;
}

/**
* Returns the name of callee if the given expression is a call expression.
* @param {import('estree').Expression | null | undefined} node
*/
export function get_callee_name(node) {
if (!node) return null;
if (node.type !== 'CallExpression') return null;
if (node.callee.type !== 'Identifier' && node.callee.type !== 'MemberExpression') return null;

const id = object(node.callee);
return id === null ? null : id.name;
}

/**
* Returns true if the attribute contains a single static text node.
* @param {import('#compiler').Attribute} attribute
Expand Down