Skip to content

Commit

Permalink
feat(compiler): Allow BigInt usage in templates (issue #11126)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowings-zy committed Feb 27, 2020
1 parent 9e05266 commit 7b626a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/instance/proxy.js
Original file line number Diff line number Diff line change
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
)

const warnNonPresent = (target, key) => {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/features/filter/filter.spec.js
Original file line number Diff line number Diff line change
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')
})
})

0 comments on commit 7b626a8

Please sign in to comment.