@iancarlos/mathscript 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/package.json +4 -4
- package/src/transpile.js +4 -2
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# MathScript
|
|
2
|
+
|
|
3
|
+
## Uso
|
|
4
|
+
|
|
5
|
+
msc --init
|
|
6
|
+
|
|
7
|
+
msc msconfig.json
|
|
8
|
+
|
|
9
|
+
## Configuración
|
|
10
|
+
|
|
11
|
+
- msc --init -> te pregunta cómo configurar
|
|
12
|
+
- Files -> archivos a traducir
|
|
13
|
+
- strict -> si es true, requiere tipado; si es false, no
|
|
14
|
+
|
|
15
|
+
## Sintaxis
|
|
16
|
+
|
|
17
|
+
### Funciones
|
|
18
|
+
|
|
19
|
+
```ms
|
|
20
|
+
using("module")
|
|
21
|
+
fn f(x) {
|
|
22
|
+
return x
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
compila a:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
require("module")
|
|
30
|
+
function f(x) {
|
|
31
|
+
return x
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Tipos
|
|
36
|
+
|
|
37
|
+
```ms
|
|
38
|
+
a: str = "string"
|
|
39
|
+
b: bool = true
|
|
40
|
+
c: obj = { "x": a, "y": b }
|
|
41
|
+
d: arr<str> = [
|
|
42
|
+
"string",
|
|
43
|
+
"list"
|
|
44
|
+
]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
compila a:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
a = "string"
|
|
51
|
+
b = true
|
|
52
|
+
c = { "x": a, "y": b }
|
|
53
|
+
d = [
|
|
54
|
+
"string",
|
|
55
|
+
"list"
|
|
56
|
+
]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Notas
|
|
60
|
+
|
|
61
|
+
- Los tipos son solo para el compilador, JS no los interpreta en runtime.
|
|
62
|
+
- Puedes usar `arr<tipo>` para listas tipadas y `obj<key,value>` para objetos complejos.
|
|
63
|
+
- Las funciones y módulos se traducen directamente a JS limpio.
|
|
64
|
+
- `strict: true` fuerza tipado, `strict: false` permite inferencia flexible.
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iancarlos/mathscript",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "ts/js superset",
|
|
5
5
|
"main": "src/transpile.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "echo \"
|
|
8
|
+
"test": "echo \"usa msc --init\"; exit 0"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"typescript": "^5.9.3"
|
|
26
26
|
},
|
|
27
|
-
"bin":{
|
|
28
|
-
"msc":"src/main.js"
|
|
27
|
+
"bin": {
|
|
28
|
+
"msc": "src/main.js"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/transpile.js
CHANGED
|
@@ -21,9 +21,11 @@ const constants = [
|
|
|
21
21
|
regex(/using\((.*?)\)/g, "requiere($1)"),
|
|
22
22
|
regex(/\bstr\b/g, "string"),
|
|
23
23
|
regex(/\bbool\b/g, "boolean"),
|
|
24
|
+
regex(/\bmap\s*<([^,]*),\s*([^,]*)>\b/g, "Record<$1, $2>"),
|
|
25
|
+
regex(/\bmap\b/g, "Record<any, any>"),
|
|
24
26
|
regex(/\bobj\b/g, "object"),
|
|
25
|
-
regex(/\barr
|
|
26
|
-
regex(/\
|
|
27
|
+
regex(/\barr<(.*?)>\b/g, "$1[]"),
|
|
28
|
+
regex(/\barr\b/g, "any[]"),
|
|
27
29
|
regex(/\bfn\b/g, "function")
|
|
28
30
|
]
|
|
29
31
|
|