Socket
Socket
Sign inDemoInstall

@condenast/ember-docs

Package Overview
Dependencies
Maintainers
293
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@condenast/ember-docs - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

tests/fixtures/classic/app/components/yield-param.js

4

index.js

@@ -22,7 +22,7 @@ const doctrine = require('doctrine');

} else if (info.type === 'component') {
return component(ast, info, jsdoc);
return component(ast, info, path);
} else if (info.type === 'service') {
return service(ast, info, jsdoc);
return service(ast, info, path);
}
}
}
{
"name": "@condenast/ember-docs",
"version": "0.1.7",
"version": "0.1.8",
"description": "Creates documentation from Ember apps / addons",

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

const commonmark = require('commonmark');
const doctrine = require('doctrine');
const utils = require('./utils');
const path = require('path');
const fs = require('fs');
const syntax = require('@glimmer/syntax');

@@ -8,3 +11,3 @@ function getPositionalParameters(ast, component) {

let positionalParams = staticProperties.find(property => property.key.name === 'positionalParams');
if (positionalParams) {

@@ -29,4 +32,4 @@ if (positionalParams.value.type === 'ArrayExpression') {

if (comment == null) return false;
let doc = doctrine.parse(comment.value, { unwrap: false, recoverable: true });
let doc = doctrine.parse(utils.unindent(comment.value), { unwrap: false, recoverable: true });
let property = doc.tags.find(tag => tag.title === 'property');

@@ -38,3 +41,3 @@ return property;

});
let doc = doctrine.parse(comment.value, { unwrap: false, recoverable: true });
let doc = doctrine.parse(utils.unindent(comment.value), { unwrap: false, recoverable: true });
let property = doc.tags.find(tag => tag.title === 'property');

@@ -65,5 +68,56 @@ let type = property.type;

module.exports = function (ast, info, jsdoc) {
function getYields(ast, filepath) {
let layout = utils.getProperties(ast).find(param => param.key.name === 'layout');
if (layout && layout.value) {
let template = utils.findImportFromReference(ast, layout.value);
let templatePath = path.normalize(filepath.split('/').slice(0, -1).join('/') + '/' + template.source + '.hbs');
if (fs.existsSync(templatePath)) {
let params = []
let hbs = fs.readFileSync(templatePath).toString();
syntax.traverse(syntax.preprocess(hbs), {
MustacheStatement(node) {
if (node.path.original === 'yield') {
params = params.concat(node.params.map(getValueFromParam));
}
},
});
return params;
}
}
return null;
}
function getValueFromParam(param) {
if (param.type === 'PathExpression') {
return {
type: 'path',
value: param.original
};
}
if (param.type === 'SubExpression') {
// parsing helpers for array, hash, etc can go here
if (param.path.original === 'hash') {
return {
type: 'hash',
value: param.hash.pairs.reduce((obj, pair) => {
obj[pair.key] = getValueFromParam(pair.value);
return obj;
}, {})
};
}
}
return {
type: null,
value: null
}
}
module.exports = function (ast, info, filepath) {
let component = utils.getMain(ast);
let mainComment = (component.leadingComments || []).find((comment) => {
let mainComment = (component && component.leadingComments || []).find((comment) => {
return comment.type === 'CommentBlock';

@@ -92,2 +146,4 @@ });

docs.parameters = getParameters(ast, component);
docs.yields = getYields(ast, filepath);
return docs;

@@ -94,0 +150,0 @@ }

@@ -7,3 +7,3 @@ const commonmark = require('commonmark');

let service = utils.getMain(ast);
let mainComment = (service.leadingComments || []).find((comment) => {
let mainComment = (service && service.leadingComments || []).find((comment) => {
return comment.type === 'CommentBlock';

@@ -10,0 +10,0 @@ });

@@ -21,3 +21,3 @@ const _ = require('lodash');

return jsdocType.name;
// Turn an expression back into a normalized TypeScript type

@@ -48,3 +48,3 @@ } else if (jsdocType && jsdocType.expression) {

let indent = text.split('\n').reduce((indentation, line) => {
if (line.length === 0) {
if (line.match(/^\s*$/) || line === '*') {
return indentation;

@@ -209,6 +209,7 @@ }

for (let s = 0, slen = statement.specifiers.length; s < slen; s++) {
if (s.imported.name === reference.name) {
let specifier = statement.specifiers[s];
if (specifier.local && specifier.local.name === reference.name) {
return {
source: statement.value,
name: s.imported ? s.imported.name : 'default'
source: statement.source.value,
name: specifier.local ? specifier.local.name : 'default'
};

@@ -288,2 +289,1 @@ }

module.exports = utils;

@@ -79,2 +79,24 @@ const parse = require('../../index');

test('yield-param', () => {
let component = parse(path.resolve(__dirname, '../fixtures/classic/app/components/yield-param.js'), {});
expect(component.name).toBe('yield-param');
expect(component.access).toBe('public');
expect(component.description).toEqual([
'<p>This component will test yield blocks</p>\n'
]);
expect(component.parameters).toEqual({
named: [{
name: 'first',
description: [''],
type: 'string'
}, {
name: 'second',
description: [''],
type: 'string'
}],
positional: []
});
});
describe('pods', () => {

@@ -81,0 +103,0 @@ test('text-field', () => {

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