zenika-open-source/immutadot

Name conflict between array.concat and string.concat

Closed this issue ยท 2 comments

Description

This happens when using immutadot in Node.
Haven't tested if this is true in browser environment.

Only for bugs ๐Ÿ›

Version : 1.0.0-rc.4

Expected behavior

Have one of the concat exported at top level ? Which one ?
Have none of them ?
Have aliased names of them exported ?
Remove one of them ?

Actual behavior

./node_modules/immutadot/index.js:66
    Object.defineProperty(exports, key, {
           ^

TypeError: Cannot redefine property: concat
    at Function.defineProperty (<anonymous>)
    at ./node_modules/immutadot/index.js:66:12
    at Array.forEach (<anonymous>)
    at ./node_modules/immutadot/index.js:64:24
    at Object.defineProperty.value (./node_modules/immutadot/index.js:5:5)
    at Object.<anonymous> (./node_modules/immutadot/index.js:13:3)

How to reproduce

const ... = require('immutadot')

This name conflict is already managed in the generated code of flow where string.concat is not exported at top level to avoid this name conflict...

This is also true for array.slice and string.slice...
Aliasing them at top level would seem a good solution, but this doesn't seem possible without hard coding it in index.js :

export {
  concat as arrayConcat,
  fill,
  filter,
  map,
  pop,
  push,
  reverse,
  shift,
  slice as arraySlice,
  sort,
  splice,
  unshift,
} from './array'

This is not very maintainable...
Moreover this is not consistent with what is done in flow... and seq.chain...