Compare commits
28 commits
Author | SHA1 | Date | |
---|---|---|---|
cd45773354 | |||
dacc38ad24 | |||
6fef7f1b64 | |||
91387a397a | |||
fa090949ef | |||
dc04b92ef2 | |||
e5978c7630 | |||
7028df3d37 | |||
d468787983 | |||
1aa8956fb2 | |||
bf3abd232c | |||
3d3865d625 | |||
438d4589d4 | |||
b740b469d4 | |||
03d906da5a | |||
b6a7c645f2 | |||
8cb01d1bd0 | |||
e906095363 | |||
2e268835e5 | |||
0334431f32 | |||
52c3c8e24e | |||
96673b993c | |||
60bc21d8ab | |||
2ef239b466 | |||
38fe05af7f | |||
4ae79e6d92 | |||
975030d7ce | |||
4b03caa360 |
38 changed files with 591 additions and 488 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Logs
|
||||
|
||||
logs
|
||||
|
@ -166,5 +167,3 @@ dist
|
|||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.\*
|
||||
|
||||
output_testing/
|
||||
|
|
|
@ -18,26 +18,26 @@ export function registerValidationChecks(services: JstqlServices) {
|
|||
* Implementation of custom validations.
|
||||
*/
|
||||
export class JstqlValidator {
|
||||
validateWildcards(case_: Case, accept: ValidationAcceptor): void {
|
||||
validateWildcards(pair: Case, accept: ValidationAcceptor): void {
|
||||
try {
|
||||
let validationResultAplTo = validateWildcardAplTo(
|
||||
collectWildcard(case_.aplTo.apl_to_code.split(""))
|
||||
collectWildcard(pair.aplTo.apl_to_code.split(""))
|
||||
);
|
||||
if (validationResultAplTo.errors.length != 0) {
|
||||
accept("error", validationResultAplTo.errors.join("\n"), {
|
||||
node: case_.aplTo,
|
||||
node: pair.aplTo,
|
||||
property: "apl_to_code",
|
||||
});
|
||||
}
|
||||
|
||||
let validationResultTraTo = validateWildcardTraTo(
|
||||
collectWildcard(case_.traTo.transform_to_code.split("")),
|
||||
collectWildcard(pair.traTo.transform_to_code.split("")),
|
||||
validationResultAplTo.env
|
||||
);
|
||||
|
||||
if (validationResultTraTo.length != 0) {
|
||||
accept("error", validationResultTraTo.join("\n"), {
|
||||
node: case_.traTo,
|
||||
node: pair.traTo,
|
||||
property: "transform_to_code",
|
||||
});
|
||||
}
|
||||
|
|
59
README.md
59
README.md
|
@ -1,58 +1 @@
|
|||
# JSTQL JavaScript Transform tool
|
||||
|
||||
This tool is created to transform JavaScript based on definitions written in a custom DSL called JSTQL
|
||||
|
||||
## JSTQL
|
||||
|
||||
This is a DSL created to define proposal transformations using templates. A transformation is defined by two templates, a template of what code snippets to search for **applicable to** and a template of how to transform those snippets **transform to**.
|
||||
|
||||
Examples of definitions for proposals can be found in [dsl_files](./dsl_files/)
|
||||
|
||||
## Running this project
|
||||
|
||||
This project exposes an api in the file [transform/transfrom.ts](./src/transform/transform.ts), which is meant to be used as this library's entry point.
|
||||
|
||||
To run this code as a standalone project, a file [index.ts](./index.ts) exists to facilitate running this project.
|
||||
|
||||
This project is created using TypeScript, and it is recommended to use [Bun](https://bun.sh/) to compile and run it.
|
||||
|
||||
### Building Langium required files
|
||||
|
||||
Firstly, building langium is required, this is done by the following:
|
||||
|
||||
```sh
|
||||
# cd into JSTQL
|
||||
cd JSTQL
|
||||
|
||||
# Install dependencies
|
||||
npm i
|
||||
|
||||
# Build langium generated files
|
||||
npm run langium:generate
|
||||
|
||||
# Build final JS source
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Running a transformation
|
||||
|
||||
Now we are ready to run this project with the pipeline on a test JS file:
|
||||
|
||||
```sh
|
||||
# cd into top level
|
||||
cd ..
|
||||
|
||||
# Install dependencies
|
||||
bun i
|
||||
|
||||
# Run an example transformation
|
||||
bun run index.ts dsl_files/pipeline.jstql test_files/test.js
|
||||
```
|
||||
|
||||
### Arguments of index.ts
|
||||
|
||||
Arguments
|
||||
|
||||
- First positional is path to JSTQL
|
||||
- Second positional is path to JS file to transform
|
||||
- -o is optional output path, if not given path is **./out.js**
|
||||
# didactic-chainsaw
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
19
demo-site/index.html
Normal file
19
demo-site/index.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Demo site</h1>
|
||||
<p></p>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,10 +1,11 @@
|
|||
proposal DoExpression{
|
||||
case arrowFunction{
|
||||
applicable to {
|
||||
"(() => {
|
||||
"() => {
|
||||
<<statements: (Statement && !ReturnStatement)+>>
|
||||
return <<returnVal : Expression>>;
|
||||
})();"
|
||||
}
|
||||
"
|
||||
}
|
||||
transform to {
|
||||
"(do {
|
||||
|
|
16
dsl_files/multi_stmt_test.jstql
Normal file
16
dsl_files/multi_stmt_test.jstql
Normal file
|
@ -0,0 +1,16 @@
|
|||
proposal MultiStmt{
|
||||
case Smthn{
|
||||
applicable to{
|
||||
"let <<ident1:Identifier>> = <<funcIdent:Identifier | MemberExpression>>();
|
||||
let <<ident2:Identifier>> = <<expr:Expression>>;
|
||||
"
|
||||
}
|
||||
|
||||
transform to {
|
||||
"const ident2 = () => {
|
||||
let <<ident1>> = <<funcIdent>>();
|
||||
return <<expr>>;
|
||||
}"
|
||||
}
|
||||
}
|
||||
}
|
14
dsl_files/pipelineDeep.jstql
Normal file
14
dsl_files/pipelineDeep.jstql
Normal file
|
@ -0,0 +1,14 @@
|
|||
proposal Pipeline{
|
||||
|
||||
case SingleArgument {
|
||||
applicable to {
|
||||
"<<someFunctionIdent:Identifier || MemberExpression>>(<<otherFunctionIdent:Identifier || MemberExpression>>(<<arggg:Identifier>>));"
|
||||
}
|
||||
|
||||
transform to {
|
||||
"(<<arggg>> |> <<otherFunctionIdent>>(%)) |> <<someFunctionIdent>>(%);"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
17
dsl_files/star.jstql
Normal file
17
dsl_files/star.jstql
Normal file
|
@ -0,0 +1,17 @@
|
|||
proposal Star{
|
||||
case a {
|
||||
applicable to {
|
||||
"let <<ident:Identifier>> = () => {
|
||||
<<statements: Statement>>
|
||||
return <<returnVal : Expression>>;
|
||||
}
|
||||
"
|
||||
}
|
||||
transform to {
|
||||
"let <<ident>> = do {
|
||||
<<statements>>
|
||||
<<returnVal>>
|
||||
}"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
proposal lol {
|
||||
case a {
|
||||
applicable to {
|
||||
"let <<a: Identifier>> = Iterator.from(<<e: Expression>>);
|
||||
let <<aa: Identifier>> = Iterator.from(<<ee: Expression>>);
|
||||
|
||||
let <<bbbb: Identifier>> = function* () {
|
||||
yield* <<aaa: Identifier>>;
|
||||
yield* <<aaaa: Identifier>>;
|
||||
}();"
|
||||
}
|
||||
transform to {
|
||||
"let <<a>> = Iterator.from(<<e>>);
|
||||
let <<aa>> = Iterator.from(<<ee>>);
|
||||
|
||||
let <<bbbb>> = Iterator.concat(<<aaa>>, <<aaaa>>);"
|
||||
}
|
||||
}
|
||||
}
|
10
dsl_files/test_single_stmt.jstql
Normal file
10
dsl_files/test_single_stmt.jstql
Normal file
|
@ -0,0 +1,10 @@
|
|||
proposal test_single_stmt{
|
||||
pair one {
|
||||
applicable to {
|
||||
"let <<aaaa: Identifier >> = <<bbbb: Expression | Identifier>>"
|
||||
}
|
||||
transform to {
|
||||
"let <<aaaa>> = 1 + <<bbbb>>;"
|
||||
}
|
||||
}
|
||||
}
|
55
index.ts
55
index.ts
|
@ -1,55 +0,0 @@
|
|||
|
||||
import {
|
||||
|
||||
transform,
|
||||
} from "./src/transform/transform";
|
||||
import { parseJSTQL } from "./src/langium/langiumRunner";
|
||||
import { parseArgs } from "util";
|
||||
|
||||
const { values: argVals, tokens: positional } = parseArgs({
|
||||
options: {
|
||||
o: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
tokens: true,
|
||||
allowPositionals: true,
|
||||
});
|
||||
const main = async () => {
|
||||
//transform(selfHostedTransformExampleMultiStmt, codeFromFile);
|
||||
console.log(positional);
|
||||
console.log(argVals);
|
||||
if (!positional) {
|
||||
throw new Error("Something is wrong with args");
|
||||
}
|
||||
if (
|
||||
!positional[0] &&
|
||||
positional[0].kind === "positional" &&
|
||||
!positional[0].value.endsWith(".jstql")
|
||||
) {
|
||||
throw new Error("First positional argument is current JSTQL file");
|
||||
}
|
||||
if (!positional[1] || !positional[1].value.endsWith(".js")) {
|
||||
throw new Error(
|
||||
"Second positional argument is JS code to be transformed"
|
||||
);
|
||||
}
|
||||
const jstql_file = positional[0].value;
|
||||
const code_file = positional[1].value;
|
||||
|
||||
let jstqlString = await Bun.file(jstql_file).text();
|
||||
let codeString = await Bun.file(code_file).text();
|
||||
|
||||
let parsedJSTQL = await parseJSTQL(jstqlString);
|
||||
|
||||
for (let proposal of parsedJSTQL) {
|
||||
let [resultString, matches] = transform(proposal.cases, codeString);
|
||||
let path = "./out.js";
|
||||
if (argVals["o"]) {
|
||||
path = argVals["o"];
|
||||
}
|
||||
await Bun.write(path, resultString);
|
||||
}
|
||||
};
|
||||
|
||||
main();
|
3
out.js
3
out.js
|
@ -1,3 +0,0 @@
|
|||
let something = Iterator.from([1, 2, 3]);
|
||||
let someOtherThing = Iterator.from([4, 5, 6]);
|
||||
let generate = Iterator.concat(something, someOtherThing);
|
94
output_files/output.js
Normal file
94
output_files/output.js
Normal file
|
@ -0,0 +1,94 @@
|
|||
function parse() {
|
||||
const input = ("input" |> document.getElementById(%)).value;
|
||||
const data = 32 |> input.slice(%);
|
||||
const compressedData = data |> decode_base64(%);
|
||||
const uncompressed = pako.inflate(compressedData, {
|
||||
to: "string"
|
||||
});
|
||||
const json = uncompressed |> JSON.parse(%);
|
||||
json |> console.log(%);
|
||||
json |> convertToDesktop(%);
|
||||
}
|
||||
function convertToDesktop(json) {
|
||||
const newValues = {
|
||||
crb: false,
|
||||
newClanRaidClassId: 0,
|
||||
newClanRaidClassLevel: 0,
|
||||
pendingImmortalSouls: 0,
|
||||
pendingRaidRubies: 0,
|
||||
immortalSouls: 0,
|
||||
lastPurchaseTime: 0,
|
||||
lastRaidAttemptTimestamp: 0,
|
||||
lastRaidRewardCheckTimestamp: 0,
|
||||
shouldShowHZERoster: false,
|
||||
lastBonusRewardCheckTimestamp: 0
|
||||
};
|
||||
const mappedValues = {
|
||||
rubies: json.rubies / 10 |> Math.round(%)
|
||||
};
|
||||
const pcSpecificValues = {
|
||||
readPatchNumber: "1.0e12",
|
||||
saveOrigin: "pc"
|
||||
};
|
||||
const hash = "7a990d405d2c6fb93aa8fbb0ec1a3b23";
|
||||
const newData = {
|
||||
...newValues,
|
||||
...json,
|
||||
...mappedValues,
|
||||
...pcSpecificValues
|
||||
};
|
||||
const compressed = pako.deflate(newData |> JSON.stringify(%), {
|
||||
to: "string"
|
||||
});
|
||||
const base64 = compressed |> btoa(%);
|
||||
const finalSaveString = hash + base64;
|
||||
("output_output" |> document.getElementById(%)).innerText = finalSaveString;
|
||||
showOutput();
|
||||
}
|
||||
function showOutput() {
|
||||
("outputs" |> document.getElementById(%)).style.visibility = "visible";
|
||||
}
|
||||
function copyOutput() {
|
||||
const output = "output_output" |> document.getElementById(%);
|
||||
output.disabled = false;
|
||||
output.focus();
|
||||
output.select();
|
||||
"copy" |> document.execCommand(%);
|
||||
output.disabled = true;
|
||||
const successElement = "copy_success_msg" |> document.getElementById(%);
|
||||
successElement.style.visibility = "visible";
|
||||
setTimeout(() => successElement.style.visibility = "hidden", 4000);
|
||||
}
|
||||
function decode_base64(s) {
|
||||
let e = {},
|
||||
i,
|
||||
k,
|
||||
v = [],
|
||||
r = "",
|
||||
w = String.fromCharCode;
|
||||
let n = [[65, 91], [97, 123], [48, 58], [43, 44], [47, 48]];
|
||||
for (z in n) {
|
||||
for (i = n[z][0]; i < n[z][1]; i++) {
|
||||
i |> w(%) |> v.push(%);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 64; i++) {
|
||||
e[v[i]] = i;
|
||||
}
|
||||
for (i = 0; i < s.length; i += 72) {
|
||||
let b = 0,
|
||||
c,
|
||||
x,
|
||||
l = 0,
|
||||
o = s.substring(i, i + 72);
|
||||
for (x = 0; x < o.length; x++) {
|
||||
c = e[x |> o.charAt(%)];
|
||||
b = (b << 6) + c;
|
||||
l += 6;
|
||||
while (l >= 8) {
|
||||
r += (b >>> (l -= 8)) % 256 |> w(%);
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
9
output_files/output_await_to_promise.js
Normal file
9
output_files/output_await_to_promise.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
async function something() {
|
||||
let a = 100;
|
||||
a *= 100000;
|
||||
return fetch("https://uib.no").then(uib => {
|
||||
a += 100000;
|
||||
a -= 1000;
|
||||
return [a, uib];
|
||||
});
|
||||
}
|
12
output_files/output_do.js
Normal file
12
output_files/output_do.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
let aaaa = do {
|
||||
let g = 100;
|
||||
let ff = 10;
|
||||
let ggg = a(b);
|
||||
100
|
||||
};
|
||||
var bbaaa = do {
|
||||
let lllll = 1 + 1;
|
||||
100 + 100;
|
||||
const aaaaa = aaaa(bb);
|
||||
lllll
|
||||
};
|
2
output_files/output_multi.js
Normal file
2
output_files/output_multi.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
let ThisTest = LOOOOOOOOL();
|
||||
let HAHHAHAH = 1 + 1;
|
4
output_files/output_pipeline.js
Normal file
4
output_files/output_pipeline.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
a |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%);
|
||||
a |> b(%, a |> b(%, a |> b(%, a |> b(%, a |> b(%, a |> b(%, a |> b(%, b)))))));
|
||||
a |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a);
|
||||
b(b(b(b(a, a, a), a, a), a, a), a, a);
|
4
output_files/pipeline_out.js
Normal file
4
output_files/pipeline_out.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
a |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%) |> w(%);
|
||||
a |> b(%, a |> b(%, a |> b(%, a |> b(%, a |> b(%, a |> b(%, a |> b(%, b)))))));
|
||||
a |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a) |> b(%, a);
|
||||
b(b(b(b(a, a, a), a, a), a, a), a, a);
|
104
output_files/test2.js
Normal file
104
output_files/test2.js
Normal file
|
@ -0,0 +1,104 @@
|
|||
return awaitedExpr.then(async _geometry => {
|
||||
const _intersectPoint = /*@__PURE__*/new Vector3();
|
||||
const _worldScale = /*@__PURE__*/new Vector3();
|
||||
const _mvPosition = /*@__PURE__*/new Vector3();
|
||||
const _alignedPosition = /*@__PURE__*/new Vector2();
|
||||
const _rotatedPosition = /*@__PURE__*/new Vector2();
|
||||
const _viewWorldMatrix = /*@__PURE__*/new Matrix4();
|
||||
const _vA = /*@__PURE__*/new Vector3();
|
||||
const _vB = /*@__PURE__*/new Vector3();
|
||||
const _vC = /*@__PURE__*/new Vector3();
|
||||
const _uvA = /*@__PURE__*/new Vector2();
|
||||
const _uvB = /*@__PURE__*/new Vector2();
|
||||
const _uvC = /*@__PURE__*/new Vector2();
|
||||
class Sprite extends Object3D {
|
||||
constructor(material = new SpriteMaterial()) {
|
||||
super();
|
||||
this.isSprite = true;
|
||||
this.type = "Sprite";
|
||||
if (_geometry === undefined) {
|
||||
_geometry = new BufferGeometry();
|
||||
const float32Array = new Float32Array([-0.5, -0.5, 0, 0, 0, 0.5, -0.5, 0, 1, 0, 0.5, 0.5, 0, 1, 1, -0.5, 0.5, 0, 0, 1]);
|
||||
const interleavedBuffer = new InterleavedBuffer(float32Array, 5);
|
||||
_geometry.setIndex([0, 1, 2, 0, 2, 3]);
|
||||
_geometry.setAttribute("position", new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
|
||||
_geometry.setAttribute("uv", new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
|
||||
}
|
||||
this.geometry = _geometry;
|
||||
this.material = material;
|
||||
this.center = new Vector2(0.5, 0.5);
|
||||
}
|
||||
raycast(raycaster, intersects) {
|
||||
if (raycaster.camera === null) {
|
||||
console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
|
||||
}
|
||||
_worldScale.setFromMatrixScale(this.matrixWorld);
|
||||
_viewWorldMatrix.copy(raycaster.camera.matrixWorld);
|
||||
this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
|
||||
_mvPosition.setFromMatrixPosition(this.modelViewMatrix);
|
||||
if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
|
||||
_worldScale.multiplyScalar(-_mvPosition.z);
|
||||
}
|
||||
const rotation = this.material.rotation;
|
||||
let sin, cos;
|
||||
if (rotation !== 0) {
|
||||
cos = Math.cos(rotation);
|
||||
sin = Math.sin(rotation);
|
||||
}
|
||||
const center = this.center;
|
||||
transformVertex(_vA.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
||||
transformVertex(_vB.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
||||
transformVertex(_vC.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
||||
_uvA.set(0, 0);
|
||||
_uvB.set(1, 0);
|
||||
_uvC.set(1, 1);
|
||||
|
||||
// check first triangle
|
||||
let intersect = raycaster.ray.intersectTriangle(_vA, _vB, _vC, false, _intersectPoint);
|
||||
if (intersect === null) {
|
||||
// check second triangle
|
||||
transformVertex(_vB.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
|
||||
_uvB.set(0, 1);
|
||||
intersect = raycaster.ray.intersectTriangle(_vA, _vC, _vB, false, _intersectPoint);
|
||||
if (intersect === null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const distance = raycaster.ray.origin.distanceTo(_intersectPoint);
|
||||
if (distance < raycaster.near || distance > raycaster.far) return;
|
||||
intersects.push({
|
||||
distance: distance,
|
||||
point: _intersectPoint.clone(),
|
||||
uv: Triangle.getInterpolation(_intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2()),
|
||||
face: null,
|
||||
object: this
|
||||
});
|
||||
}
|
||||
copy(source, recursive) {
|
||||
super.copy(source, recursive);
|
||||
if (source.center !== undefined) this.center.copy(source.center);
|
||||
this.material = source.material;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
|
||||
// compute position in camera space
|
||||
_alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale);
|
||||
|
||||
// to check if rotation is not zero
|
||||
if (sin !== undefined) {
|
||||
_rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
|
||||
_rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
|
||||
} else {
|
||||
_rotatedPosition.copy(_alignedPosition);
|
||||
}
|
||||
vertexPosition.copy(mvPosition);
|
||||
vertexPosition.x += _rotatedPosition.x;
|
||||
vertexPosition.y += _rotatedPosition.y;
|
||||
|
||||
// transform to world space
|
||||
vertexPosition.applyMatrix4(_viewWorldMatrix);
|
||||
}
|
||||
export { Sprite };
|
||||
return returnExpr;
|
||||
});
|
94
output_files/test_2.js
Normal file
94
output_files/test_2.js
Normal file
|
@ -0,0 +1,94 @@
|
|||
function parse() {
|
||||
const input = ("input" |> document.getElementById(%)).value;
|
||||
const data = 32 |> input.slice(%);
|
||||
const compressedData = data |> decode_base64(%);
|
||||
const uncompressed = compressedData |> pako.inflate(%, {
|
||||
to: "string"
|
||||
});
|
||||
const json = uncompressed |> JSON.parse(%);
|
||||
json |> console.log(%);
|
||||
json |> convertToDesktop(%);
|
||||
}
|
||||
function convertToDesktop(json) {
|
||||
const newValues = {
|
||||
crb: false,
|
||||
newClanRaidClassId: 0,
|
||||
newClanRaidClassLevel: 0,
|
||||
pendingImmortalSouls: 0,
|
||||
pendingRaidRubies: 0,
|
||||
immortalSouls: 0,
|
||||
lastPurchaseTime: 0,
|
||||
lastRaidAttemptTimestamp: 0,
|
||||
lastRaidRewardCheckTimestamp: 0,
|
||||
shouldShowHZERoster: false,
|
||||
lastBonusRewardCheckTimestamp: 0
|
||||
};
|
||||
const mappedValues = {
|
||||
rubies: json.rubies / 10 |> Math.round(%)
|
||||
};
|
||||
const pcSpecificValues = {
|
||||
readPatchNumber: "1.0e12",
|
||||
saveOrigin: "pc"
|
||||
};
|
||||
const hash = "7a990d405d2c6fb93aa8fbb0ec1a3b23";
|
||||
const newData = {
|
||||
...newValues,
|
||||
...json,
|
||||
...mappedValues,
|
||||
...pcSpecificValues
|
||||
};
|
||||
const compressed = newData |> JSON.stringify(%) |> pako.deflate(%, {
|
||||
to: "string"
|
||||
});
|
||||
const base64 = compressed |> btoa(%);
|
||||
const finalSaveString = hash + base64;
|
||||
("output_output" |> document.getElementById(%)).innerText = finalSaveString;
|
||||
showOutput();
|
||||
}
|
||||
function showOutput() {
|
||||
("outputs" |> document.getElementById(%)).style.visibility = "visible";
|
||||
}
|
||||
function copyOutput() {
|
||||
const output = "output_output" |> document.getElementById(%);
|
||||
output.disabled = false;
|
||||
output.focus();
|
||||
output.select();
|
||||
"copy" |> document.execCommand(%);
|
||||
output.disabled = true;
|
||||
const successElement = "copy_success_msg" |> document.getElementById(%);
|
||||
successElement.style.visibility = "visible";
|
||||
(() => successElement.style.visibility = "hidden") |> setTimeout(%, 4000);
|
||||
}
|
||||
function decode_base64(s) {
|
||||
let e = {},
|
||||
i,
|
||||
k,
|
||||
v = [],
|
||||
r = "",
|
||||
w = String.fromCharCode;
|
||||
let n = [[65, 91], [97, 123], [48, 58], [43, 44], [47, 48]];
|
||||
for (z in n) {
|
||||
for (i = n[z][0]; i < n[z][1]; i++) {
|
||||
i |> w(%) |> v.push(%);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 64; i++) {
|
||||
e[v[i]] = i;
|
||||
}
|
||||
for (i = 0; i < s.length; i += 72) {
|
||||
let b = 0,
|
||||
c,
|
||||
x,
|
||||
l = 0,
|
||||
o = i |> s.substring(%, i + 72);
|
||||
for (x = 0; x < o.length; x++) {
|
||||
c = e[x |> o.charAt(%)];
|
||||
b = (b << 6) + c;
|
||||
l += 6;
|
||||
while (l >= 8) {
|
||||
r += (b >>> (l -= 8)) % 256 |> w(%);
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
9
output_files/testing.js
Normal file
9
output_files/testing.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
async function something() {
|
||||
let a = 100;
|
||||
a *= 100000;
|
||||
return fetch("https://uib.no").then(uib => {
|
||||
a += 100000;
|
||||
a -= 1000;
|
||||
return [a, uib];
|
||||
});
|
||||
}
|
98
output_files/testingLOL.js
Normal file
98
output_files/testingLOL.js
Normal file
|
@ -0,0 +1,98 @@
|
|||
// "fast-glob" and `createTwoFilesPatch` are bundled here since the API uses `micromatch` and `diff` too
|
||||
import { createTwoFilesPatch } from "diff/lib/patch/create.js";
|
||||
import fastGlob from "fast-glob";
|
||||
import * as vnopts from "vnopts";
|
||||
import * as errors from "./common/errors.js";
|
||||
import getFileInfoWithoutPlugins from "./common/get-file-info.js";
|
||||
import mockable from "./common/mockable.js";
|
||||
import { clearCache as clearConfigCache, resolveConfig, resolveConfigFile } from "./config/resolve-config.js";
|
||||
import * as core from "./main/core.js";
|
||||
import { formatOptionsHiddenDefaults } from "./main/normalize-format-options.js";
|
||||
import normalizeOptions from "./main/normalize-options.js";
|
||||
import * as optionCategories from "./main/option-categories.js";
|
||||
import { clearCache as clearPluginCache, loadBuiltinPlugins, loadPlugins } from "./main/plugins/index.js";
|
||||
import { getSupportInfo as getSupportInfoWithoutPlugins, normalizeOptionSettings } from "./main/support.js";
|
||||
import { createIsIgnoredFunction } from "./utils/ignore.js";
|
||||
import isNonEmptyArray from "./utils/is-non-empty-array.js";
|
||||
import omit from "./utils/object-omit.js";
|
||||
import partition from "./utils/partition.js";
|
||||
|
||||
/**
|
||||
* @param {*} fn
|
||||
* @param {number} [optionsArgumentIndex]
|
||||
* @returns {*}
|
||||
*/
|
||||
function withPlugins(fn, optionsArgumentIndex = 1 // Usually `options` is the 2nd argument
|
||||
) {
|
||||
return async (...args) => {
|
||||
const options = args[optionsArgumentIndex] ?? {};
|
||||
const {
|
||||
plugins = []
|
||||
} = options;
|
||||
args[optionsArgumentIndex] = {
|
||||
...options,
|
||||
plugins: (await ([loadBuiltinPlugins(), plugins |> loadPlugins(%)] |> Promise.all(%))).flat()
|
||||
};
|
||||
return fn(...args);
|
||||
};
|
||||
}
|
||||
const formatWithCursor = core.formatWithCursor |> withPlugins(%);
|
||||
async function format(text, options) {
|
||||
const {
|
||||
formatted
|
||||
} = await (text |> formatWithCursor(%, {
|
||||
...options,
|
||||
cursorOffset: -1
|
||||
}));
|
||||
return formatted;
|
||||
}
|
||||
async function check(text, options) {
|
||||
return (await (text |> format(%, options))) === text;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-await
|
||||
async function clearCache() {
|
||||
clearConfigCache();
|
||||
clearPluginCache();
|
||||
}
|
||||
|
||||
/** @type {typeof getFileInfoWithoutPlugins} */
|
||||
const getFileInfo = getFileInfoWithoutPlugins |> withPlugins(%);
|
||||
|
||||
/** @type {typeof getSupportInfoWithoutPlugins} */
|
||||
const getSupportInfo = getSupportInfoWithoutPlugins |> withPlugins(%, 0);
|
||||
|
||||
// Internal shared with cli
|
||||
const sharedWithCli = {
|
||||
errors,
|
||||
optionCategories,
|
||||
createIsIgnoredFunction,
|
||||
formatOptionsHiddenDefaults,
|
||||
normalizeOptions,
|
||||
getSupportInfoWithoutPlugins,
|
||||
normalizeOptionSettings,
|
||||
vnopts: {
|
||||
ChoiceSchema: vnopts.ChoiceSchema,
|
||||
apiDescriptor: vnopts.apiDescriptor
|
||||
},
|
||||
fastGlob,
|
||||
createTwoFilesPatch,
|
||||
utils: {
|
||||
isNonEmptyArray,
|
||||
partition,
|
||||
omit
|
||||
},
|
||||
mockable
|
||||
};
|
||||
const debugApis = {
|
||||
parse: core.parse |> withPlugins(%),
|
||||
formatAST: core.formatAst |> withPlugins(%),
|
||||
formatDoc: core.formatDoc |> withPlugins(%),
|
||||
printToDoc: core.printToDoc |> withPlugins(%),
|
||||
printDocToString: core.printDocToString |> withPlugins(%),
|
||||
mockable
|
||||
};
|
||||
export { debugApis as __debug, sharedWithCli as __internal, check, clearCache as clearConfigCache, format, formatWithCursor, getFileInfo, getSupportInfo, resolveConfig, resolveConfigFile };
|
||||
export * as doc from "./document/public.js";
|
||||
export { default as version } from "./main/version.evaluate.cjs";
|
||||
export * as util from "./utils/public.js";
|
306
package-lock.json
generated
306
package-lock.json
generated
|
@ -15,8 +15,7 @@
|
|||
"@types/babel-traverse": "^6.25.10",
|
||||
"babel": "^6.23.0",
|
||||
"bun": "^1.0.4",
|
||||
"ts-node": "^10.9.1",
|
||||
"util": "^0.12.5"
|
||||
"ts-node": "^10.9.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/plugin-proposal-pipeline-operator": "^7.23.3",
|
||||
|
@ -1002,21 +1001,6 @@
|
|||
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
|
||||
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA=="
|
||||
},
|
||||
"node_modules/available-typed-arrays": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz",
|
||||
"integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"possible-typed-array-names": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/babel": {
|
||||
"version": "6.23.0",
|
||||
"resolved": "https://registry.npmjs.org/babel/-/babel-6.23.0.tgz",
|
||||
|
@ -1309,25 +1293,6 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bind": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz",
|
||||
"integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-define-property": "^1.0.0",
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-intrinsic": "^1.2.4",
|
||||
"set-function-length": "^1.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001574",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001574.tgz",
|
||||
|
@ -1487,23 +1452,6 @@
|
|||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/define-data-property": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz",
|
||||
"integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-define-property": "^1.0.0",
|
||||
"es-errors": "^1.3.0",
|
||||
"gopd": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/diff": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||
|
@ -1526,27 +1474,6 @@
|
|||
"once": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/es-define-property": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz",
|
||||
"integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.2.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-errors": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
||||
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/escalade": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
|
||||
|
@ -1720,24 +1647,6 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/for-each": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
|
||||
"integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"is-callable": "^1.1.3"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/gensync": {
|
||||
"version": "1.0.0-beta.2",
|
||||
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
|
||||
|
@ -1746,25 +1655,6 @@
|
|||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
|
||||
"integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2",
|
||||
"has-proto": "^1.0.1",
|
||||
"has-symbols": "^1.0.3",
|
||||
"hasown": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-stream": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz",
|
||||
|
@ -1794,18 +1684,6 @@
|
|||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
|
||||
"integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.1.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/got": {
|
||||
"version": "11.8.6",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-11.8.6.tgz",
|
||||
|
@ -1839,69 +1717,6 @@
|
|||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/has-property-descriptors": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz",
|
||||
"integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-define-property": "^1.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-proto": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz",
|
||||
"integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
|
||||
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-tostringtag": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
|
||||
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"has-symbols": "^1.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/hasown": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
||||
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/http-cache-semantics": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz",
|
||||
|
@ -1953,35 +1768,8 @@
|
|||
"node_modules/inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"node_modules/is-arguments": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz",
|
||||
"integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind": "^1.0.2",
|
||||
"has-tostringtag": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/is-callable": {
|
||||
"version": "1.2.7",
|
||||
"resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz",
|
||||
"integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/is-extglob": {
|
||||
"version": "2.1.1",
|
||||
|
@ -1992,21 +1780,6 @@
|
|||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/is-generator-function": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz",
|
||||
"integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"has-tostringtag": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/is-glob": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
||||
|
@ -2046,21 +1819,6 @@
|
|||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/is-typed-array": {
|
||||
"version": "1.1.13",
|
||||
"resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.13.tgz",
|
||||
"integrity": "sha512-uZ25/bUAlUY5fR4OKT4rZQEBrzQWYV9ZJYGGsUmEJ6thodVJ1HX64ePQ6Z0qPWP+m+Uq6e9UugrE38jeYsDSMw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"which-typed-array": "^1.1.14"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
|
@ -2324,15 +2082,6 @@
|
|||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/possible-typed-array-names": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz",
|
||||
"integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/pseudomap": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
|
||||
|
@ -2542,23 +2291,6 @@
|
|||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/set-function-length": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz",
|
||||
"integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"define-data-property": "^1.1.4",
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-intrinsic": "^1.2.4",
|
||||
"gopd": "^1.0.1",
|
||||
"has-property-descriptors": "^1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/shebang-command": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
|
||||
|
@ -2827,19 +2559,6 @@
|
|||
"browserslist": ">= 4.21.0"
|
||||
}
|
||||
},
|
||||
"node_modules/util": {
|
||||
"version": "0.12.5",
|
||||
"resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz",
|
||||
"integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"inherits": "^2.0.3",
|
||||
"is-arguments": "^1.0.4",
|
||||
"is-generator-function": "^1.0.7",
|
||||
"is-typed-array": "^1.1.3",
|
||||
"which-typed-array": "^1.1.2"
|
||||
}
|
||||
},
|
||||
"node_modules/util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
|
@ -2863,25 +2582,6 @@
|
|||
"which": "bin/which"
|
||||
}
|
||||
},
|
||||
"node_modules/which-typed-array": {
|
||||
"version": "1.1.15",
|
||||
"resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz",
|
||||
"integrity": "sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"available-typed-arrays": "^1.0.7",
|
||||
"call-bind": "^1.0.7",
|
||||
"for-each": "^0.3.3",
|
||||
"gopd": "^1.0.1",
|
||||
"has-tostringtag": "^1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
|
|
|
@ -20,11 +20,10 @@
|
|||
"@babel/generator": "^7.23.0",
|
||||
"@babel/parser": "^7.23.0",
|
||||
"@babel/traverse": "^7.23.0",
|
||||
"@types/babel-traverse": "^6.25.10",
|
||||
"@types/babel__traverse": "^7.20.5",
|
||||
"@types/babel-traverse": "^6.25.10",
|
||||
"babel": "^6.23.0",
|
||||
"bun": "^1.0.4",
|
||||
"ts-node": "^10.9.1",
|
||||
"util": "^0.12.5"
|
||||
"ts-node": "^10.9.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
import { SelfHostedRecipe } from "../transform/transform";
|
||||
import { transform } from "../transform/transform";
|
||||
|
||||
export function transformSH(spec: SelfHostedRecipe[], code: string) {
|
||||
let res = transform(spec, code);
|
||||
|
||||
return res;
|
||||
}
|
|
@ -1,9 +1,36 @@
|
|||
import { transform } from "./transform/transform";
|
||||
//import * as babelparser from "../babel/packages/babel-parser";
|
||||
import * as babelparser from "@babel/parser";
|
||||
//import core from "../babel/packages/babel-core";
|
||||
import { parse_with_plugins } from "./parser/parse";
|
||||
import {
|
||||
SelfHostedRecipe,
|
||||
TransformRecipe,
|
||||
transform,
|
||||
} from "./transform/transform";
|
||||
import { readdir } from "node:fs/promises";
|
||||
import { parseJSTQL } from "./langium/langiumRunner";
|
||||
|
||||
const dir = "../prettier/src";
|
||||
|
||||
const path = "test_files/test2.js";
|
||||
const file = Bun.file(path);
|
||||
const codeFromFile = await file.text();
|
||||
const main = async () => {
|
||||
let basepathExamplesJSFiles = "../three.js";
|
||||
//transform(selfHostedTransformExampleMultiStmt, codeFromFile);
|
||||
|
||||
/*
|
||||
console.log(codeFromFile);
|
||||
const jstql_file =
|
||||
"/home/rolfmg/Coding/Master/didactic-chainsaw/dsl_files/awaitToPromise.jstql";
|
||||
const test_file = Bun.file(jstql_file);
|
||||
const test_JSTQL = await test_file.text();
|
||||
let proposals = await parseJSTQL(test_JSTQL);
|
||||
|
||||
let [code, count] = transform(proposals[0].cases, codeFromFile);
|
||||
await Bun.write("output_files/test2.js", code);
|
||||
return;
|
||||
*/
|
||||
let basepathExamplesJSFiles = "../next.js";
|
||||
let examples = (await readdir(basepathExamplesJSFiles, { recursive: true }))
|
||||
.filter((x) => x.endsWith(".js"))
|
||||
.map((x) => basepathExamplesJSFiles + "/" + x);
|
||||
|
@ -13,7 +40,7 @@ const main = async () => {
|
|||
"pipeline.jstql",
|
||||
"do.jstql",
|
||||
"awaitToPromise.jstql",
|
||||
]) {
|
||||
].slice(1, 2)) {
|
||||
const jstql_file = "dsl_files/" + proposalFile;
|
||||
const test_file = Bun.file(jstql_file);
|
||||
const test_JSTQL = await test_file.text();
|
|
@ -24,7 +24,7 @@ export function parseInternalTraTo(code: string): string {
|
|||
// We encountered a closing tag
|
||||
flag = false;
|
||||
|
||||
cleanedJS += "_$$_" + temp + "_$$_";
|
||||
cleanedJS += temp;
|
||||
|
||||
i += 1;
|
||||
temp = "";
|
||||
|
@ -59,8 +59,7 @@ export function parseInternalAplTo(code: string): InternalParseResult {
|
|||
let wildcard = new WildcardParser(
|
||||
new WildcardTokenizer(temp).tokenize()
|
||||
).parse();
|
||||
wildcard.identifier.name =
|
||||
"_$$_" + wildcard.identifier.name + "_$$_";
|
||||
//wildcard.identifier.name = "_" + wildcard.identifier.name + "_";
|
||||
cleanedJS += wildcard.identifier.name;
|
||||
|
||||
prelude.push(wildcard);
|
||||
|
|
|
@ -19,13 +19,13 @@ function extractValues(types: t.Statement[]): Wildcard[] {
|
|||
if (init) {
|
||||
if (init.type == "StringLiteral") {
|
||||
init = <t.StringLiteral>init;
|
||||
let wildcard = new WildcardParser(
|
||||
prelude.push(
|
||||
new WildcardParser(
|
||||
new WildcardTokenizer(
|
||||
innerDSLVariableName + ":" + init
|
||||
).tokenize()
|
||||
).parse();
|
||||
|
||||
prelude.push(wildcard);
|
||||
).parse()
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
"Invalid usage of right side declaration in prelude"
|
||||
|
|
|
@ -116,7 +116,7 @@ export class WildcardTokenizer {
|
|||
}
|
||||
private isAlpha(val: string): boolean {
|
||||
let alphabet = new Set(
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890".split("")
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_".split("")
|
||||
);
|
||||
return alphabet.has(val);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ export function transform(
|
|||
return [output, amount];
|
||||
}
|
||||
|
||||
export function transformSelfHosted(
|
||||
function transformSelfHosted(
|
||||
recipe: TransformRecipe,
|
||||
internals: Wildcard[],
|
||||
codeAST: t.Node
|
||||
|
@ -91,8 +91,11 @@ export function transformSelfHosted(
|
|||
throw new Error("This no worky LOL");
|
||||
}
|
||||
let matches = runMatch(codeTree, applicableToTree, internals);
|
||||
//showTreePaired(matches[0].statements[0]);
|
||||
//console.log("We found", matches.length, "matches");
|
||||
|
||||
let outputAST = transformer(matches, transformToTree, codeAST, transformTo);
|
||||
|
||||
//console.log("Finished transforming");
|
||||
return [outputAST, matches.length];
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ export function transformer(
|
|||
|
||||
// For multi line applicable to
|
||||
for (let i = 0; i < match.statements.length - 1; i++) {
|
||||
//siblings[i].remove();
|
||||
siblings[i].remove();
|
||||
}
|
||||
|
||||
// For when we have matched with +
|
||||
|
@ -118,10 +118,8 @@ function extractWildcardPairs(match: Match): Map<string, t.Node[]> {
|
|||
name = node.element.aplToNode.expression.name;
|
||||
}
|
||||
|
||||
if (name && name.startsWith("_$$_")) {
|
||||
if (name) {
|
||||
if (map.has(name)) {
|
||||
console.log(name);
|
||||
console.log(map.get(name));
|
||||
throw new Error("Wildcard encountered twice!");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
let aaaa = (() => {
|
||||
let aaaa = () => {
|
||||
let g = 100;
|
||||
let ff = 10;
|
||||
let ggg = a(b);
|
||||
return 100;
|
||||
})();
|
||||
};
|
||||
|
||||
var bbaaa = (function () {
|
||||
let lllll = 1 + 1;
|
||||
|
|
7
test_files/multi_stmt_test.js
Normal file
7
test_files/multi_stmt_test.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
let a = LOOOOOOOOL();
|
||||
let b = (999 * 128) / 12;
|
||||
|
||||
const haha = () => {
|
||||
let a = LOOOOOOOOL();
|
||||
let b = (999 * 128) / 12;
|
||||
};
|
8
test_files/single_stmt.js
Normal file
8
test_files/single_stmt.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
let something = 1 + 1;
|
||||
let yikers = hahahah;
|
||||
|
||||
let lol = () => 100 + 100;
|
||||
|
||||
function haha() {
|
||||
let fhdsjkfhdsjkfhds = fjhdkslfjhdsklfjdskl;
|
||||
}
|
4
test_files/star_test.js
Normal file
4
test_files/star_test.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
let x = () => {
|
||||
let b = 0;
|
||||
return b;
|
||||
};
|
|
@ -1,6 +0,0 @@
|
|||
let something = Iterator.from([1,2,3]);
|
||||
let someOtherThing = Iterator.from([4,5,6]);
|
||||
let generate = function* () {
|
||||
yield* something;
|
||||
yield* someOtherThing;
|
||||
}();
|
|
@ -2,7 +2,7 @@
|
|||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"strict": false,
|
||||
"strict": true,
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"sourceMap": true,
|
||||
|
@ -10,6 +10,6 @@
|
|||
"moduleResolution": "node",
|
||||
"types": ["bun-types"]
|
||||
},
|
||||
"include": ["src", "index.ts"],
|
||||
"include": ["src"],
|
||||
"exclude": ["babel"]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue