@babel/plugin-transform-classes
Advanced tools
Comparing version 7.0.0-beta.49 to 7.0.0-beta.50
{ | ||
"name": "@babel/plugin-transform-classes", | ||
"version": "7.0.0-beta.49", | ||
"version": "7.0.0-beta.50", | ||
"description": "Compile ES2015 classes to ES5", | ||
@@ -9,9 +9,9 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-classes", | ||
"dependencies": { | ||
"@babel/helper-annotate-as-pure": "7.0.0-beta.49", | ||
"@babel/helper-define-map": "7.0.0-beta.49", | ||
"@babel/helper-function-name": "7.0.0-beta.49", | ||
"@babel/helper-optimise-call-expression": "7.0.0-beta.49", | ||
"@babel/helper-plugin-utils": "7.0.0-beta.49", | ||
"@babel/helper-replace-supers": "7.0.0-beta.49", | ||
"@babel/helper-split-export-declaration": "7.0.0-beta.49", | ||
"@babel/helper-annotate-as-pure": "7.0.0-beta.50", | ||
"@babel/helper-define-map": "7.0.0-beta.50", | ||
"@babel/helper-function-name": "7.0.0-beta.50", | ||
"@babel/helper-optimise-call-expression": "7.0.0-beta.50", | ||
"@babel/helper-plugin-utils": "7.0.0-beta.50", | ||
"@babel/helper-replace-supers": "7.0.0-beta.50", | ||
"@babel/helper-split-export-declaration": "7.0.0-beta.50", | ||
"globals": "^11.1.0" | ||
@@ -26,5 +26,5 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.49", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.49" | ||
"@babel/core": "7.0.0-beta.50", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.50" | ||
} | ||
} |
120
README.md
@@ -5,124 +5,16 @@ # @babel/plugin-transform-classes | ||
## Caveats | ||
See our website [@babel/plugin-transform-classes](https://new.babeljs.io/docs/en/next/babel-plugin-transform-classes.html) for more information. | ||
When extending a native class (e.g., `class extends Array {}`), the super class | ||
needs to be wrapped. This is needed to workaround two problems: | ||
- Babel transpiles classes using `SuperClass.apply(/* ... */)`, but native | ||
classes aren't callable and thus throw in this case. | ||
- Some built-in functions (like `Array`) always return a new object. Instead of | ||
returning it, Babel should treat it as the new `this`. | ||
## Install | ||
The wrapper works on IE11 and every other browser with `Object.setPrototypeOf` or `__proto__` as fallback. | ||
There is **NO IE <= 10 support**. If you need IE <= 10 it's recommended that you don't extend natives. | ||
Using npm: | ||
## Examples | ||
**In** | ||
```javascript | ||
class Test { | ||
constructor(name) { | ||
this.name = name; | ||
} | ||
logger () { | ||
console.log("Hello", this.name); | ||
} | ||
} | ||
``` | ||
**Out** | ||
```javascript | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Test = function () { | ||
function Test(name) { | ||
_classCallCheck(this, Test); | ||
this.name = name; | ||
} | ||
Test.prototype.logger = function logger() { | ||
console.log("Hello", this.name); | ||
}; | ||
return Test; | ||
}(); | ||
``` | ||
## Installation | ||
```sh | ||
npm install --save-dev @babel/plugin-transform-classes | ||
npm install --save @babel/plugin-transform-classes | ||
``` | ||
## Usage | ||
or using yarn: | ||
### Via `.babelrc` (Recommended) | ||
**.babelrc** | ||
```js | ||
// without options | ||
{ | ||
"plugins": ["@babel/plugin-transform-classes"] | ||
} | ||
// with options | ||
{ | ||
"plugins": [ | ||
["@babel/plugin-transform-classes", { | ||
"loose": true | ||
}] | ||
] | ||
} | ||
``` | ||
### Via CLI | ||
```sh | ||
babel --plugins @babel/plugin-transform-classes script.js | ||
yarn add --save @babel/plugin-transform-classes | ||
``` | ||
### Via Node API | ||
```javascript | ||
require("@babel/core").transform("code", { | ||
plugins: ["@babel/plugin-transform-classes"] | ||
}); | ||
``` | ||
## Options | ||
### `loose` | ||
`boolean`, defaults to `false`. | ||
#### Method enumerability | ||
Please note that in loose mode class methods **are** enumerable. This is not in line | ||
with the spec and you may run into issues. | ||
#### Method assignment | ||
Under loose mode, methods are defined on the class prototype with simple assignments | ||
instead of being defined. This can result in the following not working: | ||
```javascript | ||
class Foo { | ||
set bar() { | ||
throw new Error("foo!"); | ||
} | ||
} | ||
class Bar extends Foo { | ||
bar() { | ||
// will throw an error when this method is defined | ||
} | ||
} | ||
``` | ||
When `Bar.prototype.foo` is defined it triggers the setter on `Foo`. This is a | ||
case that is very unlikely to appear in production code however it's something | ||
to keep in mind. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24407
5
20
+ Added@babel/helper-annotate-as-pure@7.0.0-beta.50(transitive)
+ Added@babel/helper-define-map@7.0.0-beta.50(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.50(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.50(transitive)
+ Added@babel/helper-member-expression-to-functions@7.0.0-beta.50(transitive)
+ Added@babel/helper-optimise-call-expression@7.0.0-beta.50(transitive)
+ Added@babel/helper-plugin-utils@7.0.0-beta.50(transitive)
+ Added@babel/helper-replace-supers@7.0.0-beta.50(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.50(transitive)
- Removed@babel/helper-annotate-as-pure@7.0.0-beta.49(transitive)
- Removed@babel/helper-define-map@7.0.0-beta.49(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.49(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.49(transitive)
- Removed@babel/helper-member-expression-to-functions@7.0.0-beta.49(transitive)
- Removed@babel/helper-optimise-call-expression@7.0.0-beta.49(transitive)
- Removed@babel/helper-plugin-utils@7.0.0-beta.49(transitive)
- Removed@babel/helper-replace-supers@7.0.0-beta.49(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.49(transitive)