Socket
Socket
Sign inDemoInstall

sveltedoc-parser

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sveltedoc-parser - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

4

CHANGELOG.md

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

## [1.1.3] 03.12.2018
- [Fixed] Improve crash handling in parser logic, now all errors fall into `reject(...)` method instead throwing up
## [1.1.2] 30.11.2018

@@ -8,0 +12,0 @@

108

index.js

@@ -18,67 +18,75 @@ const fs = require('fs');

module.exports.parse = (options) => new Promise((resolve) => {
parseOptions(options);
module.exports.parse = (options) => new Promise((resolve, reject) => {
try {
parseOptions(options);
if (!options.source) {
if (options.filename) {
if (path.extname(options.filename) === '.js') {
options.source = {
template: '',
script: fs.readFileSync(options.filename, options.encoding)
};
if (!options.source) {
if (options.filename) {
if (path.extname(options.filename) === '.js') {
options.source = {
template: '',
script: fs.readFileSync(options.filename, options.encoding)
};
} else {
options.source = loadSourceFromFileContent(
fs.readFileSync(options.filename, options.encoding));
}
} else {
options.source = loadSourceFromFileContent(
fs.readFileSync(options.filename, options.encoding));
options.source = loadSourceFromFileContent(options.fileContent);
}
} else {
options.source = loadSourceFromFileContent(options.fileContent);
}
}
const component = {};
const parser = new Parser(options);
const component = {};
const parser = new Parser(options);
parser.features.forEach((feature) => {
switch (feature) {
case 'name':
case 'description':
component[feature] = null;
parser.on(feature, (value) => (component[feature] = value));
break;
parser.features.forEach((feature) => {
switch (feature) {
case 'name':
case 'description':
component[feature] = null;
parser.on(feature, (value) => (component[feature] = value));
break;
case 'keywords':
component[feature] = [];
parser.on(feature, (value) => (component[feature] = value));
break;
case 'keywords':
component[feature] = [];
parser.on(feature, (value) => (component[feature] = value));
break;
default:
component[feature] = [];
default:
component[feature] = [];
const eventName = Parser.getEventName(feature);
const eventName = Parser.getEventName(feature);
parser.on(eventName, (value) => {
const itemIndex = component[feature].findIndex(item => item.name === value.name);
parser.on(eventName, (value) => {
const itemIndex = component[feature].findIndex(item => item.name === value.name);
if (itemIndex < 0) {
component[feature].push(value);
} else {
component[feature][itemIndex] = value;
}
});
}
});
parser.on('end', () => {
parser.features.forEach((feature) => {
if (component[feature] instanceof Array) {
component[feature] = component[feature].filter((item) => {
return !options.ignoredVisibilities.includes(item.visibility);
});
if (itemIndex < 0) {
component[feature].push(value);
} else {
component[feature][itemIndex] = value;
}
});
}
});
resolve(component);
});
parser.on('end', () => {
parser.features.forEach((feature) => {
if (component[feature] instanceof Array) {
component[feature] = component[feature].filter((item) => {
return !options.ignoredVisibilities.includes(item.visibility);
});
}
});
parser.walk();
resolve(component);
});
parser.on('failure', (error) => {
reject(error);
});
parser.walk();
} catch (error) {
reject(error);
}
});

@@ -85,0 +93,0 @@

@@ -333,83 +333,91 @@ const EventEmitter = require('events');

process.nextTick(() => {
if (this.features.length === 0) {
return this.emit('end');
try {
this.internalWalk();
} catch(error) {
this.emit('failure', error);
}
});
if (this.template) {
this.parseTemplate();
}
return this;
}
if (this.ast === null) {
if (this.features.includes('name')) {
this.parseComponentName();
}
internalWalk() {
if (this.features.length === 0) {
return this.emit('end');
}
return this.emit('end');
if (this.template) {
this.parseTemplate();
}
if (this.ast === null) {
if (this.features.includes('name')) {
this.parseComponentName();
}
this.ast.body.forEach((body) => {
const entry = utils.getComment(body, this.defaultMethodVisibility, this.features);
return this.emit('end');
}
if (entry.description) {
this.emit('description', entry.description);
}
this.ast.body.forEach((body) => {
const entry = utils.getComment(body, this.defaultMethodVisibility, this.features);
if (entry.keywords.length) {
this.emit('keywords', entry.keywords);
}
if (entry.description) {
this.emit('description', entry.description);
}
if (body.type === 'ImportDeclaration') {
const specifier = body.specifiers[0];
if (entry.keywords.length) {
this.emit('keywords', entry.keywords);
}
if (specifier && specifier.type === 'ImportDefaultSpecifier') {
const source = body.source;
if (body.type === 'ImportDeclaration') {
const specifier = body.specifiers[0];
if (source && source.type === 'Literal') {
const importEntry = {
identifier: specifier.local.name,
sourceFilename: source.value
};
if (specifier && specifier.type === 'ImportDefaultSpecifier') {
const source = body.source;
if (!this.imports.hasOwnProperty(importEntry.identifier)) {
this.imports[importEntry.identifier] = importEntry;
this.emit('import', importEntry);
}
if (source && source.type === 'Literal') {
const importEntry = {
identifier: specifier.local.name,
sourceFilename: source.value
};
if (!this.imports.hasOwnProperty(importEntry.identifier)) {
this.imports[importEntry.identifier] = importEntry;
this.emit('import', importEntry);
}
}
}
}
if (body.type !== 'ExportDefaultDeclaration' && body.type !== 'ExpressionStatement') {
if (body.type === 'VariableDeclaration') {
this.identifiers[body.declarations[0].id.name] = body.declarations[0].init;
}
return;
if (body.type !== 'ExportDefaultDeclaration' && body.type !== 'ExpressionStatement') {
if (body.type === 'VariableDeclaration') {
this.identifiers[body.declarations[0].id.name] = body.declarations[0].init;
}
if (body.declaration) {
switch (body.declaration.type) {
case 'ObjectExpression':
body.declaration.properties.forEach((property) => this.extractProperties(property));
break;
return;
}
case 'Identifier':
if (this.identifiers.hasOwnProperty(body.declaration.name)) {
this.identifiers[body.declaration.name].properties.forEach((property) => this.extractProperties(property));
}
if (body.declaration) {
switch (body.declaration.type) {
case 'ObjectExpression':
body.declaration.properties.forEach((property) => this.extractProperties(property));
break;
break;
}
} else if (body.expression !== null && body.expression.right && body.expression.right.properties) {
body.expression.right.properties.forEach((property) => this.extractProperties(property));
}
case 'Identifier':
if (this.identifiers.hasOwnProperty(body.declaration.name)) {
this.identifiers[body.declaration.name].properties.forEach((property) => this.extractProperties(property));
}
if (this.features.includes('name')) {
this.parseComponentName();
break;
}
});
} else if (body.expression !== null && body.expression.right && body.expression.right.properties) {
body.expression.right.properties.forEach((property) => this.extractProperties(property));
}
this.emit('end');
if (this.features.includes('name')) {
this.parseComponentName();
}
});
return this;
this.emit('end');
}

@@ -416,0 +424,0 @@

{
"name": "sveltedoc-parser",
"version": "1.1.2",
"version": "1.1.3",
"description": "Generate a JSON documentation for a Svelte file",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

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