From 3bee2d04a315f1ed938820721134b6bf9558eab1 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 21 Jul 2022 19:12:06 +0900 Subject: [PATCH] [refactor] Improve performance by using trimRight() instead of regex replace --- src/compiler/compile/render_ssr/index.ts | 2 +- src/compiler/parse/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts index 9d2c1cc60b6..e256ba78fbf 100644 --- a/src/compiler/compile/render_ssr/index.ts +++ b/src/compiler/compile/render_ssr/index.ts @@ -237,7 +237,7 @@ function trim(nodes: TemplateNode[]) { const node = nodes[end - 1] as Text; if (node.type !== 'Text') break; - node.data = node.data.replace(/\s+$/, ''); + node.data = node.data.trimRight(); if (node.data) break; } diff --git a/src/compiler/parse/index.ts b/src/compiler/parse/index.ts index 836fb670cfd..e5e2260bc0f 100644 --- a/src/compiler/parse/index.ts +++ b/src/compiler/parse/index.ts @@ -34,7 +34,7 @@ export class Parser { throw new TypeError('Template must be a string'); } - this.template = template.replace(/\s+$/, ''); + this.template = template.trimRight(); this.filename = options.filename; this.customElement = options.customElement;