From ce332b3384d60aff025d51adcf5142c8ab63b96c Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 13 Feb 2015 17:37:35 +1100 Subject: [PATCH] fix module binding resolution - fixes #762 --- lib/6to5/traversal/scope.js | 2 +- lib/6to5/types/alias-keys.json | 3 +++ lib/6to5/types/index.js | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/6to5/traversal/scope.js b/lib/6to5/traversal/scope.js index 979f6cfc31..d84bf38f36 100644 --- a/lib/6to5/traversal/scope.js +++ b/lib/6to5/traversal/scope.js @@ -141,7 +141,7 @@ Scope.prototype.checkBlockScopedCollisions = function (kind, name, id) { if (kind === "param") return; if (kind === "hoisted" && local.kind === "let") return; - if (local.kind === "let" || local.kind === "const") { + if (local.kind === "let" || local.kind === "const" || local.kind === "module") { throw this.file.errorWithNode(id, messages.get("scopeDuplicateDeclaration", name), TypeError); } }; diff --git a/lib/6to5/types/alias-keys.json b/lib/6to5/types/alias-keys.json index 2dfddb2885..eafb015d72 100644 --- a/lib/6to5/types/alias-keys.json +++ b/lib/6to5/types/alias-keys.json @@ -22,6 +22,9 @@ "FunctionDeclaration": ["Statement", "Declaration", "Scopable", "Function"], "FunctionExpression": ["Scopable", "Function", "Expression"], + "ImportSpecifier": ["ModuleSpecifier"], + "ExportSpecifier": ["ModuleSpecifier"], + "BlockStatement": ["Statement", "Scopable"], "Program": ["Scopable"], "CatchClause": ["Scopable"], diff --git a/lib/6to5/types/index.js b/lib/6to5/types/index.js index b587d58147..8fe0e48714 100644 --- a/lib/6to5/types/index.js +++ b/lib/6to5/types/index.js @@ -590,6 +590,8 @@ t.getBindingIdentifiers = function (node) { if (t.isIdentifier(id)) { ids[id.name] = id; + } else if (t.isModuleSpecifier(id)) { + search.push(id.name || id.id); } else if (t.isExportDeclaration(id)) { if (t.isDeclaration(node.declaration)) { search.push(node.declaration); @@ -608,8 +610,6 @@ t.getBindingIdentifiers = function (node) { t.getBindingIdentifiers.keys = { AssignmentExpression: ["left"], ImportBatchSpecifier: ["name"], - ImportSpecifier: ["name", "id"], - ExportSpecifier: ["name", "id"], VariableDeclarator: ["id"], FunctionDeclaration: ["id"], ClassDeclaration: ["id"],