Add support for serializing bigints (#2581)
This commit is contained in:
parent
3e3e2cbec7
commit
be1c3eb05b
|
@ -1,5 +1,7 @@
|
|||
## 0.17.3 (Unreleased)
|
||||
|
||||
- Add support for serializing JavaScript function that capture [BigInts](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
|
||||
|
||||
### Improvements
|
||||
|
||||
- A new command, `pulumi stack rename` was added. This allows you to change the name of an existing stack in a project. Note: When a stack is renamed, the `pulumi.getStack` function in the SDK will now return a new value. If a stack name is used as part of a resource name, the next `pulumi update` will not understand that the old and new resources are logically the same. We plan to support adding aliases to individual resources so you can handle these cases. See [pulumi/pulumi#458](https://github.com/pulumi/pulumi/issues/458) for discussion on this new feature. For now, if you are unwilling to have `pulumi update` create and destroy these resources, you can rename your stack back to the old name. (fixes [pulumi/pulumi#2402](https://github.com/pulumi/pulumi/issues/2402))
|
||||
|
|
|
@ -18,7 +18,8 @@ lint::
|
|||
|
||||
build_package::
|
||||
./node_modules/.bin/tsc
|
||||
cp tests/runtime/jsClosureCases.js bin/tests/runtime
|
||||
cp tests/runtime/jsClosureCases_8.js bin/tests/runtime
|
||||
cp tests/runtime/jsClosureCases_10_4.js bin/tests/runtime
|
||||
cp README.md ../../LICENSE package.json ./dist/* bin/
|
||||
node ../../scripts/reversion.js bin/package.json ${VERSION}
|
||||
node ../../scripts/reversion.js bin/version.js ${VERSION}
|
||||
|
|
|
@ -861,6 +861,10 @@ async function getOrCreateEntryAsync(
|
|||
entry.json = obj;
|
||||
return;
|
||||
}
|
||||
else if (typeof obj === "bigint") {
|
||||
entry.expr = `${obj}n`;
|
||||
return;
|
||||
}
|
||||
else if (obj instanceof RegExp) {
|
||||
entry.regexp = obj;
|
||||
return;
|
||||
|
|
31
sdk/nodejs/tests/runtime/jsClosureCases_10_4.js
Normal file
31
sdk/nodejs/tests/runtime/jsClosureCases_10_4.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
"use strict";
|
||||
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
||||
|
||||
const cases = [];
|
||||
{
|
||||
const zeroBigInt = 0n;
|
||||
const smallBigInt = 1n;
|
||||
const negativeBigInt = -1n;
|
||||
const largeBigInt = 11111111111111111111111111111111111111111n;
|
||||
const negativeLargeBigInt = -11111111111111111111111111111111111111111n;
|
||||
|
||||
cases.push({
|
||||
title: "Captures bigint",
|
||||
// tslint:disable-next-line
|
||||
func: function () { console.log(zeroBigInt + smallBigInt + negativeBigInt + largeBigInt + negativeBigInt + negativeLargeBigInt); },
|
||||
expectText: `exports.handler = __f0;
|
||||
|
||||
function __f0() {
|
||||
return (function() {
|
||||
with({ zeroBigInt: 0n, smallBigInt: 1n, negativeBigInt: -1n, largeBigInt: 11111111111111111111111111111111111111111n, negativeLargeBigInt: -11111111111111111111111111111111111111111n }) {
|
||||
|
||||
return function () { console.log(zeroBigInt + smallBigInt + negativeBigInt + largeBigInt + negativeBigInt + negativeLargeBigInt); };
|
||||
|
||||
}
|
||||
}).apply(undefined, undefined).apply(this, arguments);
|
||||
}
|
||||
`,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.cases = cases;
|
|
@ -77,9 +77,9 @@ return async (a) => { await a; };
|
|||
cases.push({
|
||||
title: "Function captures V8 intrinsic (js)",
|
||||
func: () => { %AbortJS(0) },
|
||||
error: `Error serializing function 'func': jsClosureCases.js(0,0)
|
||||
error: `Error serializing function 'func': jsClosureCases_8.js(0,0)
|
||||
|
||||
function 'func': jsClosureCases.js(0,0): which could not be serialized because
|
||||
function 'func': jsClosureCases_8.js(0,0): which could not be serialized because
|
||||
the function could not be parsed: (...)
|
||||
|
||||
Function code:
|
|
@ -21,6 +21,7 @@ import * as pulumi from "../../index";
|
|||
import { output } from "../../output";
|
||||
import { assertAsyncThrows, asyncTest } from "../util";
|
||||
import * as typescript from "typescript";
|
||||
import * as semver from "semver";
|
||||
|
||||
import * as deploymentOnlyModule from "./deploymentOnlyModule";
|
||||
|
||||
|
@ -5785,9 +5786,13 @@ return function () { console.log(regex); foo(); };
|
|||
// We can't do this inline as node6 doesn't understand 'async functions'. And we
|
||||
// can't do this in TS as TS will convert the async-function to be a normal non-async
|
||||
// function.
|
||||
const version = Number(process.version.match(/^v(\d+)\.\d+/)![1]);
|
||||
if (version >= 8) {
|
||||
const jsCases = require("./jsClosureCases");
|
||||
if (semver.gte(process.version, "8.0.0")) {
|
||||
const jsCases = require("./jsClosureCases_8");
|
||||
cases.push(...jsCases.cases);
|
||||
}
|
||||
|
||||
if (semver.gte(process.version, "10.4.0")) {
|
||||
const jsCases = require("./jsClosureCases_10_4");
|
||||
cases.push(...jsCases.cases);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue