Skip to content

Expose animation name as a typed item in analyzeAnimation callback #604

@bartveneman

Description

@bartveneman

Context

analyzeAnimation(parsed, callback) currently emits the following item types: duration, delay, fn, direction, fill-mode, play-state, iteration-count. It does not emit a name item.

Consumers that need to extract the animation name from an animation shorthand value must maintain their own exclusion list of reserved keywords (timing keywords, direction keywords, fill-mode keywords, etc.) and treat whatever identifier remains as the name. This is fragile and duplicates knowledge that analyzeAnimation already encodes internally to disambiguate the other item types.

Proposed change

Add { type: 'name'; value: Node } to the emitted item types.

type AnimationItem =
  | { type: 'name';            value: Node }  // ← new
  | { type: 'duration';        value: Node }
  | { type: 'delay';           value: Node }
  | { type: 'fn';              value: Node }
  | { type: 'direction';       value: Node }
  | { type: 'fill-mode';       value: Node }
  | { type: 'play-state';      value: Node }
  | { type: 'iteration-count'; value: Node }

Example

import { parse_value } from '@projectwallace/css-parser/parse-value'
import { analyzeAnimation } from '@projectwallace/css-analyzer/values'

const parsed = parse_value('slide-in 300ms ease-out forwards')

analyzeAnimation(parsed, (item) => {
  if (item.type === 'name') console.log(item.value.text) // 'slide-in'
})

Motivation

Consumers that cross-reference animation names against @keyframes declarations (e.g., to detect unused or undeclared keyframes) currently carry a ~20-entry hardcoded keyword set to identify the name by exclusion. Emitting name directly removes that entirely and ensures disambiguation stays in one place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions