Skip to content

Commit

Permalink
Fix eslint run on CI
Browse files Browse the repository at this point in the history
Fix all eslint issues
Fix tests
Update version and docs
  • Loading branch information
alexprey committed Dec 10, 2019
1 parent 259534d commit e69d9da
Show file tree
Hide file tree
Showing 27 changed files with 232 additions and 175 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ 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.4] 10.12.2019

- [Fixed] Now `keywords` feature correctly supported.

Thanks to [hontas](https://github.com/hontas) for following changes:

- [Fixed] Svelte V3: Fix parsing of types for data items, defined by `@type` keyword.

## [2.3.3] 05.12.2019

Thanks to [hontas](https://github.com/hontas) for following changes:
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@ Generate a JSON documentation for a Svelte file

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

## [2.3.2] 02.12.2019
### [2.3.2] 02.12.2019

Thanks to [hontas](https://github.com/hontas) for following fixes:

- [Fixed] Svelte V3: Improve type parsing for properties with default values.
- [Fixed] Svelte V3: In some cases `type` property was setup with wrong structure and data, now it fixed.

## [2.3.3] 05.12.2019
### [2.3.3] 05.12.2019

Thanks to [hontas](https://github.com/hontas) for following changes:

- [Added] Svelte V3: Implement component documentation parsing provided by top level comment in HTML markup or in the JS section, marked with `@component` JSDoc attribute.

### [2.3.4] 10.12.2019

- [Fixed] Now `keywords` feature correctly supported.

Thanks to [hontas](https://github.com/hontas) for following changes:

- [Fixed] Svelte V3: Fix parsing of types for data items, defined by `@type` keyword.

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

## Install
Expand Down Expand Up @@ -100,6 +108,7 @@ npm install --save sveltedoc-parser
- `'helpers'` - Extract the list of component helpers (_Supported by Svelte 2_).
- `'components'` - Extract the list of imported components (_Supported by Svelte 2 and Svelte 3_).
- `'description'` - Extract the component description (_Supported by Svelte 2 and Svelte 3_).
- `'keywords'` - Extract the component keywords (_Supported by Svelte 2 and Svelte 3_).
- `'events'` - Extract the list of events that fired by this component (_Supported by Svelte 2 and Svelte 3_).
- `'slots'` - Extract the list of slots provided by this component (_Supported by Svelte 2 and Svelte 3_).
- `'transitions'` - Extract the list of transitions used by this component (_Supported by Svelte 2_).
Expand Down
6 changes: 3 additions & 3 deletions lib/detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const SVELTE_VERSION_2 = 2;
const SVELTE_VERSION_3 = 3;

function isElseIfWithoutSpaceInTemplate(template) {
return /\{\:elseif\s/gi.test(template);
return /\{:elseif\s/gi.test(template);
}

function isElseIfWithSpaceInTemplate(template) {
Expand All @@ -16,11 +16,11 @@ function isRefsIsUsedInTemplate(template) {
}

function isLetUsedForSlotInTemplate(template) {
return /\slet\:[^=]+=/gi.test(template);
return /\slet:[^=]+=/gi.test(template);
}

function isContextUsedForScriptBlock(scriptBlock) {
return /\scontext\=/gi.test(scriptBlock.attributes);
return /\scontext=/gi.test(scriptBlock.attributes);
}

function isExportDefaultUsedInBlock(scriptBlock) {
Expand Down
6 changes: 5 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function loadFileStructureFromOptions(options) {
};
} else {
const buffer = fs.readFileSync(options.filename, options.encoding);

return parseFileStructureFromContent(buffer.toString());
}
}
Expand All @@ -32,6 +33,7 @@ function loadFileStructureFromOptions(options) {

function extractHtmlBlock(content, blockName, searchStartIndex) {
const blockOuterStartIndex = content.indexOf(`<${blockName}`, searchStartIndex);

if (blockOuterStartIndex >= 0) {
const blockInnerEndIndex = content.indexOf(`</${blockName}>`, blockOuterStartIndex + blockName.length + 1);

Expand Down Expand Up @@ -67,10 +69,12 @@ function extractAllHtmlBlocks(content, blockName) {
const blocks = [];

let searchResult = extractHtmlBlock(content, blockName);

while (searchResult.block) {
blocks.push(searchResult.block);

const searchStartIndex = searchResult.block.outerPosition.end;

searchResult = extractHtmlBlock(content, blockName, searchStartIndex);
}

Expand All @@ -88,7 +92,7 @@ function parseFileStructureFromContent(fileContent) {
template: fileContent,
scripts: scriptBlocksSearchResult.blocks,
styles: styleBlocksSearchResult.blocks
}
};
}

module.exports = {
Expand Down
90 changes: 35 additions & 55 deletions lib/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const TYPE = '\\{([^\\}]*)\\}';
const PARAM_TYPE = '\\{((?:\\.\\.\\.)?[^\\}]*)=?\\}';

const TYPE_RE = new RegExp(`^\\s*${TYPE}`, 'i');
const PARAM_RE = new RegExp(`^\\s*(?:${PARAM_TYPE}\\s+)?(?:\\[\\s*(${PARAM_NAME})\\s*(?:=\s*([^\\]]+))?\\]|(${PARAM_NAME}))(?:\\s+(?:\\-\\s+)?(.*))?`, 'i');
const PARAM_RE = new RegExp(`^\\s*(?:${PARAM_TYPE}\\s+)?(?:\\[\\s*(${PARAM_NAME})\\s*(?:=\\s*([^\\]]+))?\\]|(${PARAM_NAME}))(?:\\s+(?:\\-\\s+)?(.*))?`, 'i');
const RETURN_RE = new RegExp(`^\\s*(${TYPE}\\s+)?-?(.*)`, 'i');

const DEFAULT_TYPE = 'any';
Expand All @@ -25,6 +25,7 @@ function parseType(type, param) {

function parseJSDocType(typeValue) {
typeValue = typeValue.trim();

if (typeValue.indexOf('|') > -1) {
if (typeValue.startsWith('(') && typeValue.endsWith(')')) {
typeValue = typeValue.substring(1, typeValue.length - 1).trim();
Expand All @@ -33,36 +34,36 @@ function parseJSDocType(typeValue) {
const types = typeValue.split('|');

return {
'kind': 'union',
'text': typeValue,
'type': types
kind: 'union',
text: typeValue,
type: types
.map(type => parseJSDocType(type))
.filter(type => type != null)
}
};
}

if (typeValue.startsWith('\'') && typeValue.endsWith('\'')) {
return {
'kind': 'const',
'text': typeValue,
'type': 'string',
'value': typeValue.substr(1, typeValue.length - 2)
}
kind: 'const',
text: typeValue,
type: 'string',
value: typeValue.substr(1, typeValue.length - 2)
};
}

if (typeValue === '*') {
return {
'kind': 'type',
'text': typeValue,
'type': DEFAULT_TYPE
}
kind: 'type',
text: typeValue,
type: DEFAULT_TYPE
};
}

return {
'kind': 'type',
'text': typeValue,
'type': typeValue
}
kind: 'type',
text: typeValue,
type: typeValue
};
}

function parseJSTypeFromValueNode(valueNode) {
Expand All @@ -72,24 +73,24 @@ function parseJSTypeFromValueNode(valueNode) {

if (valueNode.type === 'ArrayExpression') {
return {
'kind': 'type',
'text': 'Array<any>',
'type': 'Array<any>'
kind: 'type',
text: 'Array<any>',
type: 'Array<any>'
};
}

if (typeof(valueNode) === 'object') {
if (typeof (valueNode) === 'object') {
return {
'kind': 'type',
'text': 'any',
'type': 'any'
kind: 'type',
text: 'any',
type: 'any'
};
}

return {
'kind': 'type',
'text': typeof(valueNode),
'type': typeof(valueNode)
kind: 'type',
text: typeof (valueNode),
type: typeof (valueNode)
};
}

Expand All @@ -110,16 +111,16 @@ function parseTypeKeyword(text) {
function parseParamKeyword(text) {
const param = {
type: {
'kind': 'type',
'text': '*',
'type': DEFAULT_TYPE
kind: 'type',
text: '*',
type: DEFAULT_TYPE
},
name: null,
name: null,
optional: false,
default: null,
description: null
};

const match = PARAM_RE.exec(text);

if (match) {
Expand Down Expand Up @@ -163,27 +164,6 @@ function parseParamKeyword(text) {
}

return param;

if (match) {
if (match[2]) {
param.type = parseJSDocType(match[2]);
}

if (match[3][0] === '[') {
param.optional = true;
param.name = match[4] || match[3].substring(1, match[3].length - 1);

if (match[6]) {
param.default = match[6];
}
} else {
param.name = match[3];
}

param.description = match[7];
}

return param;
}

function parseReturnKeyword(text) {
Expand All @@ -207,4 +187,4 @@ module.exports = {
parseJSTypeFromValueNode,

DEFAULT_TYPE
};
};
Loading

0 comments on commit e69d9da

Please sign in to comment.