|
5 | 5 | */ |
6 | 6 | import * as lodash from "lodash" |
7 | 7 | import {debug} from "../common/debug" |
8 | | -import {ErrorCode, Namespace, NS, ParseError, Token, VAttribute, VDocumentFragment, VElement, VNode, VText} from "../ast" |
| 8 | +import {ErrorCode, HasLocation, Namespace, NS, ParseError, Token, VAttribute, VDocumentFragment, VElement, VNode, VText} from "../ast" |
9 | 9 | import {MATHML_ATTRIBUTE_NAME_MAP, SVG_ATTRIBUTE_NAME_MAP} from "./util/attribute-names" |
10 | 10 | import {HTML_CAN_BE_LEFT_OPEN_TAGS, HTML_NON_FHRASING_TAGS, HTML_RAWTEXT_TAGS, HTML_RCDATA_TAGS, HTML_VOID_ELEMENT_TAGS, SVG_ELEMENT_NAME_MAP} from "./util/tag-names" |
11 | 11 | import {Tokenizer, TokenType} from "./tokenizer" |
@@ -132,7 +132,7 @@ export class Parser { |
132 | 132 | * Report an invalid character error. |
133 | 133 | * @param code The error code. |
134 | 134 | */ |
135 | | - private reportParseError(token: Token, code: ErrorCode): void { |
| 135 | + private reportParseError(token: HasLocation, code: ErrorCode): void { |
136 | 136 | const error = ParseError.fromCode(code, token.range[0], token.loc.start.line, token.loc.start.column) |
137 | 137 | this.errors.push(error) |
138 | 138 |
|
@@ -185,6 +185,18 @@ export class Parser { |
185 | 185 | this.namespace = NS.HTML |
186 | 186 | } |
187 | 187 | } |
| 188 | + // Check namespace |
| 189 | + else if (node.type === "VAttribute" && node.directive === false) { |
| 190 | + const key = node.key.name |
| 191 | + const value = node.value && node.value.value |
| 192 | + |
| 193 | + if (key === "xmlns" && value !== this.namespace) { |
| 194 | + this.reportParseError(node, "x-invalid-namespace") |
| 195 | + } |
| 196 | + if (key === "xmlns:xlink" && value !== NS.XLink) { |
| 197 | + this.reportParseError(node, "x-invalid-namespace") |
| 198 | + } |
| 199 | + } |
188 | 200 | } |
189 | 201 |
|
190 | 202 | /** |
@@ -483,14 +495,6 @@ export class Parser { |
483 | 495 | throw new Error("unreachable") |
484 | 496 | } |
485 | 497 |
|
486 | | - // Check namespace |
487 | | - if (attribute.key.name === "xmlns" && token.value !== this.namespace) { |
488 | | - this.reportParseError(token, "x-invalid-namespace") |
489 | | - } |
490 | | - if (attribute.key.name === "xmlns:xlink" && token.value !== NS.XLink) { |
491 | | - this.reportParseError(token, "x-invalid-namespace") |
492 | | - } |
493 | | - |
494 | 498 | // Initialize the attribute value. |
495 | 499 | attribute.range[1] = token.range[1] |
496 | 500 | attribute.loc.end = token.loc.end |
|
0 commit comments