From a5f86c2cb45cb30557d44495d4d7bb0c3bf2107e Mon Sep 17 00:00:00 2001 From: chientrm Date: Thu, 14 Jul 2022 14:31:25 +0000 Subject: [PATCH] refactor: :recycle: fragment types --- src/compiler/parse/state/fragment.ts | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/compiler/parse/state/fragment.ts b/src/compiler/parse/state/fragment.ts index 41275a1738..f74e6360a3 100644 --- a/src/compiler/parse/state/fragment.ts +++ b/src/compiler/parse/state/fragment.ts @@ -1,16 +1,10 @@ -import tag from './tag'; -import mustache from './mustache'; -import text from './text'; -import { Parser } from '../index'; +import { Parser } from "../index"; +import mustache from "./mustache"; +import tag from "./tag"; +import text from "./text"; -export default function fragment(parser: Parser) { - if (parser.match('<')) { - return tag; - } - - if (parser.match('{')) { - return mustache; - } - - return text; -} +export default (parser: Parser) => + [ + { match: "<", fragment: tag }, + { match: "{", fragment: mustache }, + ].find(({ match }) => parser.match(match))?.fragment ?? text;