remove es20xx prefixes from plugins and rename folders (#6575)
This commit is contained in:
3
packages/babel-plugin-transform-instanceof/.npmignore
Normal file
3
packages/babel-plugin-transform-instanceof/.npmignore
Normal file
@@ -0,0 +1,3 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
33
packages/babel-plugin-transform-instanceof/README.md
Normal file
33
packages/babel-plugin-transform-instanceof/README.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# @babel/plugin-transform-instanceof
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-transform-instanceof
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["@babel/transform-instanceof"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
babel --plugins @babel/transform-instanceof script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("@babel/core").transform("code", {
|
||||
plugins: ["@babel/transform-instanceof"]
|
||||
});
|
||||
```
|
||||
17
packages/babel-plugin-transform-instanceof/package.json
Normal file
17
packages/babel-plugin-transform-instanceof/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@babel/plugin-transform-instanceof",
|
||||
"version": "7.0.0-beta.3",
|
||||
"description": "This plugin transforms all the ES2015 'instanceof' methods",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-instanceof",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@babel/core": "7.0.0-beta.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-beta.3"
|
||||
}
|
||||
}
|
||||
26
packages/babel-plugin-transform-instanceof/src/index.js
Normal file
26
packages/babel-plugin-transform-instanceof/src/index.js
Normal file
@@ -0,0 +1,26 @@
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
BinaryExpression(path) {
|
||||
const { node } = path;
|
||||
if (node.operator === "instanceof") {
|
||||
const helper = this.addHelper("instanceof");
|
||||
const isUnderHelper = path.findParent(path => {
|
||||
return (
|
||||
(path.isVariableDeclarator() && path.node.id === helper) ||
|
||||
(path.isFunctionDeclaration() &&
|
||||
path.node.id &&
|
||||
path.node.id.name === helper.name)
|
||||
);
|
||||
});
|
||||
|
||||
if (isUnderHelper) {
|
||||
return;
|
||||
} else {
|
||||
path.replaceWith(t.callExpression(helper, [node.left, node.right]));
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
1
packages/babel-plugin-transform-instanceof/test/fixtures/instanceof/instanceof/actual.js
vendored
Normal file
1
packages/babel-plugin-transform-instanceof/test/fixtures/instanceof/instanceof/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a instanceof b;
|
||||
25
packages/babel-plugin-transform-instanceof/test/fixtures/instanceof/instanceof/exec.js
vendored
Normal file
25
packages/babel-plugin-transform-instanceof/test/fixtures/instanceof/instanceof/exec.js
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var foo = {};
|
||||
foo[Symbol.hasInstance]= function () { return true; };
|
||||
|
||||
var bar = {};
|
||||
|
||||
assert.ok(bar instanceof foo);
|
||||
assert.ok(new String instanceof String);
|
||||
|
||||
//
|
||||
|
||||
function Greeting(greeting) {
|
||||
this.greeting = greeting;
|
||||
}
|
||||
|
||||
Object.defineProperty(Greeting, Symbol.hasInstance, {
|
||||
value: function(inst) {
|
||||
return inst.greeting == "hello";
|
||||
}
|
||||
});
|
||||
|
||||
var a = new Greeting("hello");
|
||||
var b = new Greeting("world");
|
||||
|
||||
assert.ok(a instanceof Greeting);
|
||||
assert.ok(!(b instanceof Greeting));
|
||||
1
packages/babel-plugin-transform-instanceof/test/fixtures/instanceof/instanceof/expected.js
vendored
Normal file
1
packages/babel-plugin-transform-instanceof/test/fixtures/instanceof/instanceof/expected.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
babelHelpers.instanceof(a, b);
|
||||
3
packages/babel-plugin-transform-instanceof/test/fixtures/instanceof/instanceof/options.json
vendored
Normal file
3
packages/babel-plugin-transform-instanceof/test/fixtures/instanceof/instanceof/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "transform-instanceof"]
|
||||
}
|
||||
3
packages/babel-plugin-transform-instanceof/test/index.js
Normal file
3
packages/babel-plugin-transform-instanceof/test/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import runner from "@babel/helper-plugin-test-runner";
|
||||
|
||||
runner(__dirname);
|
||||
Reference in New Issue
Block a user