Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol polyfill 不正确,导致 core-js 中的 polyfill 代码执行不正常 #275

Closed
qiu8310 opened this issue Aug 7, 2019 · 1 comment

Comments

@qiu8310
Copy link

qiu8310 commented Aug 7, 2019

/**
 * 最小可复现代码说明:
 *    webpack 不用任何 loader
 *    core-js 使用的版本号是 2.6.9
 */

// vconsole: https://github.com/Tencent/vConsole/blob/v3.3.2/src/lib/symbol.js
// 原代码做了判断 Symbol 是否存在,这里是为了在所有浏览器中都能复现这个 bug 才去掉 if 的判断
window.Symbol = function _Symbol() {}

// 下面两个 require 顺序不能换(比较奇葩哈,所以这个 bug 不是必现)
// 在正常的开发中,下面两行代码是被 babel-loader 引入的
require('core-js/modules/es6.regexp.replace')
require('core-js/modules/es6.regexp.split')

var base = 'abc'
base = base.replace(/a/, '1') // 返回的结果是: [""]
base = base.replace('b', '2') // 由于 base 已经不是字符串,所以这里会报错

document.body.innerHTML = base
@qiu8310
Copy link
Author

qiu8310 commented Aug 7, 2019

正常情况下,这个 bug 只有在不支持 Symbol 的浏览器,并且 babel 处理后的代码中正好有上面两个 require 才会出现

使用上面的代码,可以让这个 bug 在所有浏览器中必现

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

No branches or pull requests

2 participants