Comparing version 5.7.3 to 6.0.0
168
CHANGELOG.md
@@ -1,52 +0,48 @@ | ||
## 5.7.3 (2018-09-10) | ||
## 6.0.0 (2018-09-14) | ||
### Bug fixes | ||
Fix failure to tokenize regexps after expressions like `x.of`. | ||
Better handle variable-redefinition checks for catch bindings and functions directly under if statements. | ||
Better error message for unterminated template literals. | ||
## 5.7.2 (2018-08-24) | ||
Forbid `new.target` in top-level arrow functions. | ||
### Bug fixes | ||
Fix issue with parsing a regexp after `yield` in some contexts. | ||
Properly handle `allowAwaitOutsideFunction` in for statements. | ||
### New features | ||
Treat function declarations at the top level of modules like let bindings. | ||
The package now comes with TypeScript definitions. | ||
Don't allow async function declarations as the only statement under a label. | ||
### Breaking changes | ||
## 5.7.1 (2018-06-15) | ||
The default value of the `ecmaVersion` option is now 9 (2018). | ||
### Bug fixes | ||
Plugins work differently, and will have to be rewritten to work with this version. | ||
Make sure the walker and bin files are rebuilt on release (the previous release didn't get the up-to-date versions). | ||
The loose parser and walker have been moved into separate packages (`acorn-loose` and `acorn-walk`). | ||
## 5.7.0 (2018-06-15) | ||
## 5.7.3 (2018-09-10) | ||
### Bug fixes | ||
Fix crash in walker when walking a binding-less catch node. | ||
Fix failure to tokenize regexps after expressions like `x.of`. | ||
### New features | ||
Better error message for unterminated template literals. | ||
Upgraded to Unicode 11. | ||
## 5.7.2 (2018-08-24) | ||
## 5.6.2 (2018-06-05) | ||
### Bug fixes | ||
In the walker, go back to allowing the `baseVisitor` argument to be null to default to the default base everywhere. | ||
Properly handle `allowAwaitOutsideFunction` in for statements. | ||
## 5.6.1 (2018-06-01) | ||
Treat function declarations at the top level of modules like let bindings. | ||
### Bug fixes | ||
Don't allow async function declarations as the only statement under a label. | ||
Fix regression when passing `null` as fourth argument to `walk.recursive`. | ||
## 5.7.0 (2018-06-15) | ||
## 5.6.0 (2018-05-31) | ||
### New features | ||
### Bug fixes | ||
Upgraded to Unicode 11. | ||
Fix a bug in the walker that caused a crash when walking an object pattern spread. | ||
## 5.6.0 (2018-05-31) | ||
@@ -77,4 +73,2 @@ ### New features | ||
Fix regression in walker causing property values in object patterns to be walked as expressions. | ||
Fix misleading error message for octal escapes in template strings. | ||
@@ -84,6 +78,2 @@ | ||
### Bug fixes | ||
Support object spread in the AST walker. | ||
### New features | ||
@@ -95,8 +85,2 @@ | ||
## 5.4.1 (2018-02-02) | ||
### Bug fixes | ||
5.4.0 somehow accidentally included an old version of walk.js. | ||
## 5.4.0 (2018-02-01) | ||
@@ -152,4 +136,2 @@ | ||
The `full` and `fullAncestor` walkers no longer visit nodes multiple times. | ||
Allow shorthand properties `get` and `set` to be followed by default values. | ||
@@ -191,4 +173,2 @@ | ||
Make the ES module version of the loose parser actually work. | ||
### New features | ||
@@ -198,4 +178,2 @@ | ||
New walker functions `full` and `fullAncestor`. | ||
## 5.0.3 (2017-04-01) | ||
@@ -239,7 +217,5 @@ | ||
Don't expect semicolons after default-exported functions or classes, | ||
even when they are expressions. | ||
Don't expect semicolons after default-exported functions or classes, even when they are expressions. | ||
Check for use of `'use strict'` directives in non-simple parameter | ||
functions, even when already in strict mode. | ||
Check for use of `'use strict'` directives in non-simple parameter functions, even when already in strict mode. | ||
@@ -250,4 +226,3 @@ ## 4.0.9 (2017-02-06) | ||
Fix incorrect error raised for parenthesized simple assignment | ||
targets, so that `(x) = 1` parses again. | ||
Fix incorrect error raised for parenthesized simple assignment targets, so that `(x) = 1` parses again. | ||
@@ -258,5 +233,3 @@ ## 4.0.8 (2017-02-03) | ||
Solve spurious parenthesized pattern errors by temporarily erring on | ||
the side of accepting programs that our delayed errors don't handle | ||
correctly yet. | ||
Solve spurious parenthesized pattern errors by temporarily erring on the side of accepting programs that our delayed errors don't handle correctly yet. | ||
@@ -269,4 +242,3 @@ ## 4.0.7 (2017-02-02) | ||
Don't raise an error when a function _inside_ strict code has a | ||
non-simple parameter list. | ||
Don't raise an error when a function _inside_ strict code has a non-simple parameter list. | ||
@@ -277,5 +249,3 @@ ## 4.0.6 (2017-02-02) | ||
Fix exponential behavior (manifesting itself as a complete hang for | ||
even relatively small source files) introduced by the new 'use strict' | ||
check. | ||
Fix exponential behavior (manifesting itself as a complete hang for even relatively small source files) introduced by the new 'use strict' check. | ||
@@ -302,4 +272,2 @@ ## 4.0.5 (2017-02-02) | ||
Fix issue with loading acorn_loose.js with an AMD loader. | ||
Fix crash when `export` was followed by a keyword that can't be | ||
@@ -312,4 +280,3 @@ exported. | ||
Allow regular function declarations inside single-statement `if` | ||
branches in loose mode. Forbid them entirely in strict mode. | ||
Allow regular function declarations inside single-statement `if` branches in loose mode. Forbid them entirely in strict mode. | ||
@@ -326,4 +293,3 @@ Properly parse properties named `async` in ES2017 mode. | ||
Fix broken parsing for call expressions in default parameter values | ||
of arrow functions. | ||
Fix broken parsing for call expressions in default parameter values of arrow functions. | ||
@@ -342,4 +308,3 @@ ## 4.0.1 (2016-08-08) | ||
A number of internal method signatures changed, so plugins might need | ||
to be updated. | ||
A number of internal method signatures changed, so plugins might need to be updated. | ||
@@ -352,4 +317,3 @@ ### Bug fixes | ||
Duplicate parameter names in non-simple argument lists now always | ||
produce an error. | ||
Duplicate parameter names in non-simple argument lists now always produce an error. | ||
@@ -363,4 +327,3 @@ ### New features | ||
Support for trailing commas in call expressions when `ecmaVersion` | ||
is >= 8. | ||
Support for trailing commas in call expressions when `ecmaVersion` is >= 8. | ||
@@ -377,4 +340,3 @@ ## 3.3.0 (2016-07-25) | ||
Implement check against complex argument lists in functions that | ||
enable strict mode in ES7. | ||
Implement check against complex argument lists in functions that enable strict mode in ES7. | ||
@@ -390,11 +352,6 @@ ## 3.2.0 (2016-06-07) | ||
Don't crash when the loose parser is called without options object. | ||
### New features | ||
Visitors created with `visit.make` now have their base as _prototype_, | ||
rather than copying properties into a fresh object. | ||
Visitors created with `visit.make` now have their base as _prototype_, rather than copying properties into a fresh object. | ||
Make it possible to use `visit.ancestor` with a walk state. | ||
## 3.1.0 (2016-04-18) | ||
@@ -404,14 +361,6 @@ | ||
Fix issue where the loose parser created invalid TemplateElement nodes | ||
for unclosed template literals. | ||
Properly tokenize the division operator directly after a function expression. | ||
Properly tokenize the division operator directly after a function | ||
expression. | ||
Allow trailing comma in destructuring arrays. | ||
### New features | ||
The walker now allows defining handlers for `CatchClause` nodes. | ||
## 3.0.4 (2016-02-25) | ||
@@ -421,4 +370,3 @@ | ||
Allow update expressions as left-hand-side of the ES7 exponential | ||
operator. | ||
Allow update expressions as left-hand-side of the ES7 exponential operator. | ||
@@ -429,4 +377,3 @@ ## 3.0.2 (2016-02-10) | ||
Fix bug that accidentally made `undefined` a reserved word when | ||
parsing ES7. | ||
Fix bug that accidentally made `undefined` a reserved word when parsing ES7. | ||
@@ -439,22 +386,17 @@ ## 3.0.0 (2016-02-10) | ||
Support for comprehension syntax (which was dropped from the draft | ||
spec) has been removed. | ||
Support for comprehension syntax (which was dropped from the draft spec) has been removed. | ||
### Fixes | ||
`let` and `yield` are now “contextual keywords”, meaning you can | ||
mostly use them as identifiers in ES5 non-strict code. | ||
`let` and `yield` are now “contextual keywords”, meaning you can mostly use them as identifiers in ES5 non-strict code. | ||
A parenthesized class or function expression after `export default` is | ||
now parsed correctly. | ||
A parenthesized class or function expression after `export default` is now parsed correctly. | ||
### New features | ||
When `ecmaVersion` is set to 7, Acorn will parse the exponentiation | ||
operator (`**`). | ||
When `ecmaVersion` is set to 7, Acorn will parse the exponentiation operator (`**`). | ||
The identifier character ranges are now based on Unicode 8.0.0. | ||
Plugins can now override the `raiseRecoverable` method to override the | ||
way non-critical errors are handled. | ||
Plugins can now override the `raiseRecoverable` method to override the way non-critical errors are handled. | ||
@@ -467,5 +409,2 @@ ## 2.7.0 (2016-01-04) | ||
Make sure the loose parser always attaches a `local` property to | ||
`ImportNamespaceSpecifier` nodes. | ||
Disallow `y` rexexp flag in ES5. | ||
@@ -477,12 +416,2 @@ | ||
## 2.6.4 (2015-11-12) | ||
### Fixes | ||
Fix crash in loose parser when parsing invalid object pattern. | ||
### New features | ||
Support plugins in the loose parser. | ||
## 2.6.2 (2015-11-10) | ||
@@ -508,9 +437,2 @@ | ||
## 2.5.2 (2015-10-27) | ||
### Fixes | ||
Fix bug where the walker walked an exported `let` statement as an | ||
expression. | ||
## 2.5.0 (2015-10-27) | ||
@@ -522,5 +444,2 @@ | ||
In the loose parser, don't allow non-string-literals as import | ||
sources. | ||
Stop allowing `new.target` outside of functions. | ||
@@ -530,4 +449,3 @@ | ||
Stop allowing multiple `__proto__` properties on an object literal in | ||
strict mode. | ||
Stop allowing multiple `__proto__` properties on an object literal in strict mode. | ||
@@ -534,0 +452,0 @@ Don't allow rest parameters to be non-identifier patterns. |
@@ -6,7 +6,5 @@ { | ||
"main": "dist/acorn.js", | ||
"module": "dist/acorn.es.js", | ||
"version": "5.7.3", | ||
"engines": { | ||
"node": ">=0.4.0" | ||
}, | ||
"module": "dist/acorn.mjs", | ||
"version": "6.0.0", | ||
"engines": {"node": ">=0.4.0"}, | ||
"maintainers": [ | ||
@@ -16,3 +14,3 @@ { | ||
"email": "marijnh@gmail.com", | ||
"web": "http://marijnhaverbeke.nl" | ||
"web": "https://marijnhaverbeke.nl" | ||
}, | ||
@@ -22,7 +20,7 @@ { | ||
"email": "me@rreverser.com", | ||
"web": "http://rreverser.com/" | ||
"web": "https://rreverser.com/" | ||
}, | ||
{ | ||
"name": "Adrian Heine", | ||
"email": "http://adrianheine.de" | ||
"web": "http://adrianheine.de" | ||
} | ||
@@ -35,30 +33,3 @@ ], | ||
"license": "MIT", | ||
"scripts": { | ||
"prepare": "npm run build && node test/run.js && node test/lint.js", | ||
"test": "node test/run.js && node test/lint.js", | ||
"pretest": "npm run build:main && npm run build:loose", | ||
"test:test262": "node bin/run_test262.js", | ||
"build": "npm run build:main && npm run build:walk && npm run build:loose && npm run build:bin", | ||
"build:main": "rollup -c rollup/config.main.js", | ||
"build:walk": "rollup -c rollup/config.walk.js", | ||
"build:loose": "rollup -c rollup/config.loose.js && rollup -c rollup/config.loose_es.js", | ||
"build:bin": "rollup -c rollup/config.bin.js", | ||
"lint": "eslint src/" | ||
}, | ||
"bin": { | ||
"acorn": "./bin/acorn" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^4.10.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-node": "^5.2.1", | ||
"eslint-plugin-promise": "^3.5.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"rollup": "^0.45.0", | ||
"rollup-plugin-buble": "^0.16.0", | ||
"test262": "git+https://github.com/tc39/test262.git#3bfad28cc302fd4455badcfcbca7c5bb7ce41a72", | ||
"test262-parser-runner": "^0.4.0", | ||
"unicode-11.0.0": "^0.7.7" | ||
} | ||
"bin": {"acorn": "./bin/acorn"} | ||
} |
302
README.md
# Acorn | ||
[![Build Status](https://travis-ci.org/acornjs/acorn.svg?branch=master)](https://travis-ci.org/acornjs/acorn) | ||
[![NPM version](https://img.shields.io/npm/v/acorn.svg)](https://www.npmjs.com/package/acorn) | ||
[![CDNJS](https://img.shields.io/cdnjs/v/acorn.svg)](https://cdnjs.com/libraries/acorn) | ||
[Author funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png?force)](https://marijnhaverbeke.nl/fund/) | ||
A tiny, fast JavaScript parser written in JavaScript. | ||
A tiny, fast JavaScript parser, written completely in JavaScript. | ||
## Community | ||
@@ -23,6 +18,4 @@ | ||
The easiest way to install acorn is with [`npm`][npm]. | ||
The easiest way to install acorn is from [`npm`](https://www.npmjs.com/): | ||
[npm]: https://www.npmjs.com/ | ||
```sh | ||
@@ -38,32 +31,25 @@ npm install acorn | ||
npm install | ||
npm run build | ||
``` | ||
## Components | ||
## Interface | ||
When run in a CommonJS (node.js) or AMD environment, exported values | ||
appear in the interfaces exposed by the individual files, as usual. | ||
When loaded in the browser (Acorn works in any JS-enabled browser more | ||
recent than IE5) without any kind of module management, a single | ||
global object `acorn` will be defined, and all the exported properties | ||
will be added to that. | ||
**parse**`(input, options)` is the main interface to the library. The | ||
`input` parameter is a string, `options` can be undefined or an object | ||
setting some of the options listed below. The return value will be an | ||
abstract syntax tree object as specified by the [ESTree | ||
spec](https://github.com/estree/estree). | ||
### Main parser | ||
```javascript | ||
let acorn = require("acorn"); | ||
console.log(acorn.parse("1 + 1")); | ||
``` | ||
This is implemented in `dist/acorn.js`, and is what you get when you | ||
`require("acorn")` in node.js. | ||
**parse**`(input, options)` is used to parse a JavaScript program. | ||
The `input` parameter is a string, `options` can be undefined or an | ||
object setting some of the options listed below. The return value will | ||
be an abstract syntax tree object as specified by the | ||
[ESTree spec][estree]. | ||
When encountering a syntax error, the parser will raise a | ||
`SyntaxError` object with a meaningful message. The error object will | ||
have a `pos` property that indicates the character offset at which the | ||
error occurred, and a `loc` object that contains a `{line, column}` | ||
When encountering a syntax error, the parser will raise a | ||
`SyntaxError` object with a meaningful message. The error object will | ||
have a `pos` property that indicates the string offset at which the | ||
error occurred, and a `loc` object that contains a `{line, column}` | ||
object referring to that same position. | ||
[estree]: https://github.com/estree/estree | ||
Options can be provided by passing a second argument, which should be | ||
an object containing any of these fields: | ||
@@ -76,3 +62,4 @@ - **ecmaVersion**: Indicates the ECMAScript version to parse. Must be | ||
**NOTE**: Only 'stage 4' (finalized) ECMAScript features are being | ||
implemented by Acorn. | ||
implemented by Acorn. Other proposed new features can be implemented | ||
through plugins. | ||
@@ -106,3 +93,6 @@ - **sourceType**: Indicate the mode the code should be parsed in. Can be | ||
- **allowAwaitOutsideFunction**: By default, `await` expressions can only appear inside `async` functions. Setting this option to `true` allows to have top-level `await` expressions. They are still not allowed in non-`async` functions, though. | ||
- **allowAwaitOutsideFunction**: By default, `await` expressions can | ||
only appear inside `async` functions. Setting this option to | ||
`true` allows to have top-level `await` expressions. They are | ||
still not allowed in non-`async` functions, though. | ||
@@ -166,5 +156,6 @@ - **allowHashBang**: When this is enabled (off by default), if the | ||
rather than the `loc` object, which holds line/column data. To also | ||
add a [semi-standardized][range] `range` property holding a | ||
`[start, end]` array with the same numbers, set the `ranges` option | ||
to `true`. | ||
add a | ||
[semi-standardized](https://bugzilla.mozilla.org/show_bug.cgi?id=745678) | ||
`range` property holding a `[start, end]` array with the same | ||
numbers, set the `ranges` option to `true`. | ||
@@ -192,4 +183,2 @@ - **program**: It is possible to parse multiple files into a single | ||
[range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678 | ||
**parseExpressionAt**`(input, offset, options)` will parse a single | ||
@@ -199,5 +188,2 @@ expression in a string, and return its AST. It will not complain if | ||
**getLineInfo**`(input, offset)` can be used to get a `{line, | ||
column}` object for a given program string and character offset. | ||
**tokenizer**`(input, options)` returns an object with a `getToken` | ||
@@ -226,136 +212,27 @@ method that can be called repeatedly to get the next token, a `{start, | ||
#### Note on using with [Escodegen][escodegen] | ||
**getLineInfo**`(input, offset)` can be used to get a `{line, | ||
column}` object for a given program string and offset. | ||
Escodegen supports generating comments from AST, attached in | ||
Esprima-specific format. In order to simulate same format in | ||
Acorn, consider following example: | ||
### The `Parser` class | ||
```javascript | ||
var comments = [], tokens = []; | ||
Instances of the **`Parser`** class contain all the state and logic | ||
that drives a parse. It has static methods `parse`, | ||
`parseExpressionAt`, and `tokenizer` that match the top-level | ||
functions by the same name. | ||
var ast = acorn.parse('var x = 42; // answer', { | ||
// collect ranges for each node | ||
ranges: true, | ||
// collect comments in Esprima's format | ||
onComment: comments, | ||
// collect token ranges | ||
onToken: tokens | ||
}); | ||
When extending the parser with plugins, you need to call these methods | ||
on the extended version of the class. To extend a parser with plugins, | ||
you can use its static `extend` method. | ||
// attach comments using collected information | ||
escodegen.attachComments(ast, comments, tokens); | ||
// generate code | ||
console.log(escodegen.generate(ast, {comment: true})); | ||
// > 'var x = 42; // answer' | ||
```javascript | ||
var acorn = require("acorn"); | ||
var jsx = require("acorn-jsx"); | ||
var JSXParser = acorn.Parser.extend(jsx()); | ||
JSXParser.parse("foo(<bar/>)"); | ||
``` | ||
[escodegen]: https://github.com/estools/escodegen | ||
The `extend` method takes any number of plugin values, and returns a | ||
new `Parser` class that includes the extra parser logic provided by | ||
the plugins. | ||
### dist/acorn_loose.js ### | ||
This file implements an error-tolerant parser. It exposes a single | ||
function. The loose parser is accessible in node.js via `require("acorn/dist/acorn_loose")`. | ||
**parse_dammit**`(input, options)` takes the same arguments and | ||
returns the same syntax tree as the `parse` function in `acorn.js`, | ||
but never raises an error, and will do its best to parse syntactically | ||
invalid code in as meaningful a way as it can. It'll insert identifier | ||
nodes with name `"✖"` as placeholders in places where it can't make | ||
sense of the input. Depends on `acorn.js`, because it uses the same | ||
tokenizer. | ||
### dist/walk.js ### | ||
Implements an abstract syntax tree walker. Will store its interface in | ||
`acorn.walk` when loaded without a module system. | ||
**simple**`(node, visitors, base, state)` does a 'simple' walk over | ||
a tree. `node` should be the AST node to walk, and `visitors` an | ||
object with properties whose names correspond to node types in the | ||
[ESTree spec][estree]. The properties should contain functions | ||
that will be called with the node object and, if applicable the state | ||
at that point. The last two arguments are optional. `base` is a walker | ||
algorithm, and `state` is a start state. The default walker will | ||
simply visit all statements and expressions and not produce a | ||
meaningful state. (An example of a use of state is to track scope at | ||
each point in the tree.) | ||
```js | ||
const acorn = require("acorn") | ||
const walk = require("acorn/dist/walk") | ||
walk.simple(acorn.parse("let x = 10"), { | ||
Literal(node) { | ||
console.log(`Found a literal: ${node.value}`) | ||
} | ||
}) | ||
``` | ||
**ancestor**`(node, visitors, base, state)` does a 'simple' walk over | ||
a tree, building up an array of ancestor nodes (including the current node) | ||
and passing the array to the callbacks as a third parameter. | ||
```js | ||
const acorn = require("acorn") | ||
const walk = require("acorn/dist/walk") | ||
walk.ancestor(acorn.parse("foo('hi')"), { | ||
Literal(_, ancestors) { | ||
console.log("This literal's ancestors are:", | ||
ancestors.map(n => n.type)) | ||
} | ||
}) | ||
``` | ||
**recursive**`(node, state, functions, base)` does a 'recursive' | ||
walk, where the walker functions are responsible for continuing the | ||
walk on the child nodes of their target node. `state` is the start | ||
state, and `functions` should contain an object that maps node types | ||
to walker functions. Such functions are called with `(node, state, c)` | ||
arguments, and can cause the walk to continue on a sub-node by calling | ||
the `c` argument on it with `(node, state)` arguments. The optional | ||
`base` argument provides the fallback walker functions for node types | ||
that aren't handled in the `functions` object. If not given, the | ||
default walkers will be used. | ||
**make**`(functions, base)` builds a new walker object by using the | ||
walker functions in `functions` and filling in the missing ones by | ||
taking defaults from `base`. | ||
**full**`(node, callback, base, state)` does a 'full' | ||
walk over a tree, calling the callback with the arguments (node, state, type) | ||
for each node | ||
**fullAncestor**`(node, callback, base, state)` does a 'full' walk over | ||
a tree, building up an array of ancestor nodes (including the current node) | ||
and passing the array to the callbacks as a third parameter. | ||
```js | ||
const acorn = require("acorn") | ||
const walk = require("acorn/dist/walk") | ||
walk.full(acorn.parse("1 + 1"), node => { | ||
console.log(`There's a ${node.type} node at ${node.ch}`) | ||
}) | ||
``` | ||
**findNodeAt**`(node, start, end, test, base, state)` tries to | ||
locate a node in a tree at the given start and/or end offsets, which | ||
satisfies the predicate `test`. `start` and `end` can be either `null` | ||
(as wildcard) or a number. `test` may be a string (indicating a node | ||
type) or a function that takes `(nodeType, node)` arguments and | ||
returns a boolean indicating whether this node is interesting. `base` | ||
and `state` are optional, and can be used to specify a custom walker. | ||
Nodes are tested from inner to outer, so if two nodes match the | ||
boundaries, the inner one will be preferred. | ||
**findNodeAround**`(node, pos, test, base, state)` is a lot like | ||
`findNodeAt`, but will match any node that exists 'around' (spanning) | ||
the given position. | ||
**findNodeAfter**`(node, pos, test, base, state)` is similar to | ||
`findNodeAround`, but will match all nodes *after* the given position | ||
(testing outer nodes before inner nodes). | ||
## Command line interface | ||
@@ -368,3 +245,3 @@ | ||
- `--ecma3|--ecma5|--ecma6|--ecma7|--ecma8|--ecma9|--ecma10`: Sets the ECMAScript version | ||
to parse. Default is version 7. | ||
to parse. Default is version 9. | ||
@@ -377,3 +254,4 @@ - `--module`: Sets the parsing mode to `"module"`. Is set to `"script"` otherwise. | ||
- `--allow-hash-bang`: If the code starts with the characters #! (as in a shellscript), the first line will be treated as a comment. | ||
- `--allow-hash-bang`: If the code starts with the characters #! (as | ||
in a shellscript), the first line will be treated as a comment. | ||
@@ -388,78 +266,7 @@ - `--compact`: No whitespace is used in the AST output. | ||
## Build system | ||
## Existing plugins | ||
Acorn is written in ECMAScript 6, as a set of small modules, in the | ||
project's `src` directory, and compiled down to bigger ECMAScript 3 | ||
files in `dist` using [Browserify](http://browserify.org) and | ||
[Babel](http://babeljs.io/). If you are already using Babel, you can | ||
consider including the modules directly. | ||
The command-line test runner (`npm test`) uses the ES6 modules. The | ||
browser-based test page (`test/index.html`) uses the compiled modules. | ||
The `bin/build-acorn.js` script builds the latter from the former. | ||
If you are working on Acorn, you'll probably want to try the code out | ||
directly, without an intermediate build step. In your scripts, you can | ||
register the Babel require shim like this: | ||
require("babel-core/register") | ||
That will allow you to directly `require` the ES6 modules. | ||
## Plugins | ||
Acorn is designed support allow plugins which, within reasonable | ||
bounds, redefine the way the parser works. Plugins can add new token | ||
types and new tokenizer contexts (if necessary), and extend methods in | ||
the parser object. This is not a clean, elegant API—using it requires | ||
an understanding of Acorn's internals, and plugins are likely to break | ||
whenever those internals are significantly changed. But still, it is | ||
_possible_, in this way, to create parsers for JavaScript dialects | ||
without forking all of Acorn. And in principle it is even possible to | ||
combine such plugins, so that if you have, for example, a plugin for | ||
parsing types and a plugin for parsing JSX-style XML literals, you | ||
could load them both and parse code with both JSX tags and types. | ||
A plugin should register itself by adding a property to | ||
`acorn.plugins`, which holds a function. Calling `acorn.parse`, a | ||
`plugins` option can be passed, holding an object mapping plugin names | ||
to configuration values (or just `true` for plugins that don't take | ||
options). After the parser object has been created, the initialization | ||
functions for the chosen plugins are called with `(parser, | ||
configValue)` arguments. They are expected to use the `parser.extend` | ||
method to extend parser methods. For example, the `readToken` method | ||
could be extended like this: | ||
```javascript | ||
parser.extend("readToken", function(nextMethod) { | ||
return function(code) { | ||
console.log("Reading a token!") | ||
return nextMethod.call(this, code) | ||
} | ||
}) | ||
``` | ||
The `nextMethod` argument passed to `extend`'s second argument is the | ||
previous value of this method, and should usually be called through to | ||
whenever the extended method does not handle the call itself. | ||
Similarly, the loose parser allows plugins to register themselves via | ||
`acorn.pluginsLoose`. The extension mechanism is the same as for the | ||
normal parser: | ||
```javascript | ||
looseParser.extend("readToken", function(nextMethod) { | ||
return function() { | ||
console.log("Reading a token in the loose parser!") | ||
return nextMethod.call(this) | ||
} | ||
}) | ||
``` | ||
### Existing plugins | ||
- [`acorn-jsx`](https://github.com/RReverser/acorn-jsx): Parse [Facebook JSX syntax extensions](https://github.com/facebook/jsx) | ||
- [`acorn-objj`](https://github.com/cappuccino/acorn-objj): [Objective-J](http://www.cappuccino-project.org/learn/objective-j.html) language parser built as Acorn plugin | ||
Plugins for ECMAScript proposals: | ||
Plugins for ECMAScript proposals: | ||
@@ -473,7 +280,2 @@ - [`acorn-stage3`](https://github.com/acornjs/acorn-stage3): Parse most stage 3 proposals, bundling: | ||
- [`acorn-numeric-separator`](https://github.com/acornjs/acorn-numeric-separator): Parse [numeric separator proposal](https://github.com/tc39/proposal-numeric-separator) | ||
- [`acorn-optional-catch-binding`](https://github.com/acornjs/acorn-optional-catch-binding): Parse [optional catch binding proposal](https://github.com/tc39/proposal-optional-catch-binding) | ||
- [`acorn-private-methods`](https://github.com/acornjs/acorn-private-methods): parse [private methods, getters and setters proposal](https://github.com/tc39/proposal-private-methods) | ||
- [`acorn5-object-spread`](https://github.com/adrianheine/acorn5-object-spread): Parse [Object Rest/Spread Properties proposal](https://github.com/tc39/proposal-object-rest-spread) | ||
- [`acorn-object-rest-spread`](https://github.com/victor-homyakov/acorn-object-rest-spread): Parse [Object Rest/Spread Properties proposal](https://github.com/tc39/proposal-object-rest-spread) | ||
- [`acorn-es7`](https://github.com/angelozerr/acorn-es7): Parse [decorator syntax proposal](https://github.com/wycats/javascript-decorators) | ||
- [`acorn-static-class-property-initializer`](https://github.com/victor-homyakov/acorn-static-class-property-initializer): Partial support for static class properties from [ES Class Fields & Static Properties Proposal](https://github.com/tc39/proposal-class-public-fields) to support static property initializers in [React components written as ES6+ classes](https://babeljs.io/blog/2015/07/07/react-on-es6-plus) | ||
- [`acorn-private-methods`](https://github.com/acornjs/acorn-private-methods): parse [private methods, getters and setters proposal](https://github.com/tc39/proposal-private-methods)n |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1075313
0
1
11
9679
270
1