Preserve import binding locations during module rewriting (#7378)

* Only wrap import references that need it.

* Preserve the import binding location for sourcemaps.

* Add tests.
This commit is contained in:
Logan Smyth
2018-02-14 10:17:27 -08:00
committed by GitHub
parent 128fc6864e
commit e732ee0c5b
6 changed files with 232 additions and 6 deletions

View File

@@ -181,7 +181,13 @@ const rewriteReferencesVisitor = {
if (importData) {
const ref = buildImportReference(importData, path.node);
if (path.parentPath.isCallExpression({ callee: path.node })) {
// Preserve the binding location so that sourcemaps are nicer.
ref.loc = path.node.loc;
if (
path.parentPath.isCallExpression({ callee: path.node }) &&
t.isMemberExpression(ref)
) {
path.replaceWith(t.sequenceExpression([t.numericLiteral(0), ref]));
} else if (path.isJSXIdentifier() && t.isMemberExpression(ref)) {
const { object, property } = ref;