xp-framework / compiler

Compiles future PHP to today's PHP.
19 stars 0 forks source link

Refactor how annotations with non-constant arguments are emitted #169

Closed thekid closed 1 year ago

thekid commented 1 year ago

This pull request changes the way annotations with non-constant arguments are emitted.

Single argument

// Declaration in user code
#[Verify(fn() => extension_loaded('pcntl')]

// Previous behavior
#[Verify(eval: 'fn() => extension_loaded(\'pcntl\')')]

// Code that is emitted now
#[Verify(eval: ['fn() => extension_loaded(\'pcntl\')'])]

Multiple (and named) arguments

// Declaration in user code
#[Verify(fn() => extension_loaded('pcntl'), optional: true)]

// Previous behavior created an ambiguity with supplying a single value with the respective array
#[Verify(eval: '[\'0\' => fn() => extension_loaded(\'pcntl\'), \'optional\' => true]')]

// Code that is emitted now
#[Verify(eval: ['fn() => extension_loaded(\'pcntl\'))', 'optional' => 'true'])]

The array notation is supported by the following changes:

See also https://github.com/xp-framework/rfc/issues/338

thekid commented 1 year ago

Released in https://github.com/xp-framework/compiler/releases/tag/v8.13.0