Skip to content
This repository was archived by the owner on Sep 27, 2020. It is now read-only.
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"env": {
"es6": true,
"mocha": true,
"node": true
}
}
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
of type `VariableDeclaration` and lists of parameters are represented as
lists of nodes of type `VariableDeclaration`. This is a breaking change.

### 0.4.9

* Fix parsing of inheritance specifier with no arguments.

### 0.4.8

* Fix parsing of string literals with escaped characters.
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ try {
The `parse` method also accepts a second argument which lets you specify the
following options, in a style similar to the _esprima_ API:

| Key | Type | Default | Description |
|----------|---------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| tolerant | Boolean | false | When set to `true` it will collect syntax errors and place them in a list under the key `errors` inside the root node of the returned AST. Otherwise, it will raise a `parser.ParserError`. |
| loc | Boolean | false | When set to `true`, it will add location information to each node, with start and stop keys that contain the corresponding line and column numbers. |
| range | Boolean | false | When set to `true`, it will add range information to each node, which consists of a two-element array with start and stop character indexes in the input. |
| Key | Type | Default | Description |
|----------|---------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| tolerant | Boolean | false | When set to `true` it will collect syntax errors and place them in a list under the key `errors` inside the root node of the returned AST. Otherwise, it will raise a `parser.ParserError`. |
| loc | Boolean | false | When set to `true`, it will add location information to each node, with start and stop keys that contain the corresponding line and column numbers. Column numbers start from 0, lines start from 1. |
| range | Boolean | false | When set to `true`, it will add range information to each node, which consists of a two-element array with start and stop character indexes in the input. |


#### Example with location information
Expand Down
24 changes: 22 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type ASTNodeTypeString =
| 'NumberLiteral'
| 'Identifier'
| 'BinaryOperation'
| 'UnaryOperation'
| 'Conditional'
| 'StringLiteral'
| 'HexLiteral'
Expand Down Expand Up @@ -388,16 +389,30 @@ export type BinOp =
| '*='
| '/='
| '%=';

export type UnOp =
| '-'
| '!'
| '--'
| '++';

export interface BinaryOperation extends BaseASTNode {
type: 'BinaryOperation';
left: Expression;
right: Expression;
operator: BinOp;
}
export interface UnaryOperation extends BaseASTNode {
type: 'UnaryOperation';
subExpression: Expression;
operator: UnOp;
isPrefix: boolean;
}
export interface Conditional extends BaseASTNode {
type: 'Conditional';
trueExpression: ASTNode;
falseExpression: ASTNode;
condition: Expression;
trueExpression: Expression;
falseExpression: Expression;
}
export interface IndexAccess extends BaseASTNode {
type: 'IndexAccess';
Expand Down Expand Up @@ -499,6 +514,7 @@ export type Expression =
| IndexAccess
| TupleExpression
| BinaryOperation
| UnaryOperation
| Conditional
| MemberAccess
| FunctionCall
Expand Down Expand Up @@ -586,9 +602,11 @@ export interface Visitor {
BooleanLiteral?: (node: BooleanLiteral) => any;
Identifier?: (node: Identifier) => any;
BinaryOperation?: (node: BinaryOperation) => any;
UnaryOperation?: (node: UnaryOperation) => any;
Conditional?: (node: Conditional) => any;
IndexAccess?: (node: IndexAccess) => any;
MemberAccess?: (node: MemberAccess) => any;
FunctionCall?: (node: FunctionCall) => any;
Break?: (node: Break) => any;
HexNumber?: (node: HexNumber) => any;
DecimalNumber?: (node: DecimalNumber) => any;
Expand Down Expand Up @@ -665,4 +683,6 @@ export interface ParserOpts {
loc?: boolean;
}
export function parse(sourceCode: string, parserOpts: ParserOpts): ASTNode;
export function parseType(sourceCode: string, parserOpts: ParserOpts): ASTNode;
export function parseExpression(sourceCode: string, parserOpts: ParserOpts): Expression;
export function visit(ast: ASTNode, visitor: Visitor): void;
Loading