Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-docgen-api

Package Overview
Dependencies
Maintainers
3
Versions
271
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-docgen-api - npm Package Compare versions

Comparing version 4.32.4 to 4.33.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [4.33.0](https://github.com/vue-styleguidist/vue-styleguidist/compare/v4.32.4...v4.33.0) (2020-10-12)
### Features
* **docgen:** parse emits option from vue 3 ([0469224](https://github.com/vue-styleguidist/vue-styleguidist/commit/0469224f92355dfa867a528f8123d7ef181a387c)), closes [#965](https://github.com/vue-styleguidist/vue-styleguidist/issues/965)
## [4.32.4](https://github.com/vue-styleguidist/vue-styleguidist/compare/v4.32.3...v4.32.4) (2020-09-24)

@@ -8,0 +19,0 @@

1

dist/script-handlers/classEventHandler.d.ts

@@ -9,3 +9,4 @@ import * as bt from '@babel/types';

* @param astPath
* @deprecated use eventHandler instead
*/
export default function classEventHandler(documentation: Documentation, path: NodePath, astPath: bt.File): Promise<void>;

@@ -36,2 +36,3 @@ "use strict";

* @param astPath
* @deprecated use eventHandler instead
*/

@@ -38,0 +39,0 @@ function classEventHandler(documentation, path, astPath) {

@@ -8,3 +8,5 @@ import * as bt from '@babel/types';

/**
* Extracts events information from an object-style VueJs component
* Extracts events information from a VueJs component
* wether it's a class based component or an option based one
*
* @param documentation

@@ -15,2 +17,18 @@ * @param path

export default function eventHandler(documentation: Documentation, path: NodePath, astPath: bt.File): Promise<void>;
/**
* Extracts events information from an
* object-style VueJs component `emits` option
*
* @param documentation
* @param path
*/
export declare function eventHandlerEmits(documentation: Documentation, path: NodePath): void;
/**
* Extracts events information from an
* object-style VueJs component `methods` option
*
* @param documentation
* @param path
*/
export declare function eventHandlerMethods(documentation: Documentation, path: NodePath): void;
export declare function setEventDescriptor(eventDescriptor: EventDescriptor, jsDoc: DocBlockTags): EventDescriptor;

136

dist/script-handlers/eventHandler.js

@@ -25,3 +25,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.setEventDescriptor = void 0;
exports.setEventDescriptor = exports.eventHandlerMethods = exports.eventHandlerEmits = void 0;
var bt = __importStar(require("@babel/types"));

@@ -39,3 +39,5 @@ var recast_1 = require("recast");

/**
* Extracts events information from an object-style VueJs component
* Extracts events information from a VueJs component
* wether it's a class based component or an option based one
*
* @param documentation

@@ -47,39 +49,6 @@ * @param path

if (bt.isObjectExpression(path.node)) {
var methodsPath = path
.get('properties')
.filter(function (p) { return bt.isObjectProperty(p.node) && getPropsFilter_1.default('methods')(p); });
// if no method return
if (!methodsPath.length) {
return Promise.resolve();
}
var methodsObject = methodsPath[0].get('value');
if (bt.isObjectExpression(methodsObject.node)) {
methodsObject.get('properties').each(function (p) {
var commentedMethod = bt.isObjectMethod(p.node) ? p : p.parentPath;
var jsDocTags = (getCommentBlockAndTags(commentedMethod) || {}).tags;
if (!jsDocTags) {
return;
}
var firesTags = jsDocTags.filter(function (tag) { return tag.title === 'fires'; })[0];
if (firesTags) {
var eventName_1 = firesTags.content;
var eventDescriptor = documentation.getEventDescriptor(eventName_1);
var currentBlock = {};
var foundEventDesciptor = void 0;
var commentIndex = 1;
while (currentBlock && !foundEventDesciptor) {
currentBlock = getCommentBlockAndTags(commentedMethod, { commentIndex: ++commentIndex });
if (currentBlock &&
currentBlock.tags &&
currentBlock.tags.some(function (tag) { return tag.title === 'event' && tag.content === eventName_1; })) {
foundEventDesciptor = currentBlock;
}
}
if (foundEventDesciptor) {
setEventDescriptor(eventDescriptor, foundEventDesciptor);
}
}
});
}
eventHandlerMethods(documentation, path);
eventHandlerEmits(documentation, path);
}
// browse the entirety of the code inside the component to look for this.$emit
recast_1.visit(path.node, {

@@ -144,2 +113,93 @@ visitCallExpression: function (pathExpression) {

/**
* Extracts events information from an
* object-style VueJs component `emits` option
*
* @param documentation
* @param path
*/
function eventHandlerEmits(documentation, path) {
var emitsPath = path
.get('properties')
.filter(function (p) { return bt.isObjectProperty(p.node) && getPropsFilter_1.default('emits')(p); });
// if no emits member return
if (!emitsPath.length) {
return;
}
var emitsObject = emitsPath[0].get('value');
if (bt.isArrayExpression(emitsObject.node)) {
emitsObject.get('elements').value.forEach(function (event, i) {
if (bt.isStringLiteral(event)) {
var eventDescriptor = documentation.getEventDescriptor(event.value);
var eventPath = emitsObject.get('elements', i);
var docblock = getDocblock_1.default(eventPath);
var doclets = getDoclets_1.default(docblock || '');
setEventDescriptor(eventDescriptor, doclets);
}
});
}
else if (bt.isObjectExpression(emitsObject.node)) {
emitsObject.get('properties').value.forEach(function (event, i) {
var eventName = bt.isStringLiteral(event.key)
? event.key.value
: bt.isIdentifier(event.key)
? event.key.name
: undefined;
if (eventName) {
var eventDescriptor = documentation.getEventDescriptor(eventName);
var eventPath = emitsObject.get('properties', i);
var docblock = getDocblock_1.default(eventPath);
var doclets = getDoclets_1.default(docblock || '');
setEventDescriptor(eventDescriptor, doclets);
}
});
}
}
exports.eventHandlerEmits = eventHandlerEmits;
/**
* Extracts events information from an
* object-style VueJs component `methods` option
*
* @param documentation
* @param path
*/
function eventHandlerMethods(documentation, path) {
var methodsPath = path
.get('properties')
.filter(function (p) { return bt.isObjectProperty(p.node) && getPropsFilter_1.default('methods')(p); });
// if no method return
if (!methodsPath.length) {
return;
}
var methodsObject = methodsPath[0].get('value');
if (bt.isObjectExpression(methodsObject.node)) {
methodsObject.get('properties').each(function (p) {
var commentedMethod = bt.isObjectMethod(p.node) ? p : p.parentPath;
var jsDocTags = (getCommentBlockAndTags(commentedMethod) || {}).tags;
if (!jsDocTags) {
return;
}
var firesTags = jsDocTags.filter(function (tag) { return tag.title === 'fires'; })[0];
if (firesTags) {
var eventName_1 = firesTags.content;
var eventDescriptor = documentation.getEventDescriptor(eventName_1);
var currentBlock = {};
var foundEventDesciptor = void 0;
var commentIndex = 1;
while (currentBlock && !foundEventDesciptor) {
currentBlock = getCommentBlockAndTags(commentedMethod, { commentIndex: ++commentIndex });
if (currentBlock &&
currentBlock.tags &&
currentBlock.tags.some(function (tag) { return tag.title === 'event' && tag.content === eventName_1; })) {
foundEventDesciptor = currentBlock;
}
}
if (foundEventDesciptor) {
setEventDescriptor(eventDescriptor, foundEventDesciptor);
}
}
});
}
}
exports.eventHandlerMethods = eventHandlerMethods;
/**
* Accepted tags for conveying event properties

@@ -146,0 +206,0 @@ */

@@ -38,3 +38,3 @@ "use strict";

*/
var VUE_COMPONENTS_KEYS = ['data', 'props', 'methods', 'computed'];
var VUE_COMPONENTS_KEYS = ['data', 'props', 'methods', 'computed', 'emits'];
function isObjectExpressionComponentDefinition(node) {

@@ -41,0 +41,0 @@ return (

{
"name": "vue-docgen-api",
"version": "4.32.4",
"version": "4.33.0",
"description": "Toolbox to extract information from Vue component files for documentation generation purposes.",

@@ -41,3 +41,3 @@ "homepage": "https://vue-styleguidist.github.io",

"ts-map": "^1.0.3",
"vue-inbrowser-compiler-utils": "^4.32.1"
"vue-inbrowser-compiler-utils": "^4.33.0"
},

@@ -54,3 +54,3 @@ "devDependencies": {

},
"gitHead": "75910d5c914623742741fcdd456e81233a19eaa2"
"gitHead": "8769bab0a35f8bbaadec6cc6218ca9beba3e409a"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc