Skip to content

Destructuring module imports with const throw a redeclaration error #411

Description

@grob

Some modules in RingoJS (binary, io, ringo/events) use defineClass() which modifies the global scope. In itself that's imho quite intransparent and thus not a good idea, but alas the wrong implementation of const in Rhino leads to another problem: requiring one of these modules in conjunction with const and desctructuring assignments fails with eg. TypeError: redeclaration of var ByteArray.

Module test-a.js:

require("binary");
require("test-b");

Module test-b.js:

const {ByteArray} = require("binary");

Afais Rhino walks up the prototype chain (the global scope is the prototype of all module scopes) and tries to re-declare the const ByteArray in there, which correctly fails - but i couldn't figure out why the const isn't declared in the module scope.

Workaround: use const binary = require("binary"); in modules. Adds verbosity, but works.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions