or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

@babel/plugin-syntax-function-bind

A Babel syntax plugin that enables parsing of function bind syntax (::) in JavaScript code. This plugin extends Babel's parser to recognize the function bind operator without transforming the syntax, making it suitable for parsing purposes only.

Package Information

  • Package Name: @babel/plugin-syntax-function-bind
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install --save-dev @babel/plugin-syntax-function-bind

Core Imports

// ES6 modules
import functionBindPlugin from "@babel/plugin-syntax-function-bind";

// CommonJS
const functionBindPlugin = require("@babel/plugin-syntax-function-bind");

Basic Usage

Configure the plugin in your Babel configuration to enable parsing of function bind syntax:

// babel.config.js
module.exports = {
  plugins: ["@babel/plugin-syntax-function-bind"]
};

// .babelrc
{
  "plugins": ["@babel/plugin-syntax-function-bind"]
}

With the plugin enabled, Babel can parse function bind syntax:

// This syntax will be parsed (but not transformed)
const boundMethod = obj::method;
const boundFunction = ::obj.method;

Capabilities

Plugin Function

The main export that creates a Babel plugin using the declare helper from @babel/helper-plugin-utils.

import { declare } from "@babel/helper-plugin-utils";

/**
 * Default export: A Babel plugin created using the declare helper
 * The plugin enables parsing of function bind syntax (::) without transformation
 */
declare const plugin: (
  api: PluginAPI,
  options: object,
  dirname: string
) => PluginObject;

export default plugin;

Plugin Implementation

The plugin is implemented using Babel's declare helper:

/**
 * Plugin implementation function passed to declare()
 * @param api - Babel PluginAPI object containing version info and utilities
 * @returns PluginObject that configures the parser to recognize function bind syntax
 */
type PluginBuilder = (api: PluginAPI) => PluginObject;

interface PluginAPI {
  /** Babel version string (e.g., "7.27.1") */
  version: string;
  /** Assert minimum required Babel version */
  assertVersion: (version: number | string) => void;
}

interface PluginObject {
  /** Plugin identifier name */
  name: string;
  /** Function to modify parser options */
  manipulateOptions: (opts: any, parserOpts: ParserOptions) => void;
}

interface ParserOptions {
  /** Array of parser plugins to enable */
  plugins: string[];
}

The plugin implementation:

  1. Validates the Babel version using api.assertVersion(7) (validates Babel 7.x compatibility)
  2. Returns a plugin object with name "syntax-function-bind"
  3. Provides a manipulateOptions method that adds "functionBind" to the parser plugins array

Usage in Babel Configuration:

// babel.config.js - Using plugin by name (recommended)
module.exports = {
  plugins: ["@babel/plugin-syntax-function-bind"]
};

// .babelrc.json
{
  "plugins": ["@babel/plugin-syntax-function-bind"]
}

// Direct plugin function usage (advanced)
import functionBindPlugin from "@babel/plugin-syntax-function-bind";

module.exports = {
  plugins: [functionBindPlugin]
};

Parser Integration

When the plugin is active, Babel's parser will recognize the function bind operator (::) in the following forms:

// Function binding forms that can be parsed:
obj::method         // Bind method to obj
::obj.method        // Extract bound method from obj
obj::method()       // Bind and call immediately
::obj[method]       // Dynamic method binding

Dependencies

Runtime Dependencies

  • @babel/helper-plugin-utils: ^7.0.0 (workspace dependency) - Provides the declare helper function for creating standardized Babel plugins

Peer Dependencies

  • @babel/core: ^7.0.0-0 (Required Babel core version for plugin compatibility)

Development Dependencies

  • @babel/core: ^7.0.0 (workspace dependency) - Used for testing and development

Plugin Characteristics

  • Type: Syntax plugin (parsing only, no transformation)
  • Parser Plugin Added: "functionBind"
  • Configuration Options: None supported
  • Side Effects: None (pure syntax extension)
  • Compatibility: Babel 7.x and later
  • Module Type: ES Module with CommonJS compatibility
  • Engine Requirements: Node.js >=6.9.0

Package Exports

The plugin provides the following exports structure:

// Main export (default)
export default plugin;

// TypeScript definitions available at
// "./lib/index.d.ts"

// Package.json accessible via
// "./package.json"

Function Bind Operator Overview

The function bind operator (::) is an experimental JavaScript feature that provides syntactic sugar for binding functions to objects. While not yet part of the ECMAScript standard, this syntax plugin enables Babel to parse such code for development and experimentation purposes.

Note: This plugin only enables parsing - to actually transform function bind syntax into working JavaScript, you would need a separate transformation plugin like @babel/plugin-proposal-function-bind.