{
  "version": 3,
  "sources": ["../../../src/api/parser/apply-block-deprecated-versions.js"],
  "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { DEPRECATED_ENTRY_KEYS } from '../constants';\nimport { validateBlock } from '../validation';\nimport { getBlockAttributes } from './get-block-attributes';\nimport { applyBuiltInValidationFixes } from './apply-built-in-validation-fixes';\nimport { omit } from '../utils';\n\n/**\n * Function that takes no arguments and always returns false.\n *\n * @return {boolean} Always returns false.\n */\nfunction stubFalse() {\n\treturn false;\n}\n\n/**\n * Given a block object, returns a new copy of the block with any applicable\n * deprecated migrations applied, or the original block if it was both valid\n * and no eligible migrations exist.\n *\n * @param {import(\".\").WPBlock}                   block     Parsed and invalid block object.\n * @param {import(\".\").WPRawBlock}                rawBlock  Raw block object.\n * @param {import('../registration').WPBlockType} blockType Block type. This is normalize not necessary and\n *                                                          can be inferred from the block name,\n *                                                          but it's here for performance reasons.\n *\n * @return {import(\".\").WPBlock} Migrated block object.\n */\nexport function applyBlockDeprecatedVersions( block, rawBlock, blockType ) {\n\tconst parsedAttributes = rawBlock.attrs;\n\tconst { deprecated: deprecatedDefinitions } = blockType;\n\t// Bail early if there are no registered deprecations to be handled.\n\tif ( ! deprecatedDefinitions || ! deprecatedDefinitions.length ) {\n\t\treturn block;\n\t}\n\n\t// By design, blocks lack any sort of version tracking. Instead, to process\n\t// outdated content the system operates a queue out of all the defined\n\t// attribute shapes and tries each definition until the input produces a\n\t// valid result. This mechanism seeks to avoid polluting the user-space with\n\t// machine-specific code. An invalid block is thus a block that could not be\n\t// matched successfully with any of the registered deprecation definitions.\n\tfor ( let i = 0; i < deprecatedDefinitions.length; i++ ) {\n\t\t// A block can opt into a migration even if the block is valid by\n\t\t// defining `isEligible` on its deprecation. If the block is both valid\n\t\t// and does not opt to migrate, skip.\n\t\tconst { isEligible = stubFalse } = deprecatedDefinitions[ i ];\n\t\tif (\n\t\t\tblock.isValid &&\n\t\t\t! isEligible( parsedAttributes, block.innerBlocks, {\n\t\t\t\tblockNode: rawBlock,\n\t\t\t\tblock,\n\t\t\t} )\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Block type properties which could impact either serialization or\n\t\t// parsing are not considered in the deprecated block type by default,\n\t\t// and must be explicitly provided.\n\t\tconst deprecatedBlockType = Object.assign(\n\t\t\tomit( blockType, DEPRECATED_ENTRY_KEYS ),\n\t\t\tdeprecatedDefinitions[ i ]\n\t\t);\n\n\t\tlet migratedBlock = {\n\t\t\t...block,\n\t\t\tattributes: getBlockAttributes(\n\t\t\t\tdeprecatedBlockType,\n\t\t\t\tblock.originalContent,\n\t\t\t\tparsedAttributes\n\t\t\t),\n\t\t};\n\n\t\t// Ignore the deprecation if it produces a block which is not valid.\n\t\tlet [ isValid ] = validateBlock( migratedBlock, deprecatedBlockType );\n\n\t\t// If the migrated block is not valid initially, try the built-in fixes.\n\t\tif ( ! isValid ) {\n\t\t\tmigratedBlock = applyBuiltInValidationFixes(\n\t\t\t\tmigratedBlock,\n\t\t\t\tdeprecatedBlockType\n\t\t\t);\n\t\t\t[ isValid ] = validateBlock( migratedBlock, deprecatedBlockType );\n\t\t}\n\n\t\t// An invalid block does not imply incorrect HTML but the fact block\n\t\t// source information could be lost on re-serialization.\n\t\tif ( ! isValid ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet migratedInnerBlocks = migratedBlock.innerBlocks;\n\t\tlet migratedAttributes = migratedBlock.attributes;\n\n\t\t// A block may provide custom behavior to assign new attributes and/or\n\t\t// inner blocks.\n\t\tconst { migrate } = deprecatedBlockType;\n\t\tif ( migrate ) {\n\t\t\tlet migrated = migrate( migratedAttributes, block.innerBlocks );\n\t\t\tif ( ! Array.isArray( migrated ) ) {\n\t\t\t\tmigrated = [ migrated ];\n\t\t\t}\n\n\t\t\t[\n\t\t\t\tmigratedAttributes = parsedAttributes,\n\t\t\t\tmigratedInnerBlocks = block.innerBlocks,\n\t\t\t] = migrated;\n\t\t}\n\n\t\tblock = {\n\t\t\t...block,\n\t\t\tattribut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