goldstein 2.6.0 → 3.0.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/ChangeLog +9 -0
- package/README.md +46 -1
- package/bin/gs.js +1 -1
- package/package.json +3 -1
- package/packages/goldstein/index.js +18 -7
- package/packages/keyword-if/index.js +1 -3
- package/packages/keyword-import/index.js +34 -0
- package/packages/keyword-throw/index.js +5 -3
- package/packages/parser/index.js +1 -0
package/ChangeLog
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
2023.04.02, v3.0.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 3eeeab7 goldstein: add ability to simplify logical expressions during compilation
|
|
5
|
+
- 7959e57 goldstein: add ability to compile import gs to js
|
|
6
|
+
- c61e500 goldstein: improve compiler, disable bundling
|
|
7
|
+
- 6cd279e goldstein: enable support of ifStatments with no round braces
|
|
8
|
+
- 0ba6f9c major: goldstein: compile: use @putout/pinter instead of recast, parse: provide Babel AST
|
|
9
|
+
|
|
1
10
|
2023.04.01, v2.6.0
|
|
2
11
|
|
|
3
12
|
feature:
|
package/README.md
CHANGED
|
@@ -43,6 +43,32 @@ export {
|
|
|
43
43
|
};
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
Let's do a bit more!
|
|
47
|
+
|
|
48
|
+
```gs
|
|
49
|
+
const a = () => throw 'hello';
|
|
50
|
+
|
|
51
|
+
if a > 2 {
|
|
52
|
+
log('hello');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fn hello() {
|
|
56
|
+
console.log('hello');
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Will give us:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
const a = () => {
|
|
64
|
+
throw 'hello';
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
if (a > 2) {
|
|
68
|
+
log('hello');
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
46
72
|
## API
|
|
47
73
|
|
|
48
74
|
### `compile(source)`
|
|
@@ -133,7 +159,7 @@ Is the same as:
|
|
|
133
159
|
|
|
134
160
|
```js
|
|
135
161
|
function hello() {
|
|
136
|
-
if (
|
|
162
|
+
if (text === 'world') {
|
|
137
163
|
return '';
|
|
138
164
|
}
|
|
139
165
|
|
|
@@ -237,6 +263,25 @@ inc(5);
|
|
|
237
263
|
6
|
|
238
264
|
```
|
|
239
265
|
|
|
266
|
+
### `Import`
|
|
267
|
+
|
|
268
|
+
When you import `.gs` files during compile step it will be replaced with `.js`:
|
|
269
|
+
|
|
270
|
+
```gs
|
|
271
|
+
// hello.js
|
|
272
|
+
export const hello = () => 'world';
|
|
273
|
+
|
|
274
|
+
// index.js
|
|
275
|
+
import hello from './hello.gs';
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Will be converted to:
|
|
279
|
+
|
|
280
|
+
```js
|
|
281
|
+
// index.js
|
|
282
|
+
import hello from './hello.js';
|
|
283
|
+
```
|
|
284
|
+
|
|
240
285
|
## How to contribute?
|
|
241
286
|
|
|
242
287
|
Clone the registry, create a new keyword with a prefix `keyword-`, then create directory `fixture` and put there two files with extensions `.js` and `.gs`. Half way done 🥳!
|
package/bin/gs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goldstein",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "JavaScript with no limits",
|
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
"fix:lint": "madrun fix:lint"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@putout/printer": "^1.16.0",
|
|
28
29
|
"acorn": "^8.7.1",
|
|
29
30
|
"esbuild": "^0.17.14",
|
|
31
|
+
"estree-to-babel": "^5.0.1",
|
|
30
32
|
"putout": "^29.1.11",
|
|
31
33
|
"try-catch": "^3.0.1"
|
|
32
34
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import putout
|
|
2
|
-
|
|
3
|
-
} from 'putout';
|
|
1
|
+
import {transform} from 'putout';
|
|
2
|
+
|
|
3
|
+
import {print} from '@putout/printer';
|
|
4
4
|
import {extendParser} from '../parser/index.js';
|
|
5
5
|
import keywordFn from '../keyword-fn/index.js';
|
|
6
6
|
import keywordGuard from '../keyword-guard/index.js';
|
|
@@ -10,6 +10,10 @@ import keywordThrow from '../keyword-throw/index.js';
|
|
|
10
10
|
import stringInterpolation from '../string-interpolation/index.js';
|
|
11
11
|
import keywordCurry from '../keyword-curry/index.js';
|
|
12
12
|
import keywordFreeze from '../keyword-freeze/index.js';
|
|
13
|
+
import keywordIf from '../keyword-if/index.js';
|
|
14
|
+
import keywordImport from '../keyword-import/index.js';
|
|
15
|
+
|
|
16
|
+
import estreeToBabel from 'estree-to-babel';
|
|
13
17
|
|
|
14
18
|
export const parse = (source) => {
|
|
15
19
|
const {parse} = extendParser([
|
|
@@ -20,21 +24,28 @@ export const parse = (source) => {
|
|
|
20
24
|
keywordThrow,
|
|
21
25
|
keywordCurry,
|
|
22
26
|
keywordFreeze,
|
|
27
|
+
keywordIf,
|
|
28
|
+
keywordImport,
|
|
23
29
|
stringInterpolation,
|
|
24
30
|
]);
|
|
25
31
|
|
|
26
|
-
return parse(source);
|
|
32
|
+
return estreeToBabel(parse(source));
|
|
27
33
|
};
|
|
28
34
|
|
|
29
35
|
export const compile = (source) => {
|
|
30
36
|
const ast = parse(source);
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
|
|
38
|
+
transform(ast, source, {
|
|
33
39
|
plugins: [
|
|
34
40
|
'try-catch',
|
|
35
41
|
'declare',
|
|
42
|
+
'logical-expressions',
|
|
36
43
|
],
|
|
37
44
|
});
|
|
38
45
|
|
|
39
|
-
return
|
|
46
|
+
return fixEmpty(print(ast));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const fixEmpty = (source) => {
|
|
50
|
+
return source.replace(';;', ';');
|
|
40
51
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {tokTypes} from '../operator/index.js';
|
|
2
|
+
|
|
3
|
+
const empty = [];
|
|
4
|
+
|
|
5
|
+
export default function keywordImport(Parser) {
|
|
6
|
+
return class extends Parser {
|
|
7
|
+
parseImport(node) {
|
|
8
|
+
this.next();
|
|
9
|
+
|
|
10
|
+
// import '...'
|
|
11
|
+
if (this.type === tokTypes.string) {
|
|
12
|
+
node.specifiers = empty;
|
|
13
|
+
node.source = this.parseExprAtom();
|
|
14
|
+
} else {
|
|
15
|
+
node.specifiers = this.parseImportSpecifiers();
|
|
16
|
+
this.expectContextual('from');
|
|
17
|
+
|
|
18
|
+
node.source = this.type === tokTypes.string ? this.parseLiteral(this.value) : this.unexpected();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const {raw, value} = node.source;
|
|
22
|
+
|
|
23
|
+
if (value.endsWith('.gs')) {
|
|
24
|
+
node.source.raw = raw.replace('.gs', '.js');
|
|
25
|
+
node.source.value = value.replace(/\.gs$/, '.js');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.semicolon();
|
|
29
|
+
|
|
30
|
+
return this.finishNode(node, 'ImportDeclaration');
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -19,11 +19,13 @@ export default function keywordThrow(Parser) {
|
|
|
19
19
|
const expression = this.parseExpression();
|
|
20
20
|
|
|
21
21
|
assign(node, {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
body: [{
|
|
23
|
+
type: 'ThrowStatement',
|
|
24
|
+
argument: expression,
|
|
25
|
+
}],
|
|
24
26
|
});
|
|
25
27
|
|
|
26
|
-
return super.finishNode(node, '
|
|
28
|
+
return super.finishNode(node, 'BlockStatement');
|
|
27
29
|
}
|
|
28
30
|
};
|
|
29
31
|
}
|