A programming language that compiles into JavaScript, offering more concise and readable syntax while maintaining full JavaScript compatibility.
77
A tool that compiles CoffeeScript source files while extracting their comments for documentation purposes.
Build a tool that processes CoffeeScript source code and extracts all comments from it. The tool should compile the code to JavaScript while also capturing both line and block comments with their locations.
The tool accepts a CoffeeScript source code string as input.
The tool must extract and categorize two types of comments:
#)###)For each comment, capture:
The tool should produce a JavaScript object containing:
type, text, and lineGiven CoffeeScript code with a single line comment # Calculate sum, the tool returns the compiled JavaScript and a comments array containing one object with type "line", the text "Calculate sum", and the appropriate line number. @test
Given CoffeeScript code with a block comment ### Multi-line description here ###, the tool returns the compiled JavaScript and a comments array containing one object with type "block" and the full text content. @test
Given CoffeeScript code with both line and block comments, the tool returns all comments in order of appearance with their correct types and line numbers. @test
Given CoffeeScript code with no comments, the tool returns the compiled JavaScript and an empty comments array. @test
@generates
/**
* Compiles CoffeeScript source and extracts comments
* @param {string} source - CoffeeScript source code
* @returns {Object} Object containing compiled JS and extracted comments
* @returns {string} return.js - Compiled JavaScript code
* @returns {Array<Object>} return.comments - Array of comment objects
* @returns {string} return.comments[].type - Comment type: 'line' or 'block'
* @returns {string} return.comments[].text - Comment text content
* @returns {number} return.comments[].line - Line number of comment
*/
function compileAndExtractComments(source) {
// Implementation here
}
module.exports = { compileAndExtractComments };Provides CoffeeScript compilation with comment preservation support through the compilation API and token stream access.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-coffeescriptevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10