Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

fix(scopes): Support Function and Class Declarations without id #28

Merged
merged 1 commit into from
May 7, 2018
Merged
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
2 changes: 1 addition & 1 deletion src/attachScopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Scope {
// it's a `var` or function node, and this
// is a block scope, so we need to go up
this.parent.addDeclaration( node, isBlockDeclaration, isVar );
} else {
} else if ( node.id ) {
extractNames( node.id ).forEach( name => {
this.declarations[ name ] = true;
});
Expand Down
35 changes: 35 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,41 @@ describe( 'rollup-pluginutils', function () {
assert.ok( scope.contains( 'bar' ) );
});

it( 'supports FunctionDeclarations without id', function () {
var ast = {
"type": "Program",
"start": 0,
"end": 33,
"body": [
{
"type": "ExportDefaultDeclaration",
"start": 0,
"end": 32,
"declaration": {
"type": "FunctionDeclaration",
"start": 15,
"end": 32,
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 26,
"end": 32,
"body": []
}
}
}
],
"sourceType": "module"
};

var scope = attachScopes( ast, 'scope' );
// does not throw
});

// TODO more tests
});

Expand Down