Reference attribute is not working under before_script section with anchors

Summary

**I realized that anchors don't run correctly if they are combined with reference tags under before_script section of a parent job **

Steps to reproduce

Following configuration is working correctly:

.bar:
  - echo "Prepare environment"

.base:
  before_script:
    - !reference [.bar]

test:
  extends:
    - .base
  script:
    - echo "Build is started"

When I use an anchor under before_script section, it is failed

.foo: &foo
  - echo "Anchor test"

.bar:
  - *foo
  - echo "Prepare environment"

.base:
  before_script:
    - !reference [.bar]

test:
  extends:
    - .base
  script:
    - echo "Build is started"

Example Project

https://gitlab.com/dorukkangal/anchor_test

What is the current bug behavior?

I cannot add an anchor with reference tag under before_script section of a parent job.

What is the expected correct behavior?

I should use anchors with reference tags under before_script section of a parent job.

Relevant logs and/or screenshots

Found errors in your .gitlab-ci.yml:
jobs:build:before_script config should be an array containing strings and arrays of strings
You can also test your .gitlab-ci.yml in CI Lint