当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript SAXParser.on方法代码示例

本文整理汇总了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 = "";
                }
            }
        });
    }
开发者ID:gitter-badger,项目名称:template-lint,代码行数:48,代码来源:parse-state.ts

示例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);
                    }                       
                }
            });
        });
    }
开发者ID:Thanood,项目名称:aurelia-template-lint,代码行数:30,代码来源:repeatfor.ts

示例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;
        });
    }
开发者ID:gitter-badger,项目名称:template-lint,代码行数:13,代码来源:parse-state.ts

示例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;
            }
        }); 
    }  
开发者ID:Thanood,项目名称:aurelia-template-lint,代码行数:51,代码来源:template.ts

示例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);
                        }
                    }
                }
            });
        });
    }
开发者ID:atsu85,项目名称:template-lint,代码行数:50,代码来源:attribute-value.ts

示例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);
         }
     });
 }
开发者ID:atsu85,项目名称:template-lint,代码行数:15,代码来源:obsolete-tag.ts

示例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});
            }
        })
    }
开发者ID:Thanood,项目名称:aurelia-template-lint,代码行数:17,代码来源:slot.ts

示例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);
        });
    }
开发者ID:atsu85,项目名称:template-lint,代码行数:44,代码来源:unique-id.ts

示例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;
}
开发者ID:krizzdewizz,项目名称:vscode-tag-rename,代码行数:43,代码来源:rename.ts

示例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);
            }
        });
    }
开发者ID:atsu85,项目名称:template-lint,代码行数:21,代码来源:self-close.ts


注:本文中的parse5.SAXParser.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。