diff --git a/lib/6to5/transformers/constants.js b/lib/6to5/transformers/constants.js index 6df3a4dbfe..6257b8a985 100644 --- a/lib/6to5/transformers/constants.js +++ b/lib/6to5/transformers/constants.js @@ -55,7 +55,9 @@ exports.ForStatement = function (node) { traverse(node, function (child) { if (child._ignoreConstant) return; - if (child.type === "VariableDeclarator") { + if (child.type === "VariableDeclarator" || + child.type === "FunctionDeclaration" || + child.type === "ClassDeclaration") { check(child, child.id.name); } else if (child.type === "AssignmentExpression") { check(child, child.left.name); diff --git a/test/fixtures/syntax/constants/no-classes/actual.js b/test/fixtures/syntax/constants/no-classes/actual.js new file mode 100644 index 0000000000..4d0266bd50 --- /dev/null +++ b/test/fixtures/syntax/constants/no-classes/actual.js @@ -0,0 +1,5 @@ +const MULTIPLIER = 5; + +class MULTIPLIER { + +} diff --git a/test/fixtures/syntax/constants/no-classes/options.json b/test/fixtures/syntax/constants/no-classes/options.json new file mode 100644 index 0000000000..9b96d41ac9 --- /dev/null +++ b/test/fixtures/syntax/constants/no-classes/options.json @@ -0,0 +1,3 @@ +{ + "throws": "MULTIPLIER is read-only" +} diff --git a/test/fixtures/syntax/constants/no-functions/actual.js b/test/fixtures/syntax/constants/no-functions/actual.js new file mode 100644 index 0000000000..8b3451172f --- /dev/null +++ b/test/fixtures/syntax/constants/no-functions/actual.js @@ -0,0 +1,5 @@ +const MULTIPLIER = 5; + +function MULTIPLIER() { + +} diff --git a/test/fixtures/syntax/constants/no-functions/options.json b/test/fixtures/syntax/constants/no-functions/options.json new file mode 100644 index 0000000000..9b96d41ac9 --- /dev/null +++ b/test/fixtures/syntax/constants/no-functions/options.json @@ -0,0 +1,3 @@ +{ + "throws": "MULTIPLIER is read-only" +}