diff --git a/CHANGELOG.md b/CHANGELOG.md index bbc04bb..d41f86f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 08c766e..a908be8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/v3/parser.js b/lib/v3/parser.js index 6e8a806..f813a4c 100644 --- a/lib/v3/parser.js +++ b/lib/v3/parser.js @@ -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() diff --git a/package.json b/package.json index 533ee66..35cf341 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/svelte3/integration/events/event.markup.dispatcher.default.function.svelte b/test/svelte3/integration/events/event.markup.dispatcher.default.function.svelte new file mode 100644 index 0000000..37d119f --- /dev/null +++ b/test/svelte3/integration/events/event.markup.dispatcher.default.function.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/test/svelte3/integration/events/events.spec.js b/test/svelte3/integration/events/events.spec.js index 3699581..d72bbb2 100644 --- a/test/svelte3/integration/events/events.spec.js +++ b/test/svelte3/integration/events/events.spec.js @@ -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,