Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public EvaluateInline(inlinsStr: string, scope: any): string {
const fakeTemplateId: string = '__temp__';
const wrappedStr: string = `# ${fakeTemplateId} \r\n - ${inlinsStr}`;
try {
const input: ANTLRInputStream = new ANTLRInputStream(wrappedStr);
const lexer: LGFileLexer = new LGFileLexer(input);
const tokens: CommonTokenStream = new CommonTokenStream(lexer);
const parser: LGFileParser = new LGFileParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(TemplateErrorListener.INSTANCE);
parser.buildParseTree = true;
parser.errorHandler = new BailErrorStrategy();
const context: TemplateDefinitionContext = parser.templateDefinition();
const evaluationContext: EvaluationContext = new EvaluationContext(this.evaluationContext.TemplateContexts,
this.evaluationContext.TemplateParameters);
evaluationContext.TemplateContexts[fakeTemplateId] = context;
const evalutor: Evaluator = new Evaluator(evaluationContext);
return evalutor.EvaluateTemplate(fakeTemplateId, scope);
} catch (error) {
throw error;
}
}
}
public static FromText(lgFileContent: string): TemplateEngine {
if (lgFileContent === undefined || lgFileContent === '') {
return new TemplateEngine();
}
try {
const input: ANTLRInputStream = new ANTLRInputStream(lgFileContent);
const lexer: LGFileLexer = new LGFileLexer(input);
const tokens: CommonTokenStream = new CommonTokenStream(lexer);
const parser: LGFileParser = new LGFileParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(TemplateErrorListener.INSTANCE);
parser.buildParseTree = true;
parser.errorHandler = new BailErrorStrategy();
const context: FileContext = parser.file();
return new TemplateEngine(context);
} catch (e) {
throw e;
}
}