From 01b6b3d45f17bbc66939a000c164a5a6e6e64eda Mon Sep 17 00:00:00 2001 From: Apola Kipso Date: Tue, 13 Jun 2023 14:53:21 +0200 Subject: [PATCH] Improved hasNativeStartsWith check There are JS environments where String.startsWith() exists but doesn't support the `position` parameter (e.g. in the taskpane of Outlook web add-ins). This check ensures a version of startsWith() is present that *does* support the position parameter. --- packages/icu-messageformat-parser/parser.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/icu-messageformat-parser/parser.ts b/packages/icu-messageformat-parser/parser.ts index c28bfe08d6..5d68ea140d 100644 --- a/packages/icu-messageformat-parser/parser.ts +++ b/packages/icu-messageformat-parser/parser.ts @@ -79,7 +79,8 @@ function createLocation(start: Position, end: Position): Location { // #region Ponyfills // Consolidate these variables up top for easier toggling during debugging -const hasNativeStartsWith = !!String.prototype.startsWith +const hasNativeStartsWith = + !!String.prototype.startsWith && '_a'.startsWith('a', 1) const hasNativeFromCodePoint = !!String.fromCodePoint const hasNativeFromEntries = !!(Object as any).fromEntries const hasNativeCodePointAt = !!String.prototype.codePointAt