Skip to content

Issue with ExportSpecifier #271

@adamjmcgrath

Description

@adamjmcgrath

I've noticed an issue in 1.7.1 with ExportSpecfier caused by b99a200

var esprima = require('esprima');
var escodegen = require('escodegen'); // 1.7.1

escodegen.generate(esprima.parse('export { foo };', sourceType: 'module'));
TypeError: Cannot read property 'name' of undefined
    at CodeGenerator.Expression.ExportSpecifier (escodegen/escodegen.js:2266:54)
    at CodeGenerator.generateExpression (escodegen/escodegen.js:2428:28)
   ...

On this line:
https://github.com/estools/escodegen/blob/master/escodegen.js#L2265
var exported = (expr.id || expr.imported).name;

This should either include the ExportSpecifier:
https://github.com/estree/estree/blob/master/es6.md#exportspecifier
var exported = (expr.id || expr.imported || expr.exported).name;

Or remove the ImportSpecifier and just include the ModuleSpecifier
https://github.com/estree/estree/blob/master/es6.md#modulespecifier
var exported = (expr.id || expr.local).name;

I'll raise a PR with a fix and some test cases to prevent this regression

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions