Skip to content
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

es2020 target in tsc to allow bigint literal #176

Merged
merged 7 commits into from
Aug 16, 2022
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
2 changes: 1 addition & 1 deletion cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function build(argv) {

async function checkTsBuildWithTsc(sourceFileWithPath) {
console.log(`check TypeScript build of ${sourceFileWithPath} with tsc`)
await executeCommand(`${TSC} --noEmit --experimentalDecorators --target es5 ${sourceFileWithPath}`);
await executeCommand(`${TSC} --noEmit --experimentalDecorators --target es2020 --moduleResolution node ${sourceFileWithPath}`);
}

// Common build function
Expand Down
2 changes: 1 addition & 1 deletion examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "es5",
"target": "es2020",
"noEmit": true
},
"exclude": [
Expand Down
37 changes: 37 additions & 0 deletions tests/__tests__/typescript.ava.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Worker } from 'near-workspaces';
import test from 'ava';


test.before(async t => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();

// Prepare sandbox for tests, create accounts, deploy contracts, etx.
const root = worker.rootAccount;

// Deploy the test contract.
const typescriptContract = await root.devDeploy(
'build/typescript.wasm',
);
await typescriptContract.call(typescriptContract, 'init', {})

// Test users
const ali = await root.createSubAccount('ali');

// Save state for test runs
t.context.worker = worker;
t.context.accounts = { root, typescriptContract, ali };
});

test.after(async t => {
await t.context.worker.tearDown().catch(error => {
console.log('Failed to tear down the worker:', error);
});
});


test('bigint', async t => {
const { typescriptContract } = t.context.accounts;
let r = await typescriptContract.view('bigint', '');
t.is(r, "3");
});
9 changes: 6 additions & 3 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"postinstall": "cd .. && yarn link && cd tests && yarn link near-sdk-js",
"build": "yarn build:context-api && yarn build:math-api && yarn build:storage-api && yarn build:log-panic-api && yarn build:promise-api && yarn build:promise-batch-api && yarn build:function-params && yarn build:lookup-map && yarn build:lookup-set && yarn build:unordered-map && yarn build:unordered-set && yarn build:vector && yarn build:bytes",
"build": "yarn build:context-api && yarn build:math-api && yarn build:storage-api && yarn build:log-panic-api && yarn build:promise-api && yarn build:promise-batch-api && yarn build:function-params && yarn build:lookup-map && yarn build:lookup-set && yarn build:unordered-map && yarn build:unordered-set && yarn build:vector && yarn build:bytes && yarn build:typescript",
"build:context-api": "near-sdk-js build src/context_api.js build/context_api.wasm",
"build:math-api": "near-sdk-js build src/math_api.js build/math_api.wasm",
"build:storage-api": "near-sdk-js build src/storage_api.js build/storage_api.wasm",
Expand All @@ -20,6 +20,7 @@
"build:unordered-set": "near-sdk-js build src/unordered-set.js build/unordered-set.wasm",
"build:vector": "near-sdk-js build src/vector.js build/vector.wasm",
"build:bytes": "near-sdk-js build src/bytes.js build/bytes.wasm",
"build:typescript": "near-sdk-js build src/typescript.ts build/typescript.wasm",
"test": "ava",
"test:context-api": "ava __tests__/test_context_api.ava.js",
"test:math-api": "ava __tests__/test_math_api.ava.js",
Expand All @@ -32,12 +33,14 @@
"test:unordered-set": "ava __tests__/unordered-set.ava.js",
"test:unordered-map": "ava __tests__/unordered-map.ava.js",
"test:vector": "ava __tests__/vector.ava.js",
"test:bytes": "ava __tests__/bytes.ava.js"
"test:bytes": "ava __tests__/bytes.ava.js",
"test:typescript": "ava __tests__/typescript.ava.js"
},
"author": "Near Inc <[email protected]>",
"license": "Apache-2.0",
"devDependencies": {
"ava": "^4.2.0",
"near-workspaces": "3.1.0"
"near-workspaces": "3.1.0",
"typescript": "^4.7.4"
}
}
18 changes: 18 additions & 0 deletions tests/src/typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
NearContract,
NearBindgen,
view,
} from 'near-sdk-js'

@NearBindgen
class TypeScriptTestContract extends NearContract {
@view
bigint() {
// JSON.stringify cannot seriaize a BigInt, need manually toString
return (1n + 2n).toString()
}

default() {
return new TypeScriptTestContract()
}
}
10 changes: 10 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "es2020",
"noEmit": true
},
"exclude": [
"node_modules"
],
}
5 changes: 5 additions & 0 deletions tests/yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.