pull/15820/head
Rich Harris 4 months ago
parent 1a78e279d6
commit 90e7e0dce5

@ -274,7 +274,6 @@ function get_function_label(nodes) {
} }
/** /**
*
* @param {AST.SvelteNode} parent * @param {AST.SvelteNode} parent
* @param {Context} context * @param {Context} context
*/ */
@ -283,7 +282,6 @@ function is_variable_declaration(parent, context) {
} }
/** /**
*
* @param {AST.SvelteNode} parent * @param {AST.SvelteNode} parent
*/ */
function is_class_property_definition(parent) { function is_class_property_definition(parent) {
@ -293,28 +291,21 @@ function is_class_property_definition(parent) {
/** /**
* @param {AST.SvelteNode} node * @param {AST.SvelteNode} node
* @param {Context} context * @param {Context} context
* @returns {node is AssignmentExpression & { left: { type: 'MemberExpression' } & { object: { type: 'ThisExpression' }; property: { type: 'Identifier' | 'PrivateIdentifier' | 'Literal' } } }}
*/ */
function is_class_property_assignment_at_constructor_root(node, context) { function is_class_property_assignment_at_constructor_root(node, context) {
if ( if (
!( node.type === 'AssignmentExpression' &&
node.type === 'AssignmentExpression' && node.operator === '=' &&
node.operator === '=' && node.left.type === 'MemberExpression' &&
node.left.type === 'MemberExpression' && node.left.object.type === 'ThisExpression' &&
node.left.object.type === 'ThisExpression' && ((node.left.property.type === 'Identifier' && !node.left.computed) ||
((node.left.property.type === 'Identifier' && !node.left.computed) || node.left.property.type === 'PrivateIdentifier' ||
node.left.property.type === 'PrivateIdentifier' || node.left.property.type === 'Literal')
node.left.property.type === 'Literal')
)
) { ) {
return false; // MethodDefinition (-5) -> FunctionExpression (-4) -> BlockStatement (-3) -> ExpressionStatement (-2) -> AssignmentExpression (-1)
const parent = get_parent(context.path, -5);
return parent?.type === 'MethodDefinition' && parent.kind === 'constructor';
} }
// AssignmentExpression (here) -> ExpressionStatement (-1) -> BlockStatement (-2) -> FunctionExpression (-3) -> MethodDefinition (-4) return false;
const maybe_constructor = get_parent(context.path, -5);
return (
maybe_constructor &&
maybe_constructor.type === 'MethodDefinition' &&
maybe_constructor.kind === 'constructor'
);
} }

Loading…
Cancel
Save