Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Error with array destructuring assignment #358

Closed
skeggse opened this issue Nov 21, 2018 · 6 comments · Fixed by #379
Closed

Error with array destructuring assignment #358

skeggse opened this issue Nov 21, 2018 · 6 comments · Fixed by #379

Comments

@skeggse
Copy link

skeggse commented Nov 21, 2018

Pretty sure array destructuring assignments should work with array dereferences, but I get a TypeError.

// rollup.config.js
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';

export default {
  input: 'util.js',
  output: {
    file: 'util2.js',
    format: 'cjs',
  },
  plugins: [
    nodeResolve(),
    commonjs(),
  ],
};
// util.js
function shuffleArray(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [array[i], array[j]] = [array[j], array[i]];
  }
}

exports.shuffleArray = shuffleArray;
$ npx rollup -c rollup.config.js

util.js → util2.js...
[!] (commonjs plugin) TypeError: extractors[element.type] is not a function
util.js
TypeError: extractors[element.type] is not a function
    at .../node_modules/rollup-plugin-commonjs/dist/rollup-plugin-commonjs.cjs.js:242:43
    at Array.forEach (<anonymous>)
    at Object.ArrayPattern (.../node_modules/rollup-plugin-commonjs/dist/rollup-plugin-commonjs.cjs.js:240:17)
    at extractNames (.../node_modules/rollup-plugin-commonjs/dist/rollup-plugin-commonjs.cjs.js:224:23)
    at Object.enter (.../node_modules/rollup-plugin-commonjs/dist/rollup-plugin-commonjs.cjs.js:448:4)
    at visit (.../node_modules/estree-walker/dist/estree-walker.umd.js:31:9)
    at visit (.../node_modules/estree-walker/dist/estree-walker.umd.js:53:4)
    at visit (.../node_modules/estree-walker/dist/estree-walker.umd.js:48:5)
    at visit (.../node_modules/estree-walker/dist/estree-walker.umd.js:53:4)
    at visit (.../node_modules/estree-walker/dist/estree-walker.umd.js:48:5)
@tpluscode
Copy link

I get the same error at the following line:

[this.queryBegin, this.queryEnd] = this.callback(graph)

@arlac77
Copy link

arlac77 commented Jan 23, 2019

Same type of error but do not know the origin:

[!] (commonjs plugin) TypeError: extractors[element.type] is not a function
node_modules/@babel/parser/lib/index.js
TypeError: extractors[element.type] is not a function
    at /home/markus/build/npm-template-sync/node_modules/rollup-plugin-commonjs/src/ast-utils.js:53:41
    at Array.forEach (<anonymous>)
    at Object.ArrayPattern (/home/markus/build/npm-template-sync/node_modules/rollup-plugin-commonjs/src/ast-utils.js:52:17)
    at extractNames (/home/markus/build/npm-template-sync/node_modules/rollup-plugin-commonjs/src/ast-utils.js:36:23)
    at Object.enter (/home/markus/build/npm-template-sync/node_modules/rollup-plugin-commonjs/src/transform.js:158:4)
    at visit (/home/markus/build/npm-template-sync/node_modules/estree-walker/src/estree-walker.js:22:9)
    at visit (/home/markus/build/npm-template-sync/node_modules/estree-walker/src/estree-walker.js:44:4)
    at visit (/home/markus/build/npm-template-sync/node_modules/estree-walker/src/estree-walker.js:39:5)
    at visit (/home/markus/build/npm-template-sync/node_modules/estree-walker/src/estree-walker.js:44:4)
    at visit (/home/markus/build/npm-template-sync/node_modules/estree-walker/src/estree-walker.js:44:4)

@KevinMind
Copy link

I'm also getting this error.

I'm refactoring a node lib which had a lot of babel dependencies.. weird thing I only started getting .the error when I removed the babel dependencies. Even after reinstalling them, I still get it.

"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.1.6",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-stage-2": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^8.0.3",
"babel-jest": "^23.6.0",
"babel-plugin-dynamic-import-node": "^2.2.0",
"deepmerge": "^3.1.0",
"jsdom": "11.11.0",
"rimraf": "^2.6.2",
"rollup": "^1.1.2",
"rollup-plugin-alias": "^1.5.1",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^4.0.0"
},

@KevinMind
Copy link

This solved it for me.

commonjs({
    exclude: 'node_modules/@babel/**',
}),

I still don't know the root cause, perhaps a bug in commonJs plugin, but ignoring babel prevents the error at least for now.

@paulkenney
Copy link

This is probably a relatively straightforward change to the parse code to handle this additional case. Has anyone attempted a fix yet?

Tundon pushed a commit to Tundon/rollup-plugin-commonjs that referenced this issue Mar 25, 2019
Also a new test case is added to `misc tests -> misc tests`
@Tundon
Copy link
Contributor

Tundon commented Mar 25, 2019

I've submitted a pull request #379. This should also fix #376

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants