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

Commit c0f45be

Browse files
committed
fix(scopes): Support Function and Class Declarations without id
These declarations are used in combination with default exports ``` export default function () {}; ```
1 parent 1387dd3 commit c0f45be

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/attachScopes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Scope {
6161
// it's a `var` or function node, and this
6262
// is a block scope, so we need to go up
6363
this.parent.addDeclaration( node, isBlockDeclaration, isVar );
64-
} else {
64+
} else if ( node.id ) {
6565
extractNames( node.id ).forEach( name => {
6666
this.declarations[ name ] = true;
6767
});

test/test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,41 @@ describe( 'rollup-pluginutils', function () {
177177
assert.ok( scope.contains( 'bar' ) );
178178
});
179179

180+
it( 'supports FunctionDeclarations without id', function () {
181+
var ast = {
182+
"type": "Program",
183+
"start": 0,
184+
"end": 33,
185+
"body": [
186+
{
187+
"type": "ExportDefaultDeclaration",
188+
"start": 0,
189+
"end": 32,
190+
"declaration": {
191+
"type": "FunctionDeclaration",
192+
"start": 15,
193+
"end": 32,
194+
"id": null,
195+
"generator": false,
196+
"expression": false,
197+
"async": false,
198+
"params": [],
199+
"body": {
200+
"type": "BlockStatement",
201+
"start": 26,
202+
"end": 32,
203+
"body": []
204+
}
205+
}
206+
}
207+
],
208+
"sourceType": "module"
209+
};
210+
211+
var scope = attachScopes( ast, 'scope' );
212+
// does not throw
213+
});
214+
180215
// TODO more tests
181216
});
182217

0 commit comments

Comments
 (0)