From 1069a2be2120052193e82414bb0c78ab88ee6167 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Thu, 11 May 2023 14:29:02 +0200 Subject: [PATCH] finalize parse --- src/compiler/parse/index.js | 20 ++++++-------------- src/compiler/parse/state/tag.js | 3 ++- src/compiler/parse/utils/html.js | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/compiler/parse/index.js b/src/compiler/parse/index.js index a03c43dace..3cfae8b62b 100644 --- a/src/compiler/parse/index.js +++ b/src/compiler/parse/index.js @@ -57,7 +57,7 @@ export class Parser { meta_tags = {}; /** - * @type {LastAutoClosedTag} + * @type {{tag: string; reason: string; depth: number;}} */ last_auto_closed_tag = undefined; @@ -80,6 +80,11 @@ export class Parser { children: [] }; this.stack.push(this.html); + + /** + * @typedef {(parser: Parser) => ParserState | void} ParserState + */ + /** @type {ParserState} */ let state = fragment; while (this.index < this.template.length) { @@ -278,16 +283,3 @@ export default function parse(template, options = {}) { module: module_scripts[0] }; } - -/** - * @internal - * @typedef {(parser: Parser) => ParserState | void} ParserState - */ - -/** - * @internal - * @typedef {Object} LastAutoClosedTag - * @property {string} tag - * @property {string} reason - * @property {number} depth - */ diff --git a/src/compiler/parse/state/tag.js b/src/compiler/parse/state/tag.js index 40945ab60e..603031c08c 100644 --- a/src/compiler/parse/state/tag.js +++ b/src/compiler/parse/state/tag.js @@ -379,7 +379,8 @@ function read_attribute(parser, unique_names) { const first_value = value[0]; let expression = null; if (first_value) { - const attribute_contains_text = value.length > 1 || first_value.type === 'Text'; + const attribute_contains_text = + /** @type {any[]} */ (value).length > 1 || first_value.type === 'Text'; if (attribute_contains_text) { parser.error(parser_errors.invalid_directive_value, first_value.start); } else { diff --git a/src/compiler/parse/utils/html.js b/src/compiler/parse/utils/html.js index a0ee391c3d..febf47da43 100644 --- a/src/compiler/parse/utils/html.js +++ b/src/compiler/parse/utils/html.js @@ -128,7 +128,7 @@ const disallowed_contents = new Map([ /** * @param {string} current - * @param {string} next + * @param {string} [next] */ export function closing_tag_omitted(current, next) { if (disallowed_contents.has(current)) {