Skip to content

Commit

Permalink
Added support for ChainExpression node (#113)
Browse files Browse the repository at this point in the history
Co-authored-by: sanex3339 <yarabotayuvyandex3339>
  • Loading branch information
sanex3339 authored Aug 5, 2020
1 parent e22afb3 commit ac91373
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions estraverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
BreakStatement: 'BreakStatement',
CallExpression: 'CallExpression',
CatchClause: 'CatchClause',
ChainExpression: 'ChainExpression',
ClassBody: 'ClassBody',
ClassDeclaration: 'ClassDeclaration',
ClassExpression: 'ClassExpression',
Expand Down Expand Up @@ -159,6 +160,7 @@
BreakStatement: ['label'],
CallExpression: ['callee', 'arguments'],
CatchClause: ['param', 'body'],
ChainExpression: ['expression'],
ClassBody: ['body'],
ClassDeclaration: ['id', 'superClass', 'body'],
ClassExpression: ['id', 'superClass', 'body'],
Expand Down
37 changes: 37 additions & 0 deletions test/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,43 @@ describe('function declaration', function() {
});
});

describe('chain expression', function() {
it('traverse', function() {
const tree = {
type: 'ExpressionStatement',
expression: {
type: 'ChainExpression',
expression: {
type: 'MemberExpression',
object: {
type: 'Identifier',
name: 'a'
},
property: {
type: 'Identifier',
name: 'b'
},
computed: false,
optional: true
}
}
};

checkDump(Dumper.dump(tree), `
enter - ExpressionStatement
enter - ChainExpression
enter - MemberExpression
enter - Identifier
leave - Identifier
enter - Identifier
leave - Identifier
leave - MemberExpression
leave - ChainExpression
leave - ExpressionStatement
`);
});
});

describe('extending keys', function() {
it('traverse', function() {
const tree = {
Expand Down

0 comments on commit ac91373

Please sign in to comment.