From 26139b82ac19e258c806db3de4f33844bd0abda1 Mon Sep 17 00:00:00 2001 From: Naman Dhingra Date: Sun, 22 Sep 2024 01:22:32 +0530 Subject: [PATCH] Added note section for Symbol.metadata in the plugin-proposal-decorators plugin doc --- docs/plugin-proposal-decorators.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/plugin-proposal-decorators.md b/docs/plugin-proposal-decorators.md index 1a1dc57410..0a8005ed5f 100644 --- a/docs/plugin-proposal-decorators.md +++ b/docs/plugin-proposal-decorators.md @@ -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