Skip to content

Commit 7b626a8

Browse files
committed
feat(compiler): Allow BigInt usage in templates (issue vuejs#11126)
1 parent 9e05266 commit 7b626a8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/core/instance/proxy.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import { warn, makeMap, isNative } from '../util/index'
66
let initProxy
77

88
if (process.env.NODE_ENV !== 'production') {
9+
const supportBigInt =
10+
(typeof window !== 'undefined' && typeof window.BigInt === 'function') ||
11+
(typeof global !== 'undefined' && typeof global.BigInt === 'function')
12+
913
const allowedGlobals = makeMap(
1014
'Infinity,undefined,NaN,isFinite,isNaN,' +
1115
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
1216
'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
13-
'require' // for Webpack/Browserify
17+
'require,' + // for Webpack/Browserify
18+
(supportBigInt ? 'BigInt' : '') // for BigInt support issue #11126
1419
)
1520

1621
const warnNonPresent = (target, key) => {

test/unit/features/filter/filter.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,11 @@ describe('Filters', () => {
194194
it('support template string', () => {
195195
expect(parseFilters('`a | ${b}c` | d')).toBe('_f("d")(`a | ${b}c`)')
196196
})
197+
198+
it('bigint support', () => {
199+
const vm = new Vue({
200+
template: `<div>{{ BigInt(BigInt(10000000)) + BigInt(2000000000n) * 3000000n }}</div>`
201+
}).$mount()
202+
expect(vm.$el.textContent).toBe('6000000010000000')
203+
})
197204
})

0 commit comments

Comments
 (0)