@lit-labs/analyzer
Advanced tools
Comparing version 0.6.1-pre.0 to 0.7.0
@@ -18,2 +18,3 @@ /** | ||
export const createPackageAnalyzer = (packagePath, options = {}) => { | ||
var _a; | ||
// This logic accepts either a path to folder containing a tsconfig.json | ||
@@ -30,3 +31,3 @@ // directly inside it or a path to a specific tsconfig file. If no tsconfig | ||
if (options.exclude !== undefined) { | ||
(configFile.config.exclude ??= []).push(...options.exclude); | ||
((_a = configFile.config).exclude ?? (_a.exclude = [])).push(...options.exclude); | ||
} | ||
@@ -40,4 +41,4 @@ commandLine = ts.parseJsonConfigFileContent(configFile.config /* json */, ts.sys /* host */, packagePath /* basePath */, undefined /* existingOptions */, path.relative(packagePath, configFileName) /* configFileName */); | ||
// TODO(kschaaf): probably want to make this configurable | ||
module: 'es2021', | ||
lib: ['es2021', 'DOM'], | ||
module: 'ES2020', | ||
lib: ['es2020', 'DOM'], | ||
allowJs: true, | ||
@@ -44,0 +45,0 @@ skipLibCheck: true, |
@@ -27,3 +27,3 @@ /** | ||
get commandLine() { | ||
return (this._commandLine ??= getCommandLineFromProgram(this)); | ||
return (this._commandLine ?? (this._commandLine = getCommandLineFromProgram(this))); | ||
} | ||
@@ -30,0 +30,0 @@ getModule(modulePath) { |
@@ -12,3 +12,3 @@ /** | ||
import ts from 'typescript'; | ||
import { Described, NamedDescribed, TypedNamedDescribed, DeprecatableDescribed } from '../model.js'; | ||
import { Described, TypedNamedDescribed, DeprecatableDescribed, NamedDescribed } from '../model.js'; | ||
/** | ||
@@ -46,2 +46,6 @@ * @fileoverview | ||
* * @slot name: description | ||
* * @cssProp [--name=default] | ||
* * @cssProp [--name=default] description | ||
* * @cssProp [--name=default] - description | ||
* * @cssProp [--name=default]: description | ||
*/ | ||
@@ -48,0 +52,0 @@ export declare const parseNamedJSDocInfo: (tag: ts.JSDocTag, requireDash?: boolean) => NamedDescribed | undefined; |
@@ -31,8 +31,8 @@ /** | ||
const parseNameTypeDescRE = /^(?<name>\S+)(?:\s+{(?<type>.*)})?(?:\s+-\s+)?(?<description>[\s\S]*)$/m; | ||
// Regex for parsing name and description from JSDoc comments | ||
const parseNameDescRE = /^(?<name>^\S+)(?:\s?-\s+)?(?<description>[\s\S]*)$/m; | ||
// Regex for parsing optional name and description from JSDoc comments, where | ||
// the dash is required before the description (syntax for `@slot` tag, whose | ||
// default slot has no name) | ||
const parseNameDashDescRE = /^(?<name>^\S*)?(?:\s+-\s+(?<description>[\s\S]*))?$/m; | ||
const parseNameDashDescRE = /^\[?(?<name>[^[\]\s=]+)(?:=(?<defaultValue>[^\]]+))?\]?\s+-\s+(?<description>[\s\S]*)$/; | ||
// Regex for parsing optional name, default, and description from JSDoc comments | ||
const parseNameDescRE = /^\[?(?<name>[^[\]\s=]+)(?:=(?<defaultValue>[^\]]+))?\]?(?:\s+-\s+)?(?<description>[\s\S]*)$/; | ||
const getJSDocTagComment = (tag) => { | ||
@@ -83,2 +83,8 @@ let { comment } = tag; | ||
}; | ||
function makeDashParseError(tag, requireDash) { | ||
return new DiagnosticsError(tag, `Unexpected JSDoc format.${requireDash | ||
? ' Tag must contain a whitespace-separated dash between the name and description, ' + | ||
"i.e. '@slot header - This is the description'" | ||
: ''}`); | ||
} | ||
/** | ||
@@ -93,2 +99,6 @@ * Parses name and description from JSDoc tag for things like `@slot`, | ||
* * @slot name: description | ||
* * @cssProp [--name=default] | ||
* * @cssProp [--name=default] description | ||
* * @cssProp [--name=default] - description | ||
* * @cssProp [--name=default]: description | ||
*/ | ||
@@ -100,13 +110,15 @@ export const parseNamedJSDocInfo = (tag, requireDash = false) => { | ||
} | ||
const nameDesc = comment.match(requireDash ? parseNameDashDescRE : parseNameDescRE); | ||
const regex = requireDash ? parseNameDashDescRE : parseNameDescRE; | ||
const nameDesc = comment.match(regex); | ||
if (nameDesc === null) { | ||
throw new DiagnosticsError(tag, `Unexpected JSDoc format.${parseNameDashDescRE | ||
? ` Tag must contain a whitespace-separated dash between the name and description, i.e. '@slot header - This is the description'` | ||
: ''}`); | ||
throw makeDashParseError(tag, requireDash); | ||
} | ||
const { name, description } = nameDesc.groups; | ||
const { name, description, defaultValue } = nameDesc.groups; | ||
const info = { name }; | ||
if (description.length > 0) { | ||
if (description?.length > 0) { | ||
info.description = normalizeLineEndings(description); | ||
} | ||
if (defaultValue?.length > 0) { | ||
info.default = defaultValue; | ||
} | ||
return info; | ||
@@ -113,0 +125,0 @@ }; |
@@ -322,2 +322,3 @@ /** | ||
name: string; | ||
default?: string; | ||
} | ||
@@ -324,0 +325,0 @@ export interface TypedNamedDescribed extends NamedDescribed { |
@@ -139,3 +139,3 @@ /** | ||
get declarations() { | ||
return (this._declarations ??= Array.from(this._declarationMap.keys()).map((name) => this.getDeclaration(name))); | ||
return (this._declarations ?? (this._declarations = Array.from(this._declarationMap.keys()).map((name) => this.getDeclaration(name)))); | ||
} | ||
@@ -234,3 +234,3 @@ /** | ||
get heritage() { | ||
return (this._heritage ??= this._getHeritage()); | ||
return (this._heritage ?? (this._heritage = this._getHeritage())); | ||
} | ||
@@ -343,3 +343,3 @@ /** | ||
dereference(type) { | ||
const model = (this._model ??= this._dereference()); | ||
const model = (this._model ?? (this._model = this._dereference())); | ||
if (type !== undefined && model !== undefined && !(model instanceof type)) { | ||
@@ -359,3 +359,3 @@ throw new Error(`Expected reference to ${this.name} in module ${this.moduleSpecifier} to be of type ${type.name}`); | ||
get references() { | ||
return (this._references ??= this._getReferences()); | ||
return (this._references ?? (this._references = this._getReferences())); | ||
} | ||
@@ -362,0 +362,0 @@ } |
{ | ||
"name": "@lit-labs/analyzer", | ||
"version": "0.6.1-pre.0", | ||
"version": "0.7.0", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
360262
3727