@gi-tcg/gts-transpiler 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2085 -0
- package/package.json +7 -2
- package/__tests__/loose_plugin.test.ts +0 -69
- package/__tests__/minimal_missing_string.test.ts +0 -6
- package/__tests__/parse.test.ts +0 -38
- package/__tests__/transpile.test.ts +0 -67
- package/tsconfig.json +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gi-tcg/gts-transpiler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -9,8 +9,13 @@
|
|
|
9
9
|
"import": "./dist/index.js"
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
12
16
|
"scripts": {
|
|
13
|
-
"build": "bun build --outdir=dist --target=node --format=esm --conditions='bun' --packages=external src/index.ts"
|
|
17
|
+
"build": "bun build --outdir=dist --target=node --format=esm --conditions='bun' --packages=external src/index.ts",
|
|
18
|
+
"prepublishOnly": "bun run build"
|
|
14
19
|
},
|
|
15
20
|
"dependencies": {
|
|
16
21
|
"@jridgewell/sourcemap-codec": "^1.5.5",
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Parser } from "acorn";
|
|
2
|
-
import { DUMMY_PLACEHOLDER, loosePlugin } from "../src/parse/loose_plugin.js";
|
|
3
|
-
import { describe, test, expect } from "bun:test";
|
|
4
|
-
import { parseLoose } from "../src/parse/index.js";
|
|
5
|
-
import type { Statement } from "estree";
|
|
6
|
-
import type { AST } from "../src/types.js";
|
|
7
|
-
|
|
8
|
-
const LooseParser = Parser.extend(loosePlugin());
|
|
9
|
-
|
|
10
|
-
describe("loosePlugin", () => {
|
|
11
|
-
test("should parse incomplete dot property access in block", () => {
|
|
12
|
-
const code = "{ foo. }";
|
|
13
|
-
const ast: any = LooseParser.parse(code, { ecmaVersion: "latest" });
|
|
14
|
-
expect(ast).toBeDefined();
|
|
15
|
-
|
|
16
|
-
const block = ast.body[0];
|
|
17
|
-
expect(block.type).toBe("BlockStatement");
|
|
18
|
-
const exprStmt = block.body[0];
|
|
19
|
-
expect(exprStmt.type).toBe("ExpressionStatement");
|
|
20
|
-
const memberExpr = exprStmt.expression;
|
|
21
|
-
expect(memberExpr.type).toBe("MemberExpression");
|
|
22
|
-
expect(memberExpr.property.type).toBe("Identifier");
|
|
23
|
-
expect(memberExpr.property.name).toBe(DUMMY_PLACEHOLDER);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("should parse incomplete dot property access in if condition", () => {
|
|
27
|
-
const code = "if (a.) {}";
|
|
28
|
-
const ast: any = LooseParser.parse(code, { ecmaVersion: "latest" });
|
|
29
|
-
expect(ast).toBeDefined();
|
|
30
|
-
|
|
31
|
-
const ifStmt = ast.body[0];
|
|
32
|
-
expect(ifStmt.type).toBe("IfStatement");
|
|
33
|
-
const testExpr = ifStmt.test;
|
|
34
|
-
expect(testExpr.type).toBe("MemberExpression");
|
|
35
|
-
expect(testExpr.property.name).toBe(DUMMY_PLACEHOLDER);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("should fail on invalid bracket access", () => {
|
|
39
|
-
const code = "foo[var]";
|
|
40
|
-
expect(() => {
|
|
41
|
-
LooseParser.parse(code, { ecmaVersion: "latest" });
|
|
42
|
-
}).toThrow();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("should fail on invalid optional call argument", () => {
|
|
46
|
-
const code = "foo?.(var)";
|
|
47
|
-
expect(() => {
|
|
48
|
-
LooseParser.parse(code, { ecmaVersion: "latest" });
|
|
49
|
-
}).toThrow();
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("comment kept in loose parse", () => {
|
|
54
|
-
const code = `
|
|
55
|
-
/**
|
|
56
|
-
* @description This is a test function
|
|
57
|
-
*/
|
|
58
|
-
define character {
|
|
59
|
-
id 1101 as TestCharacter;
|
|
60
|
-
}
|
|
61
|
-
`;
|
|
62
|
-
const ast = parseLoose(code);
|
|
63
|
-
console.log(ast);
|
|
64
|
-
const defNode = ast.body.find(
|
|
65
|
-
(node: any) => node.type === "GTSDefineStatement",
|
|
66
|
-
);
|
|
67
|
-
expect(defNode).toBeDefined();
|
|
68
|
-
expect(defNode!.leadingComments).toBeDefined();
|
|
69
|
-
});
|
package/__tests__/parse.test.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { parse, parseLoose } from "../src/parse";
|
|
2
|
-
import { test, expect } from "bun:test";
|
|
3
|
-
|
|
4
|
-
test("basic test", () => {
|
|
5
|
-
const source = `
|
|
6
|
-
|
|
7
|
-
define entity {
|
|
8
|
-
id 211011 as MyEntity;
|
|
9
|
-
on endPhase {
|
|
10
|
-
usage 3 { appendTo 5 };
|
|
11
|
-
hint Cryo, 2;
|
|
12
|
-
}
|
|
13
|
-
on useSkill {
|
|
14
|
-
when :( :player.hands.length > 0 )
|
|
15
|
-
usagePerRound 1
|
|
16
|
-
:damage(Cryo, 1, query opp.next)
|
|
17
|
-
} as private _;
|
|
18
|
-
on selfDispose {
|
|
19
|
-
when :{
|
|
20
|
-
const chs = query* my.character;
|
|
21
|
-
return chs.length >= 2;
|
|
22
|
-
}
|
|
23
|
-
if (add(1, 2) > 2) {
|
|
24
|
-
:dispose(:self);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function add(a: number, b: number): number {
|
|
30
|
-
return a + b;
|
|
31
|
-
}
|
|
32
|
-
`;
|
|
33
|
-
const ast = parse(source);
|
|
34
|
-
expect(ast.type).toBe("Program");
|
|
35
|
-
expect(ast.body.length).toBe(2);
|
|
36
|
-
expect(ast.body[0].type as string).toBe("GTSDefineStatement");
|
|
37
|
-
// Bun.write("gts-parser-basic-test-ast.json", JSON.stringify(ast, null, 2));
|
|
38
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "bun:test";
|
|
2
|
-
import { parse } from "../src/parse";
|
|
3
|
-
import { transform } from "../src/transform";
|
|
4
|
-
|
|
5
|
-
test("basic transpile pipeline", () => {
|
|
6
|
-
const source = `
|
|
7
|
-
/**
|
|
8
|
-
* @id 1201
|
|
9
|
-
* @name 芭芭拉
|
|
10
|
-
* @description
|
|
11
|
-
* 无论何时都能治愈人心。
|
|
12
|
-
*/
|
|
13
|
-
define character {
|
|
14
|
-
id 1201 as Barbara;
|
|
15
|
-
since "v3.3.0";
|
|
16
|
-
tags hydro, catalyst, mondstadt;
|
|
17
|
-
health 10;
|
|
18
|
-
energy 3;
|
|
19
|
-
skills WhisperOfWater;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @id 12012
|
|
24
|
-
* @name 演唱,开始♪
|
|
25
|
-
* @description
|
|
26
|
-
* 造成1点水元素伤害,召唤歌声之环。
|
|
27
|
-
*/
|
|
28
|
-
define skill {
|
|
29
|
-
id 12011 as WhisperOfWater;
|
|
30
|
-
cost hydro, 3;
|
|
31
|
-
:damage(hydro, 1);
|
|
32
|
-
:summon(MelodyLoop);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @id 112011
|
|
37
|
-
* @name 歌声之环
|
|
38
|
-
* @description
|
|
39
|
-
* 结束阶段:治疗所有我方角色1点,然后对我方出战角色附着水元素。
|
|
40
|
-
* 可用次数:2
|
|
41
|
-
*/
|
|
42
|
-
define summon {
|
|
43
|
-
id 112011 as MelodyLoop;
|
|
44
|
-
on endPhase {
|
|
45
|
-
usage 2;
|
|
46
|
-
hint heal, 1;
|
|
47
|
-
:heal(1, query* my.character);
|
|
48
|
-
:apply(hydro, query my.active);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
`;
|
|
52
|
-
const parsed = parse(source);
|
|
53
|
-
const output = transform(
|
|
54
|
-
parsed,
|
|
55
|
-
{},
|
|
56
|
-
{ content: source, filename: "test.ts" },
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
expect(output.sourceMap?.mappings).toBeDefined();
|
|
60
|
-
expect(output.sourceMap?.sources).toEqual(["test.ts"]);
|
|
61
|
-
|
|
62
|
-
console.log(output.code);
|
|
63
|
-
Bun.write(
|
|
64
|
-
`temp/test.js`,
|
|
65
|
-
`${output.code}\n//# sourceMappingURL=${output.sourceMap.toUrl()}`,
|
|
66
|
-
);
|
|
67
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "esnext",
|
|
4
|
-
"lib": [
|
|
5
|
-
"esnext"
|
|
6
|
-
],
|
|
7
|
-
"customConditions": ["bun"],
|
|
8
|
-
"module": "preserve",
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"verbatimModuleSyntax": true,
|
|
11
|
-
"composite": true,
|
|
12
|
-
"declaration": true,
|
|
13
|
-
"emitDeclarationOnly": true,
|
|
14
|
-
"strict": true,
|
|
15
|
-
"allowJs": true,
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
},
|
|
18
|
-
}
|