CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--runtime

Babel's modular runtime helpers that provide transpilation support for modern JavaScript features

94

1.18x
Overview
Eval results
Files

task.mdevals/scenario-5/

Custom Comment Parser Plugin

Build a Babel plugin that uses a custom parser to handle special comment syntax in JavaScript code.

Overview

You need to create a Babel plugin that replaces the default JavaScript parser with a custom one. The custom parser should be able to parse standard JavaScript code while also recognizing and preserving special metadata comments in a specific format: /*@metadata key=value */.

These special comments should be extracted during parsing and made available in the AST as custom metadata that can be accessed by other plugins or tools in the Babel pipeline.

Requirements

Your plugin should:

  1. Override the default parser - Replace Babel's default parser with a custom parser implementation that extends its functionality
  2. Parse special metadata comments - Recognize and extract comments in the format /*@metadata key=value */ during the parsing phase
  3. Preserve standard parsing - Ensure all standard JavaScript syntax continues to parse correctly
  4. Attach metadata to AST - Store extracted metadata in a way that makes it accessible from the resulting AST

Test Cases

  • Parsing code with a metadata comment /*@metadata author=john */ should extract the metadata and include it in the parse result @test
  • Parsing code without metadata comments should work exactly like the default parser @test
  • Parsing code with multiple metadata comments should extract all of them @test
  • The plugin should properly integrate with Babel's transformation pipeline @test

@generates

API

/**
 * A Babel plugin that overrides the default parser to handle special metadata comments.
 *
 * The plugin exports a function that returns a Babel plugin object with a parserOverride.
 *
 * @param {Object} api - The Babel API object
 * @returns {Object} A Babel plugin object with parserOverride
 */
module.exports = function(api) {
  // Plugin implementation
};

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the core Babel transformation and parsing APIs, including the ability to override the default parser.

Install with Tessl CLI

npx tessl i tessl/npm-babel--runtime

tile.json