pxt-core
Version:
Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors
43 lines (42 loc) • 1.58 kB
TypeScript
/// <reference path="../pxtlib.d.ts" />
import * as Blockly from "blockly";
import { Environment } from "./compiler/environment";
/**
* This interface defines the optionally defined functions for mutations that Blockly
* will call if they exist.
*/
export interface MutatingBlock extends Blockly.Block {
mutation: Mutation;
mutationToDom(): Element;
domToMutation(xmlElement: Element): void;
compose(topBlock: Blockly.Block): void;
decompose(workspace: Blockly.Workspace): Blockly.Block;
}
/**
* Represents a mutation of a block
*/
export interface Mutation {
/**
* Get the unique identifier for this type of mutation
*/
getMutationType(): string;
/**
* Compile the mutation of the block into a node representation
*/
compileMutation(e: Environment, comments: string[]): pxt.blocks.JsNode;
/**
* Get a mapping of variables that were declared by this mutation and their types.
*/
getDeclaredVariables(): pxt.Map<string>;
/**
* Returns true if a variable with the given name was declared in the mutation's compiled node
*/
isDeclaredByMutation(varName: string): boolean;
}
export declare namespace MutatorTypes {
const ObjectDestructuringMutator = "objectdestructuring";
const RestParameterMutator = "restparameter";
const DefaultInstanceMutator = "defaultinstance";
}
export declare function addMutation(b: MutatingBlock, info: pxtc.SymbolInfo, mutationType: string): void;
export declare function mutateToolboxBlock(block: Node, mutationType: string, mutation: string): void;