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

fix(compiler): Allow BigInt usage in templates #11152

Merged
merged 8 commits into from Mar 30, 2021
7 changes: 6 additions & 1 deletion src/core/instance/proxy.js
Expand Up @@ -6,11 +6,16 @@ import { warn, makeMap, isNative } from '../util/index'
let initProxy

if (process.env.NODE_ENV !== 'production') {
const supportBigInt =
(typeof window !== 'undefined' && typeof window.BigInt === 'function') ||
(typeof global !== 'undefined' && typeof global.BigInt === 'function')

const allowedGlobals = makeMap(
'Infinity,undefined,NaN,isFinite,isNaN,' +
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
'require' // for Webpack/Browserify
'require,' + // for Webpack/Browserify
(supportBigInt ? 'BigInt' : '') // for BigInt support issue #11126
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to not use a conditional, the same way we allow Intl even though it's not supported before IE 11

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,That sounds right,and I will add BigInt directly in makeMap()
: )

)

const warnNonPresent = (target, key) => {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/features/filter/filter.spec.js
Expand Up @@ -194,4 +194,11 @@ describe('Filters', () => {
it('support template string', () => {
expect(parseFilters('`a | ${b}c` | d')).toBe('_f("d")(`a | ${b}c`)')
})

it('bigint support', () => {
const vm = new Vue({
template: `<div>{{ BigInt(BigInt(10000000)) + BigInt(2000000000n) * 3000000n }}</div>`
}).$mount()
expect(vm.$el.textContent).toBe('6000000010000000')
})
})