Skip to content

Commit dc450cd

Browse files
author
Joshua Horton
committed
chore(web): finalize removal of side-effect KMWString implementation
1 parent f8ea902 commit dc450cd

File tree

20 files changed

+161
-222
lines changed

20 files changed

+161
-222
lines changed

common/test/resources/model-helpers.mjs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@ import vm from 'vm';
1313
// Ensure that we can successfully load the module & apply kmwLength, as it's
1414
// needed for some of the unit tests.
1515

16-
// // Verify that the KMW string extensions are loaded via side-effect.
17-
18-
import { extendString } from '@keymanapp/web-utils';
19-
2016
import { createRequire } from "module";
2117
import { fileURLToPath } from 'url';
2218

23-
// Ensure that our KMW string-extensions activate.
24-
extendString();
25-
2619
/**
2720
* Creates a MessageEvent (for inter-worker communication), with the given data payload.
2821
*

web/src/engine/common/web-utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export { default as Version } from "./version.js";
1616

1717
export { default as globalObject } from "./globalObject.js";
1818

19-
export { default as extendString } from "./kmwstring.js";
2019
export * as KMWString from './kmwstring.js';
2120

2221
export { default as ManagedPromise } from "./managedPromise.js";

web/src/engine/common/web-utils/src/kmwstring.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
/***
2-
KeymanWeb 19.0
3-
Copyright 2025 SIL International
2+
KeymanWeb 19.0
3+
Copyright 2025 SIL International
4+
5+
NOTE: in previous versions of Keyman Engine for Web, these methods were set on the standard
6+
JS String type in a manner considered a "side-effect". (When inspecting older versions, it may help
7+
to know that they were originally implemented within a file named kmwstring.ts.)
8+
*
9+
These methods seek to support SMP-aware string functionality within the Web engine, as many
10+
keyboards exist that utilize characters within such ranges.
411
***/
512

613
/**
@@ -58,7 +65,6 @@ export function charCodeAt(s: string, index: number) {
5865
return first;
5966
}
6067

61-
6268
/**
6369
* Returns the code point index within the calling String object of the first occurrence
6470
* of the specified value, or -1 if not found.
@@ -403,29 +409,4 @@ export function charAt(s: string, index: number) { // charAtPoint
403409
} else {
404410
return ''
405411
};
406-
}
407-
408-
/*
409-
* TODO: Remove this file as part of addressing https://github.com/keymanapp/keyman/issues/2492.
410-
*/
411-
412-
declare global {
413-
interface StringConstructor {
414-
kmwEnableSupplementaryPlane(bEnable: boolean): void
415-
}
416-
}
417-
418-
export default function extendString() {
419-
/**
420-
* Enable or disable supplementary plane string handling
421-
*
422-
* @param {boolean} bEnable
423-
*/
424-
String.kmwEnableSupplementaryPlane = function(bEnable)
425-
{
426-
enableSupplementaryPlane(bEnable);
427-
}
428-
}
429-
430-
// For side-effect imports:
431-
extendString();
412+
}

