Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parseUntilOffset(options: {
offset: number;
text: string;
taglib: TagLibLookup;
includeErrors?: boolean;
}) {
const { offset, text, taglib, includeErrors } = options;
let result: ParserEvents.Any | null = null;
let parentTag: ParserEvents.OpenTagName | ParserEvents.OpenTag | null = null;
const parser = createParser(
{
onError: includeErrors && finish,
onScriptlet: finish,
onPlaceholder: finish,
onOpenTagName(ev: ParserEvents.OpenTagName) {
if (parentTag) {
ev.parent = parentTag as ParserEvents.OpenTag;
}
// Currently the parser has the wrong end position here with tag params :\
if (!ev.concise) {
ev.pos += 1;
}
ev.endPos = ev.pos + ev.tagName.length;
parentTag = ev;
// Text within XML comment
handlers.handleComment(event.value);
},
onScriptlet(event) {
// <% (code) %> or $ {}
handlers.handleScriptlet(event);
},
onError(event) {
handlers.handleError(event);
}
};
var mergedOptions = Object.assign({}, this.defaultOptions, options);
var parser = (this.parser = htmljs.createParser(listeners, {
ignorePlaceholders: mergedOptions.ignorePlaceholders,
isOpenTagOnly: function(tagName) {
return handlers.isOpenTagOnly(tagName);
}
}));
parser.parse(src, filename);
}
}
return new Promise(function (resolve: (tag: Scope | boolean) => any) {
const parser = createParser({
onError: (error: any, data: any) => {
resolve({
tagName: error.code,
scopeType: ScopeType.NO_SCOPE,
data,
});
},
onOpenTag: (event: IHtMLJSParserEvent) => {
const {
pos: startPos,
endPos,
tagName,
tagNameEndPos,
attributes,
} = event;