Skip to content

Commit

Permalink
Fix issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprey committed Nov 25, 2019
1 parent d149809 commit e48a67f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to the "svelte-intellisense" extension will be documented in

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [2.3.1] 25.11.2019

- [Fixed] Svelte V3: Fix parsing issues when anonymous functions are used in event handlers at markup (Issue #18)

## [2.3.0] 02.10.2019

- [Added] Svelte V3: Implement support of script element locations
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Generate a JSON documentation for a Svelte file
- [Added] Spec: Property `locations` was added to items and presents the list of item code locations
- [Changed] Spec: Property `loc` for items marked as depricated, see `locations` property instead

### [2.3.1] 25.11.2019

- [Fixed] Svelte V3: Fix parsing issues when anonymous functions are used in event handlers at markup (Issue #18)

Full changelog of release versions can be found [here](/CHANGELOG.md)

## Install
Expand Down
6 changes: 6 additions & 0 deletions lib/v3/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ class Parser extends EventEmitter {
}

parseMarkupExpressionBlock(expression, offset) {
// Add name for anonymous functions to prevent parser error
const regex = /^{\s*function\s+\(/i;
expression = expression.replace(regex, function() {
return "{function a(";
});

const ast = espree.parse(
expression,
this.getAstParsingOptions()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sveltedoc-parser",
"version": "2.3.0",
"version": "2.3.1",
"description": "Generate a JSON documentation for a Svelte file",
"main": "index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
</script>

<button on:click="{function () { dispatch('notify'); }}">
CLICK!
</button>
23 changes: 23 additions & 0 deletions test/svelte3/integration/events/events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ describe('SvelteDoc v3 - Events', () => {
});
});

it('Dispatch event from markup with anon function expression should be found', (done) => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'event.markup.dispatcher.default.function.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('notify');
expect(event.visibility).to.equal('public');

done();
}).catch(e => {
done(e);
});
});

it('Dispatch event from code method should be found', (done) => {
parser.parse({
version: 3,
Expand Down

0 comments on commit e48a67f

Please sign in to comment.