Skip to content

Commit

Permalink
Update typings and prepare package for new major release (4.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprey committed Nov 30, 2020
1 parent afb6115 commit f6bd789
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 77 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ 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.

## [4.0.0] UNRELEASED

- 🛠 **[Fixed]** Fix [Issue #42](https://github.com/alexprey/sveltedoc-parser/issues/42)
-**[Added]** Support to complete parsing of component method arguments [Issue #39](https://github.com/alexprey/sveltedoc-parser/issues/39). Thanks for [@soft-decay](https://github.com/soft-decay)
-**[Added]** Support to parse return types and description for methods in component [Issue #37](https://github.com/alexprey/sveltedoc-parser/issues/37). Thanks for [@soft-decay](https://github.com/soft-decay)
- 🔥 **[Breaking]** API rework for component methods description:
- `args` property was renamed to `params`;
- Change the structure of `return` item for methods:
- `desc` property was renamed to `description`;
- `type` property now contains the `JSDocType` object, instead of `string` type with text representation of type. This can be gets from `text` property of `JSDocType` object;
- [Svelte2]: method arguments was presented with plain array with names, now that replaced with objects of `SvelteMethodParamItem` type;
- 🔥 **[Breaking]** Cleanup depricated code:
- `loc` property was removed, please use `locations` instead, if you late with upgrade;
- `value` property of `SvelteComponentItem` was removed, please use `importPath` instead

## [3.0.5] 28.11.2020

- 🛠 **[Fixed]** Fix [Issue #35](https://github.com/alexprey/sveltedoc-parser/issues/35): Object literals not supported in @type keyword. Thanks for @soft-decay
Expand Down
36 changes: 1 addition & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,7 @@ Generate a JSON documentation for a Svelte file

## Changelog

## [3.0.5] 28.11.2020

- 🛠 **[Fixed]** Fix [Issue #35](https://github.com/alexprey/sveltedoc-parser/issues/35): Object literals not supported in @type keyword. Thanks for @soft-decay

### [3.0.4] 25.08.2020

- 🛠 **[Fixed]** Fix [issue #5](https://github.com/alexprey/sveltedoc-parser/issues/5) (slots items have a private access level by default)

### [3.0.3] 25.08.2020

- 🛠 **[Fixed]** Fix [issue #28](https://github.com/alexprey/sveltedoc-parser/issues/28) (Inline event handlers in markup cause errors when used without quotes)
- Change dependency from `htmlparser2` to [htmlparser2-svelte](https://www.npmjs.com/package/htmlparser2-svelte) special fork of [htmlparser2](https://www.npmjs.com/package/htmlparser2) to handle Svelte specific cases to parse markup

### [3.0.2] 24.08.2020

- 🛠 **[Fixed]** Fix issue #6 (Build a correct component name from a file name)
```
round.button.svelte -> RoundButton
```
- 🛠 **[Fixed]** Fix issue #27 (Events is not exposed from exported functions and arrow functions)
- 🛠 **[Fixed]** Fix issue #31 (Propogated events in markup should be parsed even it was before handled)
- 🛠 **[Fixed]** Fix issue #32 (Event is not registered when dispatched from functions used as a parameters of another functions)

### [3.0.1] 17.08.2020

- 🛠 **[Fixed]** Solve issue #26, support `export { variables as var }` statement.
-**[Added]** now interface `SvelteDataItem` provides a new property `localName` with information about internal name of component property.

### [3.0.0] 08.08.2020

- 🛠 **[Fixed]** Solve vulnerability issues:
- Update `espree` to `7.2.0`
- Update `htmlparser2` to `3.9.2`
- Add dependency to `eslint` to fix issues after upgrading to new versions
- 🔥 **[Breaking]** Increase requirement of Node.js to `10.0.0`, Node.js v8 now is not supported, this is related with security isssues above. Please let me know if it still required.
...TBD...

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

Expand Down
2 changes: 1 addition & 1 deletion examples/Button.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
},
"name": "question",
"optional": true,
"default": "Why?",
"defaultValue": "Why?",
"description": "a question about life, the universe, everything"
}
],
Expand Down
14 changes: 8 additions & 6 deletions lib/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ function parseParamKeyword(text) {
const param = {
type: getDefaultJSDocType(),
name: null,
optional: false,
default: null
description: null,
optional: false
};

const match = PARAM_RE.exec(text);
Expand Down Expand Up @@ -152,7 +152,7 @@ function parseParamKeyword(text) {
param.optional = true;

if (match[3]) {
param.default = match[3].trim();
param.defaultValue = match[3].trim();
}
}

Expand All @@ -175,16 +175,18 @@ function parseReturnKeyword(text) {
type: getDefaultJSDocType(),
description: null
};

const matches = RETURN_RE.exec(text);
const typeMatch = matches[2]; // type, excluding curly braces
const descMatch = matches[4]; // description, excluding prefix

if (typeMatch) {
output.type = parseJSDocType(typeMatch);
}

if (descMatch) {
output.description = descMatch.trim();
const descriptionMatch = matches[4]; // description, excluding prefix

if (descriptionMatch) {
output.description = descriptionMatch.trim();
}

return output;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "sveltedoc-parser",
"version": "3.0.5",
"version": "4.0.0",
"description": "Generate a JSON documentation for a Svelte file",
"main": "index.js",
"types": "./typings.d.ts",
"scripts": {
"lint": "eslint ./**/*.js",
"test": "mocha ./test/**/*.spec.js",
Expand Down
1 change: 0 additions & 1 deletion test/svelte2/integration/overall/overall.main.doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@
},
"name": "actionName",
"optional": false,
"default": null,
"description": "The name of action that should be performed."
}
]
Expand Down
6 changes: 3 additions & 3 deletions test/unit/jsdoc/jsdoc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('JSDoc parser module tests', () => {

expect(param).is.exist;
expect(param.name).is.equal('parameter');
expect(param.default).is.not.exist;
expect(param.defaultValue).is.not.exist;
expect(param.optional).is.true;
});

Expand All @@ -197,7 +197,7 @@ describe('JSDoc parser module tests', () => {

expect(param).is.exist;
expect(param.name).is.equal('parameter');
expect(param.default).is.not.exist;
expect(param.defaultValue).is.not.exist;
expect(param.optional).is.true;

expect(param.type).is.exist;
Expand All @@ -210,7 +210,7 @@ describe('JSDoc parser module tests', () => {

expect(param).is.exist;
expect(param.name).is.equal('parameter');
expect(param.default).is.equal('Default value');
expect(param.defaultValue).is.equal('Default value');
expect(param.optional).is.true;

expect(param.type).is.exist;
Expand Down
70 changes: 40 additions & 30 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,43 @@ export interface JSDocKeyword {
description: string;
}

export interface JSDocType {
/**
* Kind of this type.
*/
kind: 'type'|'union'|'const',
export interface JSDocTypeBase {
/**
* The text representation of this type.
*/
text: string,
}

export interface JSDocTypeElement extends JSDocTypeBase {
kind: 'type',
/**
* The type representation of this item.
* @see `'type'|'const'` in `kind` field, then this field provide the name of JS type.
* @see `'union'` in `kind` field, then this field provide the list of @see JSDocType
*/
type: string|JSDocType[],
/**
* The constant value related to this type, if can be provided.
* The name of JS type.
*/
value?: any
type: string,
}

export interface JSDocTypeUnion extends JSDocType {
export interface JSDocTypeConst extends JSDocTypeBase {
kind: 'const',
/**
* Kind of this type.
* The name of JS type.
*/
kind: 'union',
type: string,
/**
* The list of types of this item.
* The constant value related to this type, if can be provided.
*/
type: JSDocType[],
value?: any,
}

export interface JSDocTypeElement extends JSDocType {
/**
* Kind of this type.
*/
kind: 'type'|'const',
export interface JSDocTypeUnion extends JSDocTypeBase {
kind: 'union',
/**
* The type representation of this item.
* The list of possible types.
*/
type: string,
type: JSDocType[]
}

export type JSDocType = JSDocTypeElement | JSDocTypeConst | JSDocTypeUnion;

/**
* Represents a source location of symbol.
*/
Expand All @@ -72,6 +66,10 @@ export interface SourceLocation {
end: number;
}

export type JSVisibilityScope = 'public' | 'protected' | 'private';

export type JSVariableDeclarationKind = 'var' | 'let' | 'const';

export interface ISvelteItem {
/**
* The name of the item.
Expand All @@ -91,7 +89,7 @@ export interface ISvelteItem {
/**
* The visibility of item.
*/
visibility?: 'public'|'protected'|'private';
visibility?: JSVisibilityScope;
/**
* The list of parsed JSDoc keywords from related comment.
*/
Expand Down Expand Up @@ -120,7 +118,7 @@ export interface SvelteDataItem extends ISvelteItem {
* @since Svelte V3
* @since {2.0.0}
*/
kind?: 'var'|'let'|'const';
kind?: JSVariableDeclarationKind;
/**
* Provides information about property binding.
* @since Svelte V3
Expand All @@ -143,7 +141,7 @@ export interface SvelteDataItem extends ISvelteItem {
/**
* The default value of property, if provided.
*/
value?: any;
defaultValue?: any;

/**
* The original name of the imported item.
Expand Down Expand Up @@ -201,10 +199,12 @@ export interface SvelteMethodParamItem {
optional?: boolean;
/**
* The default value of optional parameter.
* @since {4.0.0}
*/
default?: string;
defaultValue?: string;
/**
* The description of the parameter.
* @since {4.0.0}
*/
description?: string;
/**
Expand All @@ -216,14 +216,21 @@ export interface SvelteMethodParamItem {
static?: boolean;
}

/**
* @deprecated
*/
export type SvelteArgItem = SvelteMethodParamItem;
/**
* @deprecated
*/
export type SvelteArgumentItem = SvelteMethodParamItem;

export interface SvelteMethodReturnItem {
/**
* The JSDocType of the return value.
*/
type: JSDocType;

/**
* The description of the return value.
*/
Expand All @@ -233,11 +240,14 @@ export interface SvelteMethodReturnItem {
export interface SvelteMethodItem extends ISvelteItem {
/**
* The list of parameter items of the method.
* @since {4.0.0}
*/
params?: SvelteMethodParamItem[];

/**
* The return item of the method. This exists if an item with 'name' equal
* to 'returns' or 'return' exists in 'keywords'.
* @since {4.0.0}
*/
return?: SvelteMethodReturnItem;
}
Expand All @@ -259,7 +269,7 @@ export interface SvelteComponentItem extends ISvelteItem {
* @since Svelte V3
* @since {2.0.0}
*/
export type SvelteEventModificator = 'preventDefault'|'stopPropagation'|'passive'|'capture'|'once';
export type SvelteEventModificator = 'preventDefault'|'stopPropagation'|'passive'|'capture'|'once'|'nonpassive';

export interface SvelteEventItem extends ISvelteItem {
/**
Expand Down

0 comments on commit f6bd789

Please sign in to comment.