<commit_before>/**
 * @author <NAME> @lgraziani2712
 * @license {@link http://www.opensource.org/licenses/mit-license.php|MIT License}
 *
 * @flow
 */
import defaultBlockParser from './blocks/defaultBlockParser';

import './blocks/action_container';

// FIXME move GameDifficulty to the corresponding module
export type GameDifficulty = 'easy' | 'normal' | 'hard';

export type BlockDefinition = {|
  builder(block: Blockly$Block, difficulty: GameDifficulty): void;
  parser?: (block: Blockly$Block) => string;
|};

/**
 * Instanciate every block required by the activity.
 *
 * @version 1.0.0
 * @param  {GameDifficulty} difficulty How complex must be the block
 * @param  {Array<string>}  blockNames A list of required blocks
 * @return {Promise<void | Error>}     Calls every instanciation.
 */
export default function instanciateEveryBlock(
  difficulty: GameDifficulty,
  blockNames: Array<string>,
) {
  return Promise.all(blockNames.map(instanciateABlock(difficulty)));
}

const instanciateABlock = (difficulty: GameDifficulty) =>
  /**
   * Instanciate one block required by the activity.
   * Each block instance is stored in `Blockly.Blocks`.
   *
   * @param  {string} blockName      The block name that will be used as ID.
   * @return {Promise<void | Error>} It loads a BlockBuilder lazily.
   */
  async (blockName: string) => {
    const blockDefinition: BlockDefinition = await import(
      /* webpackChunkName: "Blockly$Block" */`./blocks/${blockName}`);

    Blockly.Blocks[blockName] = {<commit_msg>🐛 Fix `instanciateEveryBlock`<commit_after>/**
 * @author <NAME> @lgraziani2712
 * @license {@link http://www.opensource.org/licenses/mit-license.php|MIT License}
 *
 * @flow
 */
import defaultBlockParser from './blocks/defaultBlockParser';

import './blocks/action_container';

// FIXME move GameDifficulty to the corresponding module
export type GameDifficulty = 'easy' | 'normal' | 'hard';

export type BlockDefinition = {|
  builder(block: Blockly$Block, difficulty: GameDifficulty): void;
  parser?: (block: Blockly$Block) => string;
|};

/**
 * Instanciate every block required by the activity.
 *
 * @version 1.0.0
 * @param  {GameDifficulty} difficulty How complex must be the block
 * @param  {Array<string>}  blockNames A list of required blocks
 * @return {Promise<void>}             Calls every instanciation.
 */
export default function instanciateEveryBlock(
  difficulty: GameDifficulty,
  blockNames: Array<string>,
) {
  return Promise.all(blockNames.map(instanciateABlock(difficulty)));
}

const instanciateABlock = (difficulty: GameDifficulty) =>
  /**
   * Instanciate one block required by the activity.
   * Each block instance is stored in `Blockly.Blocks`.
   *
   * @param  {string} blockName      The block name that will be used as ID.
   * @return {Promise<void | Error>} It loads a BlockBuilder lazily.
   */
  async (blockName: string) => {
    const blockDefinition: BlockDefinition = await import(
      // FIXME @see https://github.com/babel/babel-eslint/issues/507
      // eslint-disable-next-line comma-dangle
      /* webpackChunkName: "Blockly$Block" */`./blocks/${blockName}`
    ).then(mod => mod.default);

    Blockly.Blocks[blockName] = {
{'fraction_non_alphanumeric': 0.1275, 'fraction_numerical': 0.0053125, 'mean_word_length': 4.089030206677266, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '247045', 'n_tokens_mistral': 980, 'n_tokens_neox': 974, 'n_words': 272}