Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note section for Symbol.metadata in the plugin-proposal-decorators doc #2967

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/plugin-proposal-decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ require("@babel/core").transformSync("code", {
]
});
```
## Note on `Symbol.metadata`

When using decorators which either access or modify the metadata in the decorator context, you may need to use `Symbol.metadata`. However, `Symbol.metadata` is not defined globally by default because it is part of an experimental proposal (https://github.com/tc39/proposal-decorator-metadata).

To ensure `Symbol.metadata` is available globally and matches the symbol used by the Babel decorators plugin during transpilation, you need to include a polyfill that defines it.

### Steps to Include the Polyfill

Install `core-js`
```shell npm2yarn
npm install core-js
```

Import the Metadata Polyfill

```js title="Javascript"
import 'core-js/proposals/decorator-metadata-v2.js';
```

Note: This import must come before any code that uses decorators or accesses `Symbol.metadata`.

## Options

Expand Down