Skip to content

Generate .d.ts without namespace #1705

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

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 2 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ under the licensing terms detailed in LICENSE:
* Piotr Oleś <[email protected]>
* Saúl Cabrera <[email protected]>
* Chance Snow <[email protected]>
* Jerry Green <[email protected]>
* Peter Salomonsen <[email protected]>

Portions of this software are derived from third-party works licensed under
Expand All @@ -59,6 +60,6 @@ the following terms:
The 3-Clause BSD License (https://opensource.org/licenses/BSD-3-Clause)

* Arm Optimized Routines: https://github.com/ARM-software/optimized-routines

Copyright (c) Arm Limited
The MIT License (https://opensource.org/licenses/MIT)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@
"check:config": "tsc --noEmit -p src --diagnostics --listFiles",
"check:require": "tsc --noEmit --target ESNEXT --module commonjs --experimentalDecorators tests/require/index",
"check:lint": "eslint --max-warnings 0 --ext js . && eslint --max-warnings 0 --ext ts .",
"test": "npm run test:parser && npm run test:compiler && npm run test:packages && npm run test:extension && npm run test:asconfig",
"test": "npm run test:parser && npm run test:compiler && npm run test:packages && npm run test:extension && npm run test:asconfig && npm run test:imports",
"test:parser": "node tests/parser",
"test:compiler": "node --experimental-wasi-unstable-preview1 tests/compiler",
"test:packages": "cd tests/packages && npm run test",
"test:extension": "cd tests/extension && npm run test",
"test:asconfig": "cd tests/asconfig && npm run test",
"test:imports": "cd tests/imports && npm run test",
"make": "npm run clean && npm test && npm run build && npm test",
"all": "npm run check && npm run make",
"docs": "typedoc --tsconfig tsconfig-docs.json --mode modules --name \"AssemblyScript Compiler API\" --out ./docs/api --ignoreCompilerErrors --excludeNotExported --excludePrivate --excludeExternals --exclude **/std/** --includeDeclarations --readme src/README.md",
Expand Down
10 changes: 5 additions & 5 deletions src/asconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@
"untouched": {
"binaryFile": "../out/assemblyscript.untouched.wasm",
"textFile": "../out/assemblyscript.untouched.wast",
"tsdFile": "../out/assemblyscript.d.ts",
"tsdFile": "../out/assemblyscript.untouched.wasm.d.ts",
"debug": true
},
"optimized": {
"binaryFile": "../out/assemblyscript.optimized.wasm",
"textFile": "../out/assemblyscript.optimized.wast",
"tsdFile": "../out/assemblyscript.d.ts",
"tsdFile": "../out/assemblyscript.optimized.wasm.d.ts",
"optimizeLevel": 3,
"shrinkLevel": 0
},
"rtraced": {
"binaryFile": "../out/assemblyscript.rtraced.wasm",
"textFile": "../out/assemblyscript.rtraced.wast",
"tsdFile": "../out/assemblyscript.d.ts",
"tsdFile": "../out/assemblyscript.rtraced.wasm.d.ts",
"debug": true,
"use": "ASC_RTRACE=1",
"runPasses": []
},
"untouched-bootstrap": {
"binaryFile": "../out/assemblyscript.untouched-bootstrap.wasm",
"textFile": "../out/assemblyscript.untouched-bootstrap.wast",
"tsdFile": "../out/assemblyscript.d.ts",
"tsdFile": "../out/assemblyscript.untouched-bootstrap.wasm.d.ts",
"debug": true
},
"optimized-bootstrap": {
"binaryFile": "../out/assemblyscript.optimized-bootstrap.wasm",
"textFile": "../out/assemblyscript.optimized-bootstrap.wast",
"tsdFile": "../out/assemblyscript.d.ts",
"tsdFile": "../out/assemblyscript.optimized-bootstrap.wasm.d.ts",
"optimizeLevel": 3,
"shrinkLevel": 0
}
Expand Down
35 changes: 15 additions & 20 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,33 +604,28 @@ export class TSDBuilder extends ExportsWalker {
build(): string {
var sb = this.sb;
var isWasm64 = this.program.options.isWasm64;
sb.push("declare module ASModule {\n");
sb.push(" type i8 = number;\n");
sb.push(" type i16 = number;\n");
sb.push(" type i32 = number;\n");
sb.push(" type i64 = bigint;\n");
sb.push("type i8 = number;\n");
sb.push("type i16 = number;\n");
sb.push("type i32 = number;\n");
sb.push("type i64 = bigint;\n");
if (isWasm64) {
sb.push(" type isize = bigint;\n");
sb.push("type isize = bigint;\n");
} else {
sb.push(" type isize = number;\n");
sb.push("type isize = number;\n");
}
sb.push(" type u8 = number;\n");
sb.push(" type u16 = number;\n");
sb.push(" type u32 = number;\n");
sb.push(" type u64 = bigint;\n");
sb.push("type u8 = number;\n");
sb.push("type u16 = number;\n");
sb.push("type u32 = number;\n");
sb.push("type u64 = bigint;\n");
if (isWasm64) {
sb.push(" type usize = bigint;\n");
sb.push("type usize = bigint;\n");
} else {
sb.push(" type usize = number;\n");
sb.push("type usize = number;\n");
}
sb.push(" type f32 = number;\n");
sb.push(" type f64 = number;\n");
sb.push(" type bool = boolean | number;\n");
++this.indentLevel;
sb.push("type f32 = number;\n");
sb.push("type f64 = number;\n");
sb.push("type bool = boolean | number;\n");
this.walk();
--this.indentLevel;
sb.push("}\n");
sb.push("export default ASModule;\n");
return this.sb.join("");
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/imports/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js
*.wasm*
3 changes: 3 additions & 0 deletions tests/imports/add.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function add(a: i32, b: i32): i32 {
return a + b
}
10 changes: 10 additions & 0 deletions tests/imports/dynamic-import.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(async () => {
const wasm = await import('./module.wasm');

const res = wasm.add(1, 2);
if (res !== 3) {
console.error('❌ WASM dynamic import does not work as expected');
process.exit(1);
}
console.log('✔️ Can dynamically import wasm module with experimental flag');
})();
9 changes: 9 additions & 0 deletions tests/imports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "module",
"scripts": {
"build": "node ../../bin/asc --extension .as add.as -o module.wasm -d module.wasm.d.ts",
"test": "npm run build && npm run test:static && npm run test:dynamic",
"test:static": "tsc -m es2020 static-import.test.ts && node --experimental-wasm-modules static-import.test.js",
"test:dynamic": "tsc -m es2020 dynamic-import.test.ts && node --experimental-wasm-modules dynamic-import.test.js"
}
}
9 changes: 9 additions & 0 deletions tests/imports/static-import.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as wasm from './module.wasm';

const res = wasm.add(1, 2);
if (res !== 3) {
console.error('❌ WASM static import does not work as expected');
process.exit(1);
}

console.log('✔️ Can statically import wasm module with experimental flag');