CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--plugin-syntax-class-properties

Babel syntax plugin that enables parsing of class properties, private properties, and private methods

94

1.04x
Overview
Eval results
Files

task.mdevals/scenario-2/

Public Class Field Parser

Create a small module that can parse JavaScript source containing public class fields and return useful information about those fields without transforming the code.

Capabilities

Parses instance fields

  • Parsing succeeds when given a class with initialized public instance fields, and the returned AST contains nodes for each field with their initializer values preserved. @test

Parses static fields

  • Parsing succeeds when given a class with public static fields, and the returned AST marks those fields as static while preserving their initializer values. @test

Rejects invalid field syntax

  • Parsing throws a syntax error when the source contains malformed class field declarations (for example, assignments placed outside of a class body). @test

Implementation

@generates

API

/**
 * Parses JavaScript source and returns an AST that understands public class fields.
 * Throws a syntax error for invalid class field syntax.
 * @param {string} source - JavaScript code to parse.
 * @returns {import('@babel/types').File} Parsed AST.
 */
export function parseWithClassFields(source);

/**
 * Returns descriptor objects for every public class field found in the source.
 * Parsing must use the same configuration as parseWithClassFields.
 * @param {string} source
 * @returns {{ className: string, fieldName: string, static: boolean, value: string | null }[]}
 */
export function listPublicFields(source);

Dependencies { .dependencies }

@babel/plugin-syntax-class-properties { .dependency }

Allows parsing JavaScript that declares public class fields.

Install with Tessl CLI

npx tessl i tessl/npm-babel--plugin-syntax-class-properties

tile.json