diff --git a/src/compiler/utils/patterns.ts b/src/compiler/utils/patterns.ts index 317a7c1990..06b2739259 100644 --- a/src/compiler/utils/patterns.ts +++ b/src/compiler/utils/patterns.ts @@ -1,3 +1,5 @@ export const whitespace = /[ \t\r\n]/; +export const startWhitespace = /^[ \t\r\n]*/; +export const endWhitespace = /[ \t\r\n]*$/; export const dimensions = /^(?:offset|client)(?:Width|Height)$/; diff --git a/src/compiler/utils/trim.ts b/src/compiler/utils/trim.ts index 43f413bb1d..f9166fb4df 100644 --- a/src/compiler/utils/trim.ts +++ b/src/compiler/utils/trim.ts @@ -1,15 +1,9 @@ -import { whitespace } from './patterns'; +import { startWhitespace, endWhitespace } from './patterns'; export function trim_start(str: string) { - let i = 0; - while (whitespace.test(str[i])) i += 1; - - return str.slice(i); + return str.replace(startWhitespace, ''); } export function trim_end(str: string) { - let i = str.length; - while (whitespace.test(str[i - 1])) i -= 1; - - return str.slice(0, i); + return str.replace(endWhitespace, ''); }