Skip to content

Commit

Permalink
Automatically add as-bind source files
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Mar 9, 2021
1 parent 2b4fc71 commit c71e9ed
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions transform.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require("fs");
const { Transform } = require("assemblyscript/cli/transform");
const assemblyscript = require("assemblyscript");

Expand All @@ -13,9 +14,17 @@ function typeName(type) {
return type.name.text ?? type.name.identifier.text;
}

const marker = "__asbind_type_data";
const MARKER = "__asbind_type_data";
const AS_BIND_SRC = "lib/assembly/as-bind.ts";

class AsBindTransform extends Transform {
afterParse(parser) {
const bindSrc = fs.readFileSync(
require.resolve("./" + AS_BIND_SRC),
"utf8"
);
parser.parseFile(bindSrc, "~as-bind/" + AS_BIND_SRC, true);
}
afterInitialize(program) {
const exportedFunctions = [...program.elementsByDeclaration.values()]
.filter(el =>
Expand Down Expand Up @@ -57,7 +66,7 @@ class AsBindTransform extends Transform {
)
};
const typeDataExport = [...program.elementsByDeclaration.values()].find(
v => v.name === marker
v => v.name === MARKER
);
if (!typeDataExport) {
throw Error("Could not find type data export");
Expand Down

0 comments on commit c71e9ed

Please sign in to comment.