babel-plugin-component icon indicating copy to clipboard operation
babel-plugin-component copied to clipboard

fix: transform commonjs

Open peterhpchen opened this issue 3 years ago • 0 comments

Problem

@babel/plugin-transform-modules-commonjs used by @babel/preset-env for transform modules to commonjs will save which nodes have already traverse and skip them when the next traverse(https://github.com/babel/babel/blob/10978bb65a4b4e8874ca8dd3054b8c31b5838b7f/packages/babel-helper-module-transforms/src/rewrite-live-references.js#L175)

@babel/plugin-transform-modules-commonjs will save every traversed reference of node, so if the references of node are same, the babel will skip to transform the node. This is the problem of this issue.

Resolve

Just clone object to prevent use same object reference.

peterhpchen avatar Jan 20 '21 07:01 peterhpchen