Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update lg tsconfig and comments #1910

Merged
merged 5 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions libraries/botbuilder-lg/src/staticChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { Position } from './position';
import { Range } from './range';
import { TemplateExtensions } from './templateExtensions';

/// <summary>
/// LG managed code checker.
/// </summary>
/**
* LG managed code checker.
*/
export class StaticChecker extends AbstractParseTreeVisitor<Diagnostic[]> implements LGFileParserVisitor<Diagnostic[]> {
private readonly baseExpressionParser: ExpressionParser;
private readonly templates: Templates;
Expand All @@ -44,10 +44,10 @@ export class StaticChecker extends AbstractParseTreeVisitor<Diagnostic[]> implem
return this._expressionParser;
}

/// <summary>
/// Return error messages list.
/// </summary>
/// <returns>report result.</returns>
/**
* Return error messages list.
* @returns report result.
*/
public check(): Diagnostic[] {
this.visitedTemplateNames = [];
var result = [];
Expand Down
28 changes: 13 additions & 15 deletions libraries/botbuilder-lg/src/templateExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ export class TemplateExtensions {
return result.trim();
}

/// <summary>
/// Normalize authored path to os path.
/// </summary>
/// <remarks>
/// path is from authored content which doesn't know what OS it is running on.
/// This method treats / and \ both as seperators regardless of OS, for windows that means / -> \ and for linux/mac \ -> /.
/// This allows author to use ../foo.lg or ..\foo.lg as equivelents for importing.
/// </remarks>
/// <param name="ambiguousPath">authoredPath.</param>
/// <returns>path expressed as OS path.</returns>
/**
* Normalize authored path to os path.
* path is from authored content which doesn't know what OS it is running on.
* This method treats / and \ both as seperators regardless of OS, for windows that means / -> \ and for linux/mac \ -> /.
* This allows author to use ../foo.lg or ..\foo.lg as equivelents for importing.
* @param ambiguousPath authoredPath.
* @returns path expressed as OS path.
*/
public static normalizePath(ambiguousPath: string): string {
if (process.platform === 'win32') {
// map linux/mac sep -> windows
Expand All @@ -54,11 +52,11 @@ export class TemplateExtensions {
}
}

/// <summary>
/// Get prefix error message from normal template sting context.
/// </summary>
/// <param name="context">normal template sting context.</param>
/// <returns>prefix error message.</returns>
/**
* Get prefix error message from normal template sting context.
* @param context normal template sting context.
* @returns prefix error message.
*/
public static getPrefixErrorMessage(context: lp.NormalTemplateStringContext): string
{
let errorPrefix = '';
Expand Down
6 changes: 3 additions & 3 deletions libraries/botbuilder-lg/src/templateParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export declare type ImportResolverDelegate = (source: string, resourceId: string
*/
export class TemplateParser {

/// <summary>
/// option regex.
/// </summary>
/**
* option regex.
*/
private static readonly optionRegex: RegExp = new RegExp(/^> *!#(.*)$/);

/**
Expand Down
165 changes: 64 additions & 101 deletions libraries/botbuilder-lg/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,53 @@ import { AnalyzerResult } from './analyzerResult';
import { TemplateErrors } from './templateErrors';
import { TemplateExtensions } from './templateExtensions';

/// <summary>
/// LG entrance, including properties that LG file has, and evaluate functions.
/// </summary>
/**
* LG entrance, including properties that LG file has, and evaluate functions.
*/
export class Templates implements Iterable<Template> {
private items: Template[];

/// <summary>
/// Gets or sets import elements that this LG file contains directly.
/// </summary>
/// <value>
/// import elements that this LG file contains directly.
/// </value>
/**
* import elements that this LG file contains directly.
*/
public imports: TemplateImport[];

/// <summary>
/// Gets or sets diagnostics.
/// </summary>
/// <value>
/// diagnostics.
/// </value>
/**
* diagnostics.
*/
public diagnostics: Diagnostic[];

/// <summary>
/// Gets or sets all references that this LG file has from Imports
/// Notice: reference includs all child imports from the lg file,
/// not only the children belong to this lgfile directly.
/// so, reference count may >= imports count.
/// </summary>
/// <value>
/// all references that this LG file has from Imports
/// </value>
/**
* all references that this LG file has from Imports
* otice: reference includs all child imports from the lg file,
* not only the children belong to this lgfile directly.
* so, reference count may >= imports count.
*/
public references: Templates[];

/// <summary>
/// Gets or sets LG content.
/// </summary>
/// <value>
/// LG content.
/// </value>
/**
* LG content.
*/
public content: string;

/// <summary>
/// Gets or sets id of this LG file.
/// </summary>
/// <value>
/// id of this lg source. For file, is full path.
/// </value>
/**
* id of this lg source. For file, is full path.
*/
public id: string;

/// <summary>
/// Gets or sets expression parser.
/// </summary>
/// <value>
/// expression parser.
/// </value>
/**
* expression parser.
*/
public expressionParser: ExpressionParser;

/// <summary>
/// Gets or sets delegate for resolving resource id of imported lg file.
/// </summary>
/// <value>
/// Delegate for resolving resource id of imported lg file.
/// </value>
/**
* Delegate for resolving resource id of imported lg file.
*/
public importResolver: ImportResolverDelegate;

/// <summary>
/// Gets or sets lG file options.
/// </summary>
/// <value>
/// LG file options.
/// </value>
/**
* LG file options.
*/
public options: string[];

public constructor(items?: Template[],
Expand Down Expand Up @@ -143,38 +119,27 @@ export class Templates implements Iterable<Template> {
args.forEach(t => this.items.push(t));
}

/// <summary>
/// Gets a value indicating whether lG parser/checker/evaluate strict mode.
/// If strict mode is on, expression would throw exception instead of return
/// null or make the condition failed.
/// </summary>
/// <value>
/// A value indicating whether lG parser/checker/evaluate strict mode.
/// If strict mode is on, expression would throw exception instead of return
/// null or make the condition failed.
/// </value>
/**
* A value indicating whether lG parser/checker/evaluate strict mode.
* If strict mode is on, expression would throw exception instead of return
* null or make the condition failed.
*/
public get strictMode(): boolean {
return this.getStrictModeFromOptions(this.options);
}

/// <summary>
/// Gets get all templates from current lg file and reference lg files.
/// </summary>
/// <value>
/// All templates from current lg file and reference lg files.
/// </value>
/**
* All templates from current lg file and reference lg files.
*/
public get allTemplates(): Template[] {
let result = this.items;
this.references.forEach((ref): Template[] => result = result.concat(ref.items));
return Array.from(new Set(result));
}

/// <summary>
/// Gets get all diagnostics from current lg file and reference lg files.
/// </summary>
/// <value>
/// All diagnostics from current lg file and reference lg files.
/// </value>
/**
* All diagnostics from current lg file and reference lg files.
*/
public get allDiagnostics(): Diagnostic[] {
let result = this.diagnostics;
this.references.forEach((ref): Diagnostic[] => result = result.concat(ref.diagnostics));
Expand Down Expand Up @@ -205,52 +170,50 @@ export class Templates implements Iterable<Template> {
return TemplateParser.parseText(content, id, importResolver, expressionParser);
}

/// <summary>
/// Evaluate a template with given name and scope.
/// </summary>
/// <param name="templateName">Template name to be evaluated.</param>
/// <param name="scope">The state visible in the evaluation.</param>
/// <returns>Evaluate result.</returns>
/**
* Evaluate a template with given name and scope.
* @param templateName Template name to be evaluated.
* @param scope The state visible in the evaluation.
* @returns Evaluate result.
*/
public evaluate(templateName: string, scope?: object): any {
this.checkErrors();

const evaluator = new Evaluator(this.allTemplates, this.expressionParser, this.strictMode);
return evaluator.evaluateTemplate(templateName, scope);
}

/// <summary>
/// Expand a template with given name and scope.
/// Return all possible responses instead of random one.
/// </summary>
/// <param name="templateName">Template name to be evaluated.</param>
/// <param name="scope">The state visible in the evaluation.</param>
/// <returns>Expand result.</returns>
/**
* Expand a template with given name and scope.
* Return all possible responses instead of random one.
* @param templateName Template name to be evaluated.
* @param scope The state visible in the evaluation.
* @returns Expand result.
*/
public expandTemplate(templateName: string, scope?: object): string[] {
this.checkErrors();

const expander = new Expander(this.allTemplates, this.expressionParser, this.strictMode);
return expander.expandTemplate(templateName, scope);
}

/// <summary>
/// (experimental)
/// Analyzer a template to get the static analyzer results including variables and template references.
/// </summary>
/// <param name="templateName">Template name to be evaluated.</param>
/// <returns>analyzer result.</returns>
/**
* Analyzer a template to get the static analyzer results including variables and template references.
* @param templateName Template name to be evaluated.
* @returns analyzer result.
*/
public analyzeTemplate(templateName: string): AnalyzerResult {
this.checkErrors();

const analyzer = new Analyzer(this.allTemplates, this.expressionParser);
return analyzer.analyzeTemplate(templateName);
}

/// <summary>
/// Use to evaluate an inline template str.
/// </summary>
/// <param name="inlineStr">inline string which will be evaluated.</param>
/// <param name="scope">scope object or JToken.</param>
/// <returns>Evaluate result.</returns>
/**
* Use to evaluate an inline template str.
* @param inlineStr inline string which will be evaluated.
* @param scope scope object or JToken.
*/
public evaluateText(inlineStr: string, scope?: object): any
{
if (inlineStr === undefined)
Expand Down
32 changes: 15 additions & 17 deletions libraries/botbuilder-lg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"compilerOptions": {
"plugins": [
{ "name": "typescript-tslint-plugin" }
],
"target": "ESNext",
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./lib",
"rootDirs": ["./src"],
"types" : ["node"]
},
"include": [
"src/**/*"
]
}
"compilerOptions": {
"target": "es6",
"lib": ["es2015", "dom"],
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./lib",
"rootDir": "./src",
"types" : ["node"]
},
"include": [
"src/**/*"
]
}