import { CssBlockError } from "../errors" ; import { ImportedCompiledCssFile } from "../importing" ; /**
 * A regex to find the block-syntax-version annotation in a definition file.
 */ const REGEXP_BLOCK_SYNTAX_VERSION = /^\s*@block-syntax-version ([^;]+);/m ; /**
 * The earliest block-syntax-version supported by CSS Blocks. If this has been
 * bumped past version 1, that means there's a breaking change in a later version
 * of CSS Blocks that can't be automatically updated.
 */ const MIN_SUPPORTED_VERSION = 1 ; /**
 * The latest block-syntax-version supported by CSS Blocks. Anytime a patch method
 * is introduced to transform older definition files automatically, bump this number.
 * If a version later than this is found in a definition file, that means it was compiled
 * by a later version of CSS Blocks and we can't reason about it.
 */ const MAX_SUPPORTED_VERSION = 1 ; param file returns export function determineBlockSyntaxVersion ( file ) { const dfnId = file . definitionIdentifier ; const dfnContents = file . definitionContents ; const versionLookupResult = dfnContents . match ( REGEXP_BLOCK_SYNTAX_VERSION ) ; if ( ! versionLookupResult ) { throw new CssBlockError ( "Unable to process definition file because the file is missing a block-syntax-version declaration or it is malformed." , { filename : dfnId , } ) ; } const version = parseInt ( versionLookupResult [ 1 ] , 10 ) ; if ( isNaN ( version ) ) { throw new CssBlockError ( "Unable to process definition file because the declared block-syntax-version isn't a number." , { filename : dfnId , } ) ; } return version ; } param file returns export function upgradeDefinitionFileSyntax ( file ) { const version = determineBlockSyntaxVersion ( file ) ; if ( version > MAX_SUPPORTED_VERSION ) { throw new CssBlockError ( "Unable to process definition file because the syntax version of the definition file is greater than supported by CSS Blocks. You can fix this issue by upgrading CSS Blocks to the latest version." , { filename : file . definitionIdentifier , } ) ; } if ( version < MIN_SUPPORTED_VERSION ) { throw new CssBlockError ( "Unable to process definition file because the syntax of the definition can't be automatically upgraded to the latest version supported by CSS Blocks. You may be able to fix this issue by upgrading the dependency or origin file this definition file was generated from. Otherwise, you'll need to use an earlier version of CSS Blocks." , { filename : file . definitionIdentifier , } ) ; } return file ; }