@ckeditor/ckeditor5-dev-utils
Version:
Utils for CKEditor 5 development tools packages.
24 lines (23 loc) • 866 B
JavaScript
//#region src/loaders/ck-debug-loader.ts
/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/
/**
* The loader matches sentences like: `// @if CK_DEBUG // someDebugCode();` and uncomment them.
* It also uncomments code after specific flags if they are provided to the webpack configuration.
* E.g. if the `CK_DEBUG_ENGINE` flag is set to true, then all lines starting with
* `// @if CK_DEBUG_ENGINE //` will be uncommented.
*
* @param {string} source
* @param {any} map
*/
function ckDebugLoader(source, map) {
source = source.replace(/\/\/ @if (!?[\w]+) \/\/(.+)/g, (match, flagName, body) => {
if (!this.query.debugFlags.includes(flagName)) return match;
return `/* @if ${flagName} */ ${body}`;
});
this.callback(null, source, map);
}
//#endregion
export { ckDebugLoader as default };