uapte
This commit is contained in:
4
node_modules/babel-plugin-transform-class-constructor-call/.npmignore
generated
vendored
4
node_modules/babel-plugin-transform-class-constructor-call/.npmignore
generated
vendored
@@ -1,4 +0,0 @@
|
||||
node_modules
|
||||
*.log
|
||||
src
|
||||
test
|
||||
99
node_modules/babel-plugin-transform-class-constructor-call/README.md
generated
vendored
99
node_modules/babel-plugin-transform-class-constructor-call/README.md
generated
vendored
@@ -1,99 +0,0 @@
|
||||
# babel-plugin-transform-class-constructor-call (deprecated)
|
||||
|
||||
> Proposal Withdrawn: can be solved with decorators.
|
||||
|
||||
This plugin allows Babel to transform class constructors.
|
||||
|
||||
It basically allows to use the [new.target](http://mdn.io/new.target) feature on ES2015 classes:
|
||||
|
||||
```js
|
||||
class Point {
|
||||
|
||||
constructor(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
call constructor(x, y) {
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let p1 = new Point(1, 2); // OK
|
||||
let p2 = Point(3, 4); // OK
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
### Date example
|
||||
The javascript [Date](http://mdn.io/date) works this way:
|
||||
|
||||
```js
|
||||
// You can get a Date instance using the new keyword
|
||||
let now = new Date();
|
||||
console.log(now.getMonth()); // Prints '3'
|
||||
console.log(now.toString()); // Prints 'Mon Apr 11 2016 13:26:07 GMT+0100 (BST)'
|
||||
|
||||
// You can get a string of the current date using Date as a function:
|
||||
let nowStr = Date();
|
||||
console.log(nowStr); // Prints 'Mon Apr 11 2016 13:26:07 GMT+0100 (BST)'
|
||||
```
|
||||
|
||||
It is currently possible to implement something like that using [new.target](http://mdn.io/new.target) (see [example in proposal](https://github.com/tc39/ecma262/blob/master/workingdocs/callconstructor.md#motivating-example)) and this new feature makes it available for ES2015 classes.
|
||||
|
||||
A date implementation could be:
|
||||
|
||||
```js
|
||||
class Date {
|
||||
constructor() {
|
||||
// ...
|
||||
}
|
||||
|
||||
call constructor() {
|
||||
let date = new Date();
|
||||
return date.toString();
|
||||
}
|
||||
}
|
||||
|
||||
let now = new Date(); // Get a Date instance
|
||||
let nowStr = Date(); // Use the 'call constructor()' part to get a string value of the current date
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save-dev babel-plugin-transform-class-constructor-call
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["transform-class-constructor-call"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
babel --plugins transform-class-constructor-call script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("babel-core").transform("code", {
|
||||
plugins: ["transform-class-constructor-call"]
|
||||
});
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* [Inactive Proposals](https://github.com/tc39/proposals/blob/master/inactive-proposals.md)
|
||||
* [Proposal: Call Constructor](https://github.com/tc39/ecma262/blob/master/workingdocs/callconstructor.md)
|
||||
* [Blog post: ECMAScript proposal: function-callable classes](http://www.2ality.com/2015/10/call-constructor-esprop.html)
|
||||
93
node_modules/babel-plugin-transform-class-constructor-call/lib/index.js
generated
vendored
93
node_modules/babel-plugin-transform-class-constructor-call/lib/index.js
generated
vendored
@@ -1,93 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
|
||||
|
||||
var _getIterator3 = _interopRequireDefault(_getIterator2);
|
||||
|
||||
var _symbol = require("babel-runtime/core-js/symbol");
|
||||
|
||||
var _symbol2 = _interopRequireDefault(_symbol);
|
||||
|
||||
exports.default = function (_ref) {
|
||||
var t = _ref.types;
|
||||
|
||||
var ALREADY_VISITED = (0, _symbol2.default)();
|
||||
|
||||
function findConstructorCall(path) {
|
||||
var methods = path.get("body.body");
|
||||
|
||||
for (var _iterator = methods, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref2 = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref2 = _i.value;
|
||||
}
|
||||
|
||||
var method = _ref2;
|
||||
|
||||
if (method.node.kind === "constructorCall") {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function handleClassWithCall(constructorCall, classPath) {
|
||||
var _classPath = classPath,
|
||||
node = _classPath.node;
|
||||
|
||||
var ref = node.id || classPath.scope.generateUidIdentifier("class");
|
||||
|
||||
if (classPath.parentPath.isExportDefaultDeclaration()) {
|
||||
classPath = classPath.parentPath;
|
||||
classPath.insertAfter(t.exportDefaultDeclaration(ref));
|
||||
}
|
||||
|
||||
classPath.replaceWithMultiple(buildWrapper({
|
||||
CLASS_REF: classPath.scope.generateUidIdentifier(ref.name),
|
||||
CALL_REF: classPath.scope.generateUidIdentifier(ref.name + "Call"),
|
||||
CALL: t.functionExpression(null, constructorCall.node.params, constructorCall.node.body),
|
||||
CLASS: t.toExpression(node),
|
||||
WRAPPER_REF: ref
|
||||
}));
|
||||
|
||||
constructorCall.remove();
|
||||
}
|
||||
|
||||
return {
|
||||
inherits: require("babel-plugin-syntax-class-constructor-call"),
|
||||
|
||||
visitor: {
|
||||
Class: function Class(path) {
|
||||
if (path.node[ALREADY_VISITED]) return;
|
||||
path.node[ALREADY_VISITED] = true;
|
||||
|
||||
var constructorCall = findConstructorCall(path);
|
||||
|
||||
if (constructorCall) {
|
||||
handleClassWithCall(constructorCall, path);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var _babelTemplate = require("babel-template");
|
||||
|
||||
var _babelTemplate2 = _interopRequireDefault(_babelTemplate);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var buildWrapper = (0, _babelTemplate2.default)("\n let CLASS_REF = CLASS;\n var CALL_REF = CALL;\n var WRAPPER_REF = function (...args) {\n if (this instanceof WRAPPER_REF) {\n return Reflect.construct(CLASS_REF, args);\n } else {\n return CALL_REF.apply(this, args);\n }\n };\n WRAPPER_REF.__proto__ = CLASS_REF;\n WRAPPER_REF;\n");
|
||||
|
||||
module.exports = exports["default"];
|
||||
47
node_modules/babel-plugin-transform-class-constructor-call/package.json
generated
vendored
47
node_modules/babel-plugin-transform-class-constructor-call/package.json
generated
vendored
@@ -1,47 +0,0 @@
|
||||
{
|
||||
"_from": "babel-plugin-transform-class-constructor-call@^6.24.1",
|
||||
"_id": "babel-plugin-transform-class-constructor-call@6.24.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-gNwoVQWsBn3LjWxl4vbxGrd2Xvk=",
|
||||
"_location": "/babel-plugin-transform-class-constructor-call",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "babel-plugin-transform-class-constructor-call@^6.24.1",
|
||||
"name": "babel-plugin-transform-class-constructor-call",
|
||||
"escapedName": "babel-plugin-transform-class-constructor-call",
|
||||
"rawSpec": "^6.24.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^6.24.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/babel-preset-stage-1"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/babel-plugin-transform-class-constructor-call/-/babel-plugin-transform-class-constructor-call-6.24.1.tgz",
|
||||
"_shasum": "80dc285505ac067dcb8d6c65e2f6f11ab7765ef9",
|
||||
"_spec": "babel-plugin-transform-class-constructor-call@^6.24.1",
|
||||
"_where": "/Applications/XAMPP/xamppfiles/htdocs/wordpress/t-latehome/wp-content/plugins/opal-estate-pro/node_modules/babel-preset-stage-1",
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"babel-plugin-syntax-class-constructor-call": "^6.18.0",
|
||||
"babel-runtime": "^6.22.0",
|
||||
"babel-template": "^6.24.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "This plugin allows Babel to transform class constructors (deprecated)",
|
||||
"devDependencies": {
|
||||
"babel-helper-plugin-test-runner": "^6.24.1"
|
||||
},
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"name": "babel-plugin-transform-class-constructor-call",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-class-constructor-call"
|
||||
},
|
||||
"version": "6.24.1"
|
||||
}
|
||||
Reference in New Issue
Block a user