refactor(developer): rename validate-layout-file.ts

Rename `ValidateLayoutFile()` to `CompileLayoutFile()` to better reflect
the transform steps it performs, add documentation, and address review
comments.

Co-authored-by: Eberhard Beilharz <ermshiperete@users.noreply.github.com>
This commit is contained in:
Marc Durdin 2026-08-20 15:47:08 +02:00
parent cd674fd7a0
commit 3a4e72bc66
5 changed files with 19 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import { KeyAddress } from "../kmw-compiler/validate-layout-file.js";
import { KeyAddress } from "../kmw-compiler/compile-layout-file.js";
import { kmnfile } from "../kmw-compiler/compiler-globals.js";
import { CompilerErrorNamespace, CompilerErrorSeverity, CompilerEvent, CompilerMessageSpec as m, CompilerMessageObjectSpec as mx, CompilerMessageDef as def, CompilerMessageSpecWithException, KeymanUrls } from "@keymanapp/developer-utils";
import { ObjectWithCompileContext } from "@keymanapp/common-types";

View file

@ -245,7 +245,18 @@ function TransformSpecialKeys17(FDebug: boolean, sLayoutFile: string): string {
return sLayoutFile;
}
export function ValidateLayoutFile(fk: KMX.KEYBOARD, FDebug: boolean, sLayoutFile: string, sVKDictionary: string, displayMap: Osk.PuaMap): VLFOutput { // I4060 // I4139
/**
* Compile a .keyman-touch-layout file into the internal Javascript object that KeymanWeb expects
* @param data
* @param FDictionary
* @returns null if the file is structurally invalid; false if the file contains content errors, true otherwise
*
* This function performs several steps:
* - load and validate the touch layout file
* - remap the layout keys with displayMap
* - injects 'special keys' javascript transforms for downlevel support
*/
export function CompileLayoutFile(fk: KMX.KEYBOARD, FDebug: boolean, sLayoutFile: string, sVKDictionary: string, displayMap: Osk.PuaMap): VLFOutput { // I4060 // I4139
const FDictionary: string[] = sVKDictionary.split(/\s+/);
CheckDictionaryKeyValidity(fk, FDictionary); // I4142
@ -362,7 +373,7 @@ function validateLayoutFileContent(data: TouchLayout.TouchLayoutFile, FDictionar
let direction: keyof TouchLayout.TouchLayoutFlick;
if(key.flick) {
if(typeof(key.flick) != "object") {
callbacks.reportMessage(KmwCompilerMessages.Error_InvalidTouchLayoutFileFormat({msg: 'platform.layer must be an array'}));
callbacks.reportMessage(KmwCompilerMessages.Error_InvalidTouchLayoutFileFormat({msg: 'key.flick must be an object'}));
return null;
}
for(direction in key.flick) {

View file

@ -1,6 +1,6 @@
import { keyAddress, KmnCompilerMessages } from "../compiler/kmn-compiler-messages.js";
import { CompilerErrorNamespace, CompilerErrorSeverity, CompilerMessageDef as def, CompilerMessageSpec as m } from "@keymanapp/developer-utils";
import { KeyAddress } from "./validate-layout-file.js";
import { KeyAddress } from "./compile-layout-file.js";
const Namespace = CompilerErrorNamespace.KmwCompiler;
const SevInfo = CompilerErrorSeverity.Info | Namespace;

View file

@ -4,7 +4,7 @@ import { ExpandSentinel, incxstr, xstrlen } from "./util.js";
import { options, nl, FTabStop, setupGlobals, callbacks, FFix183_LadderLength, FCallFunctions, fk, minimumKeymanVersionToString, isKeyboardVersion10OrLater, isKeyboardVersion17OrLater } from "./compiler-globals.js";
import { JavaScript_ContextMatch, JavaScript_KeyAsString, JavaScript_Name, JavaScript_OutputString, JavaScript_Rules, JavaScript_Shift, JavaScript_ShiftAsString, JavaScript_Store, zeroPadHex } from './javascript-strings.js';
import { KmwCompilerMessages } from "./kmw-compiler-messages.js";
import { ValidateLayoutFile } from "./validate-layout-file.js";
import { CompileLayoutFile } from "./compile-layout-file.js";
import { VisualKeyboardFromFile } from "./visual-keyboard-compiler.js";
import { KmnCompilerResult, STORETYPE_DEBUG, STORETYPE_OPTION, STORETYPE_RESERVED } from "../compiler/compiler.js";
@ -166,7 +166,7 @@ export function WriteCompiledKeyboard(
if (sLayoutFilename != '') { // I3483
sLayoutFilename = callbacks.resolveFilename(kmnfile, sLayoutFilename);
const result = ValidateLayoutFile(keyboard, options.saveDebug, sLayoutFilename, sVKDictionary, kmxResult.displayMap);
const result = CompileLayoutFile(keyboard, options.saveDebug, sLayoutFilename, sVKDictionary, kmxResult.displayMap);
if(!result) {
sLayoutFile = '';
return null;

View file

@ -9,10 +9,10 @@ import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
// import { KmnCompiler } from '../../src/compiler/compiler.js';
import { KMX, TouchLayout } from '@keymanapp/common-types';
import { KmwCompilerMessages } from '../../src/kmw-compiler/kmw-compiler-messages.js';
import { unitTestEndpoints } from '../../src/kmw-compiler/validate-layout-file.js';
import { unitTestEndpoints } from '../../src/kmw-compiler/compile-layout-file.js';
import { setupGlobals } from '../../src/kmw-compiler/compiler-globals.js';
describe('validate-layout-file', function() {
describe('compile-layout-file', function() {
const callbacks = new TestCompilerCallbacks(this);
const options = {
shouldAddCompilerVersion: false,