Skip to content

Commit

Permalink
Build transform with esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
learnforpractice committed Nov 3, 2022
1 parent 559a43d commit d5892c0
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 68 deletions.
3 changes: 2 additions & 1 deletion ts-packages/transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"type": "module",
"scripts": {
"checks": "tsc -p tsconfig.json --noEmit",
"build": "rm -rf dist/* && tsc -p tsconfig.json"
"build": "rm -rf dist/* && npx esbuild ./src/index.ts --bundle --platform=node --target=esnext --format='esm' --outfile=./dist/index.js"
},
"bin": {
"eosio-asc": "bin/eosio-asc.js"
Expand All @@ -25,6 +25,7 @@
"@types/node": "^18.11.9",
"@types/typescript": "^2.0.0",
"assemblyscript": "0.22.0",
"esbuild": "^0.15.13",
"handlebars": "4.7.7",
"ts-dedent": "^2.2.0",
"yargs": "^17.4.1"
Expand Down
2 changes: 1 addition & 1 deletion ts-packages/transform/src/ascoption.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIOptions } from "assemblyscript/dist/asc.js";
import { SourceModifier, ModifyPoint, ModifyType } from "./preprocess/index.js";
import { SourceModifier, ModifyPoint, ModifyType } from "./preprocess";
import * as path from "path";
import * as fs from "fs";
export class APIOptionImpl implements APIOptions {
Expand Down
12 changes: 6 additions & 6 deletions ts-packages/transform/src/contract/classdef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {
DecoratorNode,
} from "assemblyscript/dist/assemblyscript.js";

import { AstUtil, ElementUtil, DecoratorUtil, EosioUtils } from "../utils/utils.js";
import { AstUtil, ElementUtil, DecoratorUtil, EosioUtils } from "../utils/utils";

import { Strings } from "../utils/primitiveutil.js";
import { FieldDef, FunctionDef, ActionFunctionDef, DBIndexFunctionDef} from "./elementdef.js";
import { NamedTypeNodeDef } from "./typedef.js";
import { RangeUtil } from "../utils/utils.js";
import { Strings } from "../utils/primitiveutil";
import { FieldDef, FunctionDef, ActionFunctionDef, DBIndexFunctionDef} from "./elementdef";
import { NamedTypeNodeDef } from "./typedef";
import { RangeUtil } from "../utils/utils";

import { ContractDecoratorKind } from "../enums/decorator.js";
import { ContractDecoratorKind } from "../enums/decorator";


export class ClassInterpreter {
Expand Down
16 changes: 8 additions & 8 deletions ts-packages/transform/src/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import {
CommonFlags,
} from "assemblyscript/dist/assemblyscript.js";

import { ElementUtil } from "../utils/utils.js";
import { ElementUtil } from "../utils/utils";

import {
ContractInterpreter,
SerializerInterpreter,
ClassInterpreter,
TableInterpreter,
VariantInterpreter,
} from "./classdef.js";
} from "./classdef";

import { NamedTypeNodeDef } from "./typedef.js";
import { RangeUtil } from "../utils/utils.js";
import { NamedTypeNodeDef } from "./typedef";
import { RangeUtil } from "../utils/utils";
import {
ABI,
ABIAction,
Expand All @@ -25,11 +25,11 @@ import {
ABITable,
ABIActionResult,
VariantDef,
} from "../abi/abi.js";
} from "../abi/abi";

import { ActionFunctionDef } from "../contract/elementdef.js";
import { TypeKindEnum } from "../enums/customtype.js";
import { TypeHelper } from "../utils/typeutil.js";
import { ActionFunctionDef } from "../contract/elementdef";
import { TypeKindEnum } from "../enums/customtype";
import { TypeHelper } from "../utils/typeutil";
import * as path from "path"

export class ContractProgram {
Expand Down
6 changes: 3 additions & 3 deletions ts-packages/transform/src/contract/decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DecoratorKind, DecoratorNode, Expression, IdentifierExpression, NodeKind } from "assemblyscript/dist/assemblyscript.js";
import { ContractDecoratorKind } from "../enums/decorator.js";
import { LowerCaseCode } from "../utils/charutil.js";
import { RangeUtil } from "../utils/utils.js";
import { ContractDecoratorKind } from "../enums/decorator";
import { LowerCaseCode } from "../utils/charutil";
import { RangeUtil } from "../utils/utils";

function fromNode(nameNode: Expression): ContractDecoratorKind {
if (nameNode.kind == NodeKind.Identifier) {
Expand Down
10 changes: 5 additions & 5 deletions ts-packages/transform/src/contract/elementdef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
FunctionDeclaration
} from "assemblyscript/dist/assemblyscript.js";

import { AstUtil, DecoratorUtil, ElementUtil, RangeUtil, EosioUtils } from "../utils/utils.js";
import { ContractDecoratorKind } from "../enums/decorator.js";
import { FieldDefHelper, TypeHelper } from "../utils/typeutil.js";
import { TypeKindEnum } from "../enums/customtype.js";
import { NamedTypeNodeDef } from "./typedef.js";
import { AstUtil, DecoratorUtil, ElementUtil, RangeUtil, EosioUtils } from "../utils/utils";
import { ContractDecoratorKind } from "../enums/decorator";
import { FieldDefHelper, TypeHelper } from "../utils/typeutil";
import { TypeKindEnum } from "../enums/customtype";
import { NamedTypeNodeDef } from "./typedef";

export class DecoratorsInfo {
decorators: DecoratorNode[] | null;
Expand Down
12 changes: 6 additions & 6 deletions ts-packages/transform/src/contract/typedef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
ClassPrototype,
} from "assemblyscript/dist/assemblyscript.js";

import { RangeUtil } from "../utils/utils.js";
import { RangeUtil } from "../utils/utils";

import { TypeHelper } from "../utils/typeutil.js";
import { TypeKindEnum } from "../enums/customtype.js";
import { ClassInterpreter } from "./classdef.js";
import { Strings } from "../utils/primitiveutil.js";
import { CONFIG } from "../config/compile.js";
import { TypeHelper } from "../utils/typeutil";
import { TypeKindEnum } from "../enums/customtype";
import { ClassInterpreter } from "./classdef";
import { Strings } from "../utils/primitiveutil";
import { CONFIG } from "../config/compile";
export class NodeTypeInfo {
constructor(public type: TypeKindEnum) {}
}
Expand Down
5 changes: 3 additions & 2 deletions ts-packages/transform/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as assemblyscript from "assemblyscript/dist/assemblyscript.js";
import { Transform } from "assemblyscript/dist/transform.js"
import { Program } from "assemblyscript/dist/assemblyscript.js";

import * as preprocess from "./preprocess/index.js";
import { getContractInfo } from "./contract/contract.js";
import * as preprocess from "./preprocess";
import { getContractInfo } from "./contract/contract";
import * as path from "path";
import process from "process"

Expand All @@ -26,6 +26,7 @@ export default class ContractTransform extends Transform {
const info = getContractInfo(program);
const out = preprocess.getExtCodeInfo(info);
process.sourceModifier = out;
console.log("++++++++out:", out);
if (!info.contract) {
return;
}
Expand Down
16 changes: 8 additions & 8 deletions ts-packages/transform/src/preprocess/handlebars.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Handlebars from "handlebars";
import { CONFIG } from "../config/compile.js";
import { FieldDef, ParameterNodeDef, ActionFunctionDef, DBIndexFunctionDef } from "../contract/elementdef.js";
import { TypeKindEnum } from "../enums/customtype.js";
import { EosioUtils } from "../utils/utils.js";
import { TypeHelper } from "../utils/typeutil.js";
import { CONFIG } from "../config/compile";
import { FieldDef, ParameterNodeDef, ActionFunctionDef, DBIndexFunctionDef } from "../contract/elementdef";
import { TypeKindEnum } from "../enums/customtype";
import { EosioUtils } from "../utils/utils";
import { TypeHelper } from "../utils/typeutil";
import { TableInterpreter, ClassInterpreter } from "../contract/classdef";
import { RangeUtil } from "../utils/utils.js";
import { NamedTypeNodeDef } from "../contract/typedef.js";
import { RangeUtil } from "../utils/utils";
import { NamedTypeNodeDef } from "../contract/typedef";
import { Range, DecoratorNode } from "assemblyscript/dist/assemblyscript.js";

import { CommonFlags } from "assemblyscript/dist/assemblyscript.js";

import { dedent } from "ts-dedent"
import process from "process"

import { AstUtil } from "../utils/utils.js";
import { AstUtil } from "../utils/utils";
import * as path from 'path'

const WIN = process.platform === "win32";
Expand Down
12 changes: 6 additions & 6 deletions ts-packages/transform/src/preprocess/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Handlebars from "./handlebars.js";
import Handlebars from "./handlebars";
import { Range } from "assemblyscript/dist/assemblyscript.js";
import { ContractProgram} from "../contract/contract.js";
import { ActionFunctionDef } from "../contract/elementdef.js";
import { ContractProgram} from "../contract/contract";
import { ActionFunctionDef } from "../contract/elementdef";

import {
mainTpl,
Expand All @@ -11,10 +11,10 @@ import {
optionalTpl,
binaryExtensionTpl,
variantTpl,
} from "../tpl/index.js";
} from "../tpl/index";

import { CONFIG } from "../config/compile.js";
import { EosioUtils, RangeUtil } from "../utils/utils.js";
import { CONFIG } from "../config/compile";
import { EosioUtils, RangeUtil } from "../utils/utils";

export class ModifyPoint {
range: Range;
Expand Down
2 changes: 1 addition & 1 deletion ts-packages/transform/src/tpl/action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONFIG } from "../config/compile.js";
import { CONFIG } from "../config/compile";
// const scope = CONFIG.scope;

// parameters: ParameterNodeDef[] = [];
Expand Down
2 changes: 1 addition & 1 deletion ts-packages/transform/src/tpl/binaryextension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONFIG } from "../config/compile.js";
import { CONFIG } from "../config/compile";

// let scope = CONFIG.scope;

Expand Down
14 changes: 7 additions & 7 deletions ts-packages/transform/src/tpl/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { mainTpl } from "./main.js";
export { actionTpl } from "./action.js";
export { tableTpl } from "./table.js";
export { serializerTpl } from "./serializer.js";
export { optionalTpl } from "./optional.js";
export { binaryExtensionTpl } from "./binaryextension.js";
export { variantTpl } from "./variant.js";
export { mainTpl } from "./main";
export { actionTpl } from "./action";
export { tableTpl } from "./table";
export { serializerTpl } from "./serializer";
export { optionalTpl } from "./optional";
export { binaryExtensionTpl } from "./binaryextension";
export { variantTpl } from "./variant";
2 changes: 1 addition & 1 deletion ts-packages/transform/src/tpl/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONFIG } from "../config/compile.js";
import { CONFIG } from "../config/compile";

export const mainTpl = `
Expand Down
2 changes: 1 addition & 1 deletion ts-packages/transform/src/tpl/optional.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONFIG } from "../config/compile.js";
import { CONFIG } from "../config/compile";

// let scope = CONFIG.scope;

Expand Down
2 changes: 1 addition & 1 deletion ts-packages/transform/src/tpl/serializer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONFIG } from "../config/compile.js";
import { CONFIG } from "../config/compile";

// let scope = CONFIG.scope;

Expand Down
2 changes: 1 addition & 1 deletion ts-packages/transform/src/tpl/table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONFIG } from "../config/compile.js";
import { CONFIG } from "../config/compile";

// let scope = CONFIG.scope;

Expand Down
2 changes: 1 addition & 1 deletion ts-packages/transform/src/tpl/variant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONFIG } from "../config/compile.js";
import { CONFIG } from "../config/compile";

// let scope = CONFIG.scope;

Expand Down
10 changes: 5 additions & 5 deletions ts-packages/transform/src/utils/typeutil.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CONFIG } from "../config/compile.js";
import { FieldDef } from "../contract/elementdef.js";
import { TypeKindEnum } from "../enums/customtype.js";
import { Strings } from "./primitiveutil.js";
import { AstUtil } from "./utils.js";
import { CONFIG } from "../config/compile"
import { FieldDef } from "../contract/elementdef";
import { TypeKindEnum } from "../enums/customtype";
import { Strings } from "./primitiveutil";
import { AstUtil } from "./utils";

export class TypeHelper {

Expand Down
6 changes: 3 additions & 3 deletions ts-packages/transform/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
StringLiteralExpression
} from "assemblyscript/dist/assemblyscript.js";

import { getCustomDecoratorKind } from "../contract/decorator.js";
import { ContractDecoratorKind } from "../enums/decorator.js";
import { Strings } from "./primitiveutil.js";
import { getCustomDecoratorKind } from "../contract/decorator";
import { ContractDecoratorKind } from "../enums/decorator";
import { Strings } from "./primitiveutil";
export class ElementUtil {
static isClass(element: Element): boolean {
if (element.kind == ElementKind.ClassPrototype) {
Expand Down
Loading

0 comments on commit d5892c0

Please sign in to comment.