You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@wordpress/warning

Package Overview
Dependencies
Maintainers
23
Versions
199
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/warning - npm Package Compare versions

Comparing version
3.37.0
to
3.37.1-next.79a2f3cdd.0
+76
babel-plugin.cjs
/**
* Internal dependencies
*/
const pkg = require( './package.json' );
/**
* Babel plugin which transforms `warning` function calls to wrap within a
* condition that checks if `SCRIPT_DEBUG === true`.
*
* @param {import('@babel/core')} babel Current Babel object.
*
* @return {import('@babel/core').PluginObj} Babel plugin object.
*/
function babelPlugin( { types: t } ) {
const seen = Symbol();
const scriptDebugCheckExpression = t.binaryExpression(
'===',
t.memberExpression(
t.identifier( 'globalThis' ),
t.identifier( 'SCRIPT_DEBUG' )
),
t.booleanLiteral( true )
);
return {
visitor: {
ImportDeclaration( path, state ) {
const { node } = path;
const isThisPackageImport =
node.source.value.indexOf( pkg.name ) !== -1;
if ( ! isThisPackageImport ) {
return;
}
const defaultSpecifier = node.specifiers.find(
( specifier ) => specifier.type === 'ImportDefaultSpecifier'
);
if ( defaultSpecifier && defaultSpecifier.local ) {
const { name } = defaultSpecifier.local;
state.callee = name;
}
},
CallExpression( path, state ) {
const { node } = path;
// Ignore if it's already been processed.
if ( node[ seen ] ) {
return;
}
const name = state.callee || state.opts.callee;
if ( path.get( 'callee' ).isIdentifier( { name } ) ) {
// Turns this code:
// warning(argument);
// into this:
// typeof SCRIPT_DEBUG !== 'undefined' && SCRIPT_DEBUG === true ? warning(argument) : void 0;
node[ seen ] = true;
path.replaceWith(
t.ifStatement(
scriptDebugCheckExpression,
t.blockStatement( [
t.expressionStatement( node ),
] )
)
);
}
},
},
};
}
module.exports = babelPlugin;
// packages/warning/src/index.ts
import { logged } from "./utils.mjs";
function isDev() {
return globalThis.SCRIPT_DEBUG === true;
}
function warning(message) {
if (!isDev()) {
return;
}
if (logged.has(message)) {
return;
}
console.warn(message);
try {
throw Error(message);
} catch (x) {
}
logged.add(message);
}
export {
warning as default
};
//# sourceMappingURL=index.mjs.map
{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { logged } from './utils';\n\nfunction isDev(): boolean {\n\t// eslint-disable-next-line @wordpress/wp-global-usage\n\treturn globalThis.SCRIPT_DEBUG === true;\n}\n\n/**\n * Shows a warning with `message` if environment is not `production`.\n *\n * @param message Message to show in the warning.\n *\n * @example\n * ```js\n * import warning from '@wordpress/warning';\n *\n * function MyComponent( props ) {\n * if ( ! props.title ) {\n * warning( '`props.title` was not passed' );\n * }\n * ...\n * }\n * ```\n */\nexport default function warning( message: string ): void {\n\tif ( ! isDev() ) {\n\t\treturn;\n\t}\n\n\t// Skip if already logged.\n\tif ( logged.has( message ) ) {\n\t\treturn;\n\t}\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\t// Throwing an error and catching it immediately to improve debugging\n\t// A consumer can use 'pause on caught exceptions'\n\t// https://github.com/facebook/react/issues/4216\n\ttry {\n\t\tthrow Error( message );\n\t} catch ( x ) {\n\t\t// Do nothing.\n\t}\n\tlogged.add( message );\n}\n"],
"mappings": ";AAGA,SAAS,cAAc;AAEvB,SAAS,QAAiB;AAEzB,SAAO,WAAW,iBAAiB;AACpC;AAmBe,SAAR,QAA0B,SAAwB;AACxD,MAAK,CAAE,MAAM,GAAI;AAChB;AAAA,EACD;AAGA,MAAK,OAAO,IAAK,OAAQ,GAAI;AAC5B;AAAA,EACD;AAGA,UAAQ,KAAM,OAAQ;AAKtB,MAAI;AACH,UAAM,MAAO,OAAQ;AAAA,EACtB,SAAU,GAAI;AAAA,EAEd;AACA,SAAO,IAAK,OAAQ;AACrB;",
"names": []
}
// packages/warning/src/utils.ts
var logged = /* @__PURE__ */ new Set();
export {
logged
};
//# sourceMappingURL=utils.mjs.map
{
"version": 3,
"sources": ["../src/utils.ts"],
"sourcesContent": ["/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n */\nexport const logged: Set< string > = new Set();\n"],
"mappings": ";AAIO,IAAM,SAAwB,oBAAI,IAAI;",
"names": []
}
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/warning/src/index.ts
var index_exports = {};
__export(index_exports, {
default: () => warning
});
module.exports = __toCommonJS(index_exports);
var import_utils = require("./utils.cjs");
function isDev() {
return globalThis.SCRIPT_DEBUG === true;
}
function warning(message) {
if (!isDev()) {
return;
}
if (import_utils.logged.has(message)) {
return;
}
console.warn(message);
try {
throw Error(message);
} catch (x) {
}
import_utils.logged.add(message);
}
//# sourceMappingURL=index.cjs.map
{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { logged } from './utils';\n\nfunction isDev(): boolean {\n\t// eslint-disable-next-line @wordpress/wp-global-usage\n\treturn globalThis.SCRIPT_DEBUG === true;\n}\n\n/**\n * Shows a warning with `message` if environment is not `production`.\n *\n * @param message Message to show in the warning.\n *\n * @example\n * ```js\n * import warning from '@wordpress/warning';\n *\n * function MyComponent( props ) {\n * if ( ! props.title ) {\n * warning( '`props.title` was not passed' );\n * }\n * ...\n * }\n * ```\n */\nexport default function warning( message: string ): void {\n\tif ( ! isDev() ) {\n\t\treturn;\n\t}\n\n\t// Skip if already logged.\n\tif ( logged.has( message ) ) {\n\t\treturn;\n\t}\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\t// Throwing an error and catching it immediately to improve debugging\n\t// A consumer can use 'pause on caught exceptions'\n\t// https://github.com/facebook/react/issues/4216\n\ttry {\n\t\tthrow Error( message );\n\t} catch ( x ) {\n\t\t// Do nothing.\n\t}\n\tlogged.add( message );\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAuB;AAEvB,SAAS,QAAiB;AAEzB,SAAO,WAAW,iBAAiB;AACpC;AAmBe,SAAR,QAA0B,SAAwB;AACxD,MAAK,CAAE,MAAM,GAAI;AAChB;AAAA,EACD;AAGA,MAAK,oBAAO,IAAK,OAAQ,GAAI;AAC5B;AAAA,EACD;AAGA,UAAQ,KAAM,OAAQ;AAKtB,MAAI;AACH,UAAM,MAAO,OAAQ;AAAA,EACtB,SAAU,GAAI;AAAA,EAEd;AACA,sBAAO,IAAK,OAAQ;AACrB;",
"names": []
}
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/warning/src/utils.ts
var utils_exports = {};
__export(utils_exports, {
logged: () => logged
});
module.exports = __toCommonJS(utils_exports);
var logged = /* @__PURE__ */ new Set();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
logged
});
//# sourceMappingURL=utils.cjs.map
{
"version": 3,
"sources": ["../src/utils.ts"],
"sourcesContent": ["/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n */\nexport const logged: Set< string > = new Set();\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,IAAM,SAAwB,oBAAI,IAAI;",
"names": []
}
+0
-2

@@ -5,4 +5,2 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->

## 3.37.0 (2025-12-23)
## 3.36.0 (2025-11-26)

@@ -9,0 +7,0 @@

## Gutenberg
Copyright 2016-2025 by the contributors
Copyright 2016-2026 by the contributors

@@ -5,0 +5,0 @@ **License for Contributions (on and after April 15, 2021)**

{
"name": "@wordpress/warning",
"version": "3.37.0",
"version": "3.37.1-next.79a2f3cdd.0",
"description": "Warning utility for WordPress.",

@@ -25,12 +25,20 @@ "author": "The WordPress Contributors",

},
"main": "build/index.js",
"module": "build-module/index.js",
"files": [
"src",
"build",
"build-module",
"build-types",
"*.md",
"babel-plugin.cjs"
],
"main": "build/index.cjs",
"module": "build-module/index.mjs",
"exports": {
".": {
"types": "./build-types/index.d.ts",
"import": "./build-module/index.js",
"require": "./build/index.js"
"import": "./build-module/index.mjs",
"require": "./build/index.cjs"
},
"./package.json": "./package.json",
"./babel-plugin": "./babel-plugin.js"
"./babel-plugin": "./babel-plugin.cjs"
},

@@ -45,3 +53,3 @@ "react-native": "src/index",

},
"gitHead": "2cf13ec6cf86153c9b3cf369bf5c59046f5cd950"
"gitHead": "6a324496a37d9a333a11d4d7fe5fb93b8152a5ba"
}
/**
* Internal dependencies
*/
const pkg = require( './package.json' );
/**
* Babel plugin which transforms `warning` function calls to wrap within a
* condition that checks if `SCRIPT_DEBUG === true`.
*
* @param {import('@babel/core')} babel Current Babel object.
*
* @return {import('@babel/core').PluginObj} Babel plugin object.
*/
function babelPlugin( { types: t } ) {
const seen = Symbol();
const scriptDebugCheckExpression = t.binaryExpression(
'===',
t.memberExpression(
t.identifier( 'globalThis' ),
t.identifier( 'SCRIPT_DEBUG' )
),
t.booleanLiteral( true )
);
return {
visitor: {
ImportDeclaration( path, state ) {
const { node } = path;
const isThisPackageImport =
node.source.value.indexOf( pkg.name ) !== -1;
if ( ! isThisPackageImport ) {
return;
}
const defaultSpecifier = node.specifiers.find(
( specifier ) => specifier.type === 'ImportDefaultSpecifier'
);
if ( defaultSpecifier && defaultSpecifier.local ) {
const { name } = defaultSpecifier.local;
state.callee = name;
}
},
CallExpression( path, state ) {
const { node } = path;
// Ignore if it's already been processed.
if ( node[ seen ] ) {
return;
}
const name = state.callee || state.opts.callee;
if ( path.get( 'callee' ).isIdentifier( { name } ) ) {
// Turns this code:
// warning(argument);
// into this:
// typeof SCRIPT_DEBUG !== 'undefined' && SCRIPT_DEBUG === true ? warning(argument) : void 0;
node[ seen ] = true;
path.replaceWith(
t.ifStatement(
scriptDebugCheckExpression,
t.blockStatement( [
t.expressionStatement( node ),
] )
)
);
}
},
},
};
}
module.exports = babelPlugin;
// packages/warning/src/index.ts
import { logged } from "./utils";
function isDev() {
return globalThis.SCRIPT_DEBUG === true;
}
function warning(message) {
if (!isDev()) {
return;
}
if (logged.has(message)) {
return;
}
console.warn(message);
try {
throw Error(message);
} catch (x) {
}
logged.add(message);
}
export {
warning as default
};
//# sourceMappingURL=index.js.map
{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { logged } from './utils';\n\nfunction isDev(): boolean {\n\t// eslint-disable-next-line @wordpress/wp-global-usage\n\treturn globalThis.SCRIPT_DEBUG === true;\n}\n\n/**\n * Shows a warning with `message` if environment is not `production`.\n *\n * @param message Message to show in the warning.\n *\n * @example\n * ```js\n * import warning from '@wordpress/warning';\n *\n * function MyComponent( props ) {\n * if ( ! props.title ) {\n * warning( '`props.title` was not passed' );\n * }\n * ...\n * }\n * ```\n */\nexport default function warning( message: string ): void {\n\tif ( ! isDev() ) {\n\t\treturn;\n\t}\n\n\t// Skip if already logged.\n\tif ( logged.has( message ) ) {\n\t\treturn;\n\t}\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\t// Throwing an error and catching it immediately to improve debugging\n\t// A consumer can use 'pause on caught exceptions'\n\t// https://github.com/facebook/react/issues/4216\n\ttry {\n\t\tthrow Error( message );\n\t} catch ( x ) {\n\t\t// Do nothing.\n\t}\n\tlogged.add( message );\n}\n"],
"mappings": ";AAGA,SAAS,cAAc;AAEvB,SAAS,QAAiB;AAEzB,SAAO,WAAW,iBAAiB;AACpC;AAmBe,SAAR,QAA0B,SAAwB;AACxD,MAAK,CAAE,MAAM,GAAI;AAChB;AAAA,EACD;AAGA,MAAK,OAAO,IAAK,OAAQ,GAAI;AAC5B;AAAA,EACD;AAGA,UAAQ,KAAM,OAAQ;AAKtB,MAAI;AACH,UAAM,MAAO,OAAQ;AAAA,EACtB,SAAU,GAAI;AAAA,EAEd;AACA,SAAO,IAAK,OAAQ;AACrB;",
"names": []
}
// packages/warning/src/utils.ts
var logged = /* @__PURE__ */ new Set();
export {
logged
};
//# sourceMappingURL=utils.js.map
{
"version": 3,
"sources": ["../src/utils.ts"],
"sourcesContent": ["/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n */\nexport const logged: Set< string > = new Set();\n"],
"mappings": ";AAIO,IAAM,SAAwB,oBAAI,IAAI;",
"names": []
}
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/warning/src/index.ts
var index_exports = {};
__export(index_exports, {
default: () => warning
});
module.exports = __toCommonJS(index_exports);
var import_utils = require("./utils");
function isDev() {
return globalThis.SCRIPT_DEBUG === true;
}
function warning(message) {
if (!isDev()) {
return;
}
if (import_utils.logged.has(message)) {
return;
}
console.warn(message);
try {
throw Error(message);
} catch (x) {
}
import_utils.logged.add(message);
}
//# sourceMappingURL=index.js.map
{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { logged } from './utils';\n\nfunction isDev(): boolean {\n\t// eslint-disable-next-line @wordpress/wp-global-usage\n\treturn globalThis.SCRIPT_DEBUG === true;\n}\n\n/**\n * Shows a warning with `message` if environment is not `production`.\n *\n * @param message Message to show in the warning.\n *\n * @example\n * ```js\n * import warning from '@wordpress/warning';\n *\n * function MyComponent( props ) {\n * if ( ! props.title ) {\n * warning( '`props.title` was not passed' );\n * }\n * ...\n * }\n * ```\n */\nexport default function warning( message: string ): void {\n\tif ( ! isDev() ) {\n\t\treturn;\n\t}\n\n\t// Skip if already logged.\n\tif ( logged.has( message ) ) {\n\t\treturn;\n\t}\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\t// Throwing an error and catching it immediately to improve debugging\n\t// A consumer can use 'pause on caught exceptions'\n\t// https://github.com/facebook/react/issues/4216\n\ttry {\n\t\tthrow Error( message );\n\t} catch ( x ) {\n\t\t// Do nothing.\n\t}\n\tlogged.add( message );\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAuB;AAEvB,SAAS,QAAiB;AAEzB,SAAO,WAAW,iBAAiB;AACpC;AAmBe,SAAR,QAA0B,SAAwB;AACxD,MAAK,CAAE,MAAM,GAAI;AAChB;AAAA,EACD;AAGA,MAAK,oBAAO,IAAK,OAAQ,GAAI;AAC5B;AAAA,EACD;AAGA,UAAQ,KAAM,OAAQ;AAKtB,MAAI;AACH,UAAM,MAAO,OAAQ;AAAA,EACtB,SAAU,GAAI;AAAA,EAEd;AACA,sBAAO,IAAK,OAAQ;AACrB;",
"names": []
}
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/warning/src/utils.ts
var utils_exports = {};
__export(utils_exports, {
logged: () => logged
});
module.exports = __toCommonJS(utils_exports);
var logged = /* @__PURE__ */ new Set();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
logged
});
//# sourceMappingURL=utils.js.map
{
"version": 3,
"sources": ["../src/utils.ts"],
"sourcesContent": ["/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n */\nexport const logged: Set< string > = new Set();\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,IAAM,SAAwB,oBAAI,IAAI;",
"names": []
}
/**
* External dependencies
*/
import { transform } from '@babel/core';
/**
* Internal dependencies
*/
import babelPlugin from '../babel-plugin';
function join( ...strings ) {
return strings.join( '\n' );
}
function transformCode( input, options = {} ) {
const { code } = transform( input, {
configFile: false,
plugins: [ [ babelPlugin, options ] ],
} );
return code;
}
describe( 'babel-plugin', () => {
it( 'should replace warning calls with import declaration', () => {
const input = join(
'import warning from "@wordpress/warning";',
'warning("a");'
);
const expected = join(
'import warning from "@wordpress/warning";',
'globalThis.SCRIPT_DEBUG === true ? warning("a") : void 0;'
);
expect( transformCode( input ) ).toEqual( expected );
} );
it( 'should not replace warning calls without import declaration', () => {
const input = 'warning("a");';
const expected = 'warning("a");';
expect( transformCode( input ) ).toEqual( expected );
} );
it( 'should replace warning calls without import declaration with plugin options', () => {
const input = 'warning("a");';
const options = { callee: 'warning' };
const expected =
'globalThis.SCRIPT_DEBUG === true ? warning("a") : void 0;';
expect( transformCode( input, options ) ).toEqual( expected );
} );
it( 'should replace multiple warning calls', () => {
const input = join(
'import warning from "@wordpress/warning";',
'warning("a");',
'warning("b");',
'warning("c");'
);
const expected = join(
'import warning from "@wordpress/warning";',
'globalThis.SCRIPT_DEBUG === true ? warning("a") : void 0;',
'globalThis.SCRIPT_DEBUG === true ? warning("b") : void 0;',
'globalThis.SCRIPT_DEBUG === true ? warning("c") : void 0;'
);
expect( transformCode( input ) ).toEqual( expected );
} );
it( 'should identify warning callee name', () => {
const input = join(
'import warn from "@wordpress/warning";',
'warn("a");',
'warn("b");',
'warn("c");'
);
const expected = join(
'import warn from "@wordpress/warning";',
'globalThis.SCRIPT_DEBUG === true ? warn("a") : void 0;',
'globalThis.SCRIPT_DEBUG === true ? warn("b") : void 0;',
'globalThis.SCRIPT_DEBUG === true ? warn("c") : void 0;'
);
expect( transformCode( input ) ).toEqual( expected );
} );
it( 'should identify warning callee name by', () => {
const input = join(
'import warn from "@wordpress/warning";',
'warn("a");',
'warn("b");',
'warn("c");'
);
const expected = join(
'import warn from "@wordpress/warning";',
'globalThis.SCRIPT_DEBUG === true ? warn("a") : void 0;',
'globalThis.SCRIPT_DEBUG === true ? warn("b") : void 0;',
'globalThis.SCRIPT_DEBUG === true ? warn("c") : void 0;'
);
expect( transformCode( input ) ).toEqual( expected );
} );
} );
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": [ "gutenberg-env" ]
}
}

Sorry, the diff of this file is not supported yet