babel-plugin-jsdoc-closure
Advanced tools
Comparing version 1.4.1 to 1.4.2
25
index.js
@@ -67,3 +67,26 @@ const parseComment = require('comment-parser'); | ||
if (lookup in imports) { | ||
replacement = imports[lookup]; | ||
let useImport = true; | ||
if (!path.extname(lookup)) { | ||
const dependency = require.resolve(path.resolve(path.dirname(resourcePath), lookup)); | ||
const content = babel.transform(fs.readFileSync(dependency, 'utf-8')); | ||
const candidates = content.ast.program.body; | ||
outer: | ||
for (let i = 0, ii = candidates.length; i < ii; ++i) { | ||
const node = candidates[i]; | ||
if (node.type == 'ExportDefaultDeclaration') { | ||
const comments = node.leadingComments; | ||
if (comments) { | ||
for (let i = 0, ii = comments.length; i < ii; ++i) { | ||
if (comments[i].value.indexOf('@enum') !== -1) { | ||
useImport = false; | ||
break outer; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (useImport) { | ||
replacement = imports[lookup]; | ||
} | ||
} | ||
@@ -70,0 +93,0 @@ newComment = comment.value.replace(new RegExp(`${type}([^~])`, 'g'), `${replacement}$1`); |
{ | ||
"name": "babel-plugin-jsdoc-closure", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Transpiles JSDoc types from namepaths to types for Closure Compiler", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -103,2 +103,17 @@ const babel = require('babel-core'); | ||
it('transforms an enum imported as default export', function() { | ||
test( | ||
'/** @module module2/types */\n' + | ||
'import Bar from \'../module1/Bar\';\n' + | ||
'/** @type {module:module1/Type} */\n' + | ||
'let foo;', | ||
'/** @module module2/types */\n' + | ||
'import Bar from \'../module1/Bar\';\n' + | ||
'/** @type {../module1/Type} */\n' + | ||
'let foo;', | ||
'./test/module2/types.js' | ||
); | ||
}); | ||
it('transforms a type with a JSDoc module path', function() { | ||
@@ -105,0 +120,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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
21367
12
452
3