or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-2/

JavaScript Identifier Validator

Build a validator that analyzes JavaScript source code to extract and validate identifiers according to ECMA-262 standards, with particular attention to Unicode support and surrogate pair handling.

Requirements

Your validator should:

  1. Extract identifiers from JavaScript source code:

    • Include variable names, function names, and property names
    • Handle both simple ASCII identifiers and Unicode identifiers
    • Support identifiers with various Unicode characters
  2. Validate identifiers according to JavaScript grammar rules:

    • Check if extracted identifiers are valid JavaScript identifiers
    • Detect reserved words that cannot be used as identifiers
    • Handle Unicode characters including surrogate pairs correctly
  3. Report validation results:

    • Return a list of all valid identifiers found
    • Flag any invalid identifiers or reserved words
    • Handle edge cases like empty input, comments, and string literals

Test Cases

  • Parsing code with ASCII identifiers like exports.hello and module.exports.world returns valid identifiers ['hello', 'world'] @test

  • Parsing code with Unicode identifiers like exports.café and exports.日本語 correctly identifies these as valid identifiers @test

  • Parsing code with reserved words like exports.class and exports.if flags these as invalid because they are reserved words @test

  • Parsing code with surrogate pairs like exports.𝕳𝖊𝖑𝖑𝖔 (mathematical bold text) correctly handles the multi-byte Unicode characters @test

Implementation

@generates

API

/**
 * Validates JavaScript identifiers from source code.
 *
 * @param {string} source - JavaScript source code to analyze
 * @returns {{ valid: string[], invalid: string[] }} Object containing arrays of valid and invalid identifiers
 */
function validateIdentifiers(source) {
  // IMPLEMENTATION HERE
}

module.exports = {
  validateIdentifiers
};

Dependencies { .dependencies }

cjs-module-lexer { .dependency }

Provides lexical analysis support for CommonJS modules