Closed akabekobeko closed 8 years ago
Thanks for report.
Ah, FunctionExpression
is not suported yet.
https://github.com/azu/babel-plugin-jsdoc-to-assert/blob/master/src/index.js
const obj = {
/**
* @param {String} message Message.
*/
log: function( message ) {
console.log( message );
}
};
I feel able to support FunctionExpression
with JSDoc.
Thanks for consideration.
ES2015 class method of Is it possible to support? In the output of Babel (Part of _createClass
) it has been separated function and comment.
I've released https://github.com/azu/babel-plugin-jsdoc-to-assert/releases/tag/2.1.0
It support FunctionExpression
transform.
babel-plugin-jsdoc-to-assert@2.1.0 and babel-preset-es2015@6.13.2
transform
/**
* @param {String} name Name.
*/
constructor( name ) {
this._name = name;
}
/**
* @param {String} message Message.
*/
log( message ) {
console.log( message );
}
}
to
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var X = function () {
function X() {
_classCallCheck(this, X);
}
_createClass(X, [{
key: "method",
/**
* @param {number} x - this is a param.
* @param {string} y - this is a param.
*/
value: function method(x, y) {
console.assert(typeof x === "number");
console.assert(typeof y === "string");
}
}]);
return X;
}();
Babel's transform order is not specified by default.
When es2015 -> jsdoc-to-assert, transform it as FunctionExpression
When jsdoc-to-assert -> es2015, transform it as ClassMethod
.
FYI, you may use passPerPreset
option for specifing order.( I never try it... )
{
"presets": [
"es2015",
"jsdoc-to-assert"
],
"passPerPreset": true
}
Was confirmed that it is fixed in the babel-plugin-jsdoc-to-assert
v2.1.0. Test is the following.
Setting of babel
is the following, tried in the babel-plugin-jsdoc-to-assert
.
babel-preset-jsdoc-to-assert and babel-plugin-jsdoc-to-assert
{
"passPerPreset": true,
"presets": [
"es2015",
"jsdoc-to-assert"
],
"env": {
"development": {
"presets": [
"power-assert"
]
}
}
}
babel-plugin-jsdoc-to-assert only
{
"passPerPreset": true,
"presets": [
"es2015"
],
"env": {
"development": {
"presets": [
"power-assert"
],
"plugins": [
"jsdoc-to-assert"
]
}
}
}
Thanks for support!
I tried in the following
package.json
.npm run build
was the execution result,normal function
and theconstructor
it was not a problem.However, If the function is of the property does not work
Sample 1.
Original code:
Transformed:
Sample 2.
Original code:
Transformed: