Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove throwing error on unrecognized binding #550

Merged
merged 1 commit into from
May 23, 2017
Merged
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
40 changes: 21 additions & 19 deletions packages/babel-plugin-minify-mangle-names/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,34 @@ module.exports = babel => {
/**
* This is useful to detect binding ids and add them to the
* scopeTracker's bindings
*
* TODO:
*
* This visitor is probably unnecessary. It was added to capture the
* bindings that was not present in scope.bindings. But, now, it looks
* like the unit and smoke tests pass without this.
*/
BindingIdentifier(path) {
if (isLabelIdentifier(path)) return;

const { scope, node: { name } } = path;
const binding = scope.getBinding(name);

if (!binding) {
// ignore the globals as it's available via Babel's API
if (scope.hasGlobal(name)) return;

// Ignore the NamedExports as they should NOT be mangled
if (
path.parentPath.isExportSpecifier() &&
path.parentKey === "exported"
) {
return;
}

// This should NOT happen ultimately. Panic if this code is reached
throw new Error(
`Binding not found for BindingIdentifier "${name}" ` +
`present in "${path.parentPath.type}". ` +
`Please report this at ${newIssueUrl}`
);
}
/**
* We have already captured the bindings when traversing through
* Scopables, if a binding identifier doesn't have a binding, it
* probably means that another transformation created a new binding,
* refer https://github.com/babel/babili/issues/549 for example -
* binding created by plugin transform-es2015-function-name
*
* So we just don't care about bindings that do not exist
*
* TODO:
*
* this deopts in DCE as this name can be removed for this particular
* case (es2015-function-name)
*/
if (!binding) return;

/**
* Detect constant violations
Expand Down