web/src/engine/common/web-utils/src/tests/stringHandling.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { KMWString } from '@keymanapp/web-utils';
55
describe('Unicode string handling', () => {
66
describe('disabled: BMP-mode, BMP-only strings', () => {
77
before(() => {
8-
String.kmwEnableSupplementaryPlane(false);
8+
KMWString.enableSupplementaryPlane(false);
99
});
1010

1111
it('charAt', () => {
@@ -118,7 +118,7 @@ describe('Unicode string handling', () => {
118118

119119
describe('enabled: SMP-mode, but BMP-only strings', () => {
120120
before(() => {
121-
String.kmwEnableSupplementaryPlane(true);
121+
KMWString.enableSupplementaryPlane(true);
122122
});
123123

124124
it('charAt', () => {
@@ -237,7 +237,7 @@ describe('Unicode string handling', () => {
237237

238238
describe('enabled: SMP-mode, with mixed-plane strings', () => {
239239
before(() => {
240-
String.kmwEnableSupplementaryPlane(true);
240+
KMWString.enableSupplementaryPlane(true);
241241
});
242242

243243
it('charAt', () => {

web/src/engine/js-processor/src/outputTarget.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { extendString, KMWString } from "@keymanapp/web-utils";
1+
import { KMWString } from "@keymanapp/web-utils";
22
import { findCommonSubstringEndIndex } from "./stringDivergence.js";
33
import { Mock } from "./mock.js";
44
import { OutputTarget as OutputTargetInterface } from 'keyman/engine/keyboard';
55

6-
extendString();
7-
86
// Defines deadkey management in a manner attachable to each element interface.
97
import { type KeyEvent } from 'keyman/engine/keyboard';
108
import { Deadkey, DeadkeyTracker } from "./deadkeys.js";

web/src/engine/main/src/keymanEngine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { LegacyAPIEvents } from "./legacyAPIEvents.js";
1515
import { EventNames, EventListener, LegacyEventEmitter } from "keyman/engine/events";
1616
import DOMCloudRequester from "keyman/engine/keyboard-storage/dom-requester";
1717
import KEYMAN_VERSION from "@keymanapp/keyman-version";
18+
import { KMWString } from "@keymanapp/web-utils";
1819

1920
// From https://stackoverflow.com/a/69328045
2021
type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
@@ -237,7 +238,7 @@ export default class KeymanEngine<
237238
config.initialize(optionSpec);
238239

239240
// Initialize supplementary plane string extensions
240-
String.kmwEnableSupplementaryPlane(true);
241+
KMWString.enableSupplementaryPlane(true);
241242

242243
// Since we're not sandboxing keyboard loads yet, we just use `window` as the jsGlobal object.
243244
// All components initialized below require a properly-configured `config.paths` or similar.

web/src/engine/predictive-text/templates/src/common.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import Outcome = LexicalModelTypes.Outcome;
66
import Suggestion = LexicalModelTypes.Suggestion;
77
import Transform = LexicalModelTypes.Transform;
88
import WithOutcome = LexicalModelTypes.WithOutcome;
9-
import { extendString, KMWString } from "@keymanapp/web-utils";
10-
11-
extendString();
9+
import { KMWString } from "@keymanapp/web-utils";
1210

1311
export const SENTINEL_CODE_UNIT = '\uFDD0';
1412

web/src/engine/predictive-text/templates/src/trie-model.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
// Worth noting: we're starting to get quite a 'library' of common model/LMLayer functionality.
2626
// Should probably make a 'lm-utils' submodule.
2727

28-
// Allows the kmwstring bindings to resolve.
29-
import { extendString, KMWString, PriorityQueue } from "@keymanapp/web-utils";
28+
import { KMWString, PriorityQueue } from "@keymanapp/web-utils";
3029
import { default as defaultWordBreaker } from "@keymanapp/models-wordbreakers";
3130

3231
import { applyTransform, isHighSurrogate, isSentinel, SENTINEL_CODE_UNIT, transformToSuggestion } from "./common.js";
@@ -47,8 +46,6 @@ import USVString = LexicalModelTypes.USVString;
4746
import WithOutcome = LexicalModelTypes.WithOutcome;
4847
import WordBreakingFunction = LexicalModelTypes.WordBreakingFunction;
4948

50-
extendString();
51-
5249
/**
5350
* @file trie-model.ts
5451
*

web/src/engine/predictive-text/templates/tests/helpers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ var _ = global;
77
// TODO: then mocha invocation is as follows:
88
// TODO: mocha -r @keymanapp/models-test-helpers test/
99

10-
import { extendString } from '@keymanapp/web-utils';
10+
import { KMWString } from '@keymanapp/web-utils';
11+
12+
// The predictive-text engine always keeps these enabled.
13+
KMWString.enableSupplementaryPlane(true);
1114

1215
import { createRequire } from "module";
1316
import { fileURLToPath } from 'url';
1417

15-
extendString();
16-
1718
/**
1819
* Load JSON fixtures from a well-known place.
1920
*/

web/src/engine/predictive-text/worker-thread/src/main/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
*/
3131

3232
/// <reference types="@keymanapp/lm-message-types" />
33-
import { extendString } from "@keymanapp/web-utils";
34-
35-
extendString();
3633

3734
import * as models from './models/index.js';
3835
import * as correction from './correction/index.js';

0 commit comments

Comments
 (0)