Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@swc/types

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swc/types

Typings for the swc project.

  • 0.1.6
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is @swc/types?

The @swc/types package provides TypeScript type definitions for the AST (Abstract Syntax Tree) nodes used by SWC, a super-fast compiler written in Rust. It is primarily used by developers working on tooling for JavaScript and TypeScript, such as linters, formatters, and compilers. By offering a structured way to represent code, it enables programmatic analysis, manipulation, and generation of JavaScript and TypeScript code.

What are @swc/types's main functionalities?

Defining AST Nodes

This code sample demonstrates how to define a simple AST node for a variable declaration in JavaScript using the types provided by @swc/types. It represents a variable `x` being declared and initialized with the value `10`.

{
  "type": "VariableDeclaration",
  "kind": "var",
  "declarations": [
    {
      "type": "VariableDeclarator",
      "id": {
        "type": "Identifier",
        "name": "x"
      },
      "init": {
        "type": "Literal",
        "value": 10,
        "raw": "10"
      }
    }
  ]
}

Manipulating AST Nodes

This function takes an AST node and, if it is a numeric literal, doubles its value. It showcases how @swc/types can be used to manipulate AST nodes programmatically.

function updateLiteralValue(node) {
  if (node.type === 'Literal' && typeof node.value === 'number') {
    node.value *= 2;
  }
  return node;
}

Other packages similar to @swc/types

Keywords

FAQs

Package last updated on 18 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc