remove es20xx prefixes from plugins and rename folders (#6575)

This commit is contained in:
Henry Zhu
2017-10-28 20:43:15 -04:00
committed by GitHub
parent 92a3caeb9c
commit 9ac326b075
1672 changed files with 1200 additions and 1203 deletions

View File

@@ -0,0 +1,3 @@
src
test
*.log

View 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"]
});
```

View 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"
}
}

View 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]));
}
}
},
},
};
}

View File

@@ -0,0 +1 @@
a instanceof b;

View 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));

View File

@@ -0,0 +1 @@
babelHelpers.instanceof(a, b);

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-instanceof"]
}

View File

@@ -0,0 +1,3 @@
import runner from "@babel/helper-plugin-test-runner";
runner(__dirname);