本文整理汇总了TypeScript中template-lint.Parser类的典型用法代码示例。如果您正苦于以下问题:TypeScript Parser类的具体用法?TypeScript Parser怎么用?TypeScript Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: init
init(parser: Parser) {
parser.on("startTag", (name, attrs, selfClosing, location) => {
this.examineTag(name, attrs, location.line, location.col);
});
parser.on("text", (text, location) => {
this.examineText(text, location.line);
});
}
示例2: init
init(parser: Parser) {
var stack = parser.state.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;
this.slots.push({ name: name, loc: loc });
for (let i = stack.length - 1; i >= 0; i--) {
let result = stack[i].attrs.find(x => this.controllers.indexOf(x.name)!= -1)
if (result){
this.reportIssue(
new Issue({
message: `slot cannot have ancestor using ${result.name}`,
line: loc.line,
column: loc.col
}));
return;
}
}
}
})
}
示例3: init
init(parser: Parser) {
parser.on("startTag", (tag, attrs, selfClosing, loc) => {
let rules = this.patterns.filter(r => {
return r.tag.test(tag);
});
if (rules) {
for (var rule of rules) {
if (!attrs.find(x => rule.attr.test(x.name))) {
let issue = new Issue({
message: rule.msg,
severity: IssueSeverity.Error,
line: loc.line,
column: loc.col,
start: loc.startOffset,
end: loc.endOffset
});
this.reportIssue(issue);
}
}
}
});
}
示例4: init
init(parser: Parser) {
var syntax: RegExp = /(.+)( +of +)(.+)/
parser.on("startTag", (tag, attrs, selfClosing, loc) => {
var self = this;
attrs.forEach(attr => {
if (attr.name == "repeat") {
let issue = new Issue({
message: "did you miss `.for` on repeat?",
line: loc.line,
column: loc.col});
self.reportIssue(issue);
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 Issue({
message: "repeat syntax should be of form `* of *`",
line: loc.line,
column: loc.col});
self.reportIssue(error);
}
}
});
});
}
示例5: init
init(parser: Parser) {
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 Issue({
message: "root element is not template",
line: location.line,
column:location.col});
this.reportIssue(error);
return;
}
this.count++;
this.first = false;
return;
}
if (name == 'template') {
if (this.count > 0) {
let stack = parser.state.stack;
let stackCount = stack.length;
if (stackCount > 0) {
this.containers.forEach(containerName => {
if(stack[stackCount-1].name == containerName)
{
let error = new Issue({
message: `template as child of <${containerName}> not allowed`,
line: location.line,
column: location.col
});
this.reportIssue(error);
}
});
}
else {
let error = new Issue({
message: "more than one template in file",
line: location.line,
column: location.col});
this.reportIssue(error);
}
}
this.count += 1;
}
});
}