CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--plugin-proposal-object-rest-spread

Babel plugin that transforms ECMAScript object rest and spread syntax into ES5-compatible code.

85

1.06x

Quality

Pending

Does it follow best practices?

Impact

85%

1.06x

Average score across 10 eval scenarios

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

task.mdevals/scenario-7/

Constant Expression Analyzer

A tool that analyzes JavaScript code to detect and report constant expressions that can be evaluated at compile time. The tool should traverse JavaScript code and identify expressions that produce constant values.

Capabilities

Detect simple constant expressions

  • Given code with const x = 5 + 3;, the analyzer reports that 5 + 3 is a constant expression with value 8 @test
  • Given code with const greeting = "Hello" + " " + "World";, the analyzer reports that the concatenation is a constant expression with value "Hello World" @test
  • Given code with const flag = true && false;, the analyzer reports that true && false is a constant expression with value false @test

Handle non-constant expressions

  • Given code with const y = x + 5; where x is a variable, the analyzer returns an empty array (no constant expressions found) @test
  • Given code with const z = Math.random();, the analyzer returns an empty array (no constant expressions found) @test

Analyze numeric operations

  • Given code with const result = 10 * 2 + 5 - 3;, the analyzer reports that this is a constant expression with value 22 @test
  • Given code with const comparison = 5 > 3;, the analyzer reports that 5 > 3 is a constant expression with value true @test

Implementation

@generates

API

/**
 * Analyzes JavaScript source code to find constant expressions
 * @param {string} sourceCode - The JavaScript source code to analyze
 * @returns {Array<ConstantExpression>} Array of detected constant expressions
 */
function analyzeConstants(sourceCode) {
  // IMPLEMENTATION HERE
}

/**
 * Represents a constant expression found in the code
 * @typedef {Object} ConstantExpression
 * @property {string} expression - The expression as a string
 * @property {any} value - The evaluated constant value
 * @property {boolean} isConstant - Whether the expression is constant (true for all returned items)
 * @property {number} line - Line number where the expression appears
 */

module.exports = {
  analyzeConstants
};

Dependencies { .dependencies }

@babel/parser { .dependency }

Parses JavaScript code into an Abstract Syntax Tree (AST) for analysis.

@satisfied-by

@babel/traverse { .dependency }

Provides AST traversal capabilities with the Path API for static expression evaluation.

@satisfied-by

tile.json