sveltedoc-parser
Advanced tools
Comparing version 2.3.3 to 2.3.4
@@ -6,2 +6,10 @@ # Change Log | ||
## [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 | ||
@@ -8,0 +16,0 @@ |
@@ -7,3 +7,3 @@ const { loadFileStructureFromOptions: loadFileContentFromOptions } = require('./helpers'); | ||
function isElseIfWithoutSpaceInTemplate(template) { | ||
return /\{\:elseif\s/gi.test(template); | ||
return /\{:elseif\s/gi.test(template); | ||
} | ||
@@ -20,7 +20,7 @@ | ||
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); | ||
} | ||
@@ -27,0 +27,0 @@ |
@@ -26,2 +26,3 @@ const fs = require('fs'); | ||
const buffer = fs.readFileSync(options.filename, options.encoding); | ||
return parseFileStructureFromContent(buffer.toString()); | ||
@@ -36,2 +37,3 @@ } | ||
const blockOuterStartIndex = content.indexOf(`<${blockName}`, searchStartIndex); | ||
if (blockOuterStartIndex >= 0) { | ||
@@ -72,2 +74,3 @@ const blockInnerEndIndex = content.indexOf(`</${blockName}>`, blockOuterStartIndex + blockName.length + 1); | ||
let searchResult = extractHtmlBlock(content, blockName); | ||
while (searchResult.block) { | ||
@@ -77,2 +80,3 @@ blocks.push(searchResult.block); | ||
const searchStartIndex = searchResult.block.outerPosition.end; | ||
searchResult = extractHtmlBlock(content, blockName, searchStartIndex); | ||
@@ -95,3 +99,3 @@ } | ||
styles: styleBlocksSearchResult.blocks | ||
} | ||
}; | ||
} | ||
@@ -98,0 +102,0 @@ |
@@ -8,3 +8,3 @@ | ||
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'); | ||
@@ -29,2 +29,3 @@ | ||
typeValue = typeValue.trim(); | ||
if (typeValue.indexOf('|') > -1) { | ||
@@ -38,8 +39,8 @@ if (typeValue.startsWith('(') && typeValue.endsWith(')')) { | ||
return { | ||
'kind': 'union', | ||
'text': typeValue, | ||
'type': types | ||
kind: 'union', | ||
text: typeValue, | ||
type: types | ||
.map(type => parseJSDocType(type)) | ||
.filter(type => type != null) | ||
} | ||
}; | ||
} | ||
@@ -49,7 +50,7 @@ | ||
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) | ||
}; | ||
} | ||
@@ -59,13 +60,13 @@ | ||
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 | ||
}; | ||
} | ||
@@ -80,13 +81,13 @@ | ||
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' | ||
}; | ||
@@ -96,5 +97,5 @@ } | ||
return { | ||
'kind': 'type', | ||
'text': typeof(valueNode), | ||
'type': typeof(valueNode) | ||
kind: 'type', | ||
text: typeof (valueNode), | ||
type: typeof (valueNode) | ||
}; | ||
@@ -120,7 +121,7 @@ } | ||
type: { | ||
'kind': 'type', | ||
'text': '*', | ||
'type': DEFAULT_TYPE | ||
kind: 'type', | ||
text: '*', | ||
type: DEFAULT_TYPE | ||
}, | ||
name: null, | ||
name: null, | ||
optional: false, | ||
@@ -130,3 +131,3 @@ default: null, | ||
}; | ||
const match = PARAM_RE.exec(text); | ||
@@ -175,23 +176,2 @@ | ||
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; | ||
} | ||
@@ -220,2 +200,2 @@ | ||
DEFAULT_TYPE | ||
}; | ||
}; |
@@ -8,2 +8,4 @@ const EventEmitter = require('events'); | ||
const hasOwnProperty = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); | ||
const DEFAULT_OPTIONS = { | ||
@@ -34,13 +36,14 @@ /** | ||
'name', | ||
'data', | ||
'computed', | ||
'methods', | ||
'actions', | ||
'helpers', | ||
'components', | ||
'description', | ||
'events', | ||
'slots', | ||
'transitions', | ||
'refs', | ||
'data', | ||
'computed', | ||
'methods', | ||
'actions', | ||
'helpers', | ||
'components', | ||
'description', | ||
'keywords', | ||
'events', | ||
'slots', | ||
'transitions', | ||
'refs', | ||
'store' | ||
@@ -62,3 +65,3 @@ ]; | ||
if (options.source.hasOwnProperty('script') && options.source.script) { | ||
if (hasOwnProperty(options.source, 'script') && options.source.script) { | ||
this.scriptOffset = options.source.scriptOffset || 0; | ||
@@ -187,3 +190,3 @@ | ||
if (this.eventsEmmited.hasOwnProperty(event.name)) { | ||
if (hasOwnProperty(this.eventsEmmited, event.name)) { | ||
const emitedEvent = this.eventsEmmited[event.name]; | ||
@@ -211,3 +214,3 @@ | ||
if (p.value && p.value.type === 'Identifier') { | ||
if (this.imports.hasOwnProperty(p.value.name)) { | ||
if (hasOwnProperty(this.imports, p.value.name)) { | ||
// TODO: 3.*, Backward compatibility: Remove this property | ||
@@ -222,4 +225,6 @@ entry.importPath = this.imports[p.value.name].sourceFilename; | ||
const typeKeyword = entry.keywords.find(kw => kw.name === 'type'); | ||
if (typeKeyword) { | ||
const parsedType = jsdoc.parseTypeKeyword(typeKeyword.description); | ||
if (parsedType) { | ||
@@ -232,5 +237,5 @@ entry.type = parsedType; | ||
if (!entry.type) { | ||
if (entry.hasOwnProperty('value')) { | ||
if (hasOwnProperty(entry, 'value')) { | ||
const parsedType = jsdoc.parseJSTypeFromValueNode(entry.value); | ||
if (parsedType) { | ||
@@ -240,5 +245,5 @@ entry.type = parsedType; | ||
entry.type = { | ||
'kind': 'type', | ||
'text': 'any', | ||
'type': 'any' | ||
kind: 'type', | ||
text: 'any', | ||
type: 'any' | ||
}; | ||
@@ -248,5 +253,5 @@ } | ||
entry.type = { | ||
'kind': 'type', | ||
'text': 'any', | ||
'type': 'any' | ||
kind: 'type', | ||
text: 'any', | ||
type: 'any' | ||
}; | ||
@@ -291,3 +296,3 @@ } | ||
if (propertyValue.hasOwnProperty('name') && !this.componentName) { | ||
if (hasOwnProperty(propertyValue, 'name') && !this.componentName) { | ||
this.componentName = propertyValue.name; | ||
@@ -305,3 +310,3 @@ | ||
switch (property.value.type) { | ||
case 'FunctionExpression': | ||
case 'FunctionExpression': { | ||
const expression = property.value.body.body.find((p) => { | ||
@@ -322,2 +327,3 @@ return p.type === 'ReturnStatement'; | ||
break; | ||
} | ||
@@ -365,3 +371,3 @@ case 'ArrowFunctionExpression': | ||
this.internalWalk(); | ||
} catch(error) { | ||
} catch (error) { | ||
this.emit('failure', error); | ||
@@ -414,3 +420,3 @@ } | ||
if (!this.imports.hasOwnProperty(importEntry.identifier)) { | ||
if (!hasOwnProperty(this.imports, importEntry.identifier)) { | ||
this.imports[importEntry.identifier] = importEntry; | ||
@@ -438,3 +444,3 @@ this.emit('import', importEntry); | ||
case 'Identifier': | ||
if (this.identifiers.hasOwnProperty(body.declaration.name)) { | ||
if (hasOwnProperty(this.identifiers, body.declaration.name)) { | ||
this.identifiers[body.declaration.name].properties.forEach((property) => this.extractProperties(property)); | ||
@@ -547,3 +553,3 @@ } | ||
} else { | ||
if (this.eventsEmmited.hasOwnProperty(event.name)) { | ||
if (hasOwnProperty(this.eventsEmmited, event.name)) { | ||
const emitedEvent = this.eventsEmmited[event.name]; | ||
@@ -622,7 +628,7 @@ | ||
parent: tagName, | ||
locations: this.includeSourceLocations && lastAttributeLocations.hasOwnProperty(name) | ||
locations: this.includeSourceLocations && hasOwnProperty(lastAttributeLocations, name) | ||
? [lastAttributeLocations[name]] | ||
: null, | ||
// TODO: Deprication - Remove this property with V3.* | ||
loc: this.includeSourceLocations && lastAttributeLocations.hasOwnProperty(name) | ||
loc: this.includeSourceLocations && hasOwnProperty(lastAttributeLocations, name) | ||
? lastAttributeLocations[name] | ||
@@ -665,10 +671,10 @@ : null | ||
modificators: nameWithModificators.slice(1), | ||
locations: this.includeSourceLocations && lastAttributeLocations.hasOwnProperty(name) | ||
locations: this.includeSourceLocations && hasOwnProperty(lastAttributeLocations, name) | ||
? [lastAttributeLocations[name]] | ||
: null, | ||
// TODO: Deprication - Remove this property with V3.* | ||
loc: this.includeSourceLocations && lastAttributeLocations.hasOwnProperty(name) | ||
loc: this.includeSourceLocations && hasOwnProperty(lastAttributeLocations, name) | ||
? lastAttributeLocations[name] | ||
: null | ||
} | ||
}; | ||
}); | ||
@@ -682,2 +688,3 @@ | ||
const matches = EVENT_EMIT_RE.exec(value); | ||
if (!matches) { | ||
@@ -690,7 +697,7 @@ return null; | ||
parent: null, | ||
locations: this.includeSourceLocations && lastAttributeLocations.hasOwnProperty(name) | ||
locations: this.includeSourceLocations && hasOwnProperty(lastAttributeLocations, name) | ||
? [lastAttributeLocations[name]] | ||
: null, | ||
// TODO: Deprication - Remove this property with V3.* | ||
loc: this.includeSourceLocations && lastAttributeLocations.hasOwnProperty(name) | ||
loc: this.includeSourceLocations && hasOwnProperty(lastAttributeLocations, name) | ||
? lastAttributeLocations[name] | ||
@@ -716,3 +723,3 @@ : null | ||
if (!this.eventsEmmited.hasOwnProperty(event.name)) { | ||
if (!hasOwnProperty(this.eventsEmmited, event.name)) { | ||
this.eventsEmmited[event.name] = event; | ||
@@ -719,0 +726,0 @@ |
@@ -16,3 +16,3 @@ const RE_VISIBILITY = /(public|protected|private)/; | ||
const parseComment = (text, defaultVisibility = DEFAULT_VISIBILITY, features = ['description', 'keywords']) => { | ||
const parseComment = (text, defaultVisibility = DEFAULT_VISIBILITY) => { | ||
const result = { | ||
@@ -51,5 +51,3 @@ keywords: [], | ||
const name = matches[1]; | ||
const description = features.includes('description') | ||
? (matches[4] || '').trim() | ||
: ''; | ||
const description = (matches[4] || '').trim(); | ||
@@ -59,12 +57,5 @@ result.keywords.push({ name, description }); | ||
if (features.includes('description')) { | ||
result.description = parsedText.substring(0, indexDescription).trim(); | ||
} | ||
result.description = parsedText.substring(0, indexDescription).trim(); | ||
result.visibility = getVisibility(result.keywords, result.visibility); | ||
if (!features.includes('keywords')) { | ||
result.keywords = []; | ||
} | ||
return result; | ||
@@ -75,3 +66,2 @@ }; | ||
defaultVisibility = DEFAULT_VISIBILITY, | ||
features, | ||
useFirst = false, | ||
@@ -98,3 +88,3 @@ useLeading = true, | ||
if (lastComment) { | ||
return parseComment(lastComment, defaultVisibility, features); | ||
return parseComment(lastComment, defaultVisibility); | ||
} | ||
@@ -101,0 +91,0 @@ |
@@ -21,2 +21,3 @@ const EventEmitter = require('events'); | ||
'description', | ||
'keywords', | ||
'events', | ||
@@ -240,5 +241,3 @@ 'slots', | ||
if (this.features.includes('keywords')) { | ||
this.emit('keywords', comment.keywords); | ||
} | ||
this.emit('keywords', comment.keywords); | ||
} | ||
@@ -337,3 +336,3 @@ } | ||
if (declaration) { | ||
const exportNodeComment = utils.getComment(node, { defaultVisibility: 'public', features: this.features, useLeading: true, useTrailing: false }); | ||
const exportNodeComment = utils.getComment(node, { defaultVisibility: 'public', useLeading: true, useTrailing: false }); | ||
@@ -704,2 +703,8 @@ if (declaration.type === 'VariableDeclaration') { | ||
} else { | ||
if (tagName === 'svelte:options' && attrs.tag) { | ||
if (this.features.includes('name')) { | ||
this.emit('name', attrs.tag); | ||
} | ||
} | ||
if (this.features.includes('events')) { | ||
@@ -706,0 +711,0 @@ // Expose events that propogated from child events |
{ | ||
"name": "sveltedoc-parser", | ||
"version": "2.3.3", | ||
"version": "2.3.4", | ||
"description": "Generate a JSON documentation for a Svelte file", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint ./*.js", | ||
"lint": "eslint ./**/*.js", | ||
"test": "mocha ./test/**/*.spec.js", | ||
@@ -9,0 +9,0 @@ "test:unit": "mocha ./test/unit/**/*.spec.js", |
@@ -19,3 +19,3 @@ # The sveltedoc parser | ||
## [2.3.2] 02.12.2019 | ||
### [2.3.2] 02.12.2019 | ||
@@ -27,3 +27,3 @@ Thanks to [hontas](https://github.com/hontas) for following fixes: | ||
## [2.3.3] 05.12.2019 | ||
### [2.3.3] 05.12.2019 | ||
@@ -34,2 +34,10 @@ Thanks to [hontas](https://github.com/hontas) for following changes: | ||
### [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) | ||
@@ -94,3 +102,3 @@ | ||
| **version** | Optional. Use `2` or `3` to specify which svelte syntax should be used. When that is not provided, parser try to detect version of the syntax. | `undefined` | | ||
| **defaultVersion** | Optional. Specify default version of svelte syntax, if auto-detector can't indetify correct version. | `undefined` | | ||
| **defaultVersion** | Optional. Specify default version of svelte syntax, if auto-detector can't identify correct version. | `undefined` | | ||
@@ -107,2 +115,3 @@ ### Supported feature names | ||
- `'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_). | ||
@@ -109,0 +118,0 @@ - `'slots'` - Extract the list of slots provided by this component (_Supported by Svelte 2 and Svelte 3_). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157466
165
2279