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

Commit f097e9f

Browse files
committed
Merge branch 'fix/declarations' of https://github.com/danez/rollup-pluginutils into danez-fix/declarations
# Conflicts: # test/test.js
2 parents 804f659 + c0f45be commit f097e9f

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
@@ -65,7 +65,7 @@ class Scope {
6565
// it's a `var` or function node, and this
6666
// is a block scope, so we need to go up
6767
this.parent.addDeclaration( node, isBlockDeclaration, isVar );
68-
} else {
68+
} else if ( node.id ) {
6969
extractNames( node.id ).forEach( name => {
7070
this.declarations[ name ] = true;
7171
});

test/test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,41 @@ describe( 'rollup-pluginutils', function () {
424424
assert.ok(scope.contains('c'));
425425
});
426426

427+
it( 'supports FunctionDeclarations without id', function () {
428+
var ast = {
429+
"type": "Program",
430+
"start": 0,
431+
"end": 33,
432+
"body": [
433+
{
434+
"type": "ExportDefaultDeclaration",
435+
"start": 0,
436+
"end": 32,
437+
"declaration": {
438+
"type": "FunctionDeclaration",
439+
"start": 15,
440+
"end": 32,
441+
"id": null,
442+
"generator": false,
443+
"expression": false,
444+
"async": false,
445+
"params": [],
446+
"body": {
447+
"type": "BlockStatement",
448+
"start": 26,
449+
"end": 32,
450+
"body": []
451+
}
452+
}
453+
}
454+
],
455+
"sourceType": "module"
456+
};
457+
458+
var scope = attachScopes( ast, 'scope' );
459+
// does not throw
460+
});
461+
427462
// TODO more tests
428463
});
429464

0 commit comments

Comments
 (0)