goldstein 2.5.1 → 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 CHANGED
@@ -1,3 +1,21 @@
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
+
10
+ 2023.04.01, v2.6.0
11
+
12
+ feature:
13
+ - ccdb0f1 package: esbuild v0.17.14
14
+ - ecf9023 package: eslint-plugin-putout v17.2.1
15
+ - 15a95e5 package: typescript v5.0.3
16
+ - 84a6049 package: putout v29.1.11
17
+ - d4f22c6 package: check-dts v0.7.1
18
+
1
19
  2023.01.06, v2.5.1
2
20
 
3
21
  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,11 +159,11 @@ Is the same as:
133
159
 
134
160
  ```js
135
161
  function hello() {
136
- if (!(text !== 'world')) {
162
+ if (text === 'world') {
137
163
  return '';
138
164
  }
139
165
 
140
- return 'Hello ' + text;
166
+ return `Hello ${text}`;
141
167
  }
142
168
  ```
143
169
 
@@ -148,20 +174,20 @@ function hello() {
148
174
  Applies [`tryCatch`](https://github.com/coderaiser/try-catch):
149
175
 
150
176
  ```gs
151
- const [error, result] = try hello(1, 2, 3);
177
+ const [error, result] = try hello('world');
152
178
  ```
153
179
 
154
180
  Is the same as:
155
181
 
156
182
  ```js
157
183
  import tryCatch from 'try-catch';
158
- const [error, result] = tryCatch(1, 2, 3);
184
+ const [error, result] = tryCatch(hello, 'world');
159
185
  ```
160
186
 
161
187
  and
162
188
 
163
189
  ```gs
164
- const [error, result] = try await hello(1, 2, 3);
190
+ const [error, result] = try await hello('world');
165
191
  ```
166
192
 
167
193
  Is the same as:
@@ -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
@@ -24,7 +24,7 @@ const outfile = compiledName.replace('~', '');
24
24
 
25
25
  esbuild.buildSync({
26
26
  entryPoints: [compiledName],
27
- bundle: true,
27
+ bundle: false,
28
28
  write: true,
29
29
  outfile,
30
30
  mainFields: ['main'],
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "goldstein",
3
- "version": "2.5.1",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
- "commitType": "colon",
6
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
7
6
  "description": "JavaScript with no limits",
8
7
  "main": "./packages/goldstein/index.js",
@@ -26,27 +25,29 @@
26
25
  "fix:lint": "madrun fix:lint"
27
26
  },
28
27
  "dependencies": {
28
+ "@putout/printer": "^1.16.0",
29
29
  "acorn": "^8.7.1",
30
- "esbuild": "^0.16.14",
31
- "putout": "^28.5.0",
30
+ "esbuild": "^0.17.14",
31
+ "estree-to-babel": "^5.0.1",
32
+ "putout": "^29.1.11",
32
33
  "try-catch": "^3.0.1"
33
34
  },
34
35
  "license": "MIT",
35
36
  "devDependencies": {
36
37
  "@cloudcmd/stub": "^4.0.1",
37
38
  "c8": "^7.5.0",
38
- "check-dts": "^0.6.3",
39
+ "check-dts": "^0.7.1",
39
40
  "escover": "^2.0.2",
40
41
  "eslint": "^8.0.0-beta.1",
41
42
  "eslint-plugin-n": "^15.2.4",
42
- "eslint-plugin-putout": "^16.0.0",
43
+ "eslint-plugin-putout": "^17.2.1",
43
44
  "madrun": "^9.0.0",
44
45
  "mock-require": "^3.0.3",
45
46
  "montag": "^1.2.1",
46
47
  "nodemon": "^2.0.2",
47
48
  "runsome": "^1.0.0",
48
49
  "supertape": "^8.0.1",
49
- "typescript": "^4.4.4",
50
+ "typescript": "^5.0.3",
50
51
  "zenload": "^2.0.0"
51
52
  },
52
53
  "engines": {
@@ -1,6 +1,6 @@
1
- import putout, {
2
- print,
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
- const jsCode = print(ast);
32
- const {code} = putout(jsCode, {
37
+
38
+ transform(ast, source, {
33
39
  plugins: [
34
40
  'try-catch',
35
- 'declare-undefined-variables',
41
+ 'declare',
42
+ 'logical-expressions',
36
43
  ],
37
44
  });
38
45
 
39
- return code;
46
+ return fixEmpty(print(ast));
47
+ };
48
+
49
+ const fixEmpty = (source) => {
50
+ return source.replace(';;', ';');
40
51
  };
@@ -1,6 +1,4 @@
1
- import {
2
- tokTypes as tt,
3
- } from '../operator/index.js';
1
+ import {tokTypes as tt} from '../operator/index.js';
4
2
 
5
3
  export default function fn(Parser) {
6
4
  return class extends Parser {
@@ -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
- operator: 'throw',
23
- argument: expression,
22
+ body: [{
23
+ type: 'ThrowStatement',
24
+ argument: expression,
25
+ }],
24
26
  });
25
27
 
26
- return super.finishNode(node, 'UnaryExpression');
28
+ return super.finishNode(node, 'BlockStatement');
27
29
  }
28
30
  };
29
31
  }
@@ -15,4 +15,5 @@ export const extendParser = (keywords) => {
15
15
  const createParse = (parser) => (a) => parser.parse(a, {
16
16
  ecmaVersion: 'latest',
17
17
  sourceType: 'module',
18
+ locations: true,
18
19
  });