本文整理匯總了TypeScript中parse5.SAXParser.on方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript SAXParser.on方法的具體用法?TypeScript SAXParser.on怎麽用?TypeScript SAXParser.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類parse5.SAXParser
的用法示例。
在下文中一共展示了SAXParser.on方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: initPreRules
initPreRules(parser: SAXParser) {
this.stack = [];
this.issues = [];
var self = this;
var stack = this.stack;
parser.on("startTag", (name, attrs, selfClosing, location) => {
self.nextScope = null;
self.nextStack = null;
if (!selfClosing && !self.isVoid(name)) {
let currentScope = self.scope;
let nextScope = ""
if (stack.length > 0)
nextScope = stack[stack.length - 1].scope;
if (self.isScope(name))
nextScope = name;
self.nextScope = nextScope;
self.nextStack = new ParseNode(currentScope, name, location);
}
});
parser.on("endTag", (name, location) => {
if (stack.length <= 0 || stack[stack.length - 1].name != name) {
let issue = new Issue({
message: "mismatched close tag",
line: location.line,
column: location.col,
severity: IssueSeverity.Error
});
self.issues.push(issue);
}
else {
stack.pop();
if (stack.length > 0) {
self.scope = stack[stack.length - 1].scope;
}
else {
self.scope = "";
}
}
});
}
示例2: init
init(parser: SAXParser, parseState: ParseState) {
super.init(parser, parseState);
var syntax:RegExp = /(.+)( +of +)(.+)/
parser.on("startTag", (tag, attrs, selfClosing, loc) => {
var self = this;
attrs.forEach(attr => {
if (attr.name == "repeat") {
let error = new RuleError("did you miss `.for` on repeat?", loc.line, loc.col);
self.reportError(error);
return;
}
if (attr.name == "repeat.for") {
var script = attr.value.trim();
var matches = script.match(syntax);
var error = null;
if(matches == null || matches.length == 0){
let error = new RuleError("repeat syntax should be of form `* of *`", loc.line, loc.col);
self.reportError(error);
}
}
});
});
}
示例3: initPostRules
initPostRules(parser: SAXParser) {
var self = this;
parser.on("startTag", () => {
if (self.nextScope !== null)
self.scope = self.nextScope;
self.nextScope = null;
if (self.nextStack != null)
self.stack.push(self.nextStack)
self.nextStack = null;
});
}
示例4: init
init(parser: SAXParser, parseState: ParseState) {
this.disable = false;
this.first = true;
this.count = 0;
parser.on('startTag', (name, attrs, selfClosing, location) => {
// Ignore Full HTML Documents
if (this.disable || name == 'html') {
this.disable = true;
return;
}
if (this.first) {
if (name != 'template') {
let error = new RuleError("root element is not template", location.line, location.col);
this.reportError(error);
return;
}
this.count++;
this.first = false;
return;
}
if (name == 'template') {
if (this.count > 0) {
let stack = parseState.stack;
let stackCount = stack.length;
if (stackCount > 0) {
this.containers.forEach(containerName => {
if(stack[stackCount-1].name == containerName)
{
let error = new RuleError(`template as child of <${containerName}> not allowed`, location.line, location.col);
this.reportError(error);
}
});
}
else {
let error = new RuleError("more than one template in file", location.line, location.col);
this.reportError(error);
}
}
this.count += 1;
}
});
}
示例5: init
init(parser: SAXParser, parseState: ParseState) {
parser.on("startTag", (tag, attrs, selfClosing, loc) => {
attrs.forEach(attr => {
var pattern = this.patterns.find(x => {
if(x.tag && x.tag != tag)
return false;
return matches != attr.name.match(x.attr);
});
if (pattern) {
var matches;
if (pattern.is != null) {
matches = attr.value.match(pattern.is);
if (matches == null || matches[0] != attr.value) {
let issue = new Issue({
message: pattern.msg || `attribute value doesn't match expected pattern`,
severity: IssueSeverity.Error,
line: loc.line,
column: loc.col,
});
this.reportIssue(issue);
}
} else if (pattern.not != null) {
matches = attr.value.match(pattern.not);
if (matches != null) {
let issue = new Issue({
message: pattern.msg || `attribute value matched a disallowed pattern`,
severity: IssueSeverity.Error,
line: loc.line,
column: loc.col
});
this.reportIssue(issue);
}
} else /* no value expected */ {
if (attr.value != "") {
let issue = new Issue({
message: pattern.msg || `attribute should not have a value`,
severity: IssueSeverity.Error,
line: loc.line,
column: loc.col
});
this.reportIssue(issue);
}
}
}
});
});
}
示例6: init
init(parser: SAXParser, parseState: ParseState) {
parser.on("startTag", (tag, attrs, selfClosing, loc) => {
var obsolete = this.obsoletes.find(x => x.tag == tag);
if (obsolete) {
let issue = new Issue({
message: `<${tag}> is obsolete`,
severity: IssueSeverity.Error,
line: loc.line,
column: loc.col,
detail: obsolete.msg || "",
});
this.reportIssue(issue);
}
});
}
示例7: init
init(parser: SAXParser, parseState: ParseState) {
var self = this;
var stack = parseState.stack;
parser.on("startTag", (tag, attrs, sc, loc) => {
if (tag == 'slot') {
var name = "";
var nameIndex = attrs.findIndex((a)=>a.name=="name");
if(nameIndex >= 0)
name = attrs[nameIndex].value;
self.slots.push({name:name, loc:loc});
}
})
}
示例8: init
init(parser: SAXParser, parseState: ParseState) {
this.ids = [];
parser.on('startTag', (name, attrs, selfClosing, loc) => {
let idAttr = attrs.find(x => x.name == "id");
if (!idAttr)
return;
var id = idAttr.value;
if (id === "") {
let issue = new Issue({
message: "id cannot be empty",
severity: IssueSeverity.Warning,
line: loc.line,
column: loc.col
});
this.reportIssue(issue);
}
else if (id.match(/^[^a-z]+|[^\w:.-]+/) != null){
let issue = new Issue({
message: "id contains illegal characters",
severity: IssueSeverity.Error,
line: loc.line,
column: loc.col
});
this.reportIssue(issue);
}
else if (this.ids.indexOf(id) != -1) {
let issue = new Issue({
message: `duplicated id: ${id}`,
severity: IssueSeverity.Error,
line: loc.line,
column: loc.col
});
this.reportIssue(issue);
}
this.ids.push(id);
});
}
示例9: findMatchingEnd
export function findMatchingEnd(text: string, pos: number, hasVoidElements: boolean): Match {
const starts: StartPositions = {};
let depth = 0;
let startFound: { name: string, depth: number, position: number };
let startMatch: Match;
let endMatch: Match;
const toId = (name: string) => name + depth;
const isVoid: (name: string) => boolean = hasVoidElements ? isVoidElement : () => false;
const parser = new parse.SAXParser({ locationInfo: true });
parser.on('startTag', (name: string, attrs, selfClosing, location: parse.LocationInfo) => {
const voidd = selfClosing || isVoid(name);
starts[toId(name)] = location;
if (inRange(pos, location.startOffset, name.length)) {
if (voidd) {
startMatch = { length: name.length, start: location.startOffset + START_LEN };
parser.stop();
} else {
startFound = { name, depth, position: location.startOffset };
}
}
if (!voidd) {
depth++;
}
});
parser.on('endTag', (name: string, location: parse.LocationInfo) => {
depth--;
if (startFound && startFound.name === name && startFound.depth === depth) {
endMatch = { length: name.length, start: startFound.position + START_LEN, end: location.startOffset + END_LEN };
parser.stop();
} else if (inRange(pos, location.startOffset + 1, name.length)) {
startMatch = { length: name.length, start: starts[toId(name)].startOffset + START_LEN, end: location.startOffset + END_LEN };
parser.stop();
}
});
parser.end(text);
return endMatch || startMatch;
}
示例10: init
init(parser: SAXParser, parseState: ParseState) {
parser.on('startTag', (name, attrs, selfClosing, loc) => {
let scope = parseState.scope;
if (scope == 'svg' || scope == 'math') {
return;
}
if (selfClosing && parseState.isVoid(name) == false) {
let issue = new Issue({
message: "self-closing element",
severity: IssueSeverity.Error,
line: loc.line,
column: loc.col
});
this.reportIssue(issue);
}
});
}