How can I use proposal-decorators
plugin in @babel/standalone
environment?
#16182
-
I want to use decorators in the I followed this document and wrote the following code: <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://unpkg.com/@babel/[email protected]/babel.min.js"></script>
<script>
Babel.registerPreset("env-plus", {
presets: [[Babel.availablePresets["env"], { loose: true }]],
plugins: [
[
Babel.availablePlugins["proposal-decorators"],
{ version: "2023-01" },
],
],
});
</script>
<script type="text/babel" data-presets="env-plus">
function decorateFoo(constructor) {
constructor.prototype.foo = 42;
}
@decorateFoo
class Example {
constructor() { }
}
console.log(new Example().foo);
</script>
</head>
</html> However, this code raises an error and does not work. Here is the error message in the browser console:
Removing the preset |
Beta Was this translation helpful? Give feedback.
Answered by
liuxingbaoyu
Dec 22, 2023
Replies: 1 comment 1 reply
-
As a temporary solution, you can set an empty <script type="text/babel" data-presets="env-plus" data-plugins="">
function decorateFoo(constructor) {
constructor.prototype.foo = 42;
}
@decorateFoo
class Example {
constructor() { }
}
console.log(new Example().foo);
</script> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
reosablo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As a temporary solution, you can set an empty
data-plugins
.