Skip to content

Commit 122207d

Browse files
feat: support native type BigInt (vuejs#2052)
1 parent 74eccb0 commit 122207d

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

packages/app-frontend/src/mixins/data-field-edit.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,16 @@ export default {
7272

7373
isValueEditable () {
7474
const type = this.interpretedValueType
75+
const customType = this.field.value?._custom?.type
76+
7577
return this.isEditable &&
7678
(
7779
type === 'null' ||
7880
type === 'literal' ||
7981
type === 'string' ||
8082
type === 'array' ||
81-
type === 'plain-object'
83+
type === 'plain-object' ||
84+
customType === 'bigint'
8285
)
8386
},
8487

packages/shared-utils/src/util.ts

+15
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ function replacerForInternal (key) {
215215
return getCustomFunctionDetails(val)
216216
} else if (type === 'symbol') {
217217
return `[native Symbol ${Symbol.prototype.toString.call(val)}]`
218+
} else if (type === 'bigint') {
219+
return getCustomBigIntDetails(val)
218220
} else if (val !== null && type === 'object') {
219221
const proto = Object.prototype.toString.call(val)
220222
if (proto === '[object Map]') {
@@ -329,6 +331,17 @@ export function reviveSet (val) {
329331
return result
330332
}
331333

334+
export function getCustomBigIntDetails (val) {
335+
const stringifiedBigInt = BigInt.prototype.toString.call(val)
336+
return {
337+
_custom: {
338+
type: 'bigint',
339+
display: `BigInt(${stringifiedBigInt})`,
340+
value: stringifiedBigInt,
341+
},
342+
}
343+
}
344+
332345
// Use a custom basename functions instead of the shimed version
333346
// because it doesn't work on Windows
334347
function basename (filename, ext) {
@@ -497,6 +510,8 @@ export function revive (val) {
497510
return reviveMap(val)
498511
} else if (custom.type === 'set') {
499512
return reviveSet(val)
513+
} else if (custom.type === 'bigint') {
514+
return BigInt(custom.value)
500515
} else if (custom._reviveId) {
501516
return reviveCache.read(custom._reviveId)
502517
} else {

packages/shell-dev-vue2/src/NativeTypes.vue

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
<h3>Map</h3>
4040
<pre>{{ mapDisplay() }}</pre>
4141

42+
<h3>BigInt</h3>
43+
<pre>{{ bigInt }}</pre>
44+
4245
<p>
4346
<button @click="testVuexSet()">
4447
Vuex Set
@@ -143,6 +146,7 @@ export default {
143146
b,
144147
c) {},
145148
veryLongText,
149+
bigInt: BigInt(Number.MAX_SAFE_INTEGER),
146150
}
147151
},
148152
computed: {

packages/shell-dev-vue3/src/NativeTypes.vue

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
<h3>Map</h3>
2929
<pre>{{ mapDisplay() }}</pre>
30+
31+
<h3>BigInt</h3>
32+
<pre>{{ bigInt }}</pre>
3033
</div>
3134
</template>
3235

@@ -122,6 +125,7 @@ export default {
122125
c) {},
123126
veryLongText,
124127
someElement: null,
128+
bigInt: BigInt(Number.MAX_SAFE_INTEGER),
125129
}
126130
},
127131

0 commit comments

Comments
 (0)