Skip to content

Commit cdcaca5

Browse files
committed
Clean up the DTS generator (1/2)
These changes aim to make the code somewhat simpler, although it seems that the DTS generator will forever remain a mess of some sort. The second commit after this should show observable performance improvements by manipulating the AST instead of stringifying and re-parsing. This commit has no effect on the contents of assemblyscript.generated.d.ts and asc.generated.d.ts. Moreover, "wrapper" files generated by the DTS generator (asc.d.ts, assemblyscript.d.ts, transform.d.ts, transform.cjs, transform.js) are now included in the tree instead of being generated, since they will never change. The transform.{c,}js files also use ES6 classes instead of functions (why not?). Also, the build.js script now imports build-dts.js instead of spawning it as a separate process. The following changes to the generator have been made: * `options.stdout` is now just a plain array * `options.main` is assumed nonexistent * `options.verbose` is assumed true * `options.sendMessage` is assumed `util.debuglog("dts")` * use `NODE_DEBUG=dts` to view the logs * `options.types` is assumed nonexistent * `options.out` is assumed nonexistent * `options.resolveModuleId` is assumed nonexistent * `options.prefix` is assumed to exist * the use of `new Promise(...)` is now removed * `import ... = require(...)` statements are assumed to never exist * double quotes are now used instead of single quotes * `else` is now on the same line as the ending brace of `if` * other style changes have been made while I'm at it * `DTS` is a constant just like `DTSLEN` * `excludesMap` is now a set called `exclusions` * `transformTypes` uses `context.factory` to create identifiers * a duplicate `currentModuleId` variable is now removed * unneeded merging of `compilerOptions` and `options` is now removed * `pathUtil.relative()` is used instead of slicing * arrow functions are used more often * (and some other things I likely forgot about)
1 parent 9fd90aa commit cdcaca5

File tree

9 files changed

+169
-344
lines changed

9 files changed

+169
-344
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
node_modules/
22
*debug.log
3-
dist/
43
build/
54
raw/
65
.history

dist/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.generated.d.ts
2+
*.map
3+
asc.js
4+
assemblyscript.js

dist/asc.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// <reference path="./asc.generated.d.ts" />
2+
export * from "types:assemblyscript/cli/index";
3+
import * as asc from "types:assemblyscript/cli/index";
4+
export default asc;

dist/assemblyscript.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// <reference path="./assemblyscript.generated.d.ts" />
2+
export * from "types:assemblyscript/src/index";
3+
import * as assemblyscript from "types:assemblyscript/src/index";
4+
export default assemblyscript;

dist/transform.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = class Transform { /* stub */ };

dist/transform.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Transform } from "./asc";

dist/transform.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export class Transform { /* stub */ };

0 commit comments

Comments
 (0)