Sha256: c6a38b7b317d9044cc3355b30d16906ea78835b2ca0b7a630e577233d0b487b9

Contents?: true

Size: 1.71 KB

Versions: 11

Compression:

Stored size: 1.71 KB

Contents

// Acorn: Loose parser
//
// This module provides an alternative parser (`parse_dammit`) that
// exposes that same interface as `parse`, but will try to parse
// anything as JavaScript, repairing syntax error the best it can.
// There are circumstances in which it will raise an error and give
// up, but they are very rare. The resulting AST will be a mostly
// valid JavaScript AST (as per the [Mozilla parser API][api], except
// that:
//
// - Return outside functions is allowed
//
// - Label consistency (no conflicts, break only to existing labels)
//   is not enforced.
//
// - Bogus Identifier nodes with a name of `"✖"` are inserted whenever
//   the parser got too confused to return anything meaningful.
//
// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
//
// The expected use for this is to *first* try `acorn.parse`, and only
// if that fails switch to `parse_dammit`. The loose parser might
// parse badly indented code incorrectly, so **don't** use it as
// your default parser.
//
// Quite a lot of acorn.js is duplicated here. The alternative was to
// add a *lot* of extra cruft to that file, making it less readable
// and slower. Copying and editing the code allowed me to make
// invasive changes and simplifications without creating a complicated
// tangle.

import {addLooseExports, defaultOptions} from "../index"
import {LooseParser, pluginsLoose} from "./state"
import "./tokenize"
import "./statement"
import "./expression"

export {LooseParser, pluginsLoose} from "./state"

defaultOptions.tabSize = 4

export function parse_dammit(input, options) {
  let p = new LooseParser(input, options)
  p.next()
  return p.parseTopLevel()
}

addLooseExports(parse_dammit, LooseParser, pluginsLoose)

Version data entries

11 entries across 10 versions & 6 rubygems

Version Path
ilog-0.4.1 node_modules/acorn-dynamic-import/node_modules/acorn/src/loose/index.js
ilog-0.4.0 node_modules/acorn-dynamic-import/node_modules/acorn/src/loose/index.js
ilog-0.3.3 node_modules/acorn-dynamic-import/node_modules/acorn/src/loose/index.js
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/acorn/src/loose/index.js
optimacms-0.4.3 spec/dummy/node_modules/acorn-dynamic-import/node_modules/acorn/src/loose/index.js
optimacms-0.4.2 spec/dummy/node_modules/acorn-dynamic-import/node_modules/acorn/src/loose/index.js
cortex-0.1.3 spec/dummy/node_modules/acorn-dynamic-import/node_modules/acorn/src/loose/index.js
guard-sass-lint-0.1.2 node_modules/acorn/src/loose/index.js
guard-sass-lint-0.1.1 node_modules/acorn/src/loose/index.js
lanes-0.8.0 node_modules/espree/node_modules/acorn/src/loose/index.js
lanes-0.8.0 node_modules/acorn/src/loose/index.js