botbuilder-lg
Advanced tools
Comparing version 4.23.1 to 4.23.2-dev1
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Analyzer = void 0; | ||
/* eslint-disable security/detect-object-injection */ | ||
/** | ||
@@ -17,3 +19,3 @@ * @module botbuilder-lg | ||
const templateExtensions_1 = require("./templateExtensions"); | ||
const keyBy = require("lodash/keyBy"); | ||
const keyBy_1 = __importDefault(require("lodash/keyBy")); | ||
const templateErrors_1 = require("./templateErrors"); | ||
@@ -35,3 +37,3 @@ /** | ||
this.templates = templates; | ||
this.templateMap = keyBy(templates.allTemplates, (t) => t.name); | ||
this.templateMap = (0, keyBy_1.default)(templates.allTemplates, (t) => t.name); | ||
this._analyzerOptions = analyzerOptions; | ||
@@ -38,0 +40,0 @@ // create an evaluator to leverage its customized function look up for checking |
@@ -53,3 +53,2 @@ "use strict"; | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
setValue(_path, _value) { | ||
@@ -56,0 +55,0 @@ return; |
@@ -36,6 +36,4 @@ "use strict"; | ||
*/ | ||
syntaxError(recognizer, offendingSymbol, line, charPositionInLine, | ||
syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
msg, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
e) { | ||
@@ -42,0 +40,0 @@ const startPosition = new position_1.Position(this.lineOffset + line, charPositionInLine); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EvaluationOptions = exports.LGCacheScope = exports.LGLineBreakStyle = void 0; | ||
/* eslint-disable security/detect-object-injection */ | ||
/** | ||
@@ -6,0 +5,0 @@ * @module botbuilder-lg |
@@ -25,5 +25,7 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Evaluator = exports.FileFormat = void 0; | ||
/* eslint-disable security/detect-object-injection */ | ||
/* eslint-disable security/detect-non-literal-fs-filename */ | ||
@@ -46,3 +48,3 @@ /** | ||
const templates_1 = require("./templates"); | ||
const keyBy = require("lodash/keyBy"); | ||
const keyBy_1 = __importDefault(require("lodash/keyBy")); | ||
const adaptive_expressions_1 = require("adaptive-expressions"); | ||
@@ -196,3 +198,3 @@ const LGTemplateParser_1 = require("./generated/LGTemplateParser"); | ||
this.templates = templates; | ||
this.templateMap = keyBy(templates.allTemplates, (t) => t.name); | ||
this.templateMap = (0, keyBy_1.default)(templates.allTemplates, (t) => t.name); | ||
this.lgOptions = opt; | ||
@@ -422,3 +424,3 @@ this.cacheResult.clear(); | ||
const templateName = this.parseTemplateName(inputTemplateName).pureTemplateName; | ||
const templateMap = keyBy(allTemplates, (t) => t.name); | ||
const templateMap = (0, keyBy_1.default)(allTemplates, (t) => t.name); | ||
if (!(templateName in templateMap)) { | ||
@@ -425,0 +427,0 @@ throw new Error(templateErrors_1.TemplateErrors.templateNotExist(templateName)); |
@@ -25,5 +25,7 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Expander = void 0; | ||
/* eslint-disable security/detect-object-injection */ | ||
/* eslint-disable security/detect-non-literal-fs-filename */ | ||
@@ -46,3 +48,3 @@ /** | ||
const templates_1 = require("./templates"); | ||
const keyBy = require("lodash/keyBy"); | ||
const keyBy_1 = __importDefault(require("lodash/keyBy")); | ||
const adaptive_expressions_1 = require("adaptive-expressions"); | ||
@@ -188,3 +190,3 @@ const LGTemplateParser_1 = require("./generated/LGTemplateParser"); | ||
this.templates = templates; | ||
this.templateMap = keyBy(templates.allTemplates, (t) => t.name); | ||
this.templateMap = (0, keyBy_1.default)(templates.allTemplates, (t) => t.name); | ||
this.lgOptions = opt; | ||
@@ -463,3 +465,3 @@ // Generate a new customized expression parser by injecting the template as functions. | ||
const templateName = this.parseTemplateName(inputTemplateName).pureTemplateName; | ||
const templateMap = keyBy(allTemplates, (t) => t.name); | ||
const templateMap = (0, keyBy_1.default)(allTemplates, (t) => t.name); | ||
if (!(templateName in templateMap)) { | ||
@@ -466,0 +468,0 @@ throw new Error(templateErrors_1.TemplateErrors.templateNotExist(templateName)); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -12,3 +15,3 @@ exports.Extractor = void 0; | ||
const tree_1 = require("antlr4ts/tree"); | ||
const keyBy = require("lodash/keyBy"); | ||
const keyBy_1 = __importDefault(require("lodash/keyBy")); | ||
/** | ||
@@ -26,3 +29,3 @@ * Lg template extracter. | ||
this.templates = templates; | ||
this.templateMap = keyBy(templates, (t) => t.name); | ||
this.templateMap = (0, keyBy_1.default)(templates, (t) => t.name); | ||
} | ||
@@ -29,0 +32,0 @@ /** |
@@ -25,3 +25,2 @@ /** | ||
export * from './templateErrors'; | ||
export * from './evaluator'; | ||
export * from './errorListener'; | ||
@@ -28,0 +27,0 @@ export * from './customizedMemory'; |
@@ -41,3 +41,2 @@ "use strict"; | ||
__exportStar(require("./templateErrors"), exports); | ||
__exportStar(require("./evaluator"), exports); | ||
__exportStar(require("./errorListener"), exports); | ||
@@ -44,0 +43,0 @@ __exportStar(require("./customizedMemory"), exports); |
"use strict"; | ||
/* eslint-disable security/detect-object-injection */ | ||
/** | ||
@@ -4,0 +3,0 @@ * @module botbuilder-lg |
"use strict"; | ||
/* eslint-disable security/detect-object-injection */ | ||
/** | ||
@@ -19,3 +18,2 @@ * @module botbuilder-lg | ||
const analyzer_1 = require("./analyzer"); | ||
const templatesParser_2 = require("./templatesParser"); | ||
const templateErrors_1 = require("./templateErrors"); | ||
@@ -144,3 +142,3 @@ const templateExtensions_1 = require("./templateExtensions"); | ||
static parseFile(filePath, importResolver, expressionParser) { | ||
return templatesParser_2.TemplatesParser.parseFile(filePath, importResolver, expressionParser).injectToExpressionFunction(); | ||
return templatesParser_1.TemplatesParser.parseFile(filePath, importResolver, expressionParser).injectToExpressionFunction(); | ||
} | ||
@@ -158,3 +156,3 @@ /** | ||
static parseText(content, id = '', importResolver, expressionParser) { | ||
return templatesParser_2.TemplatesParser.parseText(content, id, importResolver, expressionParser).injectToExpressionFunction(); | ||
return templatesParser_1.TemplatesParser.parseText(content, id, importResolver, expressionParser).injectToExpressionFunction(); | ||
} | ||
@@ -170,3 +168,3 @@ /** | ||
static parseResource(resource, importResolver, expressionParser) { | ||
return templatesParser_2.TemplatesParser.parseResource(resource, importResolver, expressionParser).injectToExpressionFunction(); | ||
return templatesParser_1.TemplatesParser.parseResource(resource, importResolver, expressionParser).injectToExpressionFunction(); | ||
} | ||
@@ -239,3 +237,3 @@ /** | ||
const newContent = `#${inlineTemplateId} ${this.newLine} - ${inlineStr}`; | ||
const newTemplates = templatesParser_2.TemplatesParser.parseTextWithRef(newContent, this); | ||
const newTemplates = templatesParser_1.TemplatesParser.parseTextWithRef(newContent, this); | ||
const evalOpt = opt !== undefined ? opt.merge(this.lgOptions) : this.lgOptions; | ||
@@ -268,3 +266,3 @@ return newTemplates.evaluate(inlineTemplateId, scope, evalOpt); | ||
const resource = new lgResource_1.LGResource(this.id, this.id, content); | ||
updatedTemplates = new templatesParser_1.TemplatesTransformer(updatedTemplates).transform(templatesParser_2.TemplatesParser.antlrParseTemplates(resource)); | ||
updatedTemplates = new templatesParser_1.TemplatesTransformer(updatedTemplates).transform(templatesParser_1.TemplatesParser.antlrParseTemplates(resource)); | ||
const originalStartLine = template.sourceRange.range.start.line - 1; | ||
@@ -306,3 +304,3 @@ this.appendDiagnosticWithOffset(updatedTemplates.diagnostics, originalStartLine); | ||
const resource = new lgResource_1.LGResource(this.id, this.id, content); | ||
updatedTemplates = new templatesParser_1.TemplatesTransformer(updatedTemplates).transform(templatesParser_2.TemplatesParser.antlrParseTemplates(resource)); | ||
updatedTemplates = new templatesParser_1.TemplatesTransformer(updatedTemplates).transform(templatesParser_1.TemplatesParser.antlrParseTemplates(resource)); | ||
this.appendDiagnosticWithOffset(updatedTemplates.diagnostics, originalStartLine); | ||
@@ -309,0 +307,0 @@ if (updatedTemplates.toArray().length > 0) { |
import { AbstractParseTreeVisitor, ParseTree } from 'antlr4ts/tree'; | ||
import { ExpressionParser } from 'adaptive-expressions'; | ||
import { FileContext } from './generated/LGFileParser'; | ||
import { FileContext, ErrorDefinitionContext, ImportDefinitionContext, OptionDefinitionContext, TemplateDefinitionContext } from './generated/LGFileParser'; | ||
import { LGResource } from './lgResource'; | ||
import { LGTemplateParserVisitor } from './generated/LGTemplateParserVisitor'; | ||
import { Templates } from './templates'; | ||
import { ErrorDefinitionContext, ImportDefinitionContext, OptionDefinitionContext, TemplateDefinitionContext } from './generated/LGFileParser'; | ||
export declare type ImportResolverDelegate = (lgResource: LGResource, resourceId: string) => LGResource; | ||
@@ -9,0 +8,0 @@ /** |
@@ -118,3 +118,2 @@ "use strict"; | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
const resource = new lgResource_1.LGResource(id, id, content); | ||
@@ -190,3 +189,2 @@ newTemplates = new TemplatesTransformer(newTemplates).transform(this.antlrParseTemplates(resource)); | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
templates = new TemplatesTransformer(templates).transform(this.antlrParseTemplates(resource)); | ||
@@ -193,0 +191,0 @@ templates.references = this.getReferences(templates, cachedTemplates, parentTemplates); |
@@ -5,3 +5,3 @@ { | ||
"description": "Bot Builder Language Generation is a library to help build sophisticated bot responses with multiple phrases and context-based expressions.", | ||
"version": "4.23.1", | ||
"version": "4.23.2-dev1", | ||
"license": "MIT", | ||
@@ -23,3 +23,3 @@ "keywords": [ | ||
"dependencies": { | ||
"adaptive-expressions": "4.23.1", | ||
"adaptive-expressions": "4.23.2-dev1", | ||
"antlr4ts": "0.5.0-alpha.4", | ||
@@ -39,3 +39,3 @@ "lodash": "^4.17.19", | ||
"depcheck": "depcheck --config ../../.depcheckrc", | ||
"lint": "eslint . --ext .js,.ts", | ||
"lint": "eslint .", | ||
"test": "yarn build && mocha tests/ --timeout 60000", | ||
@@ -42,0 +42,0 @@ "test:compat": "api-extractor run --verbose" |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable security/detect-object-injection */ | ||
/** | ||
@@ -19,3 +18,3 @@ * @module botbuilder-lg | ||
import { Templates } from './templates'; | ||
import keyBy = require('lodash/keyBy'); | ||
import keyBy from 'lodash/keyBy'; | ||
@@ -41,3 +40,4 @@ import { | ||
extends AbstractParseTreeVisitor<AnalyzerResult> | ||
implements LGTemplateParserVisitor<AnalyzerResult> { | ||
implements LGTemplateParserVisitor<AnalyzerResult> | ||
{ | ||
/** | ||
@@ -90,3 +90,3 @@ * Templates. | ||
.reverse() | ||
.map((e) => e.templateName)} => ${templateName}` | ||
.map((e) => e.templateName)} => ${templateName}`, | ||
); | ||
@@ -93,0 +93,0 @@ } |
@@ -66,3 +66,2 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
setValue(_path: string, _value: any): void { | ||
@@ -69,0 +68,0 @@ return; |
@@ -46,3 +46,3 @@ /** | ||
source?: string, | ||
code?: string | ||
code?: string, | ||
) { | ||
@@ -49,0 +49,0 @@ this.message = message; |
@@ -51,6 +51,5 @@ /** | ||
charPositionInLine: number, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
msg: string, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
e: RecognitionException | undefined | ||
e: RecognitionException | undefined, | ||
): void { | ||
@@ -60,3 +59,3 @@ const startPosition: Position = new Position(this.lineOffset + line, charPositionInLine); | ||
this.lineOffset + line, | ||
charPositionInLine + offendingSymbol.stopIndex - offendingSymbol.startIndex + 1 | ||
charPositionInLine + offendingSymbol.stopIndex - offendingSymbol.startIndex + 1, | ||
); | ||
@@ -68,3 +67,3 @@ const range: Range = new Range(startPosition, stopPosition); | ||
DiagnosticSeverity.Error, | ||
this.source | ||
this.source, | ||
); | ||
@@ -71,0 +70,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable security/detect-object-injection */ | ||
/** | ||
@@ -3,0 +2,0 @@ * @module botbuilder-lg |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable security/detect-object-injection */ | ||
/* eslint-disable security/detect-non-literal-fs-filename */ | ||
@@ -22,3 +21,3 @@ /** | ||
import { Templates } from './templates'; | ||
import keyBy = require('lodash/keyBy'); | ||
import keyBy from 'lodash/keyBy'; | ||
@@ -122,3 +121,3 @@ import { | ||
this.expressionParser = new ExpressionParser( | ||
this.customizedEvaluatorLookup(templates.expressionParser.EvaluatorLookup) | ||
this.customizedEvaluatorLookup(templates.expressionParser.EvaluatorLookup), | ||
); | ||
@@ -150,3 +149,3 @@ } | ||
.map((u: EvaluationTarget): string => u.templateName) | ||
.join(' => ')}` | ||
.join(' => ')}`, | ||
); | ||
@@ -190,3 +189,3 @@ } | ||
currentEvulateId, | ||
result | ||
result, | ||
); | ||
@@ -223,3 +222,3 @@ } | ||
body.expressionInStructure(), | ||
body.text | ||
body.text, | ||
); | ||
@@ -255,3 +254,3 @@ // Full reference to another structured template is limited to the structured template with same type | ||
result.push( | ||
this.evalExpression(item.expressionInStructure(0).text, item.expressionInStructure(0), ctx.text) | ||
this.evalExpression(item.expressionInStructure(0).text, item.expressionInStructure(0), ctx.text), | ||
); | ||
@@ -421,3 +420,3 @@ } else { | ||
switchcaseNodes[0].switchCaseStat().text, | ||
switchErrorPrefix | ||
switchErrorPrefix, | ||
); | ||
@@ -445,3 +444,3 @@ let idx = 0; | ||
caseNode.switchCaseStat().text, | ||
caseErrorPrefix | ||
caseErrorPrefix, | ||
); | ||
@@ -471,3 +470,3 @@ if (FunctionUtils.commonEquals(switchExprResult, caseExprResult)) { | ||
.replace(regex, (sub: string) => | ||
this.evalExpression(sub.split('').reverse().join('')).toString().split('').reverse().join('') | ||
this.evalExpression(sub.split('').reverse().join('')).toString().split('').reverse().join(''), | ||
) | ||
@@ -523,3 +522,3 @@ .split('') | ||
inlineContent = '', | ||
errorPrefix = '' | ||
errorPrefix = '', | ||
): void { | ||
@@ -538,3 +537,3 @@ let errorMsg = ''; | ||
errorMsg, | ||
TemplateErrors.errorExpression(inlineContent, templateName, errorPrefix) | ||
TemplateErrors.errorExpression(inlineContent, templateName, errorPrefix), | ||
); | ||
@@ -579,3 +578,3 @@ } | ||
contentLine: string, | ||
errorPrefix = '' | ||
errorPrefix = '', | ||
): boolean { | ||
@@ -607,3 +606,3 @@ const exp = TemplateExtensions.trimExpression(expressionContext.text); | ||
inlineContent = '', | ||
errorPrefix = '' | ||
errorPrefix = '', | ||
): unknown { | ||
@@ -639,114 +638,143 @@ exp = TemplateExtensions.trimExpression(exp); | ||
// Genearte a new lookup function based on one lookup function | ||
private readonly customizedEvaluatorLookup = (baseLookup: EvaluatorLookup) => ( | ||
name: string | ||
): ExpressionEvaluator => { | ||
const standardFunction = baseLookup(name); | ||
private readonly customizedEvaluatorLookup = | ||
(baseLookup: EvaluatorLookup) => | ||
(name: string): ExpressionEvaluator => { | ||
const standardFunction = baseLookup(name); | ||
if (standardFunction !== undefined) { | ||
return standardFunction; | ||
} | ||
if (standardFunction !== undefined) { | ||
return standardFunction; | ||
} | ||
const pointIndex = name.indexOf('.'); | ||
if (pointIndex > 0) { | ||
const alias = name.substr(0, pointIndex); | ||
const realTemplate = this.templates.namedReferences[alias]; | ||
if (realTemplate) { | ||
const realTemplateName = name.substr(pointIndex + 1); | ||
const pointIndex = name.indexOf('.'); | ||
if (pointIndex > 0) { | ||
const alias = name.substr(0, pointIndex); | ||
const realTemplate = this.templates.namedReferences[alias]; | ||
if (realTemplate) { | ||
const realTemplateName = name.substr(pointIndex + 1); | ||
return new ExpressionEvaluator( | ||
realTemplateName, | ||
FunctionUtils.apply(this.evaluateWithTemplates(realTemplateName, realTemplate)), | ||
ReturnType.Object, | ||
); | ||
} | ||
} | ||
if (name.startsWith('lg.')) { | ||
name = name.substring(3); | ||
} | ||
const templateName = this.parseTemplateName(name).pureTemplateName; | ||
if (templateName in this.templateMap) { | ||
return new ExpressionEvaluator( | ||
realTemplateName, | ||
FunctionUtils.apply(this.evaluateWithTemplates(realTemplateName, realTemplate)), | ||
ReturnType.Object | ||
templateName, | ||
FunctionUtils.apply(this.templateEvaluator(name)), | ||
ReturnType.Object, | ||
this.validTemplateReference, | ||
); | ||
} | ||
} | ||
if (name.startsWith('lg.')) { | ||
name = name.substring(3); | ||
} | ||
if (name === Evaluator.templateFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.templateFunctionName, | ||
FunctionUtils.apply(this.templateFunction()), | ||
ReturnType.Object, | ||
this.validateTemplateFunction, | ||
); | ||
} | ||
const templateName = this.parseTemplateName(name).pureTemplateName; | ||
if (templateName in this.templateMap) { | ||
return new ExpressionEvaluator( | ||
templateName, | ||
FunctionUtils.apply(this.templateEvaluator(name)), | ||
ReturnType.Object, | ||
this.validTemplateReference | ||
); | ||
} | ||
if (Templates.enableFromFile) { | ||
if (name === Evaluator.fromFileFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.fromFileFunctionName, | ||
FunctionUtils.apply(this.fromFile()), | ||
ReturnType.Object, | ||
(expr): void => FunctionUtils.validateOrder(expr, [ReturnType.String], ReturnType.String), | ||
); | ||
} | ||
} | ||
if (name === Evaluator.templateFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.templateFunctionName, | ||
FunctionUtils.apply(this.templateFunction()), | ||
ReturnType.Object, | ||
this.validateTemplateFunction | ||
); | ||
} | ||
if (name === Evaluator.activityAttachmentFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.activityAttachmentFunctionName, | ||
FunctionUtils.apply(this.activityAttachment()), | ||
ReturnType.Object, | ||
(expr): void => FunctionUtils.validateOrder(expr, undefined, ReturnType.Object, ReturnType.String), | ||
); | ||
} | ||
if (Templates.enableFromFile) { | ||
if (name === Evaluator.fromFileFunctionName) { | ||
if (name === Evaluator.isTemplateFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.fromFileFunctionName, | ||
FunctionUtils.apply(this.fromFile()), | ||
Evaluator.isTemplateFunctionName, | ||
FunctionUtils.apply(this.isTemplate()), | ||
ReturnType.Boolean, | ||
FunctionUtils.validateUnaryString, | ||
); | ||
} | ||
if (name === Evaluator.expandTextFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.expandTextFunctionName, | ||
FunctionUtils.apply(this.expandText()), | ||
ReturnType.Object, | ||
(expr): void => FunctionUtils.validateOrder(expr, [ReturnType.String], ReturnType.String) | ||
FunctionUtils.validateUnaryString, | ||
); | ||
} | ||
} | ||
if (name === Evaluator.activityAttachmentFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.activityAttachmentFunctionName, | ||
FunctionUtils.apply(this.activityAttachment()), | ||
ReturnType.Object, | ||
(expr): void => FunctionUtils.validateOrder(expr, undefined, ReturnType.Object, ReturnType.String) | ||
); | ||
} | ||
return undefined; | ||
}; | ||
if (name === Evaluator.isTemplateFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.isTemplateFunctionName, | ||
FunctionUtils.apply(this.isTemplate()), | ||
ReturnType.Boolean, | ||
FunctionUtils.validateUnaryString | ||
); | ||
} | ||
private readonly isTemplate = | ||
() => | ||
(args: readonly unknown[]): boolean => { | ||
const templateName = args[0].toString(); | ||
return templateName in this.templateMap; | ||
}; | ||
if (name === Evaluator.expandTextFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.expandTextFunctionName, | ||
FunctionUtils.apply(this.expandText()), | ||
ReturnType.Object, | ||
FunctionUtils.validateUnaryString | ||
); | ||
} | ||
private readonly fromFile = | ||
() => | ||
(args: readonly unknown[]): unknown => { | ||
const filePath: string = TemplateExtensions.normalizePath(args[0].toString()); | ||
const resourcePath: string = this.getResourcePath(filePath); | ||
let format = FileFormat.Evaluated; | ||
if (args.length > 1) { | ||
const expected = args[1].toString().toLowerCase(); | ||
const currentFormat = Object.values(FileFormat).find((f) => f.toLowerCase() === expected); | ||
if (currentFormat != null) { | ||
format = currentFormat; | ||
} | ||
} | ||
return undefined; | ||
}; | ||
let result: unknown; | ||
if (format === FileFormat.Binary) { | ||
result = fs.readFileSync(resourcePath); | ||
} else if (format === FileFormat.Raw) { | ||
result = fs.readFileSync(resourcePath, 'utf-8'); | ||
} else { | ||
const stringContent = fs.readFileSync(resourcePath, 'utf-8'); | ||
private readonly isTemplate = () => (args: readonly unknown[]): boolean => { | ||
const templateName = args[0].toString(); | ||
return templateName in this.templateMap; | ||
}; | ||
private readonly fromFile = () => (args: readonly unknown[]): unknown => { | ||
const filePath: string = TemplateExtensions.normalizePath(args[0].toString()); | ||
const resourcePath: string = this.getResourcePath(filePath); | ||
let format = FileFormat.Evaluated; | ||
if (args.length > 1) { | ||
const expected = args[1].toString().toLowerCase(); | ||
const currentFormat = Object.values(FileFormat).find((f) => f.toLowerCase() === expected); | ||
if (currentFormat != null) { | ||
format = currentFormat; | ||
const newScope = this.evaluationTargetStack.length > 0 ? this.currentTarget().scope : undefined; | ||
const newTemplates = new Templates( | ||
this.templates.allTemplates, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
this.expressionParser, | ||
undefined, | ||
[], | ||
undefined, | ||
this.templates.namedReferences, | ||
); | ||
result = newTemplates.evaluateText(stringContent, newScope, this.lgOptions); | ||
} | ||
} | ||
let result: unknown; | ||
if (format === FileFormat.Binary) { | ||
result = fs.readFileSync(resourcePath); | ||
} else if (format === FileFormat.Raw) { | ||
result = fs.readFileSync(resourcePath, 'utf-8'); | ||
} else { | ||
const stringContent = fs.readFileSync(resourcePath, 'utf-8'); | ||
return result; | ||
}; | ||
private readonly expandText = | ||
() => | ||
(args: readonly unknown[]): unknown => { | ||
const stringContent = args[0].toString(); | ||
const newScope = this.evaluationTargetStack.length > 0 ? this.currentTarget().scope : undefined; | ||
@@ -764,30 +792,7 @@ const newTemplates = new Templates( | ||
undefined, | ||
this.templates.namedReferences | ||
this.templates.namedReferences, | ||
); | ||
result = newTemplates.evaluateText(stringContent, newScope, this.lgOptions); | ||
} | ||
return newTemplates.evaluateText(stringContent, newScope, this.lgOptions); | ||
}; | ||
return result; | ||
}; | ||
private readonly expandText = () => (args: readonly unknown[]): unknown => { | ||
const stringContent = args[0].toString(); | ||
const newScope = this.evaluationTargetStack.length > 0 ? this.currentTarget().scope : undefined; | ||
const newTemplates = new Templates( | ||
this.templates.allTemplates, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
this.expressionParser, | ||
undefined, | ||
[], | ||
undefined, | ||
this.templates.namedReferences | ||
); | ||
return newTemplates.evaluateText(stringContent, newScope, this.lgOptions); | ||
}; | ||
/** | ||
@@ -819,24 +824,28 @@ * @private | ||
private readonly activityAttachment = () => (args: readonly unknown[]): unknown => { | ||
return { | ||
[Evaluator.LGType]: 'attachment', | ||
contenttype: args[1].toString(), | ||
content: args[0], | ||
private readonly activityAttachment = | ||
() => | ||
(args: readonly unknown[]): unknown => { | ||
return { | ||
[Evaluator.LGType]: 'attachment', | ||
contenttype: args[1].toString(), | ||
content: args[0], | ||
}; | ||
}; | ||
}; | ||
private readonly evaluateWithTemplates = (templateName: string, templates: Templates) => ( | ||
args: readonly unknown[] | ||
): unknown => { | ||
const newScope = this.constructScope(templateName, args.slice(0), templates.allTemplates); | ||
private readonly evaluateWithTemplates = | ||
(templateName: string, templates: Templates) => | ||
(args: readonly unknown[]): unknown => { | ||
const newScope = this.constructScope(templateName, args.slice(0), templates.allTemplates); | ||
return templates.evaluate(templateName, newScope); | ||
}; | ||
return templates.evaluate(templateName, newScope); | ||
}; | ||
private readonly templateFunction = () => (args: readonly unknown[]): unknown => { | ||
const templateName: string = args[0].toString(); | ||
const newScope = this.constructScope(templateName, args.slice(1), this.templates.allTemplates); | ||
private readonly templateFunction = | ||
() => | ||
(args: readonly unknown[]): unknown => { | ||
const templateName: string = args[0].toString(); | ||
const newScope = this.constructScope(templateName, args.slice(1), this.templates.allTemplates); | ||
return this.evaluateTemplate(templateName, newScope); | ||
}; | ||
return this.evaluateTemplate(templateName, newScope); | ||
}; | ||
@@ -876,7 +885,9 @@ private readonly validateTemplateFunction = (expression: Expression): void => { | ||
private readonly templateEvaluator = (templateName: string) => (args: readonly unknown[]): unknown => { | ||
const newScope = this.constructScope(templateName, Array.from(args), this.templates.allTemplates); | ||
private readonly templateEvaluator = | ||
(templateName: string) => | ||
(args: readonly unknown[]): unknown => { | ||
const newScope = this.constructScope(templateName, Array.from(args), this.templates.allTemplates); | ||
return this.evaluateTemplate(templateName, newScope); | ||
}; | ||
return this.evaluateTemplate(templateName, newScope); | ||
}; | ||
@@ -883,0 +894,0 @@ private readonly validTemplateReference = (expression: Expression): void => { |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable security/detect-object-injection */ | ||
/* eslint-disable security/detect-non-literal-fs-filename */ | ||
@@ -23,3 +22,3 @@ /** | ||
import { Templates } from './templates'; | ||
import keyBy = require('lodash/keyBy'); | ||
import keyBy from 'lodash/keyBy'; | ||
@@ -100,6 +99,6 @@ import { | ||
this.expanderExpressionParser = new ExpressionParser( | ||
this.customizedEvaluatorLookup(templates.expressionParser.EvaluatorLookup, true) | ||
this.customizedEvaluatorLookup(templates.expressionParser.EvaluatorLookup, true), | ||
); | ||
this.evaluatorExpressionParser = new ExpressionParser( | ||
this.customizedEvaluatorLookup(templates.expressionParser.EvaluatorLookup, false) | ||
this.customizedEvaluatorLookup(templates.expressionParser.EvaluatorLookup, false), | ||
); | ||
@@ -129,3 +128,3 @@ } | ||
.map((u: EvaluationTarget): string => u.templateName) | ||
.join(' => ')}` | ||
.join(' => ')}`, | ||
); | ||
@@ -235,3 +234,3 @@ } | ||
} | ||
} | ||
}, | ||
); | ||
@@ -291,3 +290,3 @@ const tempResult = []; | ||
result.push( | ||
this.evalExpression(item.expressionInStructure(0).text, item.expressionInStructure(0), ctx.text) | ||
this.evalExpression(item.expressionInStructure(0).text, item.expressionInStructure(0), ctx.text), | ||
); | ||
@@ -301,3 +300,3 @@ } else { | ||
itemStringResult, | ||
this.evalExpression(child.text, child, ctx.text, errorPrefix) | ||
this.evalExpression(child.text, child, ctx.text, errorPrefix), | ||
); | ||
@@ -342,3 +341,3 @@ } else { | ||
switchcaseNodes[0].switchCaseStat().text, | ||
switchErrorPrefix | ||
switchErrorPrefix, | ||
); | ||
@@ -367,3 +366,3 @@ let idx = 0; | ||
caseNode.switchCaseStat().text, | ||
caseErrorPrefix | ||
caseErrorPrefix, | ||
); | ||
@@ -393,3 +392,3 @@ if (FunctionUtils.commonEquals(switchExprResult[0], caseExprResult[0])) { | ||
result, | ||
this.evalExpression(child.text, child, ctx.text, prefixErrorMsg) | ||
this.evalExpression(child.text, child, ctx.text, prefixErrorMsg), | ||
); | ||
@@ -490,3 +489,3 @@ } else { | ||
contentLine: string, | ||
errorPrefix = '' | ||
errorPrefix = '', | ||
): boolean { | ||
@@ -579,121 +578,125 @@ const exp = TemplateExtensions.trimExpression(expressionContext.text); | ||
private readonly customizedEvaluatorLookup = (baseLookup: EvaluatorLookup, isExpander: boolean) => ( | ||
name: string | ||
): ExpressionEvaluator => { | ||
const standardFunction = baseLookup(name); | ||
private readonly customizedEvaluatorLookup = | ||
(baseLookup: EvaluatorLookup, isExpander: boolean) => | ||
(name: string): ExpressionEvaluator => { | ||
const standardFunction = baseLookup(name); | ||
if (standardFunction !== undefined) { | ||
return standardFunction; | ||
} | ||
if (standardFunction !== undefined) { | ||
return standardFunction; | ||
} | ||
const pointIndex = name.indexOf('.'); | ||
if (pointIndex > 0) { | ||
const alias = name.substr(0, pointIndex); | ||
const realTemplate = this.templates.namedReferences[alias]; | ||
if (realTemplate) { | ||
const realTemplateName = name.substr(pointIndex + 1); | ||
const pointIndex = name.indexOf('.'); | ||
if (pointIndex > 0) { | ||
const alias = name.substr(0, pointIndex); | ||
const realTemplate = this.templates.namedReferences[alias]; | ||
if (realTemplate) { | ||
const realTemplateName = name.substr(pointIndex + 1); | ||
return new ExpressionEvaluator( | ||
realTemplateName, | ||
FunctionUtils.apply(this.evaluateWithTemplates(realTemplateName, realTemplate)), | ||
ReturnType.Object, | ||
); | ||
} | ||
} | ||
if (name.startsWith('lg.')) { | ||
name = name.substring(3); | ||
} | ||
const templateName = this.parseTemplateName(name).pureTemplateName; | ||
if (templateName in this.templateMap) { | ||
if (isExpander) { | ||
return new ExpressionEvaluator( | ||
templateName, | ||
FunctionUtils.apply(this.templateExpander(name)), | ||
ReturnType.Object, | ||
this.validTemplateReference, | ||
); | ||
} else { | ||
return new ExpressionEvaluator( | ||
templateName, | ||
FunctionUtils.apply(this.templateEvaluator(name)), | ||
ReturnType.Object, | ||
this.validTemplateReference, | ||
); | ||
} | ||
} | ||
if (name === Evaluator.templateFunctionName) { | ||
return new ExpressionEvaluator( | ||
realTemplateName, | ||
FunctionUtils.apply(this.evaluateWithTemplates(realTemplateName, realTemplate)), | ||
ReturnType.Object | ||
Evaluator.templateFunctionName, | ||
FunctionUtils.apply(this.templateFunction()), | ||
ReturnType.Object, | ||
this.validateTemplateFunction, | ||
); | ||
} | ||
} | ||
if (name.startsWith('lg.')) { | ||
name = name.substring(3); | ||
} | ||
if (Templates.enableFromFile) { | ||
if (name === Evaluator.fromFileFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.fromFileFunctionName, | ||
FunctionUtils.apply(this.fromFile()), | ||
ReturnType.Object, | ||
(expr): void => FunctionUtils.validateOrder(expr, [ReturnType.String], ReturnType.String), | ||
); | ||
} | ||
} | ||
const templateName = this.parseTemplateName(name).pureTemplateName; | ||
if (templateName in this.templateMap) { | ||
if (isExpander) { | ||
if (name === Evaluator.activityAttachmentFunctionName) { | ||
return new ExpressionEvaluator( | ||
templateName, | ||
FunctionUtils.apply(this.templateExpander(name)), | ||
Evaluator.activityAttachmentFunctionName, | ||
FunctionUtils.apply(this.activityAttachment()), | ||
ReturnType.Object, | ||
this.validTemplateReference | ||
(expr): void => FunctionUtils.validateOrder(expr, undefined, ReturnType.Object, ReturnType.String), | ||
); | ||
} else { | ||
} | ||
if (name === Evaluator.isTemplateFunctionName) { | ||
return new ExpressionEvaluator( | ||
templateName, | ||
FunctionUtils.apply(this.templateEvaluator(name)), | ||
ReturnType.Object, | ||
this.validTemplateReference | ||
Evaluator.isTemplateFunctionName, | ||
FunctionUtils.apply(this.isTemplate()), | ||
ReturnType.Boolean, | ||
FunctionUtils.validateUnaryString, | ||
); | ||
} | ||
} | ||
if (name === Evaluator.templateFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.templateFunctionName, | ||
FunctionUtils.apply(this.templateFunction()), | ||
ReturnType.Object, | ||
this.validateTemplateFunction | ||
); | ||
} | ||
if (Templates.enableFromFile) { | ||
if (name === Evaluator.fromFileFunctionName) { | ||
if (name === Evaluator.expandTextFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.fromFileFunctionName, | ||
FunctionUtils.apply(this.fromFile()), | ||
Evaluator.expandTextFunctionName, | ||
FunctionUtils.apply(this.expandText()), | ||
ReturnType.Object, | ||
(expr): void => FunctionUtils.validateOrder(expr, [ReturnType.String], ReturnType.String) | ||
FunctionUtils.validateUnaryString, | ||
); | ||
} | ||
} | ||
if (name === Evaluator.activityAttachmentFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.activityAttachmentFunctionName, | ||
FunctionUtils.apply(this.activityAttachment()), | ||
ReturnType.Object, | ||
(expr): void => FunctionUtils.validateOrder(expr, undefined, ReturnType.Object, ReturnType.String) | ||
); | ||
} | ||
return undefined; | ||
}; | ||
if (name === Evaluator.isTemplateFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.isTemplateFunctionName, | ||
FunctionUtils.apply(this.isTemplate()), | ||
ReturnType.Boolean, | ||
FunctionUtils.validateUnaryString | ||
); | ||
} | ||
private readonly evaluateWithTemplates = | ||
(templateName: string, templates: Templates) => | ||
(args: readonly unknown[]): unknown => { | ||
const newScope = this.constructScope(templateName, args.slice(0), templates.allTemplates); | ||
if (name === Evaluator.expandTextFunctionName) { | ||
return new ExpressionEvaluator( | ||
Evaluator.expandTextFunctionName, | ||
FunctionUtils.apply(this.expandText()), | ||
ReturnType.Object, | ||
FunctionUtils.validateUnaryString | ||
); | ||
} | ||
return templates.evaluate(templateName, newScope); | ||
}; | ||
return undefined; | ||
}; | ||
private readonly templateEvaluator = | ||
(templateName: string) => | ||
(args: readonly unknown[]): unknown => { | ||
const newScope = this.constructScope(templateName, Array.from(args), this.templates.allTemplates); | ||
private readonly evaluateWithTemplates = (templateName: string, templates: Templates) => ( | ||
args: readonly unknown[] | ||
): unknown => { | ||
const newScope = this.constructScope(templateName, args.slice(0), templates.allTemplates); | ||
const value = this.expandTemplate(templateName, newScope); | ||
const randomNumber = Extensions.randomNext(this.currentTarget().scope, 0, value.length); | ||
return templates.evaluate(templateName, newScope); | ||
}; | ||
return value[randomNumber]; | ||
}; | ||
private readonly templateEvaluator = (templateName: string) => (args: readonly unknown[]): unknown => { | ||
const newScope = this.constructScope(templateName, Array.from(args), this.templates.allTemplates); | ||
private readonly templateExpander = | ||
(templateName: string) => | ||
(args: readonly unknown[]): unknown[] => { | ||
const newScope = this.constructScope(templateName, Array.from(args), this.templates.allTemplates); | ||
const value = this.expandTemplate(templateName, newScope); | ||
const randomNumber = Extensions.randomNext(this.currentTarget().scope, 0, value.length); | ||
return this.expandTemplate(templateName, newScope); | ||
}; | ||
return value[randomNumber]; | ||
}; | ||
private readonly templateExpander = (templateName: string) => (args: readonly unknown[]): unknown[] => { | ||
const newScope = this.constructScope(templateName, Array.from(args), this.templates.allTemplates); | ||
return this.expandTemplate(templateName, newScope); | ||
}; | ||
/** | ||
@@ -705,3 +708,3 @@ * @private | ||
evaluatorExpression: Expression, | ||
foundPrebuiltFunction: boolean | ||
foundPrebuiltFunction: boolean, | ||
): Expression { | ||
@@ -720,3 +723,3 @@ if (this.templateMap[expanderExpression.type]) { | ||
evaluatorExpression.children[i], | ||
foundPrebuiltFunction | ||
foundPrebuiltFunction, | ||
); | ||
@@ -728,27 +731,56 @@ } | ||
private readonly isTemplate = () => (args: readonly unknown[]): boolean => { | ||
const templateName = args[0].toString(); | ||
return templateName in this.templateMap; | ||
}; | ||
private readonly isTemplate = | ||
() => | ||
(args: readonly unknown[]): boolean => { | ||
const templateName = args[0].toString(); | ||
return templateName in this.templateMap; | ||
}; | ||
private readonly fromFile = () => (args: readonly unknown[]): unknown => { | ||
const filePath: string = TemplateExtensions.normalizePath(args[0].toString()); | ||
const resourcePath: string = this.getResourcePath(filePath); | ||
let format = FileFormat.Evaluated; | ||
if (args.length > 1) { | ||
const expected = args[1].toString().toLowerCase(); | ||
const currentFormat = Object.values(FileFormat).find((f) => f.toLowerCase() === expected); | ||
if (currentFormat != null) { | ||
format = currentFormat; | ||
private readonly fromFile = | ||
() => | ||
(args: readonly unknown[]): unknown => { | ||
const filePath: string = TemplateExtensions.normalizePath(args[0].toString()); | ||
const resourcePath: string = this.getResourcePath(filePath); | ||
let format = FileFormat.Evaluated; | ||
if (args.length > 1) { | ||
const expected = args[1].toString().toLowerCase(); | ||
const currentFormat = Object.values(FileFormat).find((f) => f.toLowerCase() === expected); | ||
if (currentFormat != null) { | ||
format = currentFormat; | ||
} | ||
} | ||
} | ||
let result: unknown; | ||
if (format === FileFormat.Binary) { | ||
result = fs.readFileSync(resourcePath); | ||
} else if (format === FileFormat.Raw) { | ||
result = fs.readFileSync(resourcePath, 'utf-8'); | ||
} else { | ||
const stringContent = fs.readFileSync(resourcePath, 'utf-8'); | ||
let result: unknown; | ||
if (format === FileFormat.Binary) { | ||
result = fs.readFileSync(resourcePath); | ||
} else if (format === FileFormat.Raw) { | ||
result = fs.readFileSync(resourcePath, 'utf-8'); | ||
} else { | ||
const stringContent = fs.readFileSync(resourcePath, 'utf-8'); | ||
const newScope = this.evaluationTargetStack.length > 0 ? this.currentTarget().scope : undefined; | ||
const newTemplates = new Templates( | ||
this.templates.allTemplates, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
this.templates.expressionParser, | ||
undefined, | ||
[], | ||
undefined, | ||
this.templates.namedReferences, | ||
); | ||
result = newTemplates.evaluateText(stringContent, newScope, this.lgOptions); | ||
} | ||
return result; | ||
}; | ||
private readonly expandText = | ||
() => | ||
(args: readonly unknown[]): unknown => { | ||
const stringContent = args[0].toString(); | ||
const newScope = this.evaluationTargetStack.length > 0 ? this.currentTarget().scope : undefined; | ||
@@ -766,30 +798,7 @@ const newTemplates = new Templates( | ||
undefined, | ||
this.templates.namedReferences | ||
this.templates.namedReferences, | ||
); | ||
result = newTemplates.evaluateText(stringContent, newScope, this.lgOptions); | ||
} | ||
return newTemplates.evaluateText(stringContent, newScope, this.lgOptions); | ||
}; | ||
return result; | ||
}; | ||
private readonly expandText = () => (args: readonly unknown[]): unknown => { | ||
const stringContent = args[0].toString(); | ||
const newScope = this.evaluationTargetStack.length > 0 ? this.currentTarget().scope : undefined; | ||
const newTemplates = new Templates( | ||
this.templates.allTemplates, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
this.templates.expressionParser, | ||
undefined, | ||
[], | ||
undefined, | ||
this.templates.namedReferences | ||
); | ||
return newTemplates.evaluateText(stringContent, newScope, this.lgOptions); | ||
}; | ||
/** | ||
@@ -821,17 +830,21 @@ * @private | ||
private readonly activityAttachment = () => (args: readonly unknown[]): Record<string, unknown> => { | ||
return { | ||
[Evaluator.LGType]: 'attachment', | ||
contenttype: args[1].toString(), | ||
content: args[0], | ||
private readonly activityAttachment = | ||
() => | ||
(args: readonly unknown[]): Record<string, unknown> => { | ||
return { | ||
[Evaluator.LGType]: 'attachment', | ||
contenttype: args[1].toString(), | ||
content: args[0], | ||
}; | ||
}; | ||
}; | ||
private readonly templateFunction = () => (args: readonly unknown[]): unknown[] => { | ||
const templateName: string = args[0].toString(); | ||
const newScope = this.constructScope(templateName, args.slice(1), this.templates.allTemplates); | ||
const value = this.expandTemplate(templateName, newScope); | ||
private readonly templateFunction = | ||
() => | ||
(args: readonly unknown[]): unknown[] => { | ||
const templateName: string = args[0].toString(); | ||
const newScope = this.constructScope(templateName, args.slice(1), this.templates.allTemplates); | ||
const value = this.expandTemplate(templateName, newScope); | ||
return value; | ||
}; | ||
return value; | ||
}; | ||
@@ -838,0 +851,0 @@ private readonly validateTemplateFunction = (expression: Expression): void => { |
@@ -9,3 +9,3 @@ /** | ||
import { AbstractParseTreeVisitor, TerminalNode } from 'antlr4ts/tree'; | ||
import keyBy = require('lodash/keyBy'); | ||
import keyBy from 'lodash/keyBy'; | ||
import { LGTemplateParserVisitor } from './generated/LGTemplateParserVisitor'; | ||
@@ -30,3 +30,4 @@ import { Template } from './template'; | ||
extends AbstractParseTreeVisitor<Map<string, string[]>> | ||
implements LGTemplateParserVisitor<Map<string, string[]>> { | ||
implements LGTemplateParserVisitor<Map<string, string[]>> | ||
{ | ||
readonly templates: Template[]; | ||
@@ -60,3 +61,3 @@ | ||
templateBodies.forEach( | ||
(templateBody) => (isNormalTemplate = isNormalTemplate && templateBody === undefined) | ||
(templateBody) => (isNormalTemplate = isNormalTemplate && templateBody === undefined), | ||
); | ||
@@ -134,4 +135,4 @@ | ||
: elseIfExpr | ||
? conditionNode.ELSEIF() | ||
: conditionNode.ELSE(); | ||
? conditionNode.ELSEIF() | ||
: conditionNode.ELSE(); | ||
const conditionLabel: string = node.text.toLowerCase(); | ||
@@ -174,4 +175,4 @@ const childTemplateBodyResult: string[] = []; | ||
: caseExpr | ||
? switchCaseStat.CASE() | ||
: switchCaseStat.DEFAULT(); | ||
? switchCaseStat.CASE() | ||
: switchCaseStat.DEFAULT(); | ||
if (switchExpr) { | ||
@@ -178,0 +179,0 @@ continue; |
@@ -25,3 +25,2 @@ /** | ||
export * from './templateErrors'; | ||
export * from './evaluator'; | ||
export * from './errorListener'; | ||
@@ -28,0 +27,0 @@ export * from './customizedMemory'; |
@@ -880,3 +880,3 @@ /** | ||
filePerLocale: Map<string, string> | undefined, | ||
defaultLanguage?: string | ||
defaultLanguage?: string, | ||
) { | ||
@@ -883,0 +883,0 @@ if (templatesPerLocale !== undefined) { |
@@ -38,3 +38,4 @@ /** | ||
extends AbstractParseTreeVisitor<Diagnostic[]> | ||
implements LGTemplateParserVisitor<Diagnostic[]> { | ||
implements LGTemplateParserVisitor<Diagnostic[]> | ||
{ | ||
private readonly templates: Templates; | ||
@@ -81,3 +82,3 @@ private currentTemplate: Template; | ||
DiagnosticSeverity.Warning, | ||
this.templates.source | ||
this.templates.source, | ||
); | ||
@@ -101,6 +102,6 @@ result.push(diagnostic); | ||
sameTemplate.name, | ||
sameTemplate.sourceRange.source | ||
sameTemplate.sourceRange.source, | ||
), | ||
DiagnosticSeverity.Error, | ||
this.templates.source | ||
this.templates.source, | ||
); | ||
@@ -157,4 +158,4 @@ templateDiagnostics.push(diagnostic); | ||
undefined, | ||
context.structuredBodyNameLine() | ||
) | ||
context.structuredBodyNameLine(), | ||
), | ||
); | ||
@@ -216,8 +217,8 @@ } | ||
: elseIfExpr | ||
? conditionNode.ELSEIF() | ||
: conditionNode.ELSE(); | ||
? conditionNode.ELSEIF() | ||
: conditionNode.ELSE(); | ||
if (node.text.split(' ').length - 1 > 1) { | ||
result.push( | ||
this.buildLGDiagnostic(TemplateErrors.invalidWhitespaceInCondition, undefined, conditionNode) | ||
this.buildLGDiagnostic(TemplateErrors.invalidWhitespaceInCondition, undefined, conditionNode), | ||
); | ||
@@ -231,4 +232,4 @@ } | ||
DiagnosticSeverity.Warning, | ||
conditionNode | ||
) | ||
conditionNode, | ||
), | ||
); | ||
@@ -246,4 +247,4 @@ } | ||
DiagnosticSeverity.Warning, | ||
conditionNode | ||
) | ||
conditionNode, | ||
), | ||
); | ||
@@ -259,3 +260,3 @@ } | ||
result.push( | ||
this.buildLGDiagnostic(TemplateErrors.invalidExpressionInCondition, undefined, conditionNode) | ||
this.buildLGDiagnostic(TemplateErrors.invalidExpressionInCondition, undefined, conditionNode), | ||
); | ||
@@ -269,3 +270,3 @@ } else { | ||
result.push( | ||
this.buildLGDiagnostic(TemplateErrors.extraExpressionInCondition, undefined, conditionNode) | ||
this.buildLGDiagnostic(TemplateErrors.extraExpressionInCondition, undefined, conditionNode), | ||
); | ||
@@ -278,3 +279,3 @@ } | ||
result.push( | ||
this.buildLGDiagnostic(TemplateErrors.missingTemplateBodyInCondition, undefined, conditionNode) | ||
this.buildLGDiagnostic(TemplateErrors.missingTemplateBodyInCondition, undefined, conditionNode), | ||
); | ||
@@ -309,7 +310,7 @@ } | ||
: caseExpr | ||
? switchCaseStat.CASE() | ||
: switchCaseStat.DEFAULT(); | ||
? switchCaseStat.CASE() | ||
: switchCaseStat.DEFAULT(); | ||
if (node.text.split(' ').length - 1 > 1) { | ||
result.push( | ||
this.buildLGDiagnostic(TemplateErrors.invalidWhitespaceInSwitchCase, undefined, switchCaseStat) | ||
this.buildLGDiagnostic(TemplateErrors.invalidWhitespaceInSwitchCase, undefined, switchCaseStat), | ||
); | ||
@@ -320,3 +321,3 @@ } | ||
result.push( | ||
this.buildLGDiagnostic(TemplateErrors.notStartWithSwitchInSwitchCase, undefined, switchCaseStat) | ||
this.buildLGDiagnostic(TemplateErrors.notStartWithSwitchInSwitchCase, undefined, switchCaseStat), | ||
); | ||
@@ -327,3 +328,7 @@ } | ||
result.push( | ||
this.buildLGDiagnostic(TemplateErrors.multipleSwithStatementInSwitchCase, undefined, switchCaseStat) | ||
this.buildLGDiagnostic( | ||
TemplateErrors.multipleSwithStatementInSwitchCase, | ||
undefined, | ||
switchCaseStat, | ||
), | ||
); | ||
@@ -337,4 +342,4 @@ } | ||
undefined, | ||
switchCaseStat | ||
) | ||
switchCaseStat, | ||
), | ||
); | ||
@@ -349,4 +354,4 @@ } | ||
DiagnosticSeverity.Warning, | ||
switchCaseStat | ||
) | ||
switchCaseStat, | ||
), | ||
); | ||
@@ -359,4 +364,4 @@ } else { | ||
DiagnosticSeverity.Warning, | ||
switchCaseStat | ||
) | ||
switchCaseStat, | ||
), | ||
); | ||
@@ -369,3 +374,3 @@ } | ||
result.push( | ||
this.buildLGDiagnostic(TemplateErrors.invalidExpressionInSwiathCase, undefined, switchCaseStat) | ||
this.buildLGDiagnostic(TemplateErrors.invalidExpressionInSwiathCase, undefined, switchCaseStat), | ||
); | ||
@@ -380,3 +385,3 @@ } else { | ||
result.push( | ||
this.buildLGDiagnostic(TemplateErrors.extraExpressionInSwitchCase, undefined, switchCaseStat) | ||
this.buildLGDiagnostic(TemplateErrors.extraExpressionInSwitchCase, undefined, switchCaseStat), | ||
); | ||
@@ -393,4 +398,4 @@ } | ||
undefined, | ||
switchCaseStat | ||
) | ||
switchCaseStat, | ||
), | ||
); | ||
@@ -468,3 +473,3 @@ } | ||
severity: DiagnosticSeverity = undefined, | ||
context: ParserRuleContext = undefined | ||
context: ParserRuleContext = undefined, | ||
): Diagnostic { | ||
@@ -471,0 +476,0 @@ const lineOffset = this.currentTemplate !== undefined ? this.currentTemplate.sourceRange.range.start.line : 0; |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable security/detect-object-injection */ | ||
/** | ||
@@ -191,3 +190,3 @@ * @module botbuilder-lg | ||
lineOffset + context.stop.line, | ||
context.stop.charPositionInLine + context.stop.text.length | ||
context.stop.charPositionInLine + context.stop.text.length, | ||
); | ||
@@ -194,0 +193,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable security/detect-object-injection */ | ||
/** | ||
@@ -23,7 +22,6 @@ * @module botbuilder-lg | ||
} from 'adaptive-expressions'; | ||
import { ImportResolverDelegate, TemplatesTransformer } from './templatesParser'; | ||
import { ImportResolverDelegate, TemplatesTransformer, TemplatesParser } from './templatesParser'; | ||
import { Evaluator } from './evaluator'; | ||
import { Expander } from './expander'; | ||
import { Analyzer } from './analyzer'; | ||
import { TemplatesParser } from './templatesParser'; | ||
import { AnalyzerResult } from './analyzerResult'; | ||
@@ -137,3 +135,3 @@ import { TemplateErrors } from './templateErrors'; | ||
source?: string, | ||
namedReferences?: Record<string, Templates> | ||
namedReferences?: Record<string, Templates>, | ||
) { | ||
@@ -241,3 +239,3 @@ this.items = items || []; | ||
importResolver?: ImportResolverDelegate, | ||
expressionParser?: ExpressionParser | ||
expressionParser?: ExpressionParser, | ||
): Templates { | ||
@@ -261,3 +259,3 @@ return TemplatesParser.parseFile(filePath, importResolver, expressionParser).injectToExpressionFunction(); | ||
importResolver?: ImportResolverDelegate, | ||
expressionParser?: ExpressionParser | ||
expressionParser?: ExpressionParser, | ||
): Templates { | ||
@@ -278,3 +276,3 @@ return TemplatesParser.parseText(content, id, importResolver, expressionParser).injectToExpressionFunction(); | ||
importResolver?: ImportResolverDelegate, | ||
expressionParser?: ExpressionParser | ||
expressionParser?: ExpressionParser, | ||
): Templates { | ||
@@ -381,3 +379,3 @@ return TemplatesParser.parseResource(resource, importResolver, expressionParser).injectToExpressionFunction(); | ||
parameters: string[], | ||
templateBody: string | ||
templateBody: string, | ||
): Templates { | ||
@@ -397,3 +395,3 @@ const template: Template = this.items.find((u: Template): boolean => u.name === templateName); | ||
template.sourceRange.range.end.line - 1, | ||
content | ||
content, | ||
); | ||
@@ -409,3 +407,3 @@ | ||
updatedTemplates = new TemplatesTransformer(updatedTemplates).transform( | ||
TemplatesParser.antlrParseTemplates(resource) | ||
TemplatesParser.antlrParseTemplates(resource), | ||
); | ||
@@ -458,3 +456,3 @@ | ||
updatedTemplates = new TemplatesTransformer(updatedTemplates).transform( | ||
TemplatesParser.antlrParseTemplates(resource) | ||
TemplatesParser.antlrParseTemplates(resource), | ||
); | ||
@@ -596,3 +594,3 @@ | ||
stopLine: number, | ||
replaceString: string | ||
replaceString: string, | ||
): string { | ||
@@ -707,4 +705,4 @@ const originList: string[] = TemplateExtensions.readLine(originString); | ||
}, | ||
ReturnType.Object | ||
) | ||
ReturnType.Object, | ||
), | ||
); | ||
@@ -711,0 +709,0 @@ } |
@@ -17,3 +17,11 @@ /* eslint-disable security/detect-non-literal-fs-filename */ | ||
import { ExpressionParser } from 'adaptive-expressions'; | ||
import { FileContext, LGFileParser } from './generated/LGFileParser'; | ||
import { | ||
FileContext, | ||
LGFileParser, | ||
ErrorDefinitionContext, | ||
ImportDefinitionContext, | ||
OptionDefinitionContext, | ||
TemplateBodyContext, | ||
TemplateDefinitionContext, | ||
} from './generated/LGFileParser'; | ||
import { LGFileLexer } from './generated/LGFileLexer'; | ||
@@ -40,10 +48,2 @@ import { LGResource } from './lgResource'; | ||
import { | ||
ErrorDefinitionContext, | ||
ImportDefinitionContext, | ||
OptionDefinitionContext, | ||
TemplateBodyContext, | ||
TemplateDefinitionContext, | ||
} from './generated/LGFileParser'; | ||
export declare type ImportResolverDelegate = (lgResource: LGResource, resourceId: string) => LGResource; | ||
@@ -81,3 +81,3 @@ | ||
importResolver?: ImportResolverDelegate, | ||
expressionParser?: ExpressionParser | ||
expressionParser?: ExpressionParser, | ||
): Templates { | ||
@@ -104,3 +104,3 @@ const fullPath = TemplateExtensions.normalizePath(filePath); | ||
importResolver?: ImportResolverDelegate, | ||
expressionParser?: ExpressionParser | ||
expressionParser?: ExpressionParser, | ||
): Templates { | ||
@@ -122,3 +122,3 @@ const resource = new LGResource(id, id, content); | ||
importResolver?: ImportResolverDelegate, | ||
expressionParser?: ExpressionParser | ||
expressionParser?: ExpressionParser, | ||
): Templates { | ||
@@ -149,3 +149,2 @@ return TemplatesParser.innerParseResource(resource, importResolver, expressionParser); | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
const resource = new LGResource(id, id, content); | ||
@@ -212,3 +211,3 @@ newTemplates = new TemplatesTransformer(newTemplates).transform(this.antlrParseTemplates(resource)); | ||
cachedTemplates: Map<string, Templates> = new Map<string, Templates>(), | ||
parentTemplates: Templates[] = [] | ||
parentTemplates: Templates[] = [], | ||
): Templates { | ||
@@ -234,3 +233,2 @@ if (!resource) { | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
templates = new TemplatesTransformer(templates).transform(this.antlrParseTemplates(resource)); | ||
@@ -278,3 +276,3 @@ templates.references = this.getReferences(templates, cachedTemplates, parentTemplates); | ||
cachedTemplates: Map<string, Templates> = new Map<string, Templates>(), | ||
parentTemplates: Templates[] = [] | ||
parentTemplates: Templates[] = [], | ||
): Templates[] { | ||
@@ -295,3 +293,3 @@ const resourcesFound = new Set<Templates>(); | ||
cachedTemplates: Map<string, Templates>, | ||
parentTemplates: Templates[] | ||
parentTemplates: Templates[], | ||
): void { | ||
@@ -311,3 +309,3 @@ resourcesFound.add(start); | ||
DiagnosticSeverity.Error, | ||
start.source | ||
start.source, | ||
); | ||
@@ -326,3 +324,3 @@ throw new TemplateException(error.message, [diagnostic]); | ||
DiagnosticSeverity.Error, | ||
start.source | ||
start.source, | ||
); | ||
@@ -340,3 +338,3 @@ throw new TemplateException(errorMsg, [diagnostic]); | ||
cachedTemplates, | ||
parentTemplates | ||
parentTemplates, | ||
); | ||
@@ -358,3 +356,3 @@ start.namedReferences[importItem.alias] = childResource; | ||
cachedTemplates, | ||
parentTemplates | ||
parentTemplates, | ||
); | ||
@@ -430,4 +428,4 @@ cachedTemplates.set(resource.id, childResource); | ||
TemplateErrors.syntaxError(`Unexpected content: '${lineContent}'`), | ||
context | ||
) | ||
context, | ||
), | ||
); | ||
@@ -461,3 +459,3 @@ } | ||
this.templates.diagnostics.push( | ||
this.buildTemplatesDiagnostic(TemplateErrors.importFormatError, context) | ||
this.buildTemplatesDiagnostic(TemplateErrors.importFormatError, context), | ||
); | ||
@@ -508,3 +506,3 @@ return; | ||
TemplateErrors.duplicatedTemplateInSameTemplate(templateName), | ||
context.templateNameLine() | ||
context.templateNameLine(), | ||
); | ||
@@ -535,3 +533,3 @@ this.templates.diagnostics.push(diagnostic); | ||
TemplateErrors.invalidTemplateName(templateName), | ||
context | ||
context, | ||
); | ||
@@ -564,3 +562,3 @@ this.templates.diagnostics.push(diagnostic); | ||
context, | ||
DiagnosticSeverity.Warning | ||
DiagnosticSeverity.Warning, | ||
); | ||
@@ -633,3 +631,3 @@ this.templates.diagnostics.push(diagnostic); | ||
leftBracketIndex + 1, | ||
templateNameLine.length - leftBracketIndex - 2 | ||
templateNameLine.length - leftBracketIndex - 2, | ||
); | ||
@@ -650,3 +648,3 @@ if (paramStr !== undefined && paramStr.trim() !== '') { | ||
context: ParserRuleContext, | ||
severity: DiagnosticSeverity = DiagnosticSeverity.Error | ||
severity: DiagnosticSeverity = DiagnosticSeverity.Error, | ||
): Diagnostic { | ||
@@ -657,3 +655,3 @@ return new Diagnostic( | ||
severity, | ||
this.templates.source | ||
this.templates.source, | ||
); | ||
@@ -660,0 +658,0 @@ } |
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
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
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1226473
23570
2
+ Addedadaptive-expressions@4.23.2-dev1(transitive)
+ Addedeslint-plugin-only-warn@1.1.0(transitive)
- Removed@types/lodash@4.17.14(transitive)
- Removed@types/lodash.isequal@4.5.8(transitive)
- Removedadaptive-expressions@4.23.1(transitive)
- Removedlodash.isequal@4.5.0(transitive)