commit 48481825b3a977708ff57928513e6f8f11355c6d Author: skybldev <skybluehexapon@outlook.com> Date: Fri Aug 30 10:19:58 2024 -0400 initial commit, pretty much done diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..43a1f95 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "deno.enable": true, + "deno.unstable": true, + "editor.tabSize": 4 +} \ No newline at end of file diff --git a/DOCS.md b/DOCS.md new file mode 100644 index 0000000..7458ef9 --- /dev/null +++ b/DOCS.md @@ -0,0 +1,86 @@ +# Documentation + +Documentation for FlowJS. + +## Types + +FlowJS mostly uses TypeScript-style types, except for `int` and `float` for +feature parity with Flowgorithm. Note that these names are slightly different +from Flowgorithm's, `int` translates to `Integer`, `float` translates to `Real`, +and the rest have similar capitalization. + +## Builtins + +### `print(x: any)` + +Translates to an `Output` statement. + +### `input(var: <Identifier: any>)` + +Translates to an `Input` statement. `var` must be a variable identifier. + +### `attr(key: string, value: string)` + +Applies a value to a specific program attribute. Available attributes: + +- **name** - the program's name +- **authors** - the program's authors +- **about** - description of the program +- **saved** - a date string in the form of `yyyy-MM-dd HH:mm:ss a` e.g. +`2022-10-23 11:10:23 AM` (keep in mind the 12-hour time format) + +**edited** and **created** are also available but are always overwritten upon +transpilation. + +### `meta(key: string, value: string)` + +Applies a value to a specific meta property of a program. Available keys: + +- **username** - your logged in user +- **hostname** - your computer's hostname +- **editVersion** - the program's edit version (starts from 1) +- **editMysteryNumber** - idk what this even is but it starts at like 2300 iirc + +### `comment(comment: string)` + +Creates a comment with the given string. + +### `insist(var: <Identifier: any>)` + +**(temporary)** · A lazy temporary soution to make the typechecker believe +that an identifier has been **defined** without affecting the output code. + +## Statements + +### `for` + +For statement syntax is slightly different from JS/TS syntax in order to have +compatibility with Flowgorithm's. + +`for (init; <end>; upd) <BlockStatement>` + +- `init` can either be `<var> = <start>` with an optional `let`. `<var>` should +always be an `<Identifier: float | int>` and `<start>` should always be a +`<NumericLiteral>`. +- `<end>` is the number to end the loop at. It should always be a +`<NumericLiteral>`. +- `upd` can either be (where `<var>` matches that of `init`): + - `<var>++/--` - This assumes step is 1 and direction is either "inc" (`++`) + or "dec" (`--`). + - `<var> +=/-= <step>` - Here you can define the step number, and direction + is either "inc" (`+=`) or "dec" (`-=`). + +#### Examples: + +```ts +for (let i = 0; 10; i++) { + print("Going up! " + i); +} +``` + +```ts +// `i` was declared earlier +for (i = 20; 10; i -= 2) { + print("Going down! " + i ) +} +``` \ No newline at end of file diff --git a/assets/template.fprg b/assets/template.fprg new file mode 100644 index 0000000..dc73fb4 --- /dev/null +++ b/assets/template.fprg @@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<flowgorithm fileversion="3.0"> + <attributes> + <attribute name="name" value="[[name]]"/> + <attribute name="authors" value="[[authors]]"/> + <attribute name="about" value="[[about]]"/> + <attribute name="saved" value="[[saved]]"/> + <attribute name="created" value="[[created]]"/> + <attribute name="edited" value="[[edited]]"/> + </attributes> + <function name="Main" type="None" variable=""> + <parameters/> + <body> +[[body]] + </body> + </function> +</flowgorithm> diff --git a/ast/benchtest.ts.ast.json b/ast/benchtest.ts.ast.json new file mode 100644 index 0000000..4e5f4f7 --- /dev/null +++ b/ast/benchtest.ts.ast.json @@ -0,0 +1,2039 @@ +{ + "type": "Module", + "span": { + "start": 1, + "end": 775, + "ctxt": 0 + }, + "body": [ + { + "type": "ExpressionStatement", + "span": { + "start": 1, + "end": 27, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1, + "end": 26, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1, + "end": 5, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 6, + "end": 16, + "ctxt": 0 + }, + "value": "username", + "raw": "\"username\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 18, + "end": 25, + "ctxt": 0 + }, + "value": "skybl", + "raw": "\"skybl\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 28, + "end": 53, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 28, + "end": 52, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 28, + "end": 32, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 33, + "end": 43, + "ctxt": 0 + }, + "value": "hostname", + "raw": "\"hostname\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 45, + "end": 51, + "ctxt": 0 + }, + "value": "pond", + "raw": "\"pond\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 54, + "end": 79, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 54, + "end": 78, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 54, + "end": 58, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 59, + "end": 72, + "ctxt": 0 + }, + "value": "editVersion", + "raw": "\"editVersion\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 74, + "end": 77, + "ctxt": 0 + }, + "value": "5", + "raw": "\"5\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 80, + "end": 114, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 80, + "end": 113, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 80, + "end": 84, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 85, + "end": 104, + "ctxt": 0 + }, + "value": "editMysteryNumber", + "raw": "\"editMysteryNumber\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 106, + "end": 112, + "ctxt": 0 + }, + "value": "2991", + "raw": "\"2991\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 115, + "end": 144, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 115, + "end": 143, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 115, + "end": 119, + "ctxt": 0 + }, + "value": "attr", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 120, + "end": 126, + "ctxt": 0 + }, + "value": "name", + "raw": "\"name\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 128, + "end": 142, + "ctxt": 0 + }, + "value": "benchtest.ts", + "raw": "\"benchtest.ts\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 145, + "end": 178, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 145, + "end": 177, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 145, + "end": 149, + "ctxt": 0 + }, + "value": "attr", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 150, + "end": 159, + "ctxt": 0 + }, + "value": "authors", + "raw": "\"authors\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 161, + "end": 176, + "ctxt": 0 + }, + "value": "skybl, ezfprg", + "raw": "\"skybl, ezfprg\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 179, + "end": 235, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 179, + "end": 234, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 179, + "end": 183, + "ctxt": 0 + }, + "value": "attr", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 184, + "end": 191, + "ctxt": 0 + }, + "value": "about", + "raw": "\"about\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 193, + "end": 233, + "ctxt": 0 + }, + "value": "test program for transpiler benchmarks", + "raw": "\"test program for transpiler benchmarks\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 237, + "end": 260, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 241, + "end": 251, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 241, + "end": 242, + "ctxt": 0 + }, + "value": "a", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 242, + "end": 247, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 244, + "end": 247, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 244, + "end": 247, + "ctxt": 0 + }, + "value": "int", + "optional": false + }, + "typeParams": null + } + } + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 250, + "end": 251, + "ctxt": 0 + }, + "value": 1, + "raw": "1" + }, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 253, + "end": 259, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 253, + "end": 254, + "ctxt": 0 + }, + "value": "b", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 254, + "end": 259, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 256, + "end": 259, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 256, + "end": 259, + "ctxt": 0 + }, + "value": "int", + "optional": false + }, + "typeParams": null + } + } + }, + "init": null, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 261, + "end": 270, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 261, + "end": 269, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 261, + "end": 266, + "ctxt": 0 + }, + "value": "input", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 267, + "end": 268, + "ctxt": 0 + }, + "value": "b", + "optional": false + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 271, + "end": 284, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 271, + "end": 283, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 271, + "end": 276, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 277, + "end": 282, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "Identifier", + "span": { + "start": 277, + "end": 278, + "ctxt": 0 + }, + "value": "a", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 281, + "end": 282, + "ctxt": 0 + }, + "value": "b", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 286, + "end": 326, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 290, + "end": 325, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 290, + "end": 291, + "ctxt": 0 + }, + "value": "c", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 291, + "end": 298, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 293, + "end": 298, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 293, + "end": 298, + "ctxt": 0 + }, + "value": "float", + "optional": false + }, + "typeParams": null + } + } + }, + "init": { + "type": "BinaryExpression", + "span": { + "start": 301, + "end": 325, + "ctxt": 0 + }, + "operator": "/", + "left": { + "type": "NumericLiteral", + "span": { + "start": 301, + "end": 303, + "ctxt": 0 + }, + "value": 20, + "raw": "20" + }, + "right": { + "type": "ParenthesisExpression", + "span": { + "start": 306, + "end": 325, + "ctxt": 0 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 307, + "end": 324, + "ctxt": 0 + }, + "operator": "^", + "left": { + "type": "ParenthesisExpression", + "span": { + "start": 307, + "end": 314, + "ctxt": 0 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 308, + "end": 313, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "NumericLiteral", + "span": { + "start": 308, + "end": 309, + "ctxt": 0 + }, + "value": 5, + "raw": "5" + }, + "right": { + "type": "Identifier", + "span": { + "start": 312, + "end": 313, + "ctxt": 0 + }, + "value": "a", + "optional": false + } + } + }, + "right": { + "type": "ParenthesisExpression", + "span": { + "start": 317, + "end": 324, + "ctxt": 0 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 318, + "end": 323, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "Identifier", + "span": { + "start": 318, + "end": 319, + "ctxt": 0 + }, + "value": "a", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 322, + "end": 323, + "ctxt": 0 + }, + "value": "b", + "optional": false + } + } + } + } + } + }, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 327, + "end": 336, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 327, + "end": 335, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 327, + "end": 332, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 333, + "end": 334, + "ctxt": 0 + }, + "value": "c", + "optional": false + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 338, + "end": 364, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 342, + "end": 356, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 342, + "end": 343, + "ctxt": 0 + }, + "value": "e", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 343, + "end": 350, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 345, + "end": 350, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 345, + "end": 350, + "ctxt": 0 + }, + "value": "float", + "optional": false + }, + "typeParams": null + } + } + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 353, + "end": 356, + "ctxt": 0 + }, + "value": 1.4, + "raw": "1.4" + }, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 358, + "end": 363, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 358, + "end": 359, + "ctxt": 0 + }, + "value": "f", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 362, + "end": 363, + "ctxt": 0 + }, + "value": 2, + "raw": "2" + }, + "definite": false + } + ] + }, + { + "type": "VariableDeclaration", + "span": { + "start": 365, + "end": 379, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 369, + "end": 378, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 369, + "end": 370, + "ctxt": 0 + }, + "value": "g", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "BinaryExpression", + "span": { + "start": 373, + "end": 378, + "ctxt": 0 + }, + "operator": "/", + "left": { + "type": "Identifier", + "span": { + "start": 373, + "end": 374, + "ctxt": 0 + }, + "value": "e", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 377, + "end": 378, + "ctxt": 0 + }, + "value": "f", + "optional": false + } + }, + "definite": false + } + ] + }, + { + "type": "VariableDeclaration", + "span": { + "start": 380, + "end": 403, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 384, + "end": 402, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 384, + "end": 385, + "ctxt": 0 + }, + "value": "h", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 385, + "end": 394, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 387, + "end": 394, + "ctxt": 0 + }, + "kind": "boolean" + } + } + }, + "init": { + "type": "BooleanLiteral", + "span": { + "start": 397, + "end": 402, + "ctxt": 0 + }, + "value": false + }, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 405, + "end": 459, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 405, + "end": 458, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 405, + "end": 410, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 411, + "end": 457, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "BinaryExpression", + "span": { + "start": 411, + "end": 453, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "BinaryExpression", + "span": { + "start": 411, + "end": 442, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "BinaryExpression", + "span": { + "start": 411, + "end": 438, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "BinaryExpression", + "span": { + "start": 411, + "end": 430, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "BinaryExpression", + "span": { + "start": 411, + "end": 426, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "BinaryExpression", + "span": { + "start": 411, + "end": 418, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 411, + "end": 414, + "ctxt": 0 + }, + "value": " ", + "raw": "\" \"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 417, + "end": 418, + "ctxt": 0 + }, + "value": "e", + "optional": false + } + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 421, + "end": 426, + "ctxt": 0 + }, + "value": " / ", + "raw": "\" / \"" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 429, + "end": 430, + "ctxt": 0 + }, + "value": "f", + "optional": false + } + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 433, + "end": 438, + "ctxt": 0 + }, + "value": " = ", + "raw": "\" = \"" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 441, + "end": 442, + "ctxt": 0 + }, + "value": "g", + "optional": false + } + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 445, + "end": 453, + "ctxt": 0 + }, + "value": ", h = ", + "raw": "\", h = \"" + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 456, + "end": 457, + "ctxt": 0 + }, + "value": "h", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 461, + "end": 482, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 465, + "end": 481, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 465, + "end": 466, + "ctxt": 0 + }, + "value": "i", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "BinaryExpression", + "span": { + "start": 469, + "end": 481, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "NumericLiteral", + "span": { + "start": 469, + "end": 470, + "ctxt": 0 + }, + "value": 2, + "raw": "2" + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 473, + "end": 481, + "ctxt": 0 + }, + "value": " hello", + "raw": "\" hello\"" + } + }, + "definite": false + } + ] + }, + { + "type": "VariableDeclaration", + "span": { + "start": 483, + "end": 504, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 487, + "end": 503, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 487, + "end": 488, + "ctxt": 0 + }, + "value": "j", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "BinaryExpression", + "span": { + "start": 491, + "end": 503, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "Identifier", + "span": { + "start": 491, + "end": 492, + "ctxt": 0 + }, + "value": "i", + "optional": false + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 495, + "end": 503, + "ctxt": 0 + }, + "value": " world", + "raw": "\" world\"" + } + }, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 505, + "end": 514, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 505, + "end": 513, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 505, + "end": 510, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 511, + "end": 512, + "ctxt": 0 + }, + "value": "j", + "optional": false + } + } + ], + "typeArguments": null + } + }, + { + "type": "IfStatement", + "span": { + "start": 516, + "end": 597, + "ctxt": 0 + }, + "test": { + "type": "BinaryExpression", + "span": { + "start": 520, + "end": 525, + "ctxt": 0 + }, + "operator": "<", + "left": { + "type": "Identifier", + "span": { + "start": 520, + "end": 521, + "ctxt": 0 + }, + "value": "a", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 524, + "end": 525, + "ctxt": 0 + }, + "value": "b", + "optional": false + } + }, + "consequent": { + "type": "BlockStatement", + "span": { + "start": 527, + "end": 559, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 531, + "end": 557, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 531, + "end": 556, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 531, + "end": 536, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 537, + "end": 555, + "ctxt": 0 + }, + "value": "a is less than b", + "raw": "\"a is less than b\"" + } + } + ], + "typeArguments": null + } + } + ] + }, + "alternate": { + "type": "BlockStatement", + "span": { + "start": 565, + "end": 597, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 569, + "end": 595, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 569, + "end": 594, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 569, + "end": 574, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 575, + "end": 593, + "ctxt": 0 + }, + "value": "a is more than b", + "raw": "'a is more than b'" + } + } + ], + "typeArguments": null + } + } + ] + } + }, + { + "type": "IfStatement", + "span": { + "start": 599, + "end": 635, + "ctxt": 0 + }, + "test": { + "type": "BooleanLiteral", + "span": { + "start": 603, + "end": 607, + "ctxt": 0 + }, + "value": true + }, + "consequent": { + "type": "BlockStatement", + "span": { + "start": 609, + "end": 635, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 613, + "end": 633, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 613, + "end": 632, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 613, + "end": 618, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 619, + "end": 631, + "ctxt": 0 + }, + "value": "single arm", + "raw": "\"single arm\"" + } + } + ], + "typeArguments": null + } + } + ] + }, + "alternate": null + }, + { + "type": "VariableDeclaration", + "span": { + "start": 637, + "end": 647, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 641, + "end": 646, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 641, + "end": 642, + "ctxt": 0 + }, + "value": "k", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 645, + "end": 646, + "ctxt": 0 + }, + "value": 0, + "raw": "0" + }, + "definite": false + } + ] + }, + { + "type": "WhileStatement", + "span": { + "start": 649, + "end": 692, + "ctxt": 0 + }, + "test": { + "type": "BinaryExpression", + "span": { + "start": 656, + "end": 662, + "ctxt": 0 + }, + "operator": "<", + "left": { + "type": "Identifier", + "span": { + "start": 656, + "end": 657, + "ctxt": 0 + }, + "value": "k", + "optional": false + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 660, + "end": 662, + "ctxt": 0 + }, + "value": 10, + "raw": "10" + } + }, + "body": { + "type": "BlockStatement", + "span": { + "start": 664, + "end": 692, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 668, + "end": 677, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 668, + "end": 676, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 668, + "end": 673, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 674, + "end": 675, + "ctxt": 0 + }, + "value": "k", + "optional": false + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 680, + "end": 690, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 680, + "end": 689, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 680, + "end": 681, + "ctxt": 0 + }, + "value": "k", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "BinaryExpression", + "span": { + "start": 684, + "end": 689, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "Identifier", + "span": { + "start": 684, + "end": 685, + "ctxt": 0 + }, + "value": "k", + "optional": false + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 688, + "end": 689, + "ctxt": 0 + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + } + }, + { + "type": "ForStatement", + "span": { + "start": 694, + "end": 734, + "ctxt": 0 + }, + "init": { + "type": "VariableDeclaration", + "span": { + "start": 699, + "end": 708, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 703, + "end": 708, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 703, + "end": 704, + "ctxt": 0 + }, + "value": "i", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 707, + "end": 708, + "ctxt": 0 + }, + "value": 0, + "raw": "0" + }, + "definite": false + } + ] + }, + "test": { + "type": "NumericLiteral", + "span": { + "start": 710, + "end": 712, + "ctxt": 0 + }, + "value": 10, + "raw": "10" + }, + "update": { + "type": "UpdateExpression", + "span": { + "start": 714, + "end": 717, + "ctxt": 0 + }, + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "span": { + "start": 714, + "end": 715, + "ctxt": 0 + }, + "value": "i", + "optional": false + } + }, + "body": { + "type": "BlockStatement", + "span": { + "start": 719, + "end": 734, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 723, + "end": 732, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 723, + "end": 731, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 723, + "end": 728, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 729, + "end": 730, + "ctxt": 0 + }, + "value": "i", + "optional": false + } + } + ], + "typeArguments": null + } + } + ] + } + }, + { + "type": "ForStatement", + "span": { + "start": 736, + "end": 775, + "ctxt": 0 + }, + "init": { + "type": "AssignmentExpression", + "span": { + "start": 741, + "end": 746, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 741, + "end": 742, + "ctxt": 0 + }, + "value": "i", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 745, + "end": 746, + "ctxt": 0 + }, + "value": 0, + "raw": "0" + } + }, + "test": { + "type": "NumericLiteral", + "span": { + "start": 748, + "end": 750, + "ctxt": 0 + }, + "value": 10, + "raw": "10" + }, + "update": { + "type": "AssignmentExpression", + "span": { + "start": 752, + "end": 758, + "ctxt": 0 + }, + "operator": "-=", + "left": { + "type": "Identifier", + "span": { + "start": 752, + "end": 753, + "ctxt": 0 + }, + "value": "i", + "optional": false + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 757, + "end": 758, + "ctxt": 0 + }, + "value": 1, + "raw": "1" + } + }, + "body": { + "type": "BlockStatement", + "span": { + "start": 760, + "end": 775, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 764, + "end": 773, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 764, + "end": 772, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 764, + "end": 769, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 770, + "end": 771, + "ctxt": 0 + }, + "value": "i", + "optional": false + } + } + ], + "typeArguments": null + } + } + ] + } + } + ], + "interpreter": null +} \ No newline at end of file diff --git a/ast/teatro-asgn7.ts.ast.json b/ast/teatro-asgn7.ts.ast.json new file mode 100644 index 0000000..1d5b662 --- /dev/null +++ b/ast/teatro-asgn7.ts.ast.json @@ -0,0 +1,1343 @@ +{ + "type": "Module", + "span": { + "start": 1, + "end": 944, + "ctxt": 0 + }, + "body": [ + { + "type": "ExpressionStatement", + "span": { + "start": 1, + "end": 27, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1, + "end": 26, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1, + "end": 5, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 6, + "end": 16, + "ctxt": 0 + }, + "value": "username", + "raw": "\"username\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 18, + "end": 25, + "ctxt": 0 + }, + "value": "skybl", + "raw": "\"skybl\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 28, + "end": 53, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 28, + "end": 52, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 28, + "end": 32, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 33, + "end": 43, + "ctxt": 0 + }, + "value": "hostname", + "raw": "\"hostname\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 45, + "end": 51, + "ctxt": 0 + }, + "value": "pond", + "raw": "\"pond\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 54, + "end": 79, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 54, + "end": 78, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 54, + "end": 58, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 59, + "end": 72, + "ctxt": 0 + }, + "value": "editVersion", + "raw": "\"editVersion\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 74, + "end": 77, + "ctxt": 0 + }, + "value": "2", + "raw": "\"2\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 80, + "end": 114, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 80, + "end": 113, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 80, + "end": 84, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 85, + "end": 104, + "ctxt": 0 + }, + "value": "editMysteryNumber", + "raw": "\"editMysteryNumber\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 106, + "end": 112, + "ctxt": 0 + }, + "value": "2513", + "raw": "\"2513\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 115, + "end": 165, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 115, + "end": 164, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 115, + "end": 119, + "ctxt": 0 + }, + "value": "attr", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 120, + "end": 126, + "ctxt": 0 + }, + "value": "name", + "raw": "\"name\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 128, + "end": 163, + "ctxt": 0 + }, + "value": "Working with a Decision Structure", + "raw": "\"Working with a Decision Structure\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 166, + "end": 198, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 166, + "end": 197, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 166, + "end": 170, + "ctxt": 0 + }, + "value": "attr", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 171, + "end": 180, + "ctxt": 0 + }, + "value": "authors", + "raw": "\"authors\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 182, + "end": 196, + "ctxt": 0 + }, + "value": "Jacob Teatro", + "raw": "\"Jacob Teatro\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 199, + "end": 289, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 199, + "end": 288, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 199, + "end": 203, + "ctxt": 0 + }, + "value": "attr", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 204, + "end": 211, + "ctxt": 0 + }, + "value": "about", + "raw": "\"about\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 213, + "end": 287, + "ctxt": 0 + }, + "value": "Current Semester: 1\nCourse Section: 0072\nBlackboard Username: jtteatro", + "raw": "\"Current Semester: 1\\nCourse Section: 0072\\nBlackboard Username: jtteatro\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 291, + "end": 322, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 295, + "end": 321, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 295, + "end": 314, + "ctxt": 0 + }, + "value": "rATE_GREATERTHAN_10", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 317, + "end": 321, + "ctxt": 0 + }, + "value": 4.1, + "raw": "4.10" + }, + "definite": false + } + ] + }, + { + "type": "VariableDeclaration", + "span": { + "start": 323, + "end": 355, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 327, + "end": 354, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 327, + "end": 347, + "ctxt": 0 + }, + "value": "rATE_6TO10_EXCLUSIVE", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 350, + "end": 354, + "ctxt": 0 + }, + "value": 3.5, + "raw": "3.50" + }, + "definite": false + } + ] + }, + { + "type": "VariableDeclaration", + "span": { + "start": 356, + "end": 387, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 360, + "end": 386, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 360, + "end": 379, + "ctxt": 0 + }, + "value": "rATE_2TO6_EXCLUSIVE", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 382, + "end": 386, + "ctxt": 0 + }, + "value": 2.25, + "raw": "2.25" + }, + "definite": false + } + ] + }, + { + "type": "VariableDeclaration", + "span": { + "start": 388, + "end": 413, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 392, + "end": 412, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 392, + "end": 405, + "ctxt": 0 + }, + "value": "rATE_LESSEQ_2", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 408, + "end": 412, + "ctxt": 0 + }, + "value": 1, + "raw": "1.00" + }, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 415, + "end": 460, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 415, + "end": 459, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 415, + "end": 420, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 421, + "end": 458, + "ctxt": 0 + }, + "value": "Welcome to the shipping calculator!", + "raw": "\"Welcome to the shipping calculator!\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 461, + "end": 496, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 461, + "end": 495, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 461, + "end": 466, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 467, + "end": 494, + "ctxt": 0 + }, + "value": "Enter the package weight:", + "raw": "\"Enter the package weight:\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 497, + "end": 518, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 501, + "end": 517, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 501, + "end": 510, + "ctxt": 0 + }, + "value": "pkgWeight", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 510, + "end": 517, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 512, + "end": 517, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 512, + "end": 517, + "ctxt": 0 + }, + "value": "float", + "optional": false + }, + "typeParams": null + } + } + }, + "init": null, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 519, + "end": 536, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 519, + "end": 535, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 519, + "end": 524, + "ctxt": 0 + }, + "value": "input", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 525, + "end": 534, + "ctxt": 0 + }, + "value": "pkgWeight", + "optional": false + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 538, + "end": 635, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 538, + "end": 634, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 538, + "end": 545, + "ctxt": 0 + }, + "value": "comment", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 546, + "end": 633, + "ctxt": 0 + }, + "value": "correcting a mistake that the assignment made, which left 6 and 10 as unhandled cases", + "raw": "\"correcting a mistake that the assignment made, which left 6 and 10 as unhandled cases\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 636, + "end": 650, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 640, + "end": 649, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 640, + "end": 644, + "ctxt": 0 + }, + "value": "rate", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 644, + "end": 649, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsLiteralType", + "span": { + "start": 646, + "end": 649, + "ctxt": 0 + }, + "literal": { + "type": "NumericLiteral", + "span": { + "start": 646, + "end": 649, + "ctxt": 0 + }, + "value": 0, + "raw": "0.0" + } + } + } + }, + "init": null, + "definite": false + } + ] + }, + { + "type": "IfStatement", + "span": { + "start": 651, + "end": 863, + "ctxt": 0 + }, + "test": { + "type": "BinaryExpression", + "span": { + "start": 655, + "end": 669, + "ctxt": 0 + }, + "operator": "<=", + "left": { + "type": "Identifier", + "span": { + "start": 655, + "end": 664, + "ctxt": 0 + }, + "value": "pkgWeight", + "optional": false + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 668, + "end": 669, + "ctxt": 0 + }, + "value": 2, + "raw": "2" + } + }, + "consequent": { + "type": "BlockStatement", + "span": { + "start": 671, + "end": 700, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 677, + "end": 698, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 677, + "end": 697, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 677, + "end": 681, + "ctxt": 0 + }, + "value": "rate", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "Identifier", + "span": { + "start": 684, + "end": 697, + "ctxt": 0 + }, + "value": "rATE_LESSEQ_2", + "optional": false + } + } + } + ] + }, + "alternate": { + "type": "IfStatement", + "span": { + "start": 706, + "end": 863, + "ctxt": 0 + }, + "test": { + "type": "BinaryExpression", + "span": { + "start": 710, + "end": 723, + "ctxt": 0 + }, + "operator": "<", + "left": { + "type": "Identifier", + "span": { + "start": 710, + "end": 719, + "ctxt": 0 + }, + "value": "pkgWeight", + "optional": false + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 722, + "end": 723, + "ctxt": 0 + }, + "value": 6, + "raw": "6" + } + }, + "consequent": { + "type": "BlockStatement", + "span": { + "start": 725, + "end": 760, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 731, + "end": 758, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 731, + "end": 757, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 731, + "end": 735, + "ctxt": 0 + }, + "value": "rate", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "Identifier", + "span": { + "start": 738, + "end": 757, + "ctxt": 0 + }, + "value": "rATE_2TO6_EXCLUSIVE", + "optional": false + } + } + } + ] + }, + "alternate": { + "type": "IfStatement", + "span": { + "start": 766, + "end": 863, + "ctxt": 0 + }, + "test": { + "type": "BinaryExpression", + "span": { + "start": 770, + "end": 784, + "ctxt": 0 + }, + "operator": "<", + "left": { + "type": "Identifier", + "span": { + "start": 770, + "end": 779, + "ctxt": 0 + }, + "value": "pkgWeight", + "optional": false + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 782, + "end": 784, + "ctxt": 0 + }, + "value": 10, + "raw": "10" + } + }, + "consequent": { + "type": "BlockStatement", + "span": { + "start": 786, + "end": 822, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 792, + "end": 820, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 792, + "end": 819, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 792, + "end": 796, + "ctxt": 0 + }, + "value": "rate", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "Identifier", + "span": { + "start": 799, + "end": 819, + "ctxt": 0 + }, + "value": "rATE_6TO10_EXCLUSIVE", + "optional": false + } + } + } + ] + }, + "alternate": { + "type": "BlockStatement", + "span": { + "start": 828, + "end": 863, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 834, + "end": 861, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 834, + "end": 860, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 834, + "end": 838, + "ctxt": 0 + }, + "value": "rate", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "Identifier", + "span": { + "start": 841, + "end": 860, + "ctxt": 0 + }, + "value": "rATE_GREATERTHAN_10", + "optional": false + } + } + } + ] + } + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 865, + "end": 889, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 865, + "end": 888, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 865, + "end": 870, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 871, + "end": 887, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 871, + "end": 880, + "ctxt": 0 + }, + "value": "Rate: $", + "raw": "\"Rate: $\"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 883, + "end": 887, + "ctxt": 0 + }, + "value": "rate", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 890, + "end": 929, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 890, + "end": 928, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 890, + "end": 895, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 896, + "end": 927, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 896, + "end": 906, + "ctxt": 0 + }, + "value": "Total: $", + "raw": "\"Total: $\"" + }, + "right": { + "type": "ParenthesisExpression", + "span": { + "start": 909, + "end": 927, + "ctxt": 0 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 910, + "end": 926, + "ctxt": 0 + }, + "operator": "*", + "left": { + "type": "Identifier", + "span": { + "start": 910, + "end": 914, + "ctxt": 0 + }, + "value": "rate", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 917, + "end": 926, + "ctxt": 0 + }, + "value": "pkgWeight", + "optional": false + } + } + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 930, + "end": 944, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 930, + "end": 943, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 930, + "end": 935, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 936, + "end": 942, + "ctxt": 0 + }, + "value": "Done", + "raw": "\"Done\"" + } + } + ], + "typeArguments": null + } + } + ], + "interpreter": null +} \ No newline at end of file diff --git a/ast/teatro-l7.ts.ast.json b/ast/teatro-l7.ts.ast.json new file mode 100644 index 0000000..2c374e3 --- /dev/null +++ b/ast/teatro-l7.ts.ast.json @@ -0,0 +1,2998 @@ +{ + "type": "Module", + "span": { + "start": 1, + "end": 1784, + "ctxt": 0 + }, + "body": [ + { + "type": "ExpressionStatement", + "span": { + "start": 1, + "end": 27, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1, + "end": 26, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1, + "end": 5, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 6, + "end": 16, + "ctxt": 0 + }, + "value": "username", + "raw": "\"username\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 18, + "end": 25, + "ctxt": 0 + }, + "value": "skybl", + "raw": "\"skybl\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 28, + "end": 53, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 28, + "end": 52, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 28, + "end": 32, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 33, + "end": 43, + "ctxt": 0 + }, + "value": "hostname", + "raw": "\"hostname\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 45, + "end": 51, + "ctxt": 0 + }, + "value": "pond", + "raw": "\"pond\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 54, + "end": 79, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 54, + "end": 78, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 54, + "end": 58, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 59, + "end": 72, + "ctxt": 0 + }, + "value": "editVersion", + "raw": "\"editVersion\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 74, + "end": 77, + "ctxt": 0 + }, + "value": "2", + "raw": "\"2\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 80, + "end": 114, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 80, + "end": 113, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 80, + "end": 84, + "ctxt": 0 + }, + "value": "meta", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 85, + "end": 104, + "ctxt": 0 + }, + "value": "editMysteryNumber", + "raw": "\"editMysteryNumber\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 106, + "end": 112, + "ctxt": 0 + }, + "value": "2519", + "raw": "\"2519\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 115, + "end": 151, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 115, + "end": 150, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 115, + "end": 119, + "ctxt": 0 + }, + "value": "attr", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 120, + "end": 126, + "ctxt": 0 + }, + "value": "name", + "raw": "\"name\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 128, + "end": 149, + "ctxt": 0 + }, + "value": "Decision structures", + "raw": "\"Decision structures\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 152, + "end": 184, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 152, + "end": 183, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 152, + "end": 156, + "ctxt": 0 + }, + "value": "attr", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 157, + "end": 166, + "ctxt": 0 + }, + "value": "authors", + "raw": "\"authors\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 168, + "end": 182, + "ctxt": 0 + }, + "value": "Jacob Teatro", + "raw": "\"Jacob Teatro\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 185, + "end": 275, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 185, + "end": 274, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 185, + "end": 189, + "ctxt": 0 + }, + "value": "attr", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 190, + "end": 197, + "ctxt": 0 + }, + "value": "about", + "raw": "\"about\"" + } + }, + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 199, + "end": 273, + "ctxt": 0 + }, + "value": "Current Semester: 1\nCourse Section: 0072\nBlackboard Username: jtteatro", + "raw": "\"Current Semester: 1\\nCourse Section: 0072\\nBlackboard Username: jtteatro\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 277, + "end": 392, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 281, + "end": 291, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 281, + "end": 284, + "ctxt": 0 + }, + "value": "TAX", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 287, + "end": 291, + "ctxt": 0 + }, + "value": 0.07, + "raw": "0.07" + }, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 297, + "end": 314, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 297, + "end": 306, + "ctxt": 0 + }, + "value": "ADULTcost", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 309, + "end": 314, + "ctxt": 0 + }, + "value": 36.75, + "raw": "36.75" + }, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 320, + "end": 337, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 320, + "end": 329, + "ctxt": 0 + }, + "value": "CHILDcost", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 332, + "end": 337, + "ctxt": 0 + }, + "value": 25.5, + "raw": "25.50" + }, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 343, + "end": 356, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 343, + "end": 349, + "ctxt": 0 + }, + "value": "MINfee", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 352, + "end": 356, + "ctxt": 0 + }, + "value": 0.5, + "raw": "0.50" + }, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 362, + "end": 375, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 362, + "end": 368, + "ctxt": 0 + }, + "value": "MAXfee", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 371, + "end": 375, + "ctxt": 0 + }, + "value": 1, + "raw": "1.00" + }, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 381, + "end": 391, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 381, + "end": 387, + "ctxt": 0 + }, + "value": "ATTEND", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "NumericLiteral", + "span": { + "start": 390, + "end": 391, + "ctxt": 0 + }, + "value": 5, + "raw": "5" + }, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 394, + "end": 445, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 394, + "end": 444, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 394, + "end": 399, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 400, + "end": 443, + "ctxt": 0 + }, + "value": "Welcome to the concert ticket calculator.", + "raw": "\"Welcome to the concert ticket calculator.\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 447, + "end": 463, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 451, + "end": 462, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 451, + "end": 457, + "ctxt": 0 + }, + "value": "adults", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 457, + "end": 462, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 459, + "end": 462, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 459, + "end": 462, + "ctxt": 0 + }, + "value": "int", + "optional": false + }, + "typeParams": null + } + } + }, + "init": null, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 464, + "end": 516, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 464, + "end": 515, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 464, + "end": 469, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 470, + "end": 514, + "ctxt": 0 + }, + "value": "Enter the number of adults (at least one):", + "raw": "\"Enter the number of adults (at least one):\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 517, + "end": 531, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 517, + "end": 530, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 517, + "end": 522, + "ctxt": 0 + }, + "value": "input", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 523, + "end": 529, + "ctxt": 0 + }, + "value": "adults", + "optional": false + } + } + ], + "typeArguments": null + } + }, + { + "type": "WhileStatement", + "span": { + "start": 532, + "end": 622, + "ctxt": 0 + }, + "test": { + "type": "BinaryExpression", + "span": { + "start": 539, + "end": 549, + "ctxt": 0 + }, + "operator": "<", + "left": { + "type": "Identifier", + "span": { + "start": 539, + "end": 545, + "ctxt": 0 + }, + "value": "adults", + "optional": false + }, + "right": { + "type": "NumericLiteral", + "span": { + "start": 548, + "end": 549, + "ctxt": 0 + }, + "value": 1, + "raw": "1" + } + }, + "body": { + "type": "BlockStatement", + "span": { + "start": 551, + "end": 622, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 557, + "end": 601, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 557, + "end": 600, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 557, + "end": 562, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 563, + "end": 599, + "ctxt": 0 + }, + "value": "You must enter at least one adult.", + "raw": "\"You must enter at least one adult.\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 606, + "end": 620, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 606, + "end": 619, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 606, + "end": 611, + "ctxt": 0 + }, + "value": "input", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 612, + "end": 618, + "ctxt": 0 + }, + "value": "adults", + "optional": false + } + } + ], + "typeArguments": null + } + } + ] + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 624, + "end": 642, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 628, + "end": 641, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 628, + "end": 636, + "ctxt": 0 + }, + "value": "children", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 636, + "end": 641, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 638, + "end": 641, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 638, + "end": 641, + "ctxt": 0 + }, + "value": "int", + "optional": false + }, + "typeParams": null + } + } + }, + "init": null, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 643, + "end": 682, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 643, + "end": 681, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 643, + "end": 648, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 649, + "end": 680, + "ctxt": 0 + }, + "value": "Ender the number of children:", + "raw": "\"Ender the number of children:\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 683, + "end": 699, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 683, + "end": 698, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 683, + "end": 688, + "ctxt": 0 + }, + "value": "input", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 689, + "end": 697, + "ctxt": 0 + }, + "value": "children", + "optional": false + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 701, + "end": 719, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 705, + "end": 718, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 705, + "end": 710, + "ctxt": 0 + }, + "value": "month", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 710, + "end": 718, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 712, + "end": 718, + "ctxt": 0 + }, + "kind": "string" + } + } + }, + "init": null, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 720, + "end": 784, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 720, + "end": 783, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 720, + "end": 725, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 726, + "end": 782, + "ctxt": 0 + }, + "value": "Enter the month of the concert (March, April, or May):", + "raw": "\"Enter the month of the concert (March, April, or May):\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "WhileStatement", + "span": { + "start": 785, + "end": 931, + "ctxt": 0 + }, + "test": { + "type": "UnaryExpression", + "span": { + "start": 792, + "end": 849, + "ctxt": 0 + }, + "operator": "!", + "argument": { + "type": "ParenthesisExpression", + "span": { + "start": 793, + "end": 849, + "ctxt": 0 + }, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 794, + "end": 848, + "ctxt": 0 + }, + "operator": "||", + "left": { + "type": "BinaryExpression", + "span": { + "start": 794, + "end": 830, + "ctxt": 0 + }, + "operator": "||", + "left": { + "type": "BinaryExpression", + "span": { + "start": 794, + "end": 810, + "ctxt": 0 + }, + "operator": "==", + "left": { + "type": "Identifier", + "span": { + "start": 794, + "end": 799, + "ctxt": 0 + }, + "value": "month", + "optional": false + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 803, + "end": 810, + "ctxt": 0 + }, + "value": "March", + "raw": "\"March\"" + } + }, + "right": { + "type": "BinaryExpression", + "span": { + "start": 814, + "end": 830, + "ctxt": 0 + }, + "operator": "==", + "left": { + "type": "Identifier", + "span": { + "start": 814, + "end": 819, + "ctxt": 0 + }, + "value": "month", + "optional": false + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 823, + "end": 830, + "ctxt": 0 + }, + "value": "April", + "raw": "\"April\"" + } + } + }, + "right": { + "type": "BinaryExpression", + "span": { + "start": 834, + "end": 848, + "ctxt": 0 + }, + "operator": "==", + "left": { + "type": "Identifier", + "span": { + "start": 834, + "end": 839, + "ctxt": 0 + }, + "value": "month", + "optional": false + }, + "right": { + "type": "StringLiteral", + "span": { + "start": 843, + "end": 848, + "ctxt": 0 + }, + "value": "May", + "raw": "\"May\"" + } + } + } + } + }, + "body": { + "type": "BlockStatement", + "span": { + "start": 851, + "end": 931, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 857, + "end": 911, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 857, + "end": 910, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 857, + "end": 862, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 863, + "end": 909, + "ctxt": 0 + }, + "value": "Only March, April, and May are valid months.", + "raw": "\"Only March, April, and May are valid months.\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 916, + "end": 929, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 916, + "end": 928, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 916, + "end": 921, + "ctxt": 0 + }, + "value": "input", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 922, + "end": 927, + "ctxt": 0 + }, + "value": "month", + "optional": false + } + } + ], + "typeArguments": null + } + } + ] + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 933, + "end": 950, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 937, + "end": 949, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 937, + "end": 941, + "ctxt": 0 + }, + "value": "name", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 941, + "end": 949, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 943, + "end": 949, + "ctxt": 0 + }, + "kind": "string" + } + } + }, + "init": null, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 951, + "end": 977, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 951, + "end": 976, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 951, + "end": 956, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 957, + "end": 975, + "ctxt": 0 + }, + "value": "Enter your name:", + "raw": "\"Enter your name:\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 978, + "end": 990, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 978, + "end": 989, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 978, + "end": 983, + "ctxt": 0 + }, + "value": "input", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 984, + "end": 988, + "ctxt": 0 + }, + "value": "name", + "optional": false + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 992, + "end": 1010, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 996, + "end": 1009, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 996, + "end": 1001, + "ctxt": 0 + }, + "value": "phone", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 1001, + "end": 1009, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 1003, + "end": 1009, + "ctxt": 0 + }, + "kind": "string" + } + } + }, + "init": null, + "definite": false + } + ] + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1011, + "end": 1045, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1011, + "end": 1044, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1011, + "end": 1016, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 1017, + "end": 1043, + "ctxt": 0 + }, + "value": "Enter your phone number:", + "raw": "\"Enter your phone number:\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1046, + "end": 1059, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1046, + "end": 1058, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1046, + "end": 1051, + "ctxt": 0 + }, + "value": "input", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "Identifier", + "span": { + "start": 1052, + "end": 1057, + "ctxt": 0 + }, + "value": "phone", + "optional": false + } + } + ], + "typeArguments": null + } + }, + { + "type": "VariableDeclaration", + "span": { + "start": 1061, + "end": 1194, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 1065, + "end": 1082, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 1065, + "end": 1077, + "ctxt": 0 + }, + "value": "totalTickets", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 1077, + "end": 1082, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 1079, + "end": 1082, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1079, + "end": 1082, + "ctxt": 0 + }, + "value": "int", + "optional": false + }, + "typeParams": null + } + } + }, + "init": null, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 1088, + "end": 1103, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 1088, + "end": 1096, + "ctxt": 0 + }, + "value": "subtotal", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 1096, + "end": 1103, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 1098, + "end": 1103, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1098, + "end": 1103, + "ctxt": 0 + }, + "value": "float", + "optional": false + }, + "typeParams": null + } + } + }, + "init": null, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 1109, + "end": 1124, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 1109, + "end": 1117, + "ctxt": 0 + }, + "value": "salesTax", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 1117, + "end": 1124, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 1119, + "end": 1124, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1119, + "end": 1124, + "ctxt": 0 + }, + "value": "float", + "optional": false + }, + "typeParams": null + } + } + }, + "init": null, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 1130, + "end": 1142, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 1130, + "end": 1135, + "ctxt": 0 + }, + "value": "total", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 1135, + "end": 1142, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 1137, + "end": 1142, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1137, + "end": 1142, + "ctxt": 0 + }, + "value": "float", + "optional": false + }, + "typeParams": null + } + } + }, + "init": null, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 1148, + "end": 1158, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 1148, + "end": 1151, + "ctxt": 0 + }, + "value": "fee", + "optional": false, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 1151, + "end": 1158, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 1153, + "end": 1158, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 1153, + "end": 1158, + "ctxt": 0 + }, + "value": "float", + "optional": false + }, + "typeParams": null + } + } + }, + "init": null, + "definite": false + }, + { + "type": "VariableDeclarator", + "span": { + "start": 1161, + "end": 1193, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 1161, + "end": 1173, + "ctxt": 0 + }, + "value": "totalTickets", + "optional": false, + "typeAnnotation": null + }, + "init": { + "type": "BinaryExpression", + "span": { + "start": 1176, + "end": 1193, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "Identifier", + "span": { + "start": 1176, + "end": 1182, + "ctxt": 0 + }, + "value": "adults", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 1185, + "end": 1193, + "ctxt": 0 + }, + "value": "children", + "optional": false + } + }, + "definite": false + } + ] + }, + { + "type": "IfStatement", + "span": { + "start": 1195, + "end": 1301, + "ctxt": 0 + }, + "test": { + "type": "BinaryExpression", + "span": { + "start": 1199, + "end": 1221, + "ctxt": 0 + }, + "operator": "<=", + "left": { + "type": "Identifier", + "span": { + "start": 1199, + "end": 1211, + "ctxt": 0 + }, + "value": "totalTickets", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 1215, + "end": 1221, + "ctxt": 0 + }, + "value": "ATTEND", + "optional": false + } + }, + "consequent": { + "type": "BlockStatement", + "span": { + "start": 1223, + "end": 1259, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 1229, + "end": 1257, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 1229, + "end": 1256, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 1229, + "end": 1232, + "ctxt": 0 + }, + "value": "fee", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "BinaryExpression", + "span": { + "start": 1235, + "end": 1256, + "ctxt": 0 + }, + "operator": "*", + "left": { + "type": "Identifier", + "span": { + "start": 1235, + "end": 1247, + "ctxt": 0 + }, + "value": "totalTickets", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 1250, + "end": 1256, + "ctxt": 0 + }, + "value": "MAXfee", + "optional": false + } + } + } + } + ] + }, + "alternate": { + "type": "BlockStatement", + "span": { + "start": 1265, + "end": 1301, + "ctxt": 0 + }, + "stmts": [ + { + "type": "ExpressionStatement", + "span": { + "start": 1271, + "end": 1299, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 1271, + "end": 1298, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 1271, + "end": 1274, + "ctxt": 0 + }, + "value": "fee", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "BinaryExpression", + "span": { + "start": 1277, + "end": 1298, + "ctxt": 0 + }, + "operator": "*", + "left": { + "type": "Identifier", + "span": { + "start": 1277, + "end": 1289, + "ctxt": 0 + }, + "value": "totalTickets", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 1292, + "end": 1298, + "ctxt": 0 + }, + "value": "MINfee", + "optional": false + } + } + } + } + ] + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1302, + "end": 1355, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 1302, + "end": 1354, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 1302, + "end": 1310, + "ctxt": 0 + }, + "value": "subtotal", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "BinaryExpression", + "span": { + "start": 1313, + "end": 1354, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "BinaryExpression", + "span": { + "start": 1313, + "end": 1331, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "Identifier", + "span": { + "start": 1313, + "end": 1319, + "ctxt": 0 + }, + "value": "adults", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 1322, + "end": 1331, + "ctxt": 0 + }, + "value": "ADULTcost", + "optional": false + } + }, + "right": { + "type": "BinaryExpression", + "span": { + "start": 1334, + "end": 1354, + "ctxt": 0 + }, + "operator": "*", + "left": { + "type": "Identifier", + "span": { + "start": 1334, + "end": 1342, + "ctxt": 0 + }, + "value": "children", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 1345, + "end": 1354, + "ctxt": 0 + }, + "value": "CHILDcost", + "optional": false + } + } + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1356, + "end": 1382, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 1356, + "end": 1381, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 1356, + "end": 1364, + "ctxt": 0 + }, + "value": "salesTax", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "BinaryExpression", + "span": { + "start": 1367, + "end": 1381, + "ctxt": 0 + }, + "operator": "*", + "left": { + "type": "Identifier", + "span": { + "start": 1367, + "end": 1375, + "ctxt": 0 + }, + "value": "subtotal", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 1378, + "end": 1381, + "ctxt": 0 + }, + "value": "TAX", + "optional": false + } + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1383, + "end": 1417, + "ctxt": 0 + }, + "expression": { + "type": "AssignmentExpression", + "span": { + "start": 1383, + "end": 1416, + "ctxt": 0 + }, + "operator": "=", + "left": { + "type": "Identifier", + "span": { + "start": 1383, + "end": 1388, + "ctxt": 0 + }, + "value": "total", + "optional": false, + "typeAnnotation": null + }, + "right": { + "type": "BinaryExpression", + "span": { + "start": 1391, + "end": 1416, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "BinaryExpression", + "span": { + "start": 1391, + "end": 1410, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "Identifier", + "span": { + "start": 1391, + "end": 1399, + "ctxt": 0 + }, + "value": "subtotal", + "optional": false + }, + "right": { + "type": "Identifier", + "span": { + "start": 1402, + "end": 1410, + "ctxt": 0 + }, + "value": "salesTax", + "optional": false + } + }, + "right": { + "type": "Identifier", + "span": { + "start": 1413, + "end": 1416, + "ctxt": 0 + }, + "value": "fee", + "optional": false + } + } + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1419, + "end": 1441, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1419, + "end": 1440, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1419, + "end": 1424, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 1425, + "end": 1439, + "ctxt": 0 + }, + "value": "Concert Bill", + "raw": "\"Concert Bill\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1442, + "end": 1465, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1442, + "end": 1464, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1442, + "end": 1447, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1448, + "end": 1463, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 1448, + "end": 1456, + "ctxt": 0 + }, + "value": "Name: ", + "raw": "\"Name: \"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 1459, + "end": 1463, + "ctxt": 0 + }, + "value": "name", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1466, + "end": 1491, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1466, + "end": 1490, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1466, + "end": 1471, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1472, + "end": 1489, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 1472, + "end": 1481, + "ctxt": 0 + }, + "value": "Phone: ", + "raw": "\"Phone: \"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 1484, + "end": 1489, + "ctxt": 0 + }, + "value": "phone", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1492, + "end": 1525, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1492, + "end": 1524, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1492, + "end": 1497, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1498, + "end": 1523, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 1498, + "end": 1515, + "ctxt": 0 + }, + "value": "Attending on: ", + "raw": "\"Attending on: \"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 1518, + "end": 1523, + "ctxt": 0 + }, + "value": "month", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1526, + "end": 1570, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1526, + "end": 1569, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1526, + "end": 1531, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1532, + "end": 1568, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 1532, + "end": 1559, + "ctxt": 0 + }, + "value": "Number of adult tickets: ", + "raw": "\"Number of adult tickets: \"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 1562, + "end": 1568, + "ctxt": 0 + }, + "value": "adults", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1571, + "end": 1617, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1571, + "end": 1616, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1571, + "end": 1576, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1577, + "end": 1615, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 1577, + "end": 1604, + "ctxt": 0 + }, + "value": "Number of child tickets: ", + "raw": "\"Number of child tickets: \"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 1607, + "end": 1615, + "ctxt": 0 + }, + "value": "children", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1618, + "end": 1640, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1618, + "end": 1639, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1618, + "end": 1623, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 1624, + "end": 1638, + "ctxt": 0 + }, + "value": "------------", + "raw": "\"------------\"" + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1641, + "end": 1673, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1641, + "end": 1672, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1641, + "end": 1646, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1647, + "end": 1671, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 1647, + "end": 1660, + "ctxt": 0 + }, + "value": "Subtotal: $", + "raw": "\"Subtotal: $\"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 1663, + "end": 1671, + "ctxt": 0 + }, + "value": "subtotal", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1674, + "end": 1707, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1674, + "end": 1706, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1674, + "end": 1679, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1680, + "end": 1705, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 1680, + "end": 1694, + "ctxt": 0 + }, + "value": "Sales tax: $", + "raw": "\"Sales tax: $\"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 1697, + "end": 1705, + "ctxt": 0 + }, + "value": "salesTax", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1708, + "end": 1742, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1708, + "end": 1741, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1708, + "end": 1713, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1714, + "end": 1740, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 1714, + "end": 1734, + "ctxt": 0 + }, + "value": "Additional fees: $", + "raw": "\"Additional fees: $\"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 1737, + "end": 1740, + "ctxt": 0 + }, + "value": "fee", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1743, + "end": 1769, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1743, + "end": 1768, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1743, + "end": 1748, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "BinaryExpression", + "span": { + "start": 1749, + "end": 1767, + "ctxt": 0 + }, + "operator": "+", + "left": { + "type": "StringLiteral", + "span": { + "start": 1749, + "end": 1759, + "ctxt": 0 + }, + "value": "Total: $", + "raw": "\"Total: $\"" + }, + "right": { + "type": "Identifier", + "span": { + "start": 1762, + "end": 1767, + "ctxt": 0 + }, + "value": "total", + "optional": false + } + } + } + ], + "typeArguments": null + } + }, + { + "type": "ExpressionStatement", + "span": { + "start": 1770, + "end": 1784, + "ctxt": 0 + }, + "expression": { + "type": "CallExpression", + "span": { + "start": 1770, + "end": 1783, + "ctxt": 0 + }, + "callee": { + "type": "Identifier", + "span": { + "start": 1770, + "end": 1775, + "ctxt": 0 + }, + "value": "print", + "optional": false + }, + "arguments": [ + { + "spread": null, + "expression": { + "type": "StringLiteral", + "span": { + "start": 1776, + "end": 1782, + "ctxt": 0 + }, + "value": "Done", + "raw": "\"Done\"" + } + } + ], + "typeArguments": null + } + } + ], + "interpreter": null +} \ No newline at end of file diff --git a/benchmarks/benchmark.ts b/benchmarks/benchmark.ts new file mode 100644 index 0000000..d5c8325 --- /dev/null +++ b/benchmarks/benchmark.ts @@ -0,0 +1,72 @@ +import * as SWC from "../src/swc.ts"; +import { CallExpression, ExpressionStatement } from "../src/swc.ts"; +import * as Trans from "../src/transformers.ts"; + +const input = Deno.readTextFileSync("./benchmarks/benchtest.ts"); + +const fakeState = { + input: "", + indent: " ", + idents: new Map<string, Trans.Ident>(), + opts: { + indent: 4, + showSourceStatements: false, + attr: {}, + meta: {}, + } +}; + +const ast = SWC.parse(input, { + syntax: "typescript", + comments: true, + target: "es2020", +}); + +const template = Deno.readTextFileSync("./assets/template.fprg"); + +Deno.bench("transform", () => { + Trans.transform(input, ast, { + indent: 3, + showSourceStatements: true, + }, template); +}); + +Deno.bench("transformBlock", () => { + Trans.transformBlock( + ast.body, + { ...fakeState, idents: new Map<string, Trans.Ident>() }, + ); +}); + +Deno.bench("transformVariableDecl", () => { + Trans.transformVariableDecl( + ast.body[7] as SWC.VariableDeclaration, + { ...fakeState, idents: new Map<string, Trans.Ident>() }, + ); +}); + +fakeState.idents = new Map<string, Trans.Ident>([ + ["a", { type: "int", defined: true }], + ["b", { type: "int", defined: true }], +]); + +Deno.bench("transformExpr :: `20 / ((5 + a) ^ (a + b))`", () => { + Trans.transformExpr( + (ast.body[10] as SWC.VariableDeclaration).declarations[0].init!, + fakeState.idents, + ); +}); + +Deno.bench("transformBlockCallExpr :: `print(a + b)`", () => { + Trans.transformBlockCallExpr( + (ast.body[9] as ExpressionStatement).expression as CallExpression, + fakeState, + ); +}); + +Deno.bench("transformIfStmt", () => { + Trans.transformIfStmt( + ast.body[19] as SWC.IfStatement, + fakeState + ); +}); \ No newline at end of file diff --git a/benchmarks/benchtest.ts b/benchmarks/benchtest.ts new file mode 100644 index 0000000..83659a3 --- /dev/null +++ b/benchmarks/benchtest.ts @@ -0,0 +1,49 @@ +meta("username", "skybl"); +meta("hostname", "pond"); +meta("editVersion", "5"); +meta("editMysteryNumber", "2991"); +attr("name", "benchtest.ts"); +attr("authors", "skybl, ezfprg"); +attr("about", "test program for transpiler benchmarks"); + +let a: int = 1, b: int; +input(b); +print(a + b); + +let c: float = 20 / ((5 + a) ^ (a + b)); +print(c); + +let e: float = 1.4, f = 2; +let g = e / f; +let h: boolean = false; + +print(" " + e + " / " + f + " = " + g + ", h = " + h); + +let i = 2 + " hello"; +let j = i + " world"; +print(j); + +if (a < b) { + print("a is less than b"); +} else { + print('a is more than b'); +} + +if (true) { + print("single arm"); +} + +let k = 0; + +while (k < 10) { + print(k); + k = k + 1; +} + +for (let l = 0; 10; l++) { + print(l); +} + +for (l = 20; 10; l -= 2) { + print(l); +} \ No newline at end of file diff --git a/benchmarks/types.d.ts b/benchmarks/types.d.ts new file mode 100644 index 0000000..4dc9ace --- /dev/null +++ b/benchmarks/types.d.ts @@ -0,0 +1,9 @@ +//// <reference no-default-lib="true" /> + +declare type int = number; +declare type float = number; + +declare function print(a: unknown): void; +declare function input(a: unknown): void; +declare function meta(a: "username" | "hostname" | "editVersion" | "editMysteryNumber", b: string): void; +declare function attr(a: "name" | "authors" | "about", b: string): void; \ No newline at end of file diff --git a/ez_flowgorithm.code-workspace b/ez_flowgorithm.code-workspace new file mode 100644 index 0000000..22b3155 --- /dev/null +++ b/ez_flowgorithm.code-workspace @@ -0,0 +1,10 @@ +{ + "folders": [ + { + "path": ".." + } + ], + "settings": { + "deno.unstable": true + } +} \ No newline at end of file diff --git a/ezauto_old.js b/ezauto_old.js new file mode 100644 index 0000000..9dadc1f --- /dev/null +++ b/ezauto_old.js @@ -0,0 +1,114 @@ +const KEYWORDS = [ + "let", + "for", + "print", + "input", + "//" +]; + +const TYPES = [ + "int", + "float", + "string", + "bool" +]; + +const PATTERNS = [ + "asgn": [ "ident", "eq", "expr" ], + "let": [ "type", "ident", "eq?", "expr" ], +]; + +class UnexpectedTokenError extends SyntaxError { + constructor (expectedTokens, token, line, col) { + const expected = expectedTokens.map((t) => `"${t}"`).join(", "); + super(`Expected ${expected} but got ${token}`); + this.lineNumber = line; + this.columnNumber = col; + } +} + +class UnexpectedEndOfInputError { + constructor (line, col) { + super(`Unexpected end of input at ${line}:${col}.`); + } +} + +const inPath = Deno.args[0]; +const dec = new TextDecoder("utf-8); +const raw = Deno.readFile(inPath); +const input = dec.decode(raw); + +const lines = input.split("\n"); + +let tree = []; +let stack = []; +let ctx = ""; + +// keyword, ident, type, num, string, op, group, eof +let expectedTokens = ["keyword", "ident"]; +let tokenType = null; +// ` `, `{`, `}` +let delim = " "; +let token = ""; + +let idents = []; + +for (let line = 0; line < lines.length; line++) { + const currentLine = lines[line]; + for (let col = 0; col < currentLine.length; col++) { + if (currentLine[col] === delim) { + tokenType = null; + const tokenHandlers = { + "keyword": () => { + if (KEYWORDS.includes(token)) { + stack.push(token); + tokenType = "keyword"; + } + }, + "ident": () => { + if (idents.includes(token)) { + stack.push(token); + idents.push(token); + tokenType = "ident"; + } + }, + }; + + for (type in expectedTokens) { + tokenHandlers[type](); + if (tokenType !== null) { + break; + } + } + + if (!expectedTokens.includes(tokenType)) { + throw new UnexpectedTokenError(expectedTokens, token, line, col); + } else { + switch (tokenType) { + case "keyword": + switch (token) { + case "let": + ctx = patterns["let"]; + expectedToken = "ident"; + delim = " "; + break; + } + break; + case "ident": + + + + } else { + token.push(line[j]); + } + + switch (mode) { + case "keyword": { + const keyword = line.split(" ")[0]; + if (KEYWORDS.includes(keyword)) { + stack.push(keyword); + } else { + throw new UnknownKeywordError(keyword, i, 0); + + + diff --git a/generate_ast.ts b/generate_ast.ts new file mode 100644 index 0000000..fbe7306 --- /dev/null +++ b/generate_ast.ts @@ -0,0 +1,7 @@ +import { parse } from "./src/swc.ts"; +import { basename } from "https://deno.land/std@0.159.0/path/posix.ts?s=basename"; + +const input = Deno.readTextFileSync(Deno.args[0]); +const ast = parse(input, { syntax: "typescript", target: "es2020" }); +const json = JSON.stringify(ast, null, 2); +Deno.writeTextFileSync(basename(Deno.args[0]) + ".ast.json", json); \ No newline at end of file diff --git a/lib/deno_swc/.github/workflows/ci.yml b/lib/deno_swc/.github/workflows/ci.yml new file mode 100644 index 0000000..dc0549a --- /dev/null +++ b/lib/deno_swc/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: ci + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: denolib/setup-deno@master + with: + deno-version: 1.12.2 + - name: Format Check + run: deno fmt --check --ignore=swc_wasm + + swc-deno-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: denolib/setup-deno@master + with: + deno-version: 1.23.0 + - uses: hecrj/setup-rust-action@v1 + with: + rust-version: nightly + + - name: Install wasm32-unknown-unknown target + run: rustup target add wasm32-unknown-unknown + + - name: Install wasm-bindgen + run: cargo install --version 0.2.72 wasm-bindgen-cli + + - name: Cache Cargo home + uses: actions/cache@v2 + with: + # See https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci + path: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git/db + key: f-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }} + + - name: Cache build output + uses: actions/cache@03e00da99d75a2204924908e1cca7902cafce66b + with: + path: target + key: | + f-cargo-target-${{ matrix.os }}-${{ matrix.profile }}- + + - name: Build + run: deno task build + + - name: Test + run: deno task test + diff --git a/lib/deno_swc/.gitignore b/lib/deno_swc/.gitignore new file mode 100644 index 0000000..34ebdf8 --- /dev/null +++ b/lib/deno_swc/.gitignore @@ -0,0 +1,6 @@ +target/ +swc_wasm/pkg +builds/ +*.exe +config.toml +.vscode/settings.json diff --git a/lib/deno_swc/.rustfmt.toml b/lib/deno_swc/.rustfmt.toml new file mode 100644 index 0000000..8e60d0c --- /dev/null +++ b/lib/deno_swc/.rustfmt.toml @@ -0,0 +1,3 @@ +max_width = 80 +tab_spaces = 2 +edition = "2021" \ No newline at end of file diff --git a/lib/deno_swc/Cargo.lock b/lib/deno_swc/Cargo.lock new file mode 100644 index 0000000..0a422c6 --- /dev/null +++ b/lib/deno_swc/Cargo.lock @@ -0,0 +1,2324 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "serde", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "ast_node" +version = "0.7.7" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "darling", + "pmutil", + "proc-macro2", + "quote", + "swc_macros_common", + "syn", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "auto_impl" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7862e21c893d65a1650125d157eaeec691439379a1cee17ee49031b79236ada4" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "better_scoped_tls" +version = "0.1.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "scoped-tls", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "block-buffer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +dependencies = [ + "generic-array", +] + +[[package]] +name = "browserslist-rs" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e55d9cadf66efd56338797ada06140423bd87f290eac200027265d79d621a266" +dependencies = [ + "ahash", + "anyhow", + "chrono", + "either", + "itertools", + "js-sys", + "nom", + "once_cell", + "quote", + "serde", + "serde-wasm-bindgen", + "serde_json", + "string_cache", + "string_cache_codegen", + "thiserror", + "wasm-bindgen", +] + +[[package]] +name = "bumpalo" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "js-sys", + "libc", + "num-integer", + "num-traits", + "time", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen", +] + +[[package]] +name = "cpufeatures" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07db9d94cbd326813772c968ccd25999e5f8ae22f4f8d1b11effa37ef6ce281d" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "crossbeam-utils", + "memoffset", + "once_cell", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ff1f980957787286a554052d03c7aee98d99cc32e09f6d45f0a814133c87978" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", +] + +[[package]] +name = "crypto-common" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "dashmap" +version = "5.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3495912c9c1ccf2e18976439f4443f3fee0fd61f424ff99fde6a66b15ecb448f" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown 0.12.1", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "debug_unreachable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a032eac705ca39214d169f83e3d3da290af06d8d1d344d1baad2fd002dca4b3" +dependencies = [ + "unreachable", +] + +[[package]] +name = "deno_swc" +version = "0.0.1" +dependencies = [ + "anyhow", + "console_error_panic_hook", + "once_cell", + "path-clean", + "serde", + "serde_json", + "swc", + "swc_common", + "swc_ecmascript", + "syn", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wee_alloc", +] + +[[package]] +name = "digest" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "enum_kind" +version = "0.2.1" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "pmutil", + "proc-macro2", + "swc_macros_common", + "syn", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "from_variant" +version = "0.1.3" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "pmutil", + "proc-macro2", + "swc_macros_common", + "syn", +] + +[[package]] +name = "generic-array" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "gimli" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "if_chain" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" + +[[package]] +name = "indexmap" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c6392766afd7964e2531940894cffe4bd8d7d17dbc3c1c4857040fd4b33bdb3" +dependencies = [ + "autocfg", + "hashbrown 0.12.1", + "serde", +] + +[[package]] +name = "is-macro" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c068d4c6b922cd6284c609cfa6dec0e41615c9c5a1a4ba729a970d8daba05fb" +dependencies = [ + "Inflector", + "pmutil", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "is_ci" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" + +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" + +[[package]] +name = "js-sys" +version = "0.3.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "json_comments" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41ee439ee368ba4a77ac70d04f14015415af8600d6c894dc1f11bd79758c57d5" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lexical" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7aefb36fd43fef7003334742cbf77b243fcd36418a1d1bdd480d613a67968f6" +dependencies = [ + "lexical-core", +] + +[[package]] +name = "lexical-core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cde5de06e8d4c2faabc400238f9ae1c74d5412d03a7bd067645ccbc47070e46" +dependencies = [ + "lexical-parse-float", + "lexical-parse-integer", + "lexical-util", + "lexical-write-float", + "lexical-write-integer", +] + +[[package]] +name = "lexical-parse-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683b3a5ebd0130b8fb52ba0bdc718cc56815b6a097e28ae5a6997d0ad17dc05f" +dependencies = [ + "lexical-parse-integer", + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-parse-integer" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d0994485ed0c312f6d965766754ea177d07f9c00c9b82a5ee62ed5b47945ee9" +dependencies = [ + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-util" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5255b9ff16ff898710eb9eb63cb39248ea8a5bb036bea8085b1a767ff6c4e3fc" +dependencies = [ + "static_assertions", +] + +[[package]] +name = "lexical-write-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accabaa1c4581f05a3923d1b4cfd124c329352288b7b9da09e766b0668116862" +dependencies = [ + "lexical-util", + "lexical-write-integer", + "static_assertions", +] + +[[package]] +name = "lexical-write-integer" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1b6f3d1f4422866b68192d62f77bc5c700bee84f3069f2469d7bc8c77852446" +dependencies = [ + "lexical-util", + "static_assertions", +] + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "lru" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c84e6fe5655adc6ce00787cf7dcaf8dc4f998a0565d23eafc207a8b08ca3349a" +dependencies = [ + "hashbrown 0.11.2", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "miette" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c90329e44f9208b55f45711f9558cec15d7ef8295cc65ecd6d4188ae8edc58c" +dependencies = [ + "atty", + "backtrace", + "miette-derive", + "once_cell", + "owo-colors", + "supports-color", + "supports-hyperlinks", + "supports-unicode", + "terminal_size", + "textwrap", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b5bc45b761bcf1b5e6e6c4128cd93b84c218721a8d9b894aa0aff4ed180174c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" +dependencies = [ + "adler", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" + +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "normpath" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a9da8c9922c35a1033d76f7272dfc2e7ee20392083d75aeea6ced23c6266578" +dependencies = [ + "winapi", +] + +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.28.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" + +[[package]] +name = "ordered-float" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87" +dependencies = [ + "num-traits", +] + +[[package]] +name = "owo-colors" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + +[[package]] +name = "path-clean" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecba01bf2678719532c5e3059e0b5f0811273d94b397088b82e3bd0a78c78fdd" + +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_macros", + "phf_shared", + "proc-macro-hack", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fdf3184dd560f160dd73922bea2d5cd6e8f064bf4b13110abd81b03697b4e0" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pmutil" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "preset_env_base" +version = "0.2.3" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "anyhow", + "browserslist-rs", + "dashmap", + "from_variant", + "once_cell", + "semver 1.0.10", + "serde", + "st-map", + "tracing", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro2" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f53dc8cf16a769a6f677e09e7ff2cd4be1ea0f48754aac39520536962011de0d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rayon" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] +name = "redox_syscall" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" + +[[package]] +name = "retain_mut" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4389f1d5789befaf6029ebd9f7dac4af7f7e3d61b69d4f30e2ac02b57e7712b0" + +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + +[[package]] +name = "ryu" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" + +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41d061efea015927ac527063765e73601444cdc344ba855bc7bd44578b25e1c" +dependencies = [ + "serde", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-wasm-bindgen" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "618365e8e586c22123d692b72a7d791d5ee697817b65a218cdf12a98870af0f7" +dependencies = [ + "fnv", + "js-sys", + "serde", + "wasm-bindgen", +] + +[[package]] +name = "serde_derive" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] + +[[package]] +name = "siphasher" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" + +[[package]] +name = "smallvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" + +[[package]] +name = "smawk" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" + +[[package]] +name = "sourcemap" +version = "6.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2ca89636b276071e7276488131f531dbf43ad1c19bc4bd5a04f6a0ce1ddc138" +dependencies = [ + "base64 0.11.0", + "if_chain", + "lazy_static", + "regex", + "rustc_version", + "serde", + "serde_json", + "url", +] + +[[package]] +name = "st-map" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc9c9f3a1df5f73b7392bd9773108fef41ad9126f0282412fd5904389f0c0c4f" +dependencies = [ + "arrayvec", + "static-map-macro", +] + +[[package]] +name = "static-map-macro" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "752564de9cd8937fdbc1c55d47ac391758c352ab3755607cc391b659fe87d56b" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "string_cache" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", +] + +[[package]] +name = "string_enum" +version = "0.3.1" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "swc_macros_common", + "syn", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "supports-color" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4872ced36b91d47bae8a214a683fe54e7078875b399dfa251df346c9b547d1f9" +dependencies = [ + "atty", + "is_ci", +] + +[[package]] +name = "supports-hyperlinks" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "590b34f7c5f01ecc9d78dba4b3f445f31df750a67621cf31626f3b7441ce6406" +dependencies = [ + "atty", +] + +[[package]] +name = "supports-unicode" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8b945e45b417b125a8ec51f1b7df2f8df7920367700d1f98aedd21e5735f8b2" +dependencies = [ + "atty", +] + +[[package]] +name = "swc" +version = "0.183.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "anyhow", + "base64 0.13.0", + "dashmap", + "either", + "indexmap", + "json_comments", + "lru", + "once_cell", + "parking_lot", + "pathdiff", + "regex", + "rustc-hash", + "serde", + "serde_json", + "sourcemap", + "swc_atoms", + "swc_cached", + "swc_common", + "swc_config", + "swc_ecma_ast", + "swc_ecma_codegen", + "swc_ecma_ext_transforms", + "swc_ecma_lints", + "swc_ecma_loader", + "swc_ecma_minifier", + "swc_ecma_parser", + "swc_ecma_preset_env", + "swc_ecma_transforms", + "swc_ecma_transforms_base", + "swc_ecma_transforms_compat", + "swc_ecma_transforms_optimization", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_ecmascript", + "swc_error_reporters", + "swc_node_comments", + "swc_timer", + "swc_visit", + "tracing", +] + +[[package]] +name = "swc_atoms" +version = "0.2.11" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "string_cache", + "string_cache_codegen", +] + +[[package]] +name = "swc_cached" +version = "0.1.1" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "anyhow", + "dashmap", + "once_cell", + "regex", + "serde", + "swc_atoms", +] + +[[package]] +name = "swc_common" +version = "0.18.7" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "ast_node", + "better_scoped_tls", + "cfg-if 1.0.0", + "debug_unreachable", + "either", + "from_variant", + "num-bigint", + "once_cell", + "parking_lot", + "rustc-hash", + "serde", + "siphasher", + "sourcemap", + "string_cache", + "swc_eq_ignore_macros", + "swc_visit", + "tracing", + "unicode-width", + "url", +] + +[[package]] +name = "swc_config" +version = "0.1.1" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_json", + "swc_config_macro", +] + +[[package]] +name = "swc_config_macro" +version = "0.1.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "swc_macros_common", + "syn", +] + +[[package]] +name = "swc_ecma_ast" +version = "0.78.1" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "is-macro", + "num-bigint", + "scoped-tls", + "serde", + "string_enum", + "swc_atoms", + "swc_common", + "unicode-id", +] + +[[package]] +name = "swc_ecma_codegen" +version = "0.108.6" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "bitflags", + "memchr", + "num-bigint", + "once_cell", + "rustc-hash", + "sourcemap", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_codegen_macros", + "tracing", +] + +[[package]] +name = "swc_ecma_codegen_macros" +version = "0.7.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "swc_macros_common", + "syn", +] + +[[package]] +name = "swc_ecma_ext_transforms" +version = "0.71.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "phf", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_utils", + "swc_ecma_visit", +] + +[[package]] +name = "swc_ecma_lints" +version = "0.42.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "auto_impl", + "dashmap", + "parking_lot", + "rayon", + "regex", + "serde", + "swc_atoms", + "swc_common", + "swc_config", + "swc_ecma_ast", + "swc_ecma_utils", + "swc_ecma_visit", +] + +[[package]] +name = "swc_ecma_loader" +version = "0.30.2" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "anyhow", + "dashmap", + "lru", + "normpath", + "once_cell", + "parking_lot", + "path-clean", + "pathdiff", + "serde", + "serde_json", + "swc_cached", + "swc_common", + "tracing", +] + +[[package]] +name = "swc_ecma_minifier" +version = "0.116.4" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "arrayvec", + "indexmap", + "once_cell", + "parking_lot", + "rayon", + "regex", + "retain_mut", + "rustc-hash", + "serde", + "serde_json", + "swc_atoms", + "swc_cached", + "swc_common", + "swc_config", + "swc_ecma_ast", + "swc_ecma_codegen", + "swc_ecma_parser", + "swc_ecma_transforms_base", + "swc_ecma_transforms_optimization", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_timer", + "tracing", + "unicode-id", +] + +[[package]] +name = "swc_ecma_parser" +version = "0.104.2" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "either", + "enum_kind", + "lexical", + "num-bigint", + "serde", + "smallvec", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "tracing", + "typed-arena", +] + +[[package]] +name = "swc_ecma_preset_env" +version = "0.131.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "anyhow", + "dashmap", + "indexmap", + "once_cell", + "preset_env_base", + "semver 1.0.10", + "serde", + "serde_json", + "st-map", + "string_enum", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms", + "swc_ecma_utils", + "swc_ecma_visit", +] + +[[package]] +name = "swc_ecma_transforms" +version = "0.156.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_transforms_compat", + "swc_ecma_transforms_module", + "swc_ecma_transforms_optimization", + "swc_ecma_transforms_proposal", + "swc_ecma_transforms_react", + "swc_ecma_transforms_typescript", + "swc_ecma_utils", + "swc_ecma_visit", +] + +[[package]] +name = "swc_ecma_transforms_base" +version = "0.86.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "better_scoped_tls", + "once_cell", + "phf", + "rustc-hash", + "serde", + "smallvec", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_parser", + "swc_ecma_utils", + "swc_ecma_visit", + "tracing", +] + +[[package]] +name = "swc_ecma_transforms_classes" +version = "0.74.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_utils", + "swc_ecma_visit", +] + +[[package]] +name = "swc_ecma_transforms_compat" +version = "0.101.1" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "arrayvec", + "indexmap", + "is-macro", + "num-bigint", + "ordered-float", + "serde", + "smallvec", + "swc_atoms", + "swc_common", + "swc_config", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_transforms_classes", + "swc_ecma_transforms_macros", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro", + "tracing", +] + +[[package]] +name = "swc_ecma_transforms_macros" +version = "0.4.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "swc_macros_common", + "syn", +] + +[[package]] +name = "swc_ecma_transforms_module" +version = "0.114.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "Inflector", + "ahash", + "anyhow", + "indexmap", + "path-clean", + "pathdiff", + "serde", + "swc_atoms", + "swc_cached", + "swc_common", + "swc_ecma_ast", + "swc_ecma_loader", + "swc_ecma_parser", + "swc_ecma_transforms_base", + "swc_ecma_utils", + "swc_ecma_visit", + "tracing", +] + +[[package]] +name = "swc_ecma_transforms_optimization" +version = "0.126.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "dashmap", + "indexmap", + "once_cell", + "rustc-hash", + "serde_json", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_parser", + "swc_ecma_transforms_base", + "swc_ecma_transforms_macros", + "swc_ecma_utils", + "swc_ecma_visit", + "tracing", +] + +[[package]] +name = "swc_ecma_transforms_proposal" +version = "0.109.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "either", + "serde", + "smallvec", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_transforms_classes", + "swc_ecma_transforms_macros", + "swc_ecma_utils", + "swc_ecma_visit", +] + +[[package]] +name = "swc_ecma_transforms_react" +version = "0.116.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "base64 0.13.0", + "dashmap", + "indexmap", + "once_cell", + "regex", + "serde", + "sha-1", + "string_enum", + "swc_atoms", + "swc_common", + "swc_config", + "swc_ecma_ast", + "swc_ecma_parser", + "swc_ecma_transforms_base", + "swc_ecma_transforms_macros", + "swc_ecma_utils", + "swc_ecma_visit", +] + +[[package]] +name = "swc_ecma_transforms_typescript" +version = "0.119.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "serde", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_transforms_react", + "swc_ecma_utils", + "swc_ecma_visit", +] + +[[package]] +name = "swc_ecma_utils" +version = "0.85.1" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "indexmap", + "once_cell", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_visit", + "tracing", +] + +[[package]] +name = "swc_ecma_visit" +version = "0.64.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "num-bigint", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_visit", + "tracing", +] + +[[package]] +name = "swc_ecmascript" +version = "0.159.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "swc_ecma_ast", + "swc_ecma_parser", +] + +[[package]] +name = "swc_eq_ignore_macros" +version = "0.1.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "swc_error_reporters" +version = "0.2.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "anyhow", + "miette", + "once_cell", + "parking_lot", + "swc_common", +] + +[[package]] +name = "swc_macros_common" +version = "0.3.5" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "swc_node_comments" +version = "0.5.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "ahash", + "dashmap", + "swc_common", +] + +[[package]] +name = "swc_timer" +version = "0.6.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "tracing", +] + +[[package]] +name = "swc_trace_macro" +version = "0.1.1" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "swc_visit" +version = "0.3.0" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "either", + "swc_visit_macros", +] + +[[package]] +name = "swc_visit_macros" +version = "0.3.1" +source = "git+https://github.com/swc-project/swc?rev=fd3501b#fd3501bf87f4e711e72e9e8fd12f64f4cfa08157" +dependencies = [ + "Inflector", + "pmutil", + "proc-macro2", + "quote", + "swc_macros_common", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "terminal_size" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +dependencies = [ + "smawk", + "unicode-linebreak", + "unicode-width", +] + +[[package]] +name = "thiserror" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tracing" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7709595b8878a4965ce5e87ebf880a7d39c9afc6837721b21a5a816a8117d921" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typed-arena" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-id" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69fe8d9274f490a36442acb4edfd0c4e473fdfc6a8b5cd32f28a0235761aedbe" + +[[package]] +name = "unicode-ident" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" + +[[package]] +name = "unicode-linebreak" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a52dcaab0c48d931f7cc8ef826fa51690a08e1ea55117ef26f89864f532383f" +dependencies = [ + "regex", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "unreachable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" +dependencies = [ + "void", +] + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +dependencies = [ + "cfg-if 1.0.0", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" + +[[package]] +name = "web-sys" +version = "0.3.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" diff --git a/lib/deno_swc/Cargo.toml b/lib/deno_swc/Cargo.toml new file mode 100644 index 0000000..cafd8fd --- /dev/null +++ b/lib/deno_swc/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +members = [ + "swc_wasm/" +] + +[profile.release] +lto = true +opt-level = "s" \ No newline at end of file diff --git a/lib/deno_swc/LICENSE b/lib/deno_swc/LICENSE new file mode 100644 index 0000000..25aee8d --- /dev/null +++ b/lib/deno_swc/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020-22 Divy Srivastava + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/deno_swc/README.md b/lib/deno_swc/README.md new file mode 100644 index 0000000..aabc6b4 --- /dev/null +++ b/lib/deno_swc/README.md @@ -0,0 +1,78 @@ +<br /> +<p align="center"> + <a href="https://github.com/littledivy/deno_swc"> + <img src="https://raw.githubusercontent.com/littledivy/deno_swc/master/assets/deno_swc.png" alt="deno_swc logo" width="310"> + </a> + <h3 align="center">deno_swc</h3> + +<p align="center"> + The SWC compiler for Deno. + </p> +</p> + + + + +# Usage + +`parse()` + +```typescript +import { parse, print } from "https://deno.land/x/swc@0.2.1/mod.ts"; + +const code = `const x: string = "Hello, Deno SWC!"`; + +const ast = parse(code, { + target: "es2019", + syntax: "typescript", + comments: false, +}); + +// { +// type: "Module", +// span: { start: 0, end: 36, ctxt: 0 }, +// body: [ +// { +// type: "VariableDeclaration", +// span: [Object], +// kind: "const", +// declare: false, +// declarations: [Array] +// } +// ], +// interpreter: null +// } +``` + +`print()` + +```typescript +const { code } = print(ast, { + minify: true, + module: { + type: "commonjs", + }, +}); + +// const x = "Hello, Deno SWC!" +``` + +...and `transform()` + +```typescript +const { code } = transform("const x: number = 2;", { + jsc: { + target: "es2016", + parser: { + syntax: "typescript", + }, + }, +}); + +// const x = 2; +``` + +## Copyright + +deno_swc is licensed under the MIT license. Please see the [LICENSE](LICENSE) +file. diff --git a/lib/deno_swc/assets/deno_swc.png b/lib/deno_swc/assets/deno_swc.png new file mode 100644 index 0000000..ae9a018 Binary files /dev/null and b/lib/deno_swc/assets/deno_swc.png differ diff --git a/lib/deno_swc/compress.ts b/lib/deno_swc/compress.ts new file mode 100644 index 0000000..2c839fc --- /dev/null +++ b/lib/deno_swc/compress.ts @@ -0,0 +1,4 @@ +import { compress } from "https://deno.land/x/lz4@v0.1.2/mod.ts"; + +const name = "./lib/deno_swc_bg.wasm"; +Deno.writeFileSync(name, compress(Deno.readFileSync(name))); diff --git a/lib/deno_swc/deno.jsonc b/lib/deno_swc/deno.jsonc new file mode 100644 index 0000000..f9661b0 --- /dev/null +++ b/lib/deno_swc/deno.jsonc @@ -0,0 +1,10 @@ +{ + "tasks": { + "build": "deno run -A --unstable https://raw.githubusercontent.com/denoland/wasmbuild/0e62b100df246567bee43eea227456222b7fc1dd/main.ts && deno task build:compress", + // Use a canary / local version of wasmbuild + "build:local": "deno run -A --unstable ../wasmbuild/main.ts && deno task build:compress", + "build:compress": "deno run --allow-read --allow-write compress.ts", + "fmt": "deno fmt --ignore=swc_wasm,lib,target --unstable && cargo fmt", + "test": "deno test -A --no-check tests/" + } +} diff --git a/lib/deno_swc/examples/parse.ts b/lib/deno_swc/examples/parse.ts new file mode 100644 index 0000000..01ac1df --- /dev/null +++ b/lib/deno_swc/examples/parse.ts @@ -0,0 +1,13 @@ +import { parse } from "../mod.ts"; + +const start = performance.now(); +console.log(parse( + ` + import * as a from "./a.ts"; +`, + { + syntax: "ecmascript", + }, +)); +const end = performance.now() - start; +console.log(`parse time: ${end}ms`); diff --git a/lib/deno_swc/examples/print.ts b/lib/deno_swc/examples/print.ts new file mode 100644 index 0000000..bf3c151 --- /dev/null +++ b/lib/deno_swc/examples/print.ts @@ -0,0 +1,32 @@ +import { parse, print } from "../mod.ts"; + +const code = ` +interface H { + h: string; +} + +const x: string = \`Hello, $\{"Hello"} Deno SWC!\`; + +switch (x) { + case "value": + console.log(x); + break; + + default: + break; +} +`; + +const ast = parse(code, { + target: "es2019", + syntax: "typescript", + comments: false, +}); +const regeneratedCode = print(ast, { + minify: true, + module: { + type: "commonjs", + }, +}).code; + +console.log(regeneratedCode); diff --git a/lib/deno_swc/examples/transform.ts b/lib/deno_swc/examples/transform.ts new file mode 100644 index 0000000..62440c4 --- /dev/null +++ b/lib/deno_swc/examples/transform.ts @@ -0,0 +1,13 @@ +import { transform } from "../mod.ts"; + +const { code } = transform("const x: number = 2;", { + // @ts-ignore: TransformConfig typings for swc_wasm and node_swc are different + "jsc": { + "target": "es2016", + "parser": { + "syntax": "typescript", + }, + }, +}); + +console.log(code); diff --git a/lib/deno_swc/lib/deno_swc.generated.js b/lib/deno_swc/lib/deno_swc.generated.js new file mode 100644 index 0000000..a9e2cde --- /dev/null +++ b/lib/deno_swc/lib/deno_swc.generated.js @@ -0,0 +1,378 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +// @generated file from build script, do not edit +// deno-lint-ignore-file +// source-hash: cd615b66c9fc26758ad0fac7a225b8fdeeb8cc3f +let wasm; + +const heap = new Array(32).fill(undefined); + +heap.push(undefined, null, true, false); + +function getObject(idx) { + return heap[idx]; +} + +let heap_next = heap.length; + +function dropObject(idx) { + if (idx < 36) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + +const cachedTextDecoder = new TextDecoder("utf-8", { + ignoreBOM: true, + fatal: true, +}); + +cachedTextDecoder.decode(); + +let cachedUint8Memory0; +function getUint8Memory0() { + if (cachedUint8Memory0.byteLength === 0) { + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8Memory0; +} + +function getStringFromWasm0(ptr, len) { + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); +} + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; +} + +let WASM_VECTOR_LEN = 0; + +const cachedTextEncoder = new TextEncoder("utf-8"); + +const encodeString = function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +}; + +function passStringToWasm0(arg, malloc, realloc) { + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length); + getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len); + + const mem = getUint8Memory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3); + const view = getUint8Memory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +let cachedInt32Memory0; +function getInt32Memory0() { + if (cachedInt32Memory0.byteLength === 0) { + cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); + } + return cachedInt32Memory0; +} +/** + * @param {string} s + * @param {any} opts + * @returns {any} + */ +export function minifySync(s, opts) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0( + s, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + wasm.minifySync(retptr, ptr0, len0, addHeapObject(opts)); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return takeObject(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** + * @param {string} s + * @param {any} opts + * @returns {any} + */ +export function parseSync(s, opts) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0( + s, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + wasm.parseSync(retptr, ptr0, len0, addHeapObject(opts)); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return takeObject(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** + * @param {any} s + * @param {any} opts + * @returns {any} + */ +export function printSync(s, opts) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.printSync(retptr, addHeapObject(s), addHeapObject(opts)); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return takeObject(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** + * @param {string} s + * @param {any} opts + * @returns {any} + */ +export function transformSync(s, opts) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0( + s, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + wasm.transformSync(retptr, ptr0, len0, addHeapObject(opts)); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return takeObject(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +const imports = { + __wbindgen_placeholder__: { + __wbg_new0_6b49a1fca8534d39: function () { + const ret = new Date(); + return addHeapObject(ret); + }, + __wbg_getTimezoneOffset_d7a89256f8181a06: function (arg0) { + const ret = getObject(arg0).getTimezoneOffset(); + return ret; + }, + __wbindgen_object_drop_ref: function (arg0) { + takeObject(arg0); + }, + __wbg_getTime_7c8d3b79f51e2b87: function (arg0) { + const ret = getObject(arg0).getTime(); + return ret; + }, + __wbg_new_693216e109162396: function () { + const ret = new Error(); + return addHeapObject(ret); + }, + __wbg_stack_0ddaca5d1abfb52f: function (arg0, arg1) { + const ret = getObject(arg1).stack; + const ptr0 = passStringToWasm0( + ret, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + }, + __wbg_error_09919627ac0992f5: function (arg0, arg1) { + try { + console.error(getStringFromWasm0(arg0, arg1)); + } finally { + wasm.__wbindgen_free(arg0, arg1); + } + }, + __wbindgen_string_new: function (arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }, + __wbindgen_json_serialize: function (arg0, arg1) { + const obj = getObject(arg1); + const ret = JSON.stringify(obj === undefined ? null : obj); + const ptr0 = passStringToWasm0( + ret, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + }, + __wbindgen_json_parse: function (arg0, arg1) { + const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }, + __wbindgen_throw: function (arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }, + }, +}; + +const wasm_url = new URL("deno_swc_bg.wasm", import.meta.url); + +/** + * Decompression callback + * + * @callback decompressCallback + * @param {Uint8Array} compressed + * @return {Uint8Array} decompressed + */ + +/** Instantiates an instance of the Wasm module returning its functions. + * @remarks It is safe to call this multiple times and once successfully + * loaded it will always return a reference to the same object. + * @param {decompressCallback=} transform + */ +export async function instantiate(transform) { + return (await instantiateWithInstance(transform)).exports; +} + +let instanceWithExports; +let lastLoadPromise; + +/** Instantiates an instance of the Wasm module along with its exports. + * @remarks It is safe to call this multiple times and once successfully + * loaded it will always return a reference to the same object. + * @param {decompressCallback=} transform + * @returns {Promise<{ + * instance: WebAssembly.Instance; + * exports: { minifySync: typeof minifySync; parseSync: typeof parseSync; printSync: typeof printSync; transformSync: typeof transformSync } + * }>} + */ +export function instantiateWithInstance(transform) { + if (instanceWithExports != null) { + return Promise.resolve(instanceWithExports); + } + if (lastLoadPromise == null) { + lastLoadPromise = (async () => { + try { + const instance = (await instantiateModule(transform)).instance; + wasm = instance.exports; + cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + instanceWithExports = { + instance, + exports: { minifySync, parseSync, printSync, transformSync }, + }; + return instanceWithExports; + } finally { + lastLoadPromise = null; + } + })(); + } + return lastLoadPromise; +} + +/** Gets if the Wasm module has been instantiated. */ +export function isInstantiated() { + return instanceWithExports != null; +} + +async function instantiateModule(transform) { + switch (wasm_url.protocol) { + case "file:": { + if (typeof Deno !== "object") { + throw new Error("file urls are not supported in this environment"); + } + + if ("permissions" in Deno) { + Deno.permissions.request({ name: "read", path: wasm_url }); + } + const wasmCode = await Deno.readFile(wasm_url); + return WebAssembly.instantiate( + !transform ? wasmCode : transform(wasmCode), + imports, + ); + } + case "https:": + case "http:": { + if (typeof Deno === "object" && "permissions" in Deno) { + Deno.permissions.request({ name: "net", host: wasm_url.host }); + } + const wasmResponse = await fetch(wasm_url); + if (transform) { + const wasmCode = new Uint8Array(await wasmResponse.arrayBuffer()); + return WebAssembly.instantiate(transform(wasmCode), imports); + } + if ( + wasmResponse.headers.get("content-type")?.toLowerCase().startsWith( + "application/wasm", + ) + ) { + return WebAssembly.instantiateStreaming(wasmResponse, imports); + } else { + return WebAssembly.instantiate( + await wasmResponse.arrayBuffer(), + imports, + ); + } + } + default: + throw new Error(`Unsupported protocol: ${wasm_url.protocol}`); + } +} diff --git a/lib/deno_swc/lib/deno_swc_bg.wasm b/lib/deno_swc/lib/deno_swc_bg.wasm new file mode 100644 index 0000000..3980cf2 Binary files /dev/null and b/lib/deno_swc/lib/deno_swc_bg.wasm differ diff --git a/lib/deno_swc/mod.ts b/lib/deno_swc/mod.ts new file mode 100644 index 0000000..bcbf228 --- /dev/null +++ b/lib/deno_swc/mod.ts @@ -0,0 +1,21 @@ +import { decompress } from "https://deno.land/x/lz4@v0.1.2/mod.ts"; +import type { + Config, + ParseOptions, + Program, +} from "https://esm.sh/@swc/core@1.2.212/types.d.ts"; +import { instantiate } from "./lib/deno_swc.generated.js"; + +const { parseSync, printSync, transformSync } = await instantiate(decompress); + +export function parse(source: string, opts: ParseOptions): Program { + return parseSync(source, opts); +} + +export function print(program: Program, opts?: Config): { code: string } { + return printSync(program, opts || {}); +} + +export function transform(source: string, opts: Config): { code: string } { + return transformSync(source, opts); +} diff --git a/lib/deno_swc/swc_wasm/Cargo.toml b/lib/deno_swc/swc_wasm/Cargo.toml new file mode 100644 index 0000000..5c7a096 --- /dev/null +++ b/lib/deno_swc/swc_wasm/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "deno_swc" +version = "0.0.1" +authors = ["Divy Srivastava <dj.srivastava23@gmail.com>"] +edition = "2018" +publish = false + +[lib] +crate_type = ["cdylib"] +path = "lib.rs" + +[dependencies] +anyhow = "1.0.42" +wee_alloc = { version = "0.4.5", optional = true } +console_error_panic_hook = "0.1.6" +once_cell = "1.3.1" +path-clean = "0.1" +serde = {version = "1", features = ["derive"]} +serde_json = "1" +swc = { git = "https://github.com/swc-project/swc", rev = "fd3501b" } +swc_ecmascript = { git = "https://github.com/swc-project/swc", rev = "fd3501b" } +swc_common = { git = "https://github.com/swc-project/swc", rev = "fd3501b" } +wasm-bindgen = {version = "0.2", features = ["serde-serialize"]} +wasm-bindgen-futures = "0.4.8" +syn = "1.0.65" +url = "2.2.2" + +[features] +default = ["wee_alloc"] + diff --git a/lib/deno_swc/swc_wasm/build.js b/lib/deno_swc/swc_wasm/build.js new file mode 100644 index 0000000..66caa80 --- /dev/null +++ b/lib/deno_swc/swc_wasm/build.js @@ -0,0 +1,106 @@ +import { encode } from "https://deno.land/std@0.103.0/encoding/base64.ts"; +import Terser from "https://esm.sh/terser@4.8.0"; +import * as lz4 from "https://deno.land/x/lz4@v0.1.2/mod.ts"; + +const name = "deno_swc"; + +const encoder = new TextEncoder(); + +async function requires(...executables) { + const where = Deno.build.os === "windows" ? "where" : "which"; + + for (const executable of executables) { + const process = Deno.run({ + cmd: [where, executable], + stderr: "null", + stdin: "null", + stdout: "null", + }); + + if (!(await process.status()).success) { + err(`Could not find required build tool ${executable}`); + } + } +} + +async function run(msg, cmd) { + log(msg); + + const process = Deno.run({ cmd }); + + if (!(await process.status()).success) { + err(`${msg} failed`); + } +} + +function log(text) { + console.log(`[log] ${text}`); +} + +function err(text) { + console.log(`[err] ${text}`); + return Deno.exit(1); +} + +await requires("rustup", "rustc", "cargo", "wasm-bindgen"); + +if (!(await Deno.stat("Cargo.toml")).isFile) { + err(`the build script should be executed in the "${name}" root`); +} + +await run("building wasm", ["cargo", "build", "--release", "--target", "wasm32-unknown-unknown"]); + +await run( + "building using wasm-pack", + ["wasm-bindgen", "target/wasm32-unknown-unknown/release/deno_swc.wasm" , "--target", "deno", "--weak-refs", "--out-dir", "pkg/"], +); + +const wasm = await Deno.readFile(`pkg/${name}_bg.wasm`); + +const compressed = lz4.compress(wasm); +console.log( + `compressed wasm using lz4 (reduction: ${wasm.length - + compressed.length} bytes, size: ${compressed.length} bytes)`, +); + +const encoded = encode(compressed); + +log( + `encoded wasm using base64, size increase: ${encoded.length - + wasm.length} bytes`, +); + +log("inlining wasm in js"); +const source = `import * as lz4 from "https://deno.land/x/lz4@v0.1.2/mod.ts";export const source=lz4.decompress(Uint8Array.from(atob("${encoded}"),c=>c.charCodeAt(0)));`; + +let init = await Deno.readTextFile(`pkg/${name}.js`); +let lines = init.split('\n'); +// We want to replace this code. +for (let i = 1; i < 4; i++) lines.splice(-i); +init = lines.join('\n'); +init += `\nconst wasmModule = new WebAssembly.Module(source);\nconst wasmInstance = new WebAssembly.Instance(wasmModule, imports);\nconst wasm = wasmInstance.exports;\n`; +console.log(init) + +log("minifying js"); +const output = Terser.minify(`${source}\n${init}`, { + mangle: { module: true }, + output: { + preamble: "//deno-fmt-ignore-file", + }, +}); + +if (output.error) { + err(`encountered error when minifying: ${output.error}`); +} + +const reduction = new Blob([(`${source}\n${init}`)]).size - + new Blob([output.code]).size; +log(`minified js, size reduction: ${reduction} bytes`); + +log(`writing output to file ("wasm.js")`); +await Deno.writeFile("wasm.js", encoder.encode(output.code)); + +const outputFile = await Deno.stat("wasm.js"); +log( + `output file ("wasm.js"), final size is: ${outputFile.size} bytes`, +); diff --git a/lib/deno_swc/swc_wasm/lib.rs b/lib/deno_swc/swc_wasm/lib.rs new file mode 100644 index 0000000..5b24e72 --- /dev/null +++ b/lib/deno_swc/swc_wasm/lib.rs @@ -0,0 +1,184 @@ +// From https://github.com/swc-project/swc/blob/main/crates/binding_core_wasm/src/lib.rs + +use anyhow::{Context, Error}; +use once_cell::sync::Lazy; +use std::sync::Arc; +use swc::{ + config::{ + ErrorFormat, JsMinifyOptions, Options, ParseOptions, SourceMapsConfig, + }, + try_with_handler, Compiler, +}; +use swc_common::{comments::Comments, FileName, FilePathMapping, SourceMap}; +use swc_ecmascript::ast::{EsVersion, Program}; +use wasm_bindgen::prelude::*; + +fn convert_err(err: Error, error_format: ErrorFormat) -> JsValue { + error_format.format(&err).into() +} + +#[wasm_bindgen(js_name = "minifySync")] +pub fn minify_sync(s: &str, opts: JsValue) -> Result<JsValue, JsValue> { + console_error_panic_hook::set_once(); + + let c = compiler(); + + try_with_handler( + c.cm.clone(), + swc::HandlerOpts { + ..Default::default() + }, + |handler| { + c.run(|| { + let opts: JsMinifyOptions = + opts.into_serde().context("failed to parse options")?; + + let fm = c.cm.new_source_file(FileName::Anon, s.into()); + let program = c + .minify(fm, handler, &opts) + .context("failed to minify file")?; + + JsValue::from_serde(&program).context("failed to serialize json") + }) + }, + ) + .map_err(|e| convert_err(e, ErrorFormat::Normal)) +} + +#[wasm_bindgen(js_name = "parseSync")] +pub fn parse_sync(s: &str, opts: JsValue) -> Result<JsValue, JsValue> { + console_error_panic_hook::set_once(); + + let c = compiler(); + + try_with_handler( + c.cm.clone(), + swc::HandlerOpts { + ..Default::default() + }, + |handler| { + c.run(|| { + let opts: ParseOptions = + opts.into_serde().context("failed to parse options")?; + + let fm = c.cm.new_source_file(FileName::Anon, s.into()); + + let cmts = c.comments().clone(); + let comments = if opts.comments { + Some(&cmts as &dyn Comments) + } else { + None + }; + + let program = c + .parse_js( + fm, + handler, + opts.target, + opts.syntax, + opts.is_module, + comments, + ) + .context("failed to parse code")?; + + JsValue::from_serde(&program).context("failed to serialize json") + }) + }, + ) + .map_err(|e| convert_err(e, ErrorFormat::Normal)) +} + +#[wasm_bindgen(js_name = "printSync")] +pub fn print_sync(s: JsValue, opts: JsValue) -> Result<JsValue, JsValue> { + console_error_panic_hook::set_once(); + + let c = compiler(); + + try_with_handler( + c.cm.clone(), + swc::HandlerOpts { + ..Default::default() + }, + |_handler| { + c.run(|| { + let opts: Options = + opts.into_serde().context("failed to parse options")?; + + let program: Program = + s.into_serde().context("failed to deserialize program")?; + + let s = c + .print( + &program, + None, + None, + true, + opts.codegen_target().unwrap_or(EsVersion::Es2020), + opts + .source_maps + .clone() + .unwrap_or(SourceMapsConfig::Bool(false)), + &Default::default(), + None, + opts.config.minify.into(), + None, + opts.config.emit_source_map_columns.into_bool(), + false, + ) + .context("failed to print code")?; + + JsValue::from_serde(&s).context("failed to serialize json") + }) + }, + ) + .map_err(|e| convert_err(e, ErrorFormat::Normal)) +} + +#[wasm_bindgen(js_name = "transformSync")] +pub fn transform_sync(s: &str, opts: JsValue) -> Result<JsValue, JsValue> { + console_error_panic_hook::set_once(); + + let c = compiler(); + let opts: Options = opts + .into_serde() + .context("failed to parse options") + .map_err(|e| convert_err(e, ErrorFormat::Normal))?; + + let error_format = opts.experimental.error_format.unwrap_or_default(); + + try_with_handler( + c.cm.clone(), + swc::HandlerOpts { + ..Default::default() + }, + |handler| { + c.run(|| { + let fm = c.cm.new_source_file( + if opts.filename.is_empty() { + FileName::Anon + } else { + FileName::Real(opts.filename.clone().into()) + }, + s.into(), + ); + let out = c + .process_js_file(fm, handler, &opts) + .context("failed to process input file")?; + + JsValue::from_serde(&out).context("failed to serialize json") + }) + }, + ) + .map_err(|e| convert_err(e, error_format)) +} + +/// Get global sourcemap +fn compiler() -> Arc<Compiler> { + static C: Lazy<Arc<Compiler>> = Lazy::new(|| { + let cm = Arc::new(SourceMap::new(FilePathMapping::empty())); + + Arc::new(Compiler::new(cm)) + }); + + C.clone() +} diff --git a/lib/deno_swc/tests/deps.ts b/lib/deno_swc/tests/deps.ts new file mode 100644 index 0000000..b57376e --- /dev/null +++ b/lib/deno_swc/tests/deps.ts @@ -0,0 +1 @@ +export { assert, assertEquals } from "https://deno.land/std/testing/asserts.ts"; diff --git a/lib/deno_swc/tests/parse.test.ts b/lib/deno_swc/tests/parse.test.ts new file mode 100644 index 0000000..9079a9d --- /dev/null +++ b/lib/deno_swc/tests/parse.test.ts @@ -0,0 +1,49 @@ +import { parse } from "../mod.ts"; +import { assertEquals } from "./deps.ts"; + +Deno.test("parse (no error)", () => { + const result = parse("const x: number = 2;", { + "syntax": "typescript", + }); + assertEquals(result, { + type: "Module", + body: [ + { + declarations: [ + { + definite: false, + id: { + optional: false, + span: { ctxt: 0, end: 8, start: 7 }, + type: "Identifier", + typeAnnotation: { + span: { ctxt: 0, end: 16, start: 8 }, + type: "TsTypeAnnotation", + typeAnnotation: { + kind: "number", + span: { ctxt: 0, end: 16, start: 10 }, + type: "TsKeywordType", + }, + }, + value: "x", + }, + init: { + raw: "2", + span: { ctxt: 0, end: 20, start: 19 }, + type: "NumericLiteral", + value: 2, + }, + span: { ctxt: 0, end: 20, start: 7 }, + type: "VariableDeclarator", + }, + ], + declare: false, + kind: "const", + span: { ctxt: 0, end: 21, start: 1 }, + type: "VariableDeclaration", + }, + ], + interpreter: null, + span: { ctxt: 0, end: 21, start: 1 }, + }); +}); diff --git a/lib/deno_swc/tests/print.test.ts b/lib/deno_swc/tests/print.test.ts new file mode 100644 index 0000000..a38a109 --- /dev/null +++ b/lib/deno_swc/tests/print.test.ts @@ -0,0 +1,32 @@ +import { print } from "../mod.ts"; +import { assertEquals } from "./deps.ts"; + +Deno.test("print (no error)", () => { + const result = print({ + "type": "Module", + "span": { "start": 21, "end": 33, "ctxt": 0 }, + "body": [{ + "type": "ClassDeclaration", + "identifier": { + "type": "Identifier", + "span": { "start": 27, "end": 28, "ctxt": 0 }, + "value": "X", + "optional": false, + }, + "declare": false, + "span": { "start": 21, "end": 32, "ctxt": 0 }, + "decorators": [], + "body": [], + "superClass": null, + "isAbstract": false, + "typeParams": null, + "superTypeParams": null, + "implements": [], + }, { + "type": "EmptyStatement", + "span": { "start": 32, "end": 33, "ctxt": 0 }, + }], + "interpreter": null, + }, {}); + assertEquals(result.code.trim(), "class X {\n}\n;"); +}); diff --git a/lib/deno_swc/tests/transform.test.ts b/lib/deno_swc/tests/transform.test.ts new file mode 100644 index 0000000..faffcb6 --- /dev/null +++ b/lib/deno_swc/tests/transform.test.ts @@ -0,0 +1,16 @@ +import { transform } from "../mod.ts"; +import { assertEquals } from "./deps.ts"; + +Deno.test("transform (no error)", () => { + const result = transform("const x: number = 2; console.log(x);", { + // deno-lint-ignore ban-ts-comment + // @ts-ignore + "jsc": { + "target": "es2016", + "parser": { + "syntax": "typescript", + }, + }, + }); + assertEquals(result.code.trim(), "const x = 2;\nconsole.log(x);"); +}); diff --git a/lib/deno_swc/version.ts b/lib/deno_swc/version.ts new file mode 100644 index 0000000..65b2fe4 --- /dev/null +++ b/lib/deno_swc/version.ts @@ -0,0 +1 @@ +export const version = "0.2.1"; diff --git a/reference/empty-test.fprg b/reference/empty-test.fprg new file mode 100644 index 0000000..4e214eb --- /dev/null +++ b/reference/empty-test.fprg @@ -0,0 +1,15 @@ +<?xml version="1.0"?> +<flowgorithm fileversion="3.0"> + <attributes> + <attribute name="name" value=""/> + <attribute name="authors" value="skybl"/> + <attribute name="about" value=""/> + <attribute name="saved" value="2022-10-11 01:08:26 AM"/> + <attribute name="created" value="c2t5Ymw7UE9ORDsyMDIyLTEwLTExOzAxOjA1OjQ0IEFNOzIxMDY="/> + <attribute name="edited" value="c2t5Ymw7UE9ORDsyMDIyLTEwLTExOzAxOjA4OjI2IEFNOzQ7MjIyMA=="/> + </attributes> + <function name="Main" type="None" variable=""> + <parameters/> + <body/> + </function> +</flowgorithm> diff --git a/reference/out.fprg b/reference/out.fprg new file mode 100644 index 0000000..532d07b --- /dev/null +++ b/reference/out.fprg @@ -0,0 +1,67 @@ +<?xml version="1.0"?> +<flowgorithm fileversion="3.0"> + <attributes> + <attribute name="name" value="benchtest.ts"/> + <attribute name="authors" value="skybl, ezfprg"/> + <attribute name="about" value="test program for transpiler benchmarks"/> + <attribute name="saved" value="2022-10-19 01:17:24 AM"/> + <attribute name="created" value="c2t5Ymw7cG9uZDsyMDIyLTEwLTE5OzAxOjE3OjI0IEFN"/> + <attribute name="edited" value="c2t5Ymw7cG9uZDsyMDIyLTEwLTE5OzAxOjE3OjI0IEFNOzU7Mjk5MQ=="/> + </attributes> + <function name="Main" type="None" variable=""> + <parameters/> + <body> + <declare name="a, b" type="Integer" array="False" size=""/> + <assign variable="a" expression="1"/> + <input variable="b"/> + <output expression="a + b" newline="True"/> + <declare name="c" type="Real" array="False" size=""/> + <assign variable="c" expression="20 / ((5 + a) ^ (a + b))"/> + <output expression="c" newline="True"/> + <declare name="f" type="Integer" array="False" size=""/> + <declare name="e" type="Real" array="False" size=""/> + <assign variable="e" expression="1.4"/> + <assign variable="f" expression="2"/> + <declare name="g" type="Real" array="False" size=""/> + <assign variable="g" expression="e / f"/> + <declare name="h" type="Boolean" array="False" size=""/> + <assign variable="h" expression="false"/> + <output expression="" " & e & " / " & f & " = " & g & ", h = " & h" newline="True"/> + <declare name="i" type="String" array="False" size=""/> + <assign variable="i" expression="2 & " hello""/> + <declare name="j" type="String" array="False" size=""/> + <assign variable="j" expression="i & " world""/> + <output expression="j" newline="True"/> + <if expression="a < b"> + <then> + <output expression=""a is less than b"" newline="True"/> + </then> + <else> + <output expression=""a is more than b"" newline="True"/> + </else> + </if> + <if expression="true"> + <then> + <output expression=""single arm"" newline="True"/> + </then> + <else> + </else> + </if> + <declare name="k" type="Integer" array="False" size=""/> + <assign variable="k" expression="0"/> + <while expression="k < 10"> + <output expression="k" newline="True"/> + <assign variable="k" expression="k + 1"/> + </while> + <declare name="l" type="Integer" array="False" size=""/> + <assign variable="l" expression="0"/> + <for variable="l" start="0" end="10" direction="inc" step="1"> + <output expression="l" newline="True"/> + </for> + <for variable="l" start="20" end="10" direction="dec" step="2"> + <output expression="l" newline="True"/> + </for> + + </body> + </function> +</flowgorithm> diff --git a/reference/ref-alt.fprg b/reference/ref-alt.fprg new file mode 100644 index 0000000..317705f --- /dev/null +++ b/reference/ref-alt.fprg @@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<flowgorithm fileversion="3.0"> + <attributes> + <attribute name="name" value=""/> + <attribute name="authors" value="skybl"/> + <attribute name="about" value=""/> + <attribute name="saved" value="2022-10-07 06:41:15 PM"/> + <attribute name="created" value="c2t5Ymw7UE9ORDsyMDIyLTEwLTA3OzA2OjQwOjQ4IFBNOzIxMzQ="/> + <attribute name="edited" value="c2t5Ymw7UE9ORDsyMDIyLTEwLTA3OzA2OjQxOjE1IFBNOzE7MjIzNw=="/> + </attributes> + <function name="Main" type="None" variable=""> + <parameters/> + <body> + <output expression="10 / 2" newline="True"/> + </body> + </function> +</flowgorithm> diff --git a/reference/reference-new-new-new b/reference/reference-new-new-new new file mode 100644 index 0000000..444a896 --- /dev/null +++ b/reference/reference-new-new-new @@ -0,0 +1,45 @@ +<?xml version="1.0"?> +<flowgorithm fileversion="3.0"> + <attributes> + <attribute name="name" value="Test Name"/> + <attribute name="authors" value="skybl"/> + <attribute name="about" value="Test Description"/> + <attribute name="saved" value="2022-10-07 01:22:57 AM"/> + <attribute name="created" value="c2t5Ymw7REVTS1RPUC03VEFWOEpBOzIwMjItMTAtMDY7MDE6NDU6MDMgQU07Mjg3Mg=="/> + <attribute name="edited" value="c2t5Ymw7REVTS1RPUC03VEFWOEpBOzIwMjItMTAtMDc7MDE6MjI6NTcgQU07NTsyOTg5"/> + </attributes> + <function name="Main" type="None" variable=""> + <parameters/> + <body> + <comment text="this is a comment"/> + <declare name="a, b" type="Integer" array="False" size=""/> + <assign variable="a" expression="1"/> + <input variable="b"/> + <output expression="a + b" newline="True"/> + <if expression="a < b"> + <then> + <output expression=""good"" newline="True"/> + </then> + <else> + <output expression=""bad"" newline="True"/> + </else> + </if> + <while expression="a < 5"> + <output expression=""a is now " & a" newline="True"/> + <assign variable="a" expression="a + 1"/> + </while> + <for variable="b" start="0" end="10" direction="inc" step="1"> + <output expression=""b is now " & b" newline="True"/> + </for> + </body> + </function> + <function name="foo" type="Integer" variable="b"> + <parameters> + <parameter name="a" type="Integer" array="False"/> + </parameters> + <body> + <declare name="b" type="Integer" array="False" size=""/> + <assign variable="b" expression="a"/> + </body> + </function> +</flowgorithm> diff --git a/reference/reference-new-new.fprg b/reference/reference-new-new.fprg new file mode 100644 index 0000000..421b4a6 --- /dev/null +++ b/reference/reference-new-new.fprg @@ -0,0 +1,44 @@ +<?xml version="1.0"?> +<flowgorithm fileversion="3.0"> + <attributes> + <attribute name="name" value="Test Name"/> + <attribute name="authors" value="skybl"/> + <attribute name="about" value="Test Description"/> + <attribute name="saved" value="2022-10-07 12:29:19 AM"/> + <attribute name="created" value="c2t5Ymw7REVTS1RPUC03VEFWOEpBOzIwMjItMTAtMDY7MDE6NDU6MDMgQU07Mjg3Mg=="/> + <attribute name="edited" value="c2t5Ymw7REVTS1RPUC03VEFWOEpBOzIwMjItMTAtMDc7MTI6Mjk6MTkgQU07NDsyOTk1"/> + </attributes> + <function name="Main" type="None" variable=""> + <parameters/> + <body> + <declare name="a, b" type="Integer" array="False" size=""/> + <assign variable="a" expression="1"/> + <input variable="b"/> + <output expression="a + b" newline="True"/> + <if expression="a < b"> + <then> + <output expression=""good"" newline="True"/> + </then> + <else> + <output expression=""bad"" newline="True"/> + </else> + </if> + <while expression="a < 5"> + <output expression=""a is now " & a" newline="True"/> + <assign variable="a" expression="a + 1"/> + </while> + <for variable="b" start="0" end="10" direction="inc" step="1"> + <output expression=""b is now " & b" newline="True"/> + </for> + </body> + </function> + <function name="foo" type="Integer" variable="b"> + <parameters> + <parameter name="a" type="Integer" array="False"/> + </parameters> + <body> + <declare name="b" type="Integer" array="False" size=""/> + <assign variable="b" expression="a"/> + </body> + </function> +</flowgorithm> diff --git a/reference/reference-new.fprg b/reference/reference-new.fprg new file mode 100644 index 0000000..6dc14b9 --- /dev/null +++ b/reference/reference-new.fprg @@ -0,0 +1,44 @@ +<?xml version="1.0"?> +<flowgorithm fileversion="3.0"> + <attributes> + <attribute name="name" value="Test Name"/> + <attribute name="authors" value="skybl"/> + <attribute name="about" value="Test Description"/> + <attribute name="saved" value="2022-10-07 12:17:19 AM"/> + <attribute name="created" value="c2t5Ymw7REVTS1RPUC03VEFWOEpBOzIwMjItMTAtMDY7MDE6NDU6MDMgQU07Mjg3Mg=="/> + <attribute name="edited" value="c2t5Ymw7REVTS1RPUC03VEFWOEpBOzIwMjItMTAtMDc7MTI6MTc6MTkgQU07MjsyOTkw"/> + </attributes> + <function name="Main" type="None" variable=""> + <parameters/> + <body> + <declare name="a, b" type="Integer" array="False" size=""/> + <assign variable="a" expression="1"/> + <input variable="b"/> + <output expression="a + b" newline="True"/> + <if expression="a < b"> + <then> + <output expression=""good"" newline="True"/> + </then> + <else> + <output expression=""bad"" newline="True"/> + </else> + </if> + <while expression="a < 5"> + <output expression=""a is now " & a" newline="True"/> + <assign variable="a" expression="a + 1"/> + </while> + <for variable="b" start="0" end="10" direction="inc" step="1"> + <output expression=""b is now " & b" newline="True"/> + </for> + </body> + </function> + <function name="foo" type="Integer" variable="b"> + <parameters> + <parameter name="a" type="Integer" array="False"/> + </parameters> + <body> + <declare name="b" type="Integer" array="False" size=""/> + <assign variable="b" expression="a"/> + </body> + </function> +</flowgorithm> diff --git a/reference/reference.fprg b/reference/reference.fprg new file mode 100644 index 0000000..2e442ee --- /dev/null +++ b/reference/reference.fprg @@ -0,0 +1,45 @@ +<?xml version="1.0"?> +<flowgorithm fileversion="3.0"> + <attributes> + <attribute name="name" value="Test Name"/> + <attribute name="authors" value="skybl"/> + <attribute name="about" value="Test Description"/> + <attribute name="saved" value="2022-10-06 01:53:41 AM"/> + <attribute name="created" value="c2t5Ymw7REVTS1RPUC03VEFWOEpBOzIwMjItMTAtMDY7MDE6NDU6MDMgQU07Mjg3Mg=="/> + <attribute name="edited" value="c2t5Ymw7REVTS1RPUC03VEFWOEpBOzIwMjItMTAtMDY7MDE6NTM6NDEgQU07MTsyOTgx"/> + </attributes> + <function name="Main" type="None" variable=""> + <parameters/> + <body> + <declare name="a, b" type="Integer" array="False" size=""/> + <assign variable="a" expression="1"/> + <input variable="b"/> + <output expression="a + b" newline="True"/> + <if expression="a < b"> + <then> + <output expression=""good"" newline="True"/> + </then> + <else> + <output expression=""bad"" newline="True"/> + </else> + </if> + <while expression="a < 5"> + <output expression=""a is now " & a" newline="True"/> + <assign variable="a" expression="a + 1"/> + </while> + <for variable="b" start="0" end="10" direction="inc" step="1"> + <output expression=""b is now " & b" newline="True"/> + </for> + <call expression="foo(a)"/> + </body> + </function> + <function name="foo" type="Integer" variable="b"> + <parameters> + <parameter name="a" type="Integer" array="False"/> + </parameters> + <body> + <declare name="b" type="Integer" array="False" size=""/> + <assign variable="b" expression="a"/> + </body> + </function> +</flowgorithm> diff --git a/scratch/asgn_6_sequential.ts b/scratch/asgn_6_sequential.ts new file mode 100644 index 0000000..3fb796e --- /dev/null +++ b/scratch/asgn_6_sequential.ts @@ -0,0 +1,22 @@ +meta("username", "skybl"); +meta("hostname", "pond"); +meta("editVersion", "4"); +meta("editMysteryNumber", "2982"); +attr("name", "DESIGN/CREATE A PROGRAM USING THE SEQUENCE STRUCTURE AND NAMED CONSTANTS"); +attr("authors", "Jacob Teatro"); +attr("about", "Current Semester: 1\nCourse Section: 0072\nBlackboard Username: jtteatro"); + +let userBal: int, userOverdrafts: int; +let OVERDRAFTfee = 2, MINfee = 0.01; + +print("Bank Calculator v0.0.1"); +print("Please enter your current balance: "); +input(userBal); +print("Please enter the number of overdrafts you have had this month: "); +input(userOverdrafts); + +let totalMinFee = userBal * MINfee; +let totalOverdraftFee = userOverdrafts * OVERDRAFTfee; + +print("Your total fee is: " + (totalMinFee + totalOverdraftFee)); +print("Thank you for using Bank Calculator v0.0.1"); diff --git a/scratch/asgn_7_decision.ts b/scratch/asgn_7_decision.ts new file mode 100644 index 0000000..fe6ec03 --- /dev/null +++ b/scratch/asgn_7_decision.ts @@ -0,0 +1,7 @@ +meta("username", "skybl"); +meta("hostname", "pond"); +meta("editVersion", "4"); +meta("editMysteryNumber", "2982"); +attr("name", "DESIGN/CREATE A PROGRAM USING THE SEQUENCE STRUCTURE AND NAMED CONSTANTS"); +attr("authors", "Jacob Teatro"); +attr("about", "Current Semester: 1\nCourse Section: 0072\nBlackboard Username: jtteatro"); diff --git a/scratch/fprg_errant.ts b/scratch/fprg_errant.ts new file mode 100644 index 0000000..9eaa386 --- /dev/null +++ b/scratch/fprg_errant.ts @@ -0,0 +1,7 @@ +let y = 0; +while (y < 2) { + let i = 0; + print(i); +} + +print(i); diff --git a/scratch/optimization.md b/scratch/optimization.md new file mode 100644 index 0000000..8f2b185 --- /dev/null +++ b/scratch/optimization.md @@ -0,0 +1,72 @@ +benchmark time (avg) (min … max) p75 p99 p995 +----------------------------------------------------------------------------------- ----------------------------- +transform 53.55 µs/iter (40.47 µs … 3.71 ms) 49.03 µs 221.54 µs 332.98 µs +transformBlock 11.67 µs/iter (9.46 µs … 869.33 µs) 10.8 µs 33.09 µs 36.68 µs +transformVariableDecl 612.18 ns/iter (531.9 ns … 960.45 ns) 615.87 ns 960.45 ns 960.45 ns +transformExpr :: `20 / ((5 + a) ^ (a + b))` 509.35 ns/iter (466.79 ns … 773.72 ns) 515.96 ns 756.48 ns 773.72 ns +transformBlockCallExpr :: `print(a + b)` 451 ns/iter (403.7 ns … 772.28 ns) 462.06 ns 700.4 ns 772.28 ns + +[+] check if string contains escapable characters before + replacing + +transform 36.27 µs/iter (29.66 µs … 1.42 ms) 33.1 µs 104.82 µs 247.19 µs +transformBlock 5.72 µs/iter (5.63 µs … 6.17 µs) 5.71 µs 6.17 µs 6.17 µs +transformVariableDecl 312.97 ns/iter (289.81 ns … 432.07 ns) 319.6 ns 389.74 ns 432.07 ns +transformExpr :: `20 / ((5 + a) ^ (a + b))` 453.37 ns/iter (429.78 ns … 523.84 ns) 459.99 ns 495.72 ns 523.84 ns +transformBlockCallExpr :: `print(a + b)` 194.72 ns/iter (184.87 ns … 239.98 ns) 198.91 ns 227.68 ns 239.71 ns + +[-] move idents into TransformState, had to change + benchmarks slightly + +transform 37.73 µs/iter (29.89 µs … 1.74 ms) 34.41 µs 147.62 µs 244.81 µs +transformBlock 6.17 µs/iter (5.36 µs … 660.08 µs) 6.28 µs 8.71 µs 11.31 µs +transformVariableDecl 329.67 ns/iter (300.06 ns … 503.69 ns) 332.52 ns 492.28 ns 503.69 ns +transformExpr :: `20 / ((5 + a) ^ (a + b))` 473.44 ns/iter (431.62 ns … 637.82 ns) 479.82 ns 582.41 ns 637.82 ns +transformBlockCallExpr :: `print(a + b)` 197.26 ns/iter (179.65 ns … 319.4 ns) 202.18 ns 241.29 ns 244.67 ns + +[-] switch back to using strings as types + +transform 37.13 µs/iter (31.27 µs … 2.54 ms) 33.76 µs 112.42 µs 226.41 µs +transformBlock 7.41 µs/iter (6.83 µs … 576.56 µs) 7.19 µs 10.87 µs 21.64 µs +transformVariableDecl 523.43 ns/iter (503.78 ns … 672.13 ns) 525.52 ns 628.98 ns 672.13 ns +transformExpr :: `20 / ((5 + a) ^ (a + b))` 450.4 ns/iter (430.57 ns … 542.85 ns) 455.2 ns 514.45 ns 542.85 ns +transformBlockCallExpr :: `print(a + b)` 189.01 ns/iter (180.33 ns … 286.61 ns) 192.17 ns 219.97 ns 248.98 ns + +[+] iterate through typeNames instead of Object.entries() + in transformVariableDecl() + +transform 36.18 µs/iter (29.69 µs … 3.26 ms) 32.74 µs 94.19 µs 242.39 µs +transformBlock 5.93 µs/iter (5.44 µs … 832.39 µs) 5.85 µs 8.3 µs 9.77 µs +transformVariableDecl 333.23 ns/iter (316.84 ns … 426.59 ns) 336.35 ns 412.75 ns 426.59 ns +transformExpr :: `20 / ((5 + a) ^ (a + b))` 445.46 ns/iter (426.16 ns … 512.61 ns) 450.72 ns 501.26 ns 512.61 ns +transformBlockCallExpr :: `print(a + b)` 191.11 ns/iter (183.08 ns … 240.99 ns) 194.36 ns 216 ns 223.62 ns + +[+] made indent a string in state, add indent string + before statement instead of passing it + +transform 34.06 µs/iter (28.41 µs … 1.44 ms) 30.99 µs 110.45 µs 222.66 µs +transformBlock 5.62 µs/iter (5.01 µs … 1.08 ms) 5.58 µs 6.8 µs 8.48 µs +transformVariableDecl 306.54 ns/iter (291.54 ns … 392.86 ns) 309.48 ns 344.42 ns 392.86 ns +transformExpr :: `20 / ((5 + a) ^ (a + b))` 457.71 ns/iter (431.29 ns … 581.16 ns) 461.86 ns 526.14 ns 581.16 ns +transformBlockCallExpr :: `print(a + b)` 184.39 ns/iter (172.76 ns … 208.97 ns) 188.07 ns 200.83 ns 201.95 ns + +[-] dammit turns out that the regex escape thing wasn't + even matching + +transform 42.14 µs/iter (35.64 µs … 1.48 ms) 38.14 µs 148.44 µs 270.71 µs +transformBlock 7.67 µs/iter (7.17 µs … 533.04 µs) 7.57 µs 9.11 µs 10.88 µs +transformVariableDecl 305.22 ns/iter (291.67 ns … 367.68 ns) 308.55 ns 348.5 ns 367.68 ns +transformExpr :: `20 / ((5 + a) ^ (a + b))` 442.14 ns/iter (425.39 ns … 481.67 ns) 446.63 ns 479.34 ns 481.67 ns +transformBlockCallExpr :: `print(a + b)` 173.47 ns/iter (166.02 ns … 210.7 ns) 177.27 ns 190.81 ns 198.78 ns + +[-] added if statement support, longer benchtest.ts + +transform 50.17 µs/iter (41.6 µs … 2.42 ms) 44.86 µs 200.54 µs 320.54 µs +transformBlock 10.34 µs/iter (9.74 µs … 548.07 µs) 10.14 µs 14.01 µs 20.94 µs +transformVariableDecl 302.8 ns/iter (290.01 ns … 361.69 ns) 305.75 ns 338.17 ns 361.69 ns +transformExpr :: `20 / ((5 + a) ^ (a + b))` 468.38 ns/iter (451.07 ns … 499.1 ns) 472.42 ns 497.34 ns 499.1 ns +transformBlockCallExpr :: `print(a + b)` 180.34 ns/iter (173.4 ns … 205.18 ns) 183.79 ns 196.68 ns 204.69 ns +transformIfStmt 1.56 µs/iter (1.53 µs … 1.67 µs) 1.58 µs 1.67 µs 1.67 µs + +? try making each type declaration group a string and directly append to it? + diff --git a/scratch/qmelztest.ts b/scratch/qmelztest.ts new file mode 100644 index 0000000..2e9c982 --- /dev/null +++ b/scratch/qmelztest.ts @@ -0,0 +1,9 @@ +// new +function a(arg: unknown): asserts arg is string; + +// my impl +function b<T>(arg: T): T extends string ? void : never; + +declare let v: string | number; +a(v); +let x: string = v; \ No newline at end of file diff --git a/scratch/test_includes-vs-logic.ts b/scratch/test_includes-vs-logic.ts new file mode 100644 index 0000000..cfed6a6 --- /dev/null +++ b/scratch/test_includes-vs-logic.ts @@ -0,0 +1,28 @@ +const lua: string[] = [ + "zero", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine" +]; + +Deno.bench("randomgen", () => { + lua[Math.round(Math.random() * 10)]; +}); + +Deno.bench("includes", () => { + const input = lua[Math.round(Math.random() * 10)]; + + ["zero", "five", "six", "nine"].includes(input); +}); + +Deno.bench("logic", () => { + const input = lua[Math.round(Math.random() * 10)]; + + input === "zero" || input === "five" || input === "six" || input === "nine"; +}); \ No newline at end of file diff --git a/scratch/test_lutable-vs-luarray.ts b/scratch/test_lutable-vs-luarray.ts new file mode 100644 index 0000000..e69de29 diff --git a/scratch/test_numcmp-vs-logic.ts b/scratch/test_numcmp-vs-logic.ts new file mode 100644 index 0000000..d4d5c51 --- /dev/null +++ b/scratch/test_numcmp-vs-logic.ts @@ -0,0 +1,82 @@ +import { Type as NType } from "../src/type_utils.ts"; + +const sTypes = ["int", "string", "bool"]; + +let i = 0; + +setInterval(() => { + const r1 = Math.floor(Math.random() * 10 / 3); + const r2 = Math.floor(Math.random() * 10 / 3); + + console.log(`run ${i} comparing ${sTypes[r1]} and ${sTypes[r2]}`); + + const _a: NType = r1; + const _b: NType = r2 + + Deno.bench("NType (boolop)", () => { + _a === _b || _a + _b !== 8; + }); + + Deno.bench("NType (switch)", () => { + let c: boolean; + + if (_a === _b) { + c = true; + } else { + switch (_a + _b) { + case 4: + case 10: c = true; break + case 8: c = false; + } + } + }); + + const a = sTypes[r1]; + const b = sTypes[r2]; + + Deno.bench("SType (if)", () => { + let c: boolean; + + if (a === b) { + c = true; + } else { + if ((a === "int" && b === "string") || (a === "string" && b === "int")) { + c = true; + } else if ((a === "int" && b === "boolean") || (a === "boolean" && b === "int")) { + c = false; + } else if ((a === "boolean" && b === "string") || (a === "string" && b === "boolean")) { + c = true; + } + } + }); + + Deno.bench("SType (boolop)", () => { + let c: boolean; + + if (a === b) { + c = true; + } else { + c = ( + ((a === "int" && b === "string") || (a === "string" && b === "int")) + || ((a === "boolean" && b === "string") || (a === "string" && b === "boolean")) + || !((a === "int" && b === "boolean") || (a === "boolean" || b === "int")) + ); + } + }); + + Deno.bench("SType (if+includes)", () => { + let c: boolean; + + if (a === b) { + c = true; + } else { + c = ( + ([a, b].includes("int") && [a, b].includes("string")) + || ([a, b].includes("boolean") && [a, b].includes("string")) + || !([a, b].includes("int") && [a, b].includes("boolean")) + ); + } + }); + + i++; +}, 5000); \ No newline at end of file diff --git a/scratch/test_switch-vs-lut.ts b/scratch/test_switch-vs-lut.ts new file mode 100644 index 0000000..01765ca --- /dev/null +++ b/scratch/test_switch-vs-lut.ts @@ -0,0 +1,54 @@ +const lua: string[] = [ + "zero", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine" +]; + +Deno.bench("randomgen", () => { + lua[Math.round(Math.random() * 10)]; +}); + +Deno.bench("switch", () => { + const input = lua[Math.round(Math.random() * 10)]; + + let a; + + switch (input) { + case "zero": a = 0; break; + case "one": a = 1; break; + case "two": a = 2; break; + case "three": a = 3; break; + case "four": a = 4; break; + case "five": a = 5; break; + case "six": a = 6; break; + case "seven": a = 7; break; + case "eight": a = 8; break; + case "nine": a = 9; break; + } +}); + +Deno.bench("lookup table", () => { + const input = lua[Math.round(Math.random() * 10)]; + + const lut: Record<string, number> = { + zero: 0, + one: 1, + two: 2, + three: 3, + four: 4, + five: 5, + six: 6, + seven: 7, + eight: 8, + nine: 9 + }; + + const a = lut[input]; +}); diff --git a/src/errors.ts b/src/errors.ts new file mode 100644 index 0000000..3ce804c --- /dev/null +++ b/src/errors.ts @@ -0,0 +1,92 @@ +import { Type, validKeys } from "./type_utils.ts"; + +export class InvalidTypeAnnotation extends SyntaxError { + constructor (value: string, position: number) { + super(`Could not determine type from \`<: ${value}>\`. (at ${position})`); + } +} + +export class MissingType extends SyntaxError { + constructor (variable: string, position: number) { + super(`A type was not given when declaring \`${variable}\`. (at ${position})`); + } +} + +export class InvalidType extends TypeError { + constructor (expected: Type | string, got: Type | string, position: number) { + super(`Expected \`${expected}\`, got \`${got}\`. (at ${position})`); + } +} + +export class InvalidSyntaxType extends SyntaxError { + constructor (expected: string, got: string, position: number) { + super(`Expected \`<${expected}>\`, got \`<${got}>\`. (at ${position})`); + } +} + +export class InvalidExpression extends SyntaxError { + constructor (type: string, position: number) { + super(`Unknown or unsupported expression or literal type \`${type}\`. (at ${position})`); + } +} + +export class InvalidBinaryOp extends TypeError { + constructor (a: Type, b: Type, op: string, position: number) { + super(`Cannot perform operation \`${op}\` on \`${a}\` and \`${b}\`. (at ${position})`); + } +} + +export class UndefinedReference extends ReferenceError { + constructor (name: string, position: number) { + super(`\`${name}\` is not defined, or is a builtin that cannot be used in an expression. (at ${position})`); + } +} + +export class InvalidAssignmentTarget extends SyntaxError { + constructor (position: number) { + super(`Left-hand side of assignment must be an \`Identifier\`. Destructuring not supported. (at ${position})`); + } +} + +export class InvalidArgumentCount extends SyntaxError { + constructor (name: string, count: number, expected: number, position: number) { + super(`\`${name}\` expects ${expected} arguments, got ${count}. (at ${position})`); + } +} + +export class InvalidAttrOrMeta extends Error { + constructor (key: string, group: "attr" | "meta", position: number) { + super(`Expected \`${validKeys[group].join(", ")}\`, got \`${key}\`. (at ${position})`); + } +} + +export class AlreadyDefined extends ReferenceError { + constructor (decl: string, position: number) { + super(`\`${decl}\` is already defined. (at ${position})`); + } +} + +export class ForMissingEnd extends SyntaxError { + constructor (position: number) { + super(`Missing direction and end in for statement (at ${position})\nSee DOCS.md for more info on for statements.`); + } +} + +export class ForMissingInit extends SyntaxError { + constructor (position: number) { + super(`Missing init in for statement (at ${position})\nSee DOCS.md for more info on for statements.`); + } +} + +export class ForVariableMismatch extends SyntaxError { + constructor (expected: string, got: string, position: number) { + super(`Expected \`${expected}\`, got \`${got}\` (at ${position})\nSee DOCS.md for more info on for statements.`); + } +} + +export class ForInvalidOperator extends InvalidSyntaxType { + constructor (op: string, position: number) { + super("+= | -=", op, position); + this.message = `Invalid operator in for statement: ${this.message}\nSee DOCS.md for more info on for statements.`; + } +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..7b0139c --- /dev/null +++ b/src/main.ts @@ -0,0 +1,36 @@ +import { parse } from "./swc.ts"; +import { transform } from "./transformers.ts"; +import { join, basename, dirname } from "https://deno.land/std/path/mod.ts"; + +const inPath = Deno.args[0]; +const input = Deno.readTextFileSync(inPath); + +const ast = parse(input, { + syntax: "typescript", + comments: true, + target: "es2020", +}); + +const template = Deno.readTextFileSync("./assets/template.fprg"); + +const output = transform(input, ast, { + indent: 3, + showSourceStatements: false +}, template); + +if (Deno.args.length > 1) { + Deno.writeTextFileSync(Deno.args[1], output); +} else { + const inPathBasename = basename(inPath); + const dot = inPathBasename.lastIndexOf("."); + const outPath = join( + dirname(inPath), + dot > -1 + ? inPathBasename.slice(0, dot) + ".fprg" + : inPathBasename + ".fprg" + ); + console.log(outPath); + Deno.writeTextFileSync(outPath, output); +} + +console.log(output); diff --git a/src/statements.ts b/src/statements.ts new file mode 100644 index 0000000..6edd284 --- /dev/null +++ b/src/statements.ts @@ -0,0 +1,78 @@ +import { Type } from "./type_utils.ts"; +import { escapeXML, capitalize } from "./utils.ts"; + +const typeToFPRGType: Record<Type, string> = { + int: "Integer", + float: "Real", + string: "String", + boolean: "Boolean", +} + +export function declare (name: string, type: Type): string { + return `<declare ` + + `name="${name}" ` + + `type="${typeToFPRGType[type]}" ` + + `array="False" ` + + `size=""/>\n`; +} + +export function assign (variable: string, expr: string): string { + return `<assign ` + + `variable="${variable}" ` + + `expression="${escapeXML(expr)}"/>\n`; +} + +export function output (expr: string, newline: boolean): string { + return `<output ` + + `expression="${escapeXML(expr)}" ` + + `newline="${capitalize(newline.toString())}"/>\n`; +} + +export function input (variable: string): string { + return `<input ` + + `variable="${variable}"/>\n`; +} + +export function comment (text: string): string { + return `<comment text="${escapeXML(text)}"/>\n`; +} + +export function _if ( + indent: string, + expr: string, + arm1: string, + arm2?: string +): string { + const exIndent = indent + " "; + return `${indent}<if expression="${escapeXML(expr)}">\n` + + `${exIndent}<then>\n${arm1}${exIndent}</then>\n` + + `${exIndent}<else>\n${arm2 ?? ""}${exIndent}</else>\n` + + `${indent}</if>\n`; +} + +export function _while ( + indent: string, + expr: string, + arm: string +): string { + return `${indent}<while expression="${escapeXML(expr)}">\n` + + `${arm}${indent}</while>\n`; +} + +export function _for ( + indent: string, + variable: string, + start: number, + end: number, + direction: "inc" | "dec", + step: number, + body: string +): string { + return `${indent}<for ` + + `variable="${variable}" ` + + `start="${start}" ` + + `end="${end}" ` + + `direction="${direction}" ` + + `step="${step}">\n` + + `${body}${indent}</for>\n`; +} \ No newline at end of file diff --git a/src/swc.ts b/src/swc.ts new file mode 100755 index 0000000..909b12f --- /dev/null +++ b/src/swc.ts @@ -0,0 +1,32 @@ +import {instantiate} from "../lib/deno_swc/lib/deno_swc.generated.js"; +import {decompress} from "https://deno.land/x/lz4@v0.1.2/mod.ts"; +import type { + Config, + JsMinifyOptions, + ParseOptions, + Program, +} from "https://esm.sh/@swc/core@1.2.212/types.d.ts"; + +const { + parseSync, + printSync, + transformSync, + minifySync, +} = await instantiate(decompress); + +export function parse(source: string, opts: ParseOptions): Program{ + return parseSync(source, opts); +} + +export function print(program: Program, opts?: Config): string{ + return printSync(program, opts ?? {}).code; +} + + return transformSync(source, opts).code; +} + +export function minify(source: string, opts?: JsMinifyOptions): string{ + return minifySync(source, opts ?? {}).code; +} + +export * from "https://esm.sh/@swc/core@1.2.212/types.d.ts"; diff --git a/src/transformers.ts b/src/transformers.ts new file mode 100644 index 0000000..3b81201 --- /dev/null +++ b/src/transformers.ts @@ -0,0 +1,738 @@ +import { format } from "https://deno.land/std@0.146.0/datetime/mod.ts"; + +import { Type } from "./type_utils.ts"; +import * as TypeUtils from "./type_utils.ts"; + +import { capitalize, escapeXML } from "./utils.ts"; + +import * as SWC from "./swc.ts"; +import * as Errors from "./errors.ts"; +import * as Statements from "./statements.ts"; +import { BlockStatement, NumericLiteral, Statement } from "./swc.ts"; + +export interface Ident { type: Type; defined: boolean; } +export interface Assignment { name: string; value: string } +export type Idents = Map<string, Ident>; +export type ProgramAttributes = Partial<{ + [index: string]: string; + name: string; + authors: string; + about: string; + saved: string; + created: string; + edited: string; +}> +export type ProgramMetadata = Partial<{ + [index: string]: string | number; + username: string; + hostname: string; + editversion: number; + editMysteryNumber: number; +}>; +export interface TransformOptions { + [index: string]: number | boolean | ProgramAttributes | ProgramMetadata; + showSourceStatements: boolean; + attr: ProgramAttributes; + meta: ProgramMetadata; +}; +export interface TransformState { + input: string; + idents: Map<string, Ident>; + indent: string; + opts: TransformOptions; +} + +export function transform ( + input: string, + ast: SWC.Module | SWC.Program, + options: Partial<TransformOptions>, + customTemplate?: string +): string { + const state: TransformState = { + input: input, + indent: " ".repeat(3), + idents: new Map(), + opts: { + showSourceStatements: options.showSourceStatements ?? false, + attr: { ...options.attr }, + meta: { ...options.meta }, + } + }; + + const body = transformBlock(ast.body, state); + + const meta: ProgramMetadata = { + username: state.opts.meta.username ?? "ezfprg", + hostname: state.opts.meta.hostname ?? "deno", + editVersion: state.opts.meta.editVersion ?? 1, + editMysteryNumber: state.opts.meta.editMysteryNumber ?? 2980, + }; + + const now = format(new Date(), "yyyy-MM-dd hh:mm:ss a"); + const created = `${meta.username};${meta.hostname};${now.replace(" ", ";")}`; + const edited = `${created};${meta.editVersion};${meta.editMysteryNumber}`; + + const attr: ProgramAttributes = { + name: state.opts.attr.name ?? "Untitled", + authors: state.opts.attr.authors ?? "ezfprg", + about: state.opts.attr.about ?? "Converted from TypeScript by ezfprg", + saved: state.opts.attr.saved ?? now, + created: btoa(created), + edited: btoa(edited), + }; + + let template = customTemplate + ?? Deno.readTextFileSync("./assets/template.fprg"); + + for (const [k, v] of Object.entries(attr)) { + template = template.replace(`[[${k}]]`, v!); + } + + return template.replace("[[body]]", () => body); +} + +export function transformBlock ( + block: Array<SWC.Statement> | Array<SWC.ModuleItem>, + state: TransformState, +) { + let output = ""; + + for (const stmt of block) { + if (state.opts.showSourceStatements) { + const rawStmt = state.input.slice( + stmt.span.start - 1, + stmt.span.end - 1 + ); + output += state.indent + Statements.comment(rawStmt); + } + + switch (stmt.type) { + case "VariableDeclaration": + output += transformVariableDecl(stmt, state); + break; + case "ExpressionStatement": { + switch (stmt.expression.type) { + case "AssignmentExpression": + output += transformAssignmentExpr(stmt.expression, state); + break; + case "CallExpression": + output += transformBlockCallExpr(stmt.expression, state); + break; + } + } break; + case "IfStatement": + output += transformIfStmt(stmt, state); + break; + case "WhileStatement": + output += transformWhileStmt(stmt, state); + break; + case "ForStatement": + output += transformForStmt(stmt, state); + break; + } + } + + return output; +} + +export function transformNewScope ( + body: BlockStatement, + state: TransformState, +): string { + if (body.stmts.length === 0) return ""; + + const oldIndent = state.indent.toString(); + const oldIdents: Idents = new Map(state.idents); + + state.indent = state.indent + " "; + + const out = transformBlock(body.stmts, state); + + state.indent = oldIndent; + state.idents = oldIdents; + + return out; +} + +export function transformExpr ( + expr: SWC.Literal | SWC.Expression, + idents: Map<string, Ident>, +): [string, Type] { + switch (expr.type) { + case "NumericLiteral": { + // @ts-ignore - ts thinks that raw does not exist in a NumericLiteral + const val = "raw" in expr ? expr.raw : expr.value.toString(); + return [val, val.includes(".") ? "float" : "int"]; + } + case "StringLiteral": + return [`"${expr.value}"`, "string"]; + case "BooleanLiteral": + return [expr.value.toString(), "boolean"]; + case "Identifier": + case "CallExpression": { + let name: string; + if (expr.type === "Identifier") { + name = expr.value; + } else if ("value" in expr.callee) { + name = expr.callee.value.toString(); + } else { + throw new Errors.InvalidExpression(expr.callee.type, expr.span.start); + } + + const matchedIdent = idents.get(name); + if (!matchedIdent || !matchedIdent.defined) { + throw new Errors.UndefinedReference(name, expr.span.start); + } + + return [name, matchedIdent.type]; + } + case "ParenthesisExpression": { + const [_expr, exprType] = transformExpr(expr.expression, idents); + return [`(${_expr})`, exprType]; + } + case "UnaryExpression": { + const [_expr, exprType] = transformExpr(expr.argument, idents); + return [`${expr.operator}${_expr}`, exprType]; + } + case "BinaryExpression": { + const [left, lType] = transformExpr(expr.left, idents); + const [right, rType] = transformExpr(expr.right, idents); + + if (!TypeUtils.validateBinaryOpTypes(lType, rType, expr.operator)) { + throw new Errors.InvalidBinaryOp( + lType, + rType, + expr.operator, + expr.span.start + ); + } + + const op = [lType, rType].includes("string") && expr.operator === "+" + ? "&" + : expr.operator; + const type = TypeUtils.castValidBinaryOpTypes(lType, rType, op); + + return [`${left} ${op} ${right}`, type]; + } + default: + // @ts-ignore: fuck you ts + throw new Errors.InvalidExpression(expr.type, expr.span.start); + } +} + +export function transformBlockCallExpr ( + expr: SWC.CallExpression, + state: TransformState, +): string { + let name: string; + + if ("value" in expr.callee) { + name = expr.callee.value.toString(); + } else { + throw new Errors.InvalidExpression( + expr.callee.type, + expr.span.start + ); + } + + switch (name) { + case "println": { + if (expr.arguments.length < 1) { + throw new Errors.InvalidArgumentCount( + name, + expr.arguments.length, + 1, + expr.span.start + ); + } + + const [newExpr, _] = transformExpr( + expr.arguments[0].expression, + state.idents, + ); + + return state.indent + Statements.output(newExpr, true); + } + case "print": { + if (expr.arguments.length < 1) { + throw new Errors.InvalidArgumentCount( + name, + expr.arguments.length, + 1, + expr.span.start + ); + } + + const [newExpr, _] = transformExpr( + expr.arguments[0].expression, + state.idents, + ); + + return state.indent + Statements.output(newExpr, false); + } + case "input": { + if (expr.arguments.length !== 1) { + throw new Errors.InvalidArgumentCount( + name, + expr.arguments.length, + 1, + expr.span.start + ); + } + + if (expr.arguments[0].expression.type !== "Identifier") { + throw new Errors.InvalidSyntaxType( + expr.arguments[0].expression.type, + "<Identifier>", + expr.span.start + ); + } + + const variable = expr.arguments[0].expression.value.toString(); + const matchedIdent = state.idents.get(variable); + + if (!matchedIdent) { + throw new Errors.UndefinedReference(variable, expr.span.start); + } + + state.idents.set(variable, { ...matchedIdent, defined: true }); + return state.indent + Statements.input(variable); + } + case "attr": + case "meta": { + if (expr.arguments.length !== 2) { + throw new Errors.InvalidArgumentCount( + name, + expr.arguments.length, + 2, + expr.span.start + ); + } + + for (const arg of expr.arguments) { + if (arg.expression.type !== "StringLiteral") { + throw new Errors.InvalidSyntaxType( + expr.arguments[0].expression.type, + "<StringLiteral>", + expr.span.start + ); + } + } + + const args = expr.arguments + .map((a) => a.expression as SWC.StringLiteral); + + const key: string = args[0].value; + + if (TypeUtils.validKeys[name].includes(key)) { + if (state.opts[name][key] === undefined) { + state.opts[name][key] = args[1].value; + } + } else { + throw new Errors.InvalidAttrOrMeta(key, name, expr.span.start); + } + + return ""; + } + case "comment": { + if (expr.arguments.length !== 1) { + throw new Errors.InvalidArgumentCount( + name, + expr.arguments.length, + 1, + expr.span.start + ); + } + + if (expr.arguments[0].expression.type !== "StringLiteral") { + throw new Errors.InvalidSyntaxType( + expr.arguments[0].expression.type, + "<StringLiteral>", + expr.span.start + ); + } + + const comment = expr.arguments[0].expression.value.toString(); + return state.indent + Statements.comment(comment); + } + case "insist": { + if (expr.arguments.length !== 1) { + throw new Errors.InvalidArgumentCount( + name, + expr.arguments.length, + 1, + expr.span.start + ); + } + + if (expr.arguments[0].expression.type !== "Identifier") { + throw new Errors.InvalidSyntaxType( + expr.arguments[0].expression.type, + "<Identifier>", + expr.span.start + ); + } + + const ident = expr.arguments[0].expression.value; + const matchedIdent = state.idents.get(ident); + + if (!matchedIdent) { + throw new Errors.UndefinedReference(ident, expr.span.start); + } + + state.idents.set(ident, { ...matchedIdent, defined: true }); + return ""; + } + default: + throw new Errors.UndefinedReference(name, expr.span.start); + } +} + +export function transformAssignmentExpr ( + expr: SWC.AssignmentExpression, + state: TransformState +): string { + if (expr.left.type !== "Identifier") { + throw new Errors.InvalidAssignmentTarget(expr.span.start); + } + + const name = expr.left.value; + const matchedIdent = state.idents.get(name); + + if (!matchedIdent) { + throw new Errors.UndefinedReference(name, expr.span.start); + } + + const type = matchedIdent.type; + const [newExpr, exprType] = transformExpr(expr.right, state.idents); + + if (!TypeUtils.validateAssignmentTypes(type, exprType)) { + throw new Errors.InvalidType(type, exprType, expr.span.start); + } + + if (!matchedIdent.defined) { + state.idents.set(name, { ...matchedIdent, defined: true }); + } + + return state.indent + Statements.assign(name, newExpr); +} + +export function transformVariableDecl ( + stmt: SWC.VariableDeclaration, + state: TransformState, +) { + let output = ""; + + const declarations: Record<Type, string[]> = { + int: [], + float: [], + string: [], + boolean: [], + }; + + const assignments = new Array<Assignment>(); + + for (const decl of stmt.declarations) { + if (decl.id.type !== "Identifier") { + throw new Errors.InvalidAssignmentTarget(decl.span.start); + } + + if (state.idents.has(decl.id.value)) { + throw new Errors.AlreadyDefined(decl.id.value, decl.id.span.start); + } + + let type: Type | undefined; + + if (decl.id.typeAnnotation) { + const annot = decl.id.typeAnnotation.typeAnnotation; + + if ("kind" in annot) { + type = annot.kind as Type; + } else if ("typeName" in annot) { + // @ts-ignore: who the fuck asked + L + ratio + type = annot.typeName.value; + } else { + throw new Errors.InvalidTypeAnnotation( + annot.type, + decl.id.span.start + ); + } + + if (!TypeUtils.typeNames.includes(type!)) { + throw new Errors.InvalidType( + "int | float | string | boolean", + type!, + stmt.span.start + ); + } + } + + if (decl.init) { + const [expr, exprType] = transformExpr(decl.init, state.idents); + + if (type && !TypeUtils.validateAssignmentTypes(type!, exprType)) { + throw new Errors.InvalidType(type, exprType, decl.span.start); + } else if (!type) { + type = exprType; + } + assignments.push({ name: decl.id.value, value: expr }); + } + + if (!type) { + throw new Errors.MissingType(decl.id.value, stmt.span.start); + } + + declarations[type].push(decl.id.value); + state.idents.set( + decl.id.value, + { type: type, defined: decl.init !== null } + ); + } + + TypeUtils.typeNames.forEach((type) => { + const names = declarations[type]; + if (names.length > 0) { + output += state.indent + Statements.declare( + names.join(", "), + type as Type + ); + } + }); + + assignments.forEach((a) => { + output += state.indent + Statements.assign(a.name, a.value); + }); + + return output; +} + +export function transformIfStmt ( + stmt: SWC.IfStatement, + state: TransformState +): string { + const [expr, exprType] = transformExpr(stmt.test, state.idents); + + if (exprType !== "boolean") { + throw new Errors.InvalidType("boolean", exprType, stmt.span.start); + } + + let arm1: string; + if (stmt.consequent && stmt.consequent.type === "BlockStatement") { + arm1 = transformNewScope(stmt.consequent, state); + } else { + throw new Errors.InvalidSyntaxType( + "BlockStatement", + stmt.consequent.type, + stmt.span.start + ); + } + + let arm2 = ""; + + if (stmt.alternate) { + if (stmt.alternate.type === "BlockStatement") { + arm2 = transformNewScope(stmt.alternate, state); + } else if (stmt.alternate.type === "IfStatement") { + const oldIndent = state.indent; + state.indent += " "; + arm2 = transformIfStmt(stmt.alternate, state); + state.indent = oldIndent; + } else { + throw new Errors.InvalidSyntaxType( + "BlockStatement", + stmt.alternate.type, + stmt.span.start + ); + } + } + + return Statements._if(state.indent, expr, arm1, arm2); +} + +export function transformWhileStmt ( + stmt: SWC.WhileStatement, + state: TransformState +): string { + const [expr, exprType] = transformExpr(stmt.test, state.idents); + + if (exprType !== "boolean") { + throw new Errors.InvalidType("boolean", exprType, stmt.span.start); + } + + let body: string; + + if (stmt.body && stmt.body.type === "BlockStatement") { + body = transformNewScope(stmt.body, state); + } else { + throw new Errors.InvalidSyntaxType( + "BlockStatement", + stmt.body.type, + stmt.span.start + ); + } + + return Statements._while(state.indent, expr, body); +} + +export function transformForStmt ( + stmt: SWC.ForStatement, + state: TransformState +): string { + let output = ""; + let variable: string; + let start: number; + + if (!stmt.init) { + throw new Errors.ForMissingInit(stmt.span.start); + } else if (stmt.init.type === "VariableDeclaration") { + const decl = stmt.init.declarations[0]; + if (decl.id.type !== "Identifier") { + throw new Errors.InvalidSyntaxType( + "Identifier", + decl.id.type, + stmt.init.span.start + ); + } else if (!decl.init || decl.init.type !== "NumericLiteral") { + throw new Errors.InvalidSyntaxType( + "NumericLiteral", + decl.init?.type ?? "Nothing", + stmt.init.span.start + ); + } + + variable = (decl.id as SWC.Identifier).value; + start = (decl.init as SWC.NumericLiteral).value; + + output += state.indent + transformVariableDecl(stmt.init, state); + } else if (stmt.init.type === "AssignmentExpression") { + if (stmt.init.left.type !== "Identifier") { + throw new Errors.InvalidSyntaxType( + "Identifier", + stmt.init.left.type, + stmt.init.span.start + ); + } else if (stmt.init.right.type !== "NumericLiteral") { + throw new Errors.InvalidSyntaxType( + "NumericLiteral", + stmt.init?.type, + stmt.init.span.start + ); + } + + variable = stmt.init.left.value; + start = stmt.init.right.value; + } else { + throw new Errors.InvalidSyntaxType( + "VariableDeclaration | AssignmentExpression", + stmt.init.type, + stmt.span.start + ); + } + + if (!stmt.test) { + throw new SyntaxError( + ); + } else if (stmt.test.type !== "NumericLiteral") { + throw new Errors.InvalidSyntaxType( + "NumericLiteral", + stmt.test.type, + stmt.span.start + ); + } + + const end: number = stmt.test.value; + let step: number; + let direction: "inc" | "dec"; + + if (!stmt.update) { + throw new Errors.ForMissingEnd(stmt.span.start); + } else if (stmt.update.type === "UpdateExpression") { + if (stmt.update.argument.type !== "Identifier") { + throw new Errors.InvalidSyntaxType( + "Identifier", + stmt.update.argument.type, + stmt.update.span.start + ); + } else if (stmt.update.argument.value !== variable) { + throw new Errors.ForVariableMismatch( + variable, + stmt.update.argument.value, + stmt.update.span.start + ); + } else if (stmt.update.operator === "++") { + step = 1; + direction = "inc"; + } else if (stmt.update.operator === "--") { + step = 1; + direction = "dec"; + } else { + throw new Errors.ForInvalidOperator( + stmt.update.operator, + stmt.update.span.start + ); + } + } else if (stmt.update.type === "AssignmentExpression") { + if (stmt.update.left.type !== "Identifier") { + throw new Errors.InvalidSyntaxType( + "Identifier", + stmt.update.left.type, + stmt.update.span.start + ); + } else if (stmt.update.left.value !== variable) { + throw new Errors.ForVariableMismatch( + variable, + stmt.update.left.value, + stmt.update.span.start + ); + } + + if (stmt.update.operator === "+=") { + direction = "inc"; + } else if (stmt.update.operator === "-=") { + direction = "dec"; + } else { + throw new Errors.ForInvalidOperator( + stmt.update.operator, + stmt.update.span.start + ); + } + + if (stmt.update.right.type !== "NumericLiteral") { + throw new Errors.InvalidSyntaxType( + "NumericLiteral", + stmt.update.right.type, + stmt.update.span.start + ); + } + + step = stmt.update.right.value; + } else { + throw new Errors.InvalidSyntaxType( + "UpdateExpression | AssignmentExpression", + stmt.update.type, + stmt.span.start + ); + } + + let body: string; + if (stmt.body && stmt.body.type === "BlockStatement") { + body = transformNewScope(stmt.body, state); + } else { + throw new Errors.InvalidSyntaxType( + "BlockStatement", + stmt.body.type, + stmt.span.start + ); + } + + output += Statements._for( + state.indent, + variable, + start, + end, + direction, + step, + body + ); + return output; +} \ No newline at end of file diff --git a/src/type_utils.ts b/src/type_utils.ts new file mode 100644 index 0000000..ab97756 --- /dev/null +++ b/src/type_utils.ts @@ -0,0 +1,51 @@ +import * as SWC from "./swc.ts"; + +export type Type = "int" | "float" | "string" | "boolean"; + +export const typeNames: Array<Type> = ["int", "float", "string", "boolean"]; +export const validKeys: Record<string, Array<string>> = { + attr: ["name", "authors", "about"], + meta: ["username", "hostname", "editVersion", "editMysteryNumber"], +}; +export const numOps = [ + "+", "-", "*", "/", "%", "^", + "<=", ">=", "<", ">", "==", "!=" +]; +export const boolOps = ["&&", "||", "!", "==", "!="]; +export const stringOps = ["+", "==", "!="]; + +export function validateBinaryOpTypes ( + a: Type, + b: Type, + op: SWC.BinaryOperator, +): boolean { + // For purposes of validation, float and int are the same + a = a === "float" ? "int" : a; + b = b === "float" ? "int" : b; + if (a === b) { + switch (a) { + case "int": return numOps.includes(op); + case "string": return stringOps.includes(op); + case "boolean": return boolOps.includes(op); + } + } + return [a, b].includes("string") && op === "+"; +} + +export function validateAssignmentTypes (a: Type, b: Type) { + return a === b + || (a === "float" && b === "int") + || (a === "int" && b === "float"); +} + +export function castValidBinaryOpTypes ( + a: Type, + b: Type, + op: SWC.BinaryOperator +): Type { + return ["<", ">", "<=", ">=", "==", "!=", "&&", "||"].includes(op) + ? "boolean" + : a === b + ? a + : [a, b].includes("string") ? "string" : "float"; +} \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..2b242c8 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,13 @@ +export function escapeXML (input: string): string { + if (input.match(/[&<>"\n]/)) return input + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll(`"`, """) + .replaceAll("\n", " "); + return input; +} + +export function capitalize (str: string): string { + return str[0].toUpperCase() + str.slice(1); +} \ No newline at end of file