UNPKG

literate-elm

Version:

Runs literate Elm code blocks and calculates Elm expressions

37 lines 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findIntroducedSymbols = void 0; /** * Extracts Elm symbols introduced in the given code block. * * E.g. * spec : Spec * → name "spec", type "Spec" * sparkline : String -> Spec * → name "sparkline", type "String -> Spec" (partially applied function) * * @param code */ const findIntroducedSymbols = (code) => { const result = []; let insideMultiLineString = false; code.split("\n").forEach((line) => { if (line.match('"""')) { insideMultiLineString = !insideMultiLineString; } if (insideMultiLineString) { return; } const match = line.match(/^([_a-zA-Z][_a-zA-Z0-9]{0,})\s*:\s*(.*)\s*$/); if (match) { const typeWithTrimmedComment = match[2].split("--")[0].trim(); result.push({ name: match[1], type: typeWithTrimmedComment, }); } }); return result; }; exports.findIntroducedSymbols = findIntroducedSymbols; //# sourceMappingURL=findIntroducedSymbols.js.map