From 92ebfb995d0ddec3d9ea77b5b3a6c3b8d6babfc8 Mon Sep 17 00:00:00 2001 From: Alexey Mulyukin Date: Tue, 30 Oct 2018 17:36:19 +0300 Subject: [PATCH] Small design fixes --- .gitignore | 2 +- .npmignore | 4 +++ README.md | 31 +++++++++++++++++-- package.json | 2 +- .../event.method.fire.identifier.svelte | 23 ++++++++++++++ test/events/events.spec.js | 24 ++++++++++++++ 6 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 .npmignore create mode 100644 test/events/event.method.fire.identifier.svelte diff --git a/.gitignore b/.gitignore index 97bfbfa..356b4d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /node_modules *.log -/build \ No newline at end of file +/build diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..5a3d649 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +/test +.eslintrc.json +.gitignore +yarn.lock \ No newline at end of file diff --git a/README.md b/README.md index 3ceef7f..4b33c48 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,16 @@ # The sveltedoc parser -## Key Features +Generate a JSON documentation for a Svelte file + +[![npm](https://img.shields.io/npm/v/sveltedoc-parser.svg)](https://www.npmjs.com/package/sveltedoc-parser) + +## Install + +```shell +npm install --save sveltedoc-parser +``` + +## Features - JSDoc support - Extract the component description from JSDoc @@ -22,10 +32,27 @@ |---------|-----------|---------------| | **filename** | The filename to parse. **Required**, unless `fileContent` is passed. | | | **fileContent** | The file content to parse. **Required**, unless `filename` is passed. | | -| **encoding** | The file encoding. | 'utf8' | +| **encoding** | The file encoding. | `utf8` | | **features** | The component features to parse and extracting. | By default used all supported features. | | **ignoredVisibilities** | The list of ignored visibilities. | `['private', 'protected']` | +## Usage + +```js +const sveltedoc = require('sveltedoc-parser'); +const options = { + filename: 'main.svelte' +}; + +sveltedoc.parse(options) + .then(componentDoc => { + console.log(componentDoc); + }) + .catch(e => { + console.error(e); + }); +``` + ## Issues All list of known issues presented at [this page](https://github.com/alexprey/sveltedoc-parser/issues). diff --git a/package.json b/package.json index 0f070f4..d6892e6 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@sveltedoc/parser", + "name": "sveltedoc-parser", "version": "1.0.0", "description": "Generate a JSON documentation for a Svelte file", "main": "index.js", diff --git a/test/events/event.method.fire.identifier.svelte b/test/events/event.method.fire.identifier.svelte new file mode 100644 index 0000000..56e37a5 --- /dev/null +++ b/test/events/event.method.fire.identifier.svelte @@ -0,0 +1,23 @@ +
+ +
+ + \ No newline at end of file diff --git a/test/events/events.spec.js b/test/events/events.spec.js index 05194f4..76a5057 100644 --- a/test/events/events.spec.js +++ b/test/events/events.spec.js @@ -53,6 +53,30 @@ describe('Events', () => { }); }); + it('Fired events with identifier event name in component methods should be parsed', (done) => { + parser.parse({ + filename: path.resolve(__dirname, 'event.method.fire.identifier.svelte'), + features: ['events'], + ignoredVisibilities: [] + }).then((doc) => { + expect(doc, 'Document should be provided').to.exist; + expect(doc.events, 'Document events should be parsed').to.exist; + + expect(doc.events.length).to.equal(1); + const event = doc.events[0]; + + expect(event, 'Event should be a valid entity').to.exist; + expect(event.name).to.equal('click'); + expect(event.visibility).to.equal('public'); + expect(event.parent).to.be.null; + expect(event.description).to.equal('Event fired when user clicked on button.'); + + done(); + }).catch(e => { + done(e); + }); + }); + it('Propogated events in markup should be parsed', (done) => { parser.parse({ filename: path.resolve(__dirname, 'event.markup.propogate.svelte'),