Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option setOrigRanges for parsing docs #227

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions index.d.ts
Expand Up @@ -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.
*
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Expand Up @@ -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)
Expand All @@ -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 &&
Expand Down