Skip to content

feat: support native type BigInt #2052

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

Merged
merged 4 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/app-frontend/src/mixins/data-field-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ export default {

isValueEditable () {
const type = this.interpretedValueType
const customType = this.field.value?._custom?.type

return this.isEditable &&
(
type === 'null' ||
type === 'literal' ||
type === 'string' ||
type === 'array' ||
type === 'plain-object'
type === 'plain-object' ||
customType === 'bigint'
)
},

Expand Down
15 changes: 15 additions & 0 deletions packages/shared-utils/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ function replacerForInternal (key) {
return getCustomFunctionDetails(val)
} else if (type === 'symbol') {
return `[native Symbol ${Symbol.prototype.toString.call(val)}]`
} else if (type === 'bigint') {
return getCustomBigIntDetails(val)
} else if (val !== null && type === 'object') {
const proto = Object.prototype.toString.call(val)
if (proto === '[object Map]') {
Expand Down Expand Up @@ -329,6 +331,17 @@ export function reviveSet (val) {
return result
}

export function getCustomBigIntDetails (val) {
const stringifiedBigInt = BigInt.prototype.toString.call(val)
return {
_custom: {
type: 'bigint',
display: `BigInt(${stringifiedBigInt})`,
value: stringifiedBigInt,
},
}
}

// Use a custom basename functions instead of the shimed version
// because it doesn't work on Windows
function basename (filename, ext) {
Expand Down Expand Up @@ -497,6 +510,8 @@ export function revive (val) {
return reviveMap(val)
} else if (custom.type === 'set') {
return reviveSet(val)
} else if (custom.type === 'bigint') {
return BigInt(custom.value)
} else if (custom._reviveId) {
return reviveCache.read(custom._reviveId)
} else {
Expand Down
4 changes: 4 additions & 0 deletions packages/shell-dev-vue2/src/NativeTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<h3>Map</h3>
<pre>{{ mapDisplay() }}</pre>

<h3>BigInt</h3>
<pre>{{ bigInt }}</pre>

<p>
<button @click="testVuexSet()">
Vuex Set
Expand Down Expand Up @@ -143,6 +146,7 @@ export default {
b,
c) {},
veryLongText,
bigInt: BigInt(Number.MAX_SAFE_INTEGER),
}
},
computed: {
Expand Down
4 changes: 4 additions & 0 deletions packages/shell-dev-vue3/src/NativeTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

<h3>Map</h3>
<pre>{{ mapDisplay() }}</pre>

<h3>BigInt</h3>
<pre>{{ bigInt }}</pre>
</div>
</template>

Expand Down Expand Up @@ -122,6 +125,7 @@ export default {
c) {},
veryLongText,
someElement: null,
bigInt: BigInt(Number.MAX_SAFE_INTEGER),
}
},

Expand Down