From 8d26b4a19d2b92a8334eaf2e030168e4bfcdda89 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Tue, 23 Aug 2022 11:20:46 +0900 Subject: [PATCH] [chore] improve performance by using `trimRight()` instead of regex replace (#7706) --- 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;