babel-plugin-jsdoc-closure
Advanced tools
Comparing version 1.3.3 to 1.3.4
19
index.js
@@ -123,8 +123,2 @@ const parseComment = require('comment-parser'); | ||
comment = babel.transform(`/*${newComment}*/`).ast.comments[0]; | ||
if (path.parent && path.parent.type == 'ReturnStatement') { | ||
const parenthesized = babel.types.parenthesizedExpression(node); | ||
parenthesized.comments = path.parent.argument.comments; | ||
delete path.parent.argument.comments; | ||
path.parent.argument = parenthesized; | ||
} | ||
comments[i] = comment; | ||
@@ -161,6 +155,17 @@ } else { | ||
babel = b; | ||
const t = babel.types; | ||
return { | ||
visitor: { | ||
Program: function(path, state) { | ||
ReturnStatement(path) { | ||
const argument = path.node.argument; | ||
if (argument && argument.comments && argument.extra && argument.extra.parenthesized) { | ||
const parenthesized = t.parenthesizedExpression(path.node.argument); | ||
const comments = path.node.argument.comments; | ||
delete path.node.argument.comments; | ||
parenthesized.comments = comments; | ||
path.node.argument = parenthesized; | ||
} | ||
}, | ||
Program(path, state) { | ||
recast = state.file.opts.parserOpts && state.file.opts.parserOpts.parser == 'recast'; | ||
@@ -167,0 +172,0 @@ commentsProperty = recast ? 'comments' : 'leadingComments'; |
{ | ||
"name": "babel-plugin-jsdoc-closure", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "Transpiles JSDoc types from namepaths to types for Closure Compiler", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -60,2 +60,20 @@ const babel = require('babel-core'); | ||
it('transforms an object property type cast with an imported module in a return statement', function() { | ||
// requires recast, and causes line break changes unfortunately | ||
const source = | ||
'/** @module module2/types */\n' + | ||
'function getFoo() {\n' + | ||
' return /** @type {Object} */ ({\n foo: /** @type {module:module1/Foo} */ (\'bar\')\n });\n' + | ||
'}'; | ||
const expected = | ||
'/** @module module2/types */\n' + | ||
'function getFoo() {\n' + | ||
' return (\n /** @type {Object} */ ({\n foo: /** @type {module1$Foo} */ (\'bar\')\n })\n );\n' + | ||
'}\n' + | ||
'const module1$Foo = require(\'../module1/Foo\');'; | ||
const filename = './test/module2/types.js'; | ||
const got = babel.transform(source, Object.assign({filename}, recastOptions)); | ||
assert.equal(got.code, expected); | ||
}); | ||
it('transforms a type with an imported default export', function() { | ||
@@ -62,0 +80,0 @@ test( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19663
398