Skip to content

Commit

Permalink
chore: remove get_callee_name (#9595)
Browse files Browse the repository at this point in the history
no longer necessary with the enhanced get_rune function
  • Loading branch information
Rich-Harris authored Nov 22, 2023
1 parent 13c6c27 commit 5f6c5ca
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 24 deletions.
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

1 comment on commit 5f6c5ca

@vercel
Copy link

@vercel vercel bot commented on 5f6c5ca Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-5-preview-svelte.vercel.app
svelte-5-preview.vercel.app
svelte-octane.vercel.app
svelte-5-preview-git-main-svelte.vercel.app

Please sign in to comment.