Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mind. When in doubt, use `.parse()`.

| Version | Changes |
| --------- | -------------------------------------------------- |
| `v8.0.0` | Added `locations` |
| `v7.28.0` | Added `sourceType: "commonjs"` |
| `v7.27.0` | Added `allowYieldOutsideFunction` |
| `v7.26.0` | Added `startIndex` |
Expand Down Expand Up @@ -94,6 +95,11 @@ mind. When in doubt, use `.parse()`.
The resulting AST will have an `errors` property representing an array of all the parsing errors.
Note that even when this option is enabled, `@babel/parser` could throw for unrecoverable errors.

- **locations**: Can be one of `true`, `false` or `packed`.
`true` is the default and will add a `loc` property to each node, which is an object with `start` and `end` properties, which are objects containing `line` and `column` numbers.
When set to `false`, the "loc" property will not be included in the output AST.
When set to `packed`, the `parse` function will return an `Uint32Array` of the form (`[line1, column1, line2, column2, ...]`). You can access the line and column numbers of a node with `locData[node.start * 2]` for the starting line, `locData[node.start * 2 + 1]` for the starting column, `locData[node.end * 2]` for the ending line and `locData[node.end * 2 + 1]` for the ending column.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example for packed? Do we not also return an AST?


- **plugins**: Array containing the plugins that you want to enable.

- **sourceType**: Indicate the mode the code should be parsed in. Can be
Expand Down