angular-html-parser
Advanced tools
@@ -14,3 +14,3 @@ import { ParseSourceSpan } from "../parse_util.mjs"; | ||
| declare namespace ast_d_exports { | ||
| export { Attribute, Block, BlockParameter, CDATA, Comment, Component, Directive, DocType, Element, Expansion, ExpansionCase, LetDeclaration, Node, NodeWithI18n, RecursiveVisitor, Text, Visitor, visitAll }; | ||
| export { Attribute, Block, BlockParameter, CDATA, Comment, Component, Directive, DocType, Element, Expansion, ExpansionCase, LetDeclaration, Node, NodeWithI18n, RecursiveVisitor, StartTagComment, Text, Visitor, visitAll }; | ||
| } | ||
@@ -21,3 +21,3 @@ interface BaseNode { | ||
| } | ||
| type Node = Attribute | CDATA | Comment | DocType | Element | Expansion | ExpansionCase | Text | Block | BlockParameter | LetDeclaration | Component | Directive; | ||
| type Node = Attribute | CDATA | Comment | DocType | Element | Expansion | ExpansionCase | Text | Block | BlockParameter | LetDeclaration | Component | Directive | StartTagComment; | ||
| declare abstract class NodeWithI18n implements BaseNode { | ||
@@ -73,2 +73,10 @@ sourceSpan: ParseSourceSpan; | ||
| } | ||
| declare class StartTagComment implements BaseNode { | ||
| value: string; | ||
| type: 'single' | 'multi'; | ||
| sourceSpan: ParseSourceSpan; | ||
| constructor(value: string, type: 'single' | 'multi', sourceSpan: ParseSourceSpan); | ||
| visit(visitor: Visitor, context: any): any; | ||
| readonly kind = "startTagComment"; | ||
| } | ||
| declare class Element extends NodeWithI18n { | ||
@@ -84,3 +92,4 @@ name: string; | ||
| readonly isVoid: boolean; | ||
| constructor(name: string, attrs: Attribute[], directives: Directive[], children: Node[], isSelfClosing: boolean, sourceSpan: ParseSourceSpan, startSourceSpan: ParseSourceSpan, endSourceSpan: (ParseSourceSpan | null) | undefined, nameSpan: (ParseSourceSpan | null) | undefined, isVoid: boolean, i18n?: I18nMeta); | ||
| comments: StartTagComment[]; | ||
| constructor(name: string, attrs: Attribute[], directives: Directive[], children: Node[], isSelfClosing: boolean, sourceSpan: ParseSourceSpan, startSourceSpan: ParseSourceSpan, endSourceSpan: (ParseSourceSpan | null) | undefined, nameSpan: (ParseSourceSpan | null) | undefined, isVoid: boolean, i18n?: I18nMeta, comments?: StartTagComment[]); | ||
| visit(visitor: Visitor, context: any): any; | ||
@@ -124,3 +133,4 @@ readonly kind = "element"; | ||
| endSourceSpan: ParseSourceSpan | null; | ||
| constructor(componentName: string, tagName: string | null, fullName: string, attrs: Attribute[], directives: Directive[], children: Node[], isSelfClosing: boolean, sourceSpan: ParseSourceSpan, startSourceSpan: ParseSourceSpan, endSourceSpan?: ParseSourceSpan | null, i18n?: I18nMeta); | ||
| comments: StartTagComment[]; | ||
| constructor(componentName: string, tagName: string | null, fullName: string, attrs: Attribute[], directives: Directive[], children: Node[], isSelfClosing: boolean, sourceSpan: ParseSourceSpan, startSourceSpan: ParseSourceSpan, endSourceSpan?: ParseSourceSpan | null, i18n?: I18nMeta, comments?: StartTagComment[]); | ||
| visit(visitor: Visitor, context: any): any; | ||
@@ -175,2 +185,3 @@ readonly kind = "component"; | ||
| visitDirective(directive: Directive, context: any): any; | ||
| visitAttributeComment?(comment: StartTagComment, context: any): any; | ||
| } | ||
@@ -182,2 +193,3 @@ declare function visitAll(visitor: Visitor, nodes: Node[], context?: any): any[]; | ||
| visitAttribute(ast: Attribute, context: any): any; | ||
| visitAttributeComment(ast: StartTagComment, context: any): any; | ||
| visitText(ast: Text, context: any): any; | ||
@@ -184,0 +196,0 @@ visitCdata(ast: CDATA, context: any): any; |
@@ -100,2 +100,16 @@ //#region ../compiler/src/ml_parser/ast.ts | ||
| }; | ||
| var StartTagComment = class { | ||
| value; | ||
| type; | ||
| sourceSpan; | ||
| constructor(value, type, sourceSpan) { | ||
| this.value = value; | ||
| this.type = type; | ||
| this.sourceSpan = sourceSpan; | ||
| } | ||
| visit(visitor, context) { | ||
| return visitor.visitAttributeComment ? visitor.visitAttributeComment(this, context) : void 0; | ||
| } | ||
| kind = "startTagComment"; | ||
| }; | ||
| var Element = class extends NodeWithI18n { | ||
@@ -111,3 +125,4 @@ name; | ||
| isVoid; | ||
| constructor(name, attrs, directives, children, isSelfClosing, sourceSpan, startSourceSpan, endSourceSpan = null, nameSpan = null, isVoid, i18n) { | ||
| comments; | ||
| constructor(name, attrs, directives, children, isSelfClosing, sourceSpan, startSourceSpan, endSourceSpan = null, nameSpan = null, isVoid, i18n, comments = []) { | ||
| super(sourceSpan, i18n); | ||
@@ -123,2 +138,3 @@ this.name = name; | ||
| this.isVoid = isVoid; | ||
| this.comments = comments; | ||
| } | ||
@@ -185,3 +201,4 @@ visit(visitor, context) { | ||
| endSourceSpan; | ||
| constructor(componentName, tagName, fullName, attrs, directives, children, isSelfClosing, sourceSpan, startSourceSpan, endSourceSpan = null, i18n) { | ||
| comments; | ||
| constructor(componentName, tagName, fullName, attrs, directives, children, isSelfClosing, sourceSpan, startSourceSpan, endSourceSpan = null, i18n, comments = []) { | ||
| super(sourceSpan, i18n); | ||
@@ -197,2 +214,3 @@ this.componentName = componentName; | ||
| this.endSourceSpan = endSourceSpan; | ||
| this.comments = comments; | ||
| } | ||
@@ -271,2 +289,3 @@ visit(visitor, context) { | ||
| visit(ast.directives); | ||
| visit(ast.comments); | ||
| visit(ast.children); | ||
@@ -276,2 +295,3 @@ }); | ||
| visitAttribute(ast, context) {} | ||
| visitAttributeComment(ast, context) {} | ||
| visitText(ast, context) {} | ||
@@ -298,2 +318,3 @@ visitCdata(ast, context) {} | ||
| visit(component.attrs); | ||
| visit(component.comments); | ||
| visit(component.children); | ||
@@ -318,2 +339,2 @@ }); | ||
| //#endregion | ||
| export { Attribute, Block, BlockParameter, CDATA, Comment, Component, Directive, DocType, Element, Expansion, ExpansionCase, LetDeclaration, RecursiveVisitor, Text, visitAll }; | ||
| export { Attribute, Block, BlockParameter, CDATA, Comment, Component, Directive, DocType, Element, Expansion, ExpansionCase, LetDeclaration, RecursiveVisitor, StartTagComment, Text, visitAll }; |
@@ -63,3 +63,3 @@ import { mergeNsAndName } from "./tags.mjs"; | ||
| _allowHtmComponentClosingTags; | ||
| _allowInElementComments; | ||
| _allowStartTagComments; | ||
| _currentTokenStart = null; | ||
@@ -91,3 +91,3 @@ _currentTokenType = null; | ||
| this._allowHtmComponentClosingTags = options.allowHtmComponentClosingTags || false; | ||
| this._allowInElementComments = options.allowInElementComments ?? true; | ||
| this._allowStartTagComments = options.allowStartTagComments ?? true; | ||
| const range = options.range || { | ||
@@ -503,3 +503,3 @@ endPos: _file.content.length, | ||
| this._beginToken(12, start); | ||
| this._endToken([content], spanEnd); | ||
| this._endToken([content, "single"], spanEnd); | ||
| this._attemptCharCodeUntilFn(isNotWhitespace); | ||
@@ -526,3 +526,3 @@ } | ||
| this._beginToken(12, start); | ||
| this._endToken([content], spanEnd); | ||
| this._endToken([content, "multi"], spanEnd); | ||
| } | ||
@@ -550,3 +550,3 @@ _consumeTagOpen(start) { | ||
| while (true) { | ||
| if (this._allowInElementComments) { | ||
| if (this._allowStartTagComments) { | ||
| const commentStart = this._cursor.clone(); | ||
@@ -553,0 +553,0 @@ if (this._attemptStr("//")) { |
| import { getNsPrefix, mergeNsAndName, splitNsName } from "./tags.mjs"; | ||
| import { ParseError, ParseSourceSpan } from "../parse_util.mjs"; | ||
| import { Attribute, Block, BlockParameter, CDATA, Comment, Component, Directive, DocType, Element, Expansion, ExpansionCase, LetDeclaration, Text } from "./ast.mjs"; | ||
| import { Attribute, Block, BlockParameter, CDATA, Comment, Component, Directive, DocType, Element, Expansion, ExpansionCase, LetDeclaration, StartTagComment, Text } from "./ast.mjs"; | ||
| import { NAMED_ENTITIES } from "./entities.mjs"; | ||
@@ -250,3 +250,4 @@ import { tokenize } from "./lexer.mjs"; | ||
| const directives = []; | ||
| this._consumeAttributesAndDirectives(attrs, directives); | ||
| const comments = []; | ||
| this._consumeAttributesAndDirectives(attrs, directives, comments); | ||
| const fullName = this._getElementFullName(startTagToken, this._getClosestElementLikeParent()); | ||
@@ -268,3 +269,3 @@ const tagDef = this._getTagDefinition(fullName); | ||
| const nameSpan = new ParseSourceSpan(startTagToken.sourceSpan.start.moveBy(1), startTagToken.sourceSpan.end); | ||
| const el = new Element(fullName, attrs, directives, [], selfClosing, span, startSpan, void 0, nameSpan, (tagDef === null || tagDef === void 0 ? void 0 : tagDef.isVoid) ?? false); | ||
| const el = new Element(fullName, attrs, directives, [], selfClosing, span, startSpan, void 0, nameSpan, (tagDef === null || tagDef === void 0 ? void 0 : tagDef.isVoid) ?? false, void 0, comments); | ||
| const parent = this._getContainer(); | ||
@@ -284,3 +285,4 @@ const isClosedByChild = parent !== null && !!((_this$_getTagDefiniti4 = this._getTagDefinition(parent)) === null || _this$_getTagDefiniti4 === void 0 ? void 0 : _this$_getTagDefiniti4.isClosedByChild(el.name)); | ||
| const directives = []; | ||
| this._consumeAttributesAndDirectives(attrs, directives); | ||
| const comments = []; | ||
| this._consumeAttributesAndDirectives(attrs, directives, comments); | ||
| const closestElement = this._getClosestElementLikeParent(); | ||
@@ -293,3 +295,3 @@ const tagName = this._getComponentTagName(startToken, closestElement); | ||
| const span = new ParseSourceSpan(startToken.sourceSpan.start, end, startToken.sourceSpan.fullStart); | ||
| const node = new Component(componentName, tagName, fullName, attrs, directives, [], selfClosing, span, new ParseSourceSpan(startToken.sourceSpan.start, end, startToken.sourceSpan.fullStart), void 0); | ||
| const node = new Component(componentName, tagName, fullName, attrs, directives, [], selfClosing, span, new ParseSourceSpan(startToken.sourceSpan.start, end, startToken.sourceSpan.fullStart), void 0, void 0, comments); | ||
| const parent = this._getContainer(); | ||
@@ -304,3 +306,3 @@ const isClosedByChild = parent !== null && node.tagName !== null && !!((_this$_getTagDefiniti5 = this._getTagDefinition(parent)) === null || _this$_getTagDefiniti5 === void 0 ? void 0 : _this$_getTagDefiniti5.isClosedByChild(node.tagName)); | ||
| } | ||
| _consumeAttributesAndDirectives(attributesResult, directivesResult) { | ||
| _consumeAttributesAndDirectives(attributesResult, directivesResult, commentsResult) { | ||
| while (this._peek.type === 15 || this._peek.type === 40 || this._peek.type === 12) if (this._peek.type === 40) directivesResult.push(this._consumeDirective(this._peek)); | ||
@@ -310,3 +312,3 @@ else if (this._peek.type === 15) attributesResult.push(this._consumeAttr(this._advance())); | ||
| const commentToken = this._advance(); | ||
| this._addToParent(new Comment(commentToken.parts[0], commentToken.sourceSpan)); | ||
| commentsResult.push(new StartTagComment(commentToken.parts[0], commentToken.parts[1], commentToken.sourceSpan)); | ||
| } | ||
@@ -313,0 +315,0 @@ } |
+2
-2
@@ -23,7 +23,7 @@ import { TagContentType } from "./compiler/src/ml_parser/tags.mjs"; | ||
| /** | ||
| * allow in-element comments | ||
| * allow comments in start tag | ||
| * | ||
| * defaults to false | ||
| */ | ||
| allowInElementComments?: boolean; | ||
| allowStartTagComments?: boolean; | ||
| /** | ||
@@ -30,0 +30,0 @@ * do not lowercase tag names before querying their tag definitions |
+2
-2
@@ -11,3 +11,3 @@ import { TagContentType } from "./compiler/src/ml_parser/tags.mjs"; | ||
| function parseHtml(input, options = {}) { | ||
| const { canSelfClose = false, allowHtmComponentClosingTags = false, allowInElementComments = false, isTagNameCaseSensitive = false, getTagContentType, tokenizeAngularBlocks = false, tokenizeAngularLetDeclaration = false, enableAngularSelectorlessSyntax = false } = options; | ||
| const { canSelfClose = false, allowHtmComponentClosingTags = false, allowStartTagComments = false, isTagNameCaseSensitive = false, getTagContentType, tokenizeAngularBlocks = false, tokenizeAngularLetDeclaration = false, enableAngularSelectorlessSyntax = false } = options; | ||
| htmlParser ?? (htmlParser = new HtmlParser()); | ||
@@ -18,3 +18,3 @@ return htmlParser.parse(input, "angular-html-parser", { | ||
| allowHtmComponentClosingTags, | ||
| allowInElementComments, | ||
| allowStartTagComments, | ||
| tokenizeBlocks: tokenizeAngularBlocks, | ||
@@ -21,0 +21,0 @@ tokenizeLet: tokenizeAngularLetDeclaration, |
+1
-1
| { | ||
| "name": "angular-html-parser", | ||
| "version": "10.9.0", | ||
| "version": "10.10.0", | ||
| "description": "A HTML parser extracted from Angular with some modifications", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/prettier/angular-html-parser", |
193419
0.69%5400
0.43%