From db8b24eff5be0e89cf3c3b7c106cc73e96e9364e Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Thu, 11 May 2023 14:10:09 +0200 Subject: [PATCH] Lint and format src/compiler/parse/read/script.js --- src/compiler/parse/read/script.js | 77 +++++++++++++++---------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/src/compiler/parse/read/script.js b/src/compiler/parse/read/script.js index 3721779e1d..76643096f1 100644 --- a/src/compiler/parse/read/script.js +++ b/src/compiler/parse/read/script.js @@ -11,17 +11,16 @@ const regex_starts_with_closing_script_tag = /^<\/script\s*>/; * @returns {string} */ function get_context(parser, attributes, start) { - const context = attributes.find((attribute) => attribute.name === 'context'); - if (!context) - return 'default'; - if (context.value.length !== 1 || context.value[0].type !== 'Text') { - parser.error(parser_errors.invalid_script_context_attribute, start); - } - const value = context.value[0].data; - if (value !== 'module') { - parser.error(parser_errors.invalid_script_context_value, context.start); - } - return value; + const context = attributes.find((attribute) => attribute.name === 'context'); + if (!context) return 'default'; + if (context.value.length !== 1 || context.value[0].type !== 'Text') { + parser.error(parser_errors.invalid_script_context_attribute, start); + } + const value = context.value[0].data; + if (value !== 'module') { + parser.error(parser_errors.invalid_script_context_value, context.start); + } + return value; } /** @@ -31,35 +30,31 @@ function get_context(parser, attributes, start) { * @returns {Script} */ export default function read_script(parser, start, attributes) { - const script_start = parser.index; - const data = parser.read_until(regex_closing_script_tag, parser_errors.unclosed_script); - if (parser.index >= parser.template.length) { - parser.error(parser_errors.unclosed_script); - } - const source = parser.template.slice(0, script_start).replace(regex_not_newline_characters, ' ') + data; - parser.read(regex_starts_with_closing_script_tag); + const script_start = parser.index; + const data = parser.read_until(regex_closing_script_tag, parser_errors.unclosed_script); + if (parser.index >= parser.template.length) { + parser.error(parser_errors.unclosed_script); + } + const source = + parser.template.slice(0, script_start).replace(regex_not_newline_characters, ' ') + data; + parser.read(regex_starts_with_closing_script_tag); - /** - * @type {Program} - */ - let ast; - try { - ast = acorn.parse(source); - } - catch (err) { - parser.acorn_error(err); - } - // TODO is this necessary? - ast.start = script_start; - return { - type: 'Script', - start, - end: parser.index, - context: get_context(parser, attributes, start), - content: ast - }; + /** + * @type {Program} + */ + let ast; + try { + ast = acorn.parse(source); + } catch (err) { + parser.acorn_error(err); + } + // TODO is this necessary? + ast.start = script_start; + return { + type: 'Script', + start, + end: parser.index, + context: get_context(parser, attributes, start), + content: ast + }; } - - - -