diff --git a/index.d.ts b/index.d.ts index c3298801..4100f6e1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -117,6 +117,13 @@ export interface Options extends Schema.Options { * Default: `false` */ keepCstNodes?: boolean + /** + * Set original ranges (support \r\n line endings) for included cstNodes + * Only has an effect if `keepCstNodes` is enabled + * + * Default: `false` + */ + setOrigRanges?: boolean /** * Store the original node type when parsing documents. * diff --git a/src/index.js b/src/index.js index 9894e8f0..94ae878d 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,9 @@ export { Document, parseCST } export function parseAllDocuments(src, options) { const stream = [] let prev - for (const cstDoc of parseCST(src)) { + const cst = parseCST(src) + if (options && options.setOrigRanges) cst.setOrigRanges() + for (const cstDoc of cst) { const doc = new Document(undefined, null, options) doc.parse(cstDoc, prev) stream.push(doc) @@ -22,6 +24,7 @@ export function parseAllDocuments(src, options) { export function parseDocument(src, options) { const cst = parseCST(src) + if (options && options.setOrigRanges) cst.setOrigRanges() const doc = new Document(cst[0], null, options) if ( cst.length > 1 &&