a declaration is a reference

goodbye-acorn
Nic 2 weeks ago
parent 461d4e940d
commit 0a2d6ee487

@ -5,7 +5,7 @@ import { walk } from 'zimmerframe';
import { ExpressionMetadata } from './nodes.js';
import * as b from '#compiler/builders';
import * as e from '../errors.js';
import { bindingOf, parentOf } from '@teasel/parser';
import { referenceOf, parentOf } from '@teasel/parser';
import {
extract_identifiers,
tables_of,
@ -1086,6 +1086,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
answer.bindings.length === 0
) {
for (const reference of answer.references) {
if (reference.declares) continue;
references.push(new Reference(reference.node, scope, path, false, undefined, reference));
}
return;
@ -1182,6 +1183,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
]);
}
for (const reference of answer.references) {
if (reference.declares) continue;
const binding = reference.binding === null ? undefined : from_parser.get(reference.binding);
entries.push([
reference.node,
@ -1232,7 +1234,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
/** The parser's declaration a Svelte binding stands for, once declared. @param {Identifier} id */
function declared(id) {
const parsed = bindingOf(id);
const parsed = referenceOf(id)?.binding;
return parsed ? from_parser.get(parsed) : undefined;
}

@ -1,7 +1,7 @@
/** @import { AST, Scope } from '#compiler' */
/** @import * as ESTree from 'estree' */
import { walk } from 'zimmerframe';
import { bindingOf } from '@teasel/parser';
import { referenceOf } from '@teasel/parser';
/**
* @typedef {import('@teasel/parser').Root} Tables
@ -673,8 +673,7 @@ export const value_names = new WeakSet();
* @param {ESTree.Node | AST.SvelteNode | null | undefined} parent
*/
export function is_reference(node, parent) {
const binding = bindingOf(node);
if (binding !== undefined || value_names.has(node)) return true;
if (referenceOf(node) !== undefined || value_names.has(node)) return true;
if (!parent) return true;
switch (parent.type) {
case 'MemberExpression':

Loading…
Cancel
Save