This commit is contained in:
hatuhn
2019-09-13 09:45:04 +07:00
parent f14a34ba19
commit 558fb07261
16790 changed files with 0 additions and 1642370 deletions

View File

@@ -1,4 +0,0 @@
node_modules
*.log
src
test

View File

@@ -1,83 +0,0 @@
# babel-plugin-transform-decorators
> Compile class and object decorators to ES5
## Example
(examples are from proposal)
### Simple class decorator
```js
@annotation
class MyClass { }
function annotation(target) {
target.annotated = true;
}
```
### Class decorator
```js
@isTestable(true)
class MyClass { }
function isTestable(value) {
return function decorator(target) {
target.isTestable = value;
}
}
```
### Class function decorator
```js
class C {
@enumerable(false)
method() { }
}
function enumerable(value) {
return function (target, key, descriptor) {
descriptor.enumerable = value;
return descriptor;
}
}
```
## Installation
```sh
npm install --save-dev babel-plugin-transform-decorators
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["transform-decorators"]
}
```
### Via CLI
```sh
babel --plugins transform-decorators script.js
```
### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["transform-decorators"]
});
```
## References
* [Proposal: Javascript Decorators](https://github.com/wycats/javascript-decorators/blob/master/README.md)

View File

@@ -1,194 +0,0 @@
"use strict";
exports.__esModule = true;
var _create = require("babel-runtime/core-js/object/create");
var _create2 = _interopRequireDefault(_create);
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
exports.default = function (_ref) {
var t = _ref.types;
function cleanDecorators(decorators) {
return decorators.reverse().map(function (dec) {
return dec.expression;
});
}
function transformClass(path, ref, state) {
var nodes = [];
state;
var classDecorators = path.node.decorators;
if (classDecorators) {
path.node.decorators = null;
classDecorators = cleanDecorators(classDecorators);
for (var _iterator = classDecorators, _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 decorator = _ref2;
nodes.push(buildClassDecorator({
CLASS_REF: ref,
DECORATOR: decorator
}));
}
}
var map = (0, _create2.default)(null);
for (var _iterator2 = path.get("body.body"), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref3;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref3 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref3 = _i2.value;
}
var method = _ref3;
var decorators = method.node.decorators;
if (!decorators) continue;
var _alias = t.toKeyAlias(method.node);
map[_alias] = map[_alias] || [];
map[_alias].push(method.node);
method.remove();
}
for (var alias in map) {
var items = map[alias];
items;
}
return nodes;
}
function hasDecorators(path) {
if (path.isClass()) {
if (path.node.decorators) return true;
for (var _iterator3 = path.node.body.body, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
var _ref4;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref4 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref4 = _i3.value;
}
var method = _ref4;
if (method.decorators) {
return true;
}
}
} else if (path.isObjectExpression()) {
for (var _iterator4 = path.node.properties, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) {
var _ref5;
if (_isArray4) {
if (_i4 >= _iterator4.length) break;
_ref5 = _iterator4[_i4++];
} else {
_i4 = _iterator4.next();
if (_i4.done) break;
_ref5 = _i4.value;
}
var prop = _ref5;
if (prop.decorators) {
return true;
}
}
}
return false;
}
function doError(path) {
throw path.buildCodeFrameError("Decorators are not officially supported yet in 6.x pending a proposal update.\nHowever, if you need to use them you can install the legacy decorators transform with:\n\nnpm install babel-plugin-transform-decorators-legacy --save-dev\n\nand add the following line to your .babelrc file:\n\n{\n \"plugins\": [\"transform-decorators-legacy\"]\n}\n\nThe repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy.\n ");
}
return {
inherits: require("babel-plugin-syntax-decorators"),
visitor: {
ClassExpression: function ClassExpression(path) {
if (!hasDecorators(path)) return;
doError(path);
(0, _babelHelperExplodeClass2.default)(path);
var ref = path.scope.generateDeclaredUidIdentifier("ref");
var nodes = [];
nodes.push(t.assignmentExpression("=", ref, path.node));
nodes = nodes.concat(transformClass(path, ref, this));
nodes.push(ref);
path.replaceWith(t.sequenceExpression(nodes));
},
ClassDeclaration: function ClassDeclaration(path) {
if (!hasDecorators(path)) return;
doError(path);
(0, _babelHelperExplodeClass2.default)(path);
var ref = path.node.id;
var nodes = [];
nodes = nodes.concat(transformClass(path, ref, this).map(function (expr) {
return t.expressionStatement(expr);
}));
nodes.push(t.expressionStatement(ref));
path.insertAfter(nodes);
},
ObjectExpression: function ObjectExpression(path) {
if (!hasDecorators(path)) return;
doError(path);
}
}
};
};
var _babelTemplate = require("babel-template");
var _babelTemplate2 = _interopRequireDefault(_babelTemplate);
var _babelHelperExplodeClass = require("babel-helper-explode-class");
var _babelHelperExplodeClass2 = _interopRequireDefault(_babelHelperExplodeClass);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var buildClassDecorator = (0, _babelTemplate2.default)("\n CLASS_REF = DECORATOR(CLASS_REF) || CLASS_REF;\n");
module.exports = exports["default"];

View File

@@ -1,49 +0,0 @@
{
"_from": "babel-plugin-transform-decorators@^6.24.1",
"_id": "babel-plugin-transform-decorators@6.24.1",
"_inBundle": false,
"_integrity": "sha1-eIAT2PjGtSIr33s0Q5Df13Vp4k0=",
"_location": "/babel-plugin-transform-decorators",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "babel-plugin-transform-decorators@^6.24.1",
"name": "babel-plugin-transform-decorators",
"escapedName": "babel-plugin-transform-decorators",
"rawSpec": "^6.24.1",
"saveSpec": null,
"fetchSpec": "^6.24.1"
},
"_requiredBy": [
"/babel-preset-stage-2"
],
"_resolved": "https://registry.npmjs.org/babel-plugin-transform-decorators/-/babel-plugin-transform-decorators-6.24.1.tgz",
"_shasum": "788013d8f8c6b5222bdf7b344390dfd77569e24d",
"_spec": "babel-plugin-transform-decorators@^6.24.1",
"_where": "/Applications/XAMPP/xamppfiles/htdocs/wordpress/t-latehome/wp-content/plugins/opal-estate-pro/node_modules/babel-preset-stage-2",
"bundleDependencies": false,
"dependencies": {
"babel-helper-explode-class": "^6.24.1",
"babel-plugin-syntax-decorators": "^6.13.0",
"babel-runtime": "^6.22.0",
"babel-template": "^6.24.1",
"babel-types": "^6.24.1"
},
"deprecated": false,
"description": "Compile class and object decorators to ES5",
"devDependencies": {
"babel-helper-plugin-test-runner": "^6.24.1"
},
"keywords": [
"babel-plugin"
],
"license": "MIT",
"main": "lib/index.js",
"name": "babel-plugin-transform-decorators",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-decorators"
},
"version": "6.24.1"
}