goldstein 5.2.0 → 5.4.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,20 @@
1
+ 2024.05.07, v5.4.0
2
+
3
+ feature:
4
+ - 0758d6a rm build
5
+
6
+ 2024.05.06, v5.3.0
7
+
8
+ feature:
9
+ - 98f3048 goldstein: add ability to parse no async code with await
10
+ - 45c7363 @putout/plugin-goldstein: eslint-plugin-putout v22.7.0
11
+ - 3964832 @putout/plugin-goldstein: @putout/test v9.1.0
12
+ - aa689c7 @putout/plugin-goldstein: eslint v9.2.0
13
+ - 1399854 @putout/plugin-goldstein: c8 v9.1.0
14
+ - a728422 goldstein: redlint v3.14.1
15
+ - 6f03127 goldstein: eslint v9.2.0
16
+ - 23c8eb3 goldstein: @putout/plugin-declare v4.0.0
17
+
1
18
  2024.02.20, v5.2.0
2
19
 
3
20
  feature:
package/README.md CHANGED
@@ -100,10 +100,7 @@ By default, all keywords mentioned in the next section used, but you can limit t
100
100
  You can add any keywords, and even create your own:
101
101
 
102
102
  ```js
103
- import {
104
- compile,
105
- keywords,
106
- } from 'goldstein';
103
+ import {compile, keywords} from 'goldstein';
107
104
 
108
105
  const source = `
109
106
  fn hello() {
@@ -185,10 +182,7 @@ parse(`
185
182
  You can make any modifications to **Goldstein AST** and then `print` back to **Goldstein**:
186
183
 
187
184
  ```js
188
- import {
189
- parse,
190
- print,
191
- } from 'goldstein';
185
+ import {parse, print} from 'goldstein';
192
186
 
193
187
  const ast = parse(`const t = try f('hello')`);
194
188
  const source = print(ast);
@@ -302,7 +296,7 @@ Is the same as:
302
296
  ```js
303
297
  import tryToCatch from 'try-catch';
304
298
 
305
- const [error, result] = await tryToCatch(1, 2, 3);
299
+ const [error, result] = await tryToCatch(hello, 'world');
306
300
  ```
307
301
 
308
302
  ### `should`
@@ -413,6 +407,22 @@ That absolutely fine, it will be converted to:
413
407
  function hello() {}
414
408
  ```
415
409
 
410
+ ### `asyn`-less `Function` with `await`
411
+
412
+ ```gs
413
+ function hello() {
414
+ await world();
415
+ }
416
+ ```
417
+
418
+ In js:
419
+
420
+ ```js
421
+ async function hello() {
422
+ await world();
423
+ }
424
+ ```
425
+
416
426
  ## How to contribute?
417
427
 
418
428
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goldstein",
3
- "version": "5.2.0",
3
+ "version": "5.4.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,13 +25,13 @@
25
25
  "coverage": "madrun coverage",
26
26
  "lint": "madrun lint",
27
27
  "fix:lint": "madrun fix:lint",
28
- "build": "madrun build",
29
28
  "wisdom": "madrun wisdom"
30
29
  },
31
30
  "dependencies": {
32
- "@putout/plugin-declare": "^3.0.0",
31
+ "@putout/plugin-declare": "^4.0.0",
33
32
  "@putout/plugin-logical-expressions": "^5.0.0",
34
33
  "@putout/plugin-try-catch": "^3.0.0",
34
+ "@putout/plugin-promises": "^14.1.0",
35
35
  "@putout/printer": "^8.0.1",
36
36
  "acorn": "^8.7.1",
37
37
  "esbuild": "^0.20.1",
@@ -45,17 +45,18 @@
45
45
  "devDependencies": {
46
46
  "@babel/core": "^8.0.0-alpha.5",
47
47
  "@cloudcmd/stub": "^4.0.1",
48
+ "@putout/plugin-goldstein": "./rules/goldstein",
48
49
  "@putout/test": "^9.0.1",
49
50
  "c8": "^9.1.0",
50
51
  "check-dts": "^0.7.1",
51
52
  "escover": "^4.0.1",
52
- "eslint": "^8.48.0",
53
- "eslint-plugin-n": "^16.0.1",
53
+ "eslint": "^9.2.0",
54
54
  "eslint-plugin-putout": "^22.0.0",
55
55
  "madrun": "^10.0.0",
56
56
  "mock-require": "^3.0.3",
57
57
  "montag": "^1.2.1",
58
58
  "nodemon": "^3.0.1",
59
+ "redlint": "^3.14.1",
59
60
  "runsome": "^1.0.0",
60
61
  "supertape": "^10.1.0",
61
62
  "typescript": "^5.0.3"
@@ -5,10 +5,7 @@ import * as removeImportTry from './remove-import-try/index.js';
5
5
  import * as applyTry from './apply-try/index.js';
6
6
  import * as addArray from './add-array/index.js';
7
7
  import * as applyIfLet from './apply-if-let/index.js';
8
- import {
9
- fixEmpty,
10
- parse,
11
- } from '../goldstein/index.js';
8
+ import {fixEmpty, parse} from '../goldstein/index.js';
12
9
 
13
10
  export const convert = (source) => {
14
11
  const ast = estreeToBabel(parse(source));
@@ -3,6 +3,7 @@ import {print} from '@putout/printer';
3
3
  import tryCatchPlugin from '@putout/plugin-try-catch';
4
4
  import declarePlugin from '@putout/plugin-declare';
5
5
  import logicalExpressionsPlugin from '@putout/plugin-logical-expressions';
6
+ import promisesPlugin from '@putout/plugin-promises';
6
7
  import {parse} from './parser.js';
7
8
 
8
9
  export * from './parser.js';
@@ -19,6 +20,7 @@ export const compile = (source, options = {}) => {
19
20
  ['try-catch', tryCatchPlugin],
20
21
  ['declare', declarePlugin],
21
22
  ['logical-expressions', logicalExpressionsPlugin],
23
+ ['promises', promisesPlugin],
22
24
  ],
23
25
  });
24
26
 
@@ -12,6 +12,7 @@ import keywordIf from '../keyword-if/index.js';
12
12
  import keywordImport from '../keyword-import/index.js';
13
13
  import keywordArrow from '../keyword-arrow/index.js';
14
14
  import keywordAddArray from '../keyword-add-array/index.js';
15
+ import keywordNoAsync from '../keyword-no-async/index.js';
15
16
 
16
17
  const defaultKeywords = {
17
18
  keywordFn,
@@ -26,6 +27,7 @@ const defaultKeywords = {
26
27
  keywordArrow,
27
28
  keywordAddArray,
28
29
  stringInterpolation,
30
+ keywordNoAsync,
29
31
  };
30
32
 
31
33
  export const keywords = defaultKeywords;
@@ -1,7 +1,4 @@
1
- import {
2
- addKeyword,
3
- TokenType,
4
- } from '../operator/index.js';
1
+ import {addKeyword, TokenType} from '../operator/index.js';
5
2
 
6
3
  export default function fn(Parser) {
7
4
  Parser.acorn.keywordTypes.fn = new TokenType('fn', {
@@ -1,8 +1,5 @@
1
1
  import {types} from 'putout';
2
- import {
3
- addKeyword,
4
- TokenType,
5
- } from '../operator/index.js';
2
+ import {addKeyword, TokenType} from '../operator/index.js';
6
3
 
7
4
  const {
8
5
  isObjectExpression,
@@ -58,7 +58,8 @@ function createIfLet({isParenL}) {
58
58
  id: assignmentExpression.left,
59
59
  init: assignmentExpression.right,
60
60
  }],
61
- }, ifNode],
61
+ },
62
+ ifNode],
62
63
  };
63
64
 
64
65
  return this.finishNode(node, 'BlockStatement');
@@ -0,0 +1,36 @@
1
+ const {defineProperty} = Object;
2
+
3
+ export default function fn(Parser) {
4
+ return class extends Parser {
5
+ parseFunction(node, statement, allowExpressionBody, isAsync, forInit) {
6
+ return super.parseFunction(node, statement, allowExpressionBody, true, forInit);
7
+ }
8
+
9
+ checkUnreserved({start, end, name}) {
10
+ if (this.inGenerator && name === 'yield')
11
+ this.raiseRecoverable(start, `Cannot use 'yield' as identifier inside a generator`);
12
+
13
+ if (this.inAsync && name === 'await')
14
+ this.raiseRecoverable(start, `Cannot use 'await' as identifier inside an async function`);
15
+
16
+ if (this.currentThisScope().inClassFieldInit && name === 'arguments')
17
+ this.raiseRecoverable(start, `Cannot use 'arguments' in class field initializer`);
18
+
19
+ if (this.inClassStaticBlock && (name === 'arguments' || name === 'await'))
20
+ this.raise(start, `Cannot use ${name} in class static initialization block`);
21
+
22
+ if (this.keywords.test(name))
23
+ this.raise(start, `Unexpected keyword '` + name + `'`);
24
+
25
+ if (this.options.ecmaVersion < 6 && this.input.slice(start, end).includes('\\'))
26
+ return;
27
+
28
+ const re = this.strict ? this.reservedWordsStrict : this.reservedWords;
29
+
30
+ if (re.test(name) && !this.inAsync && name === 'await')
31
+ defineProperty(this, 'inAsync', {
32
+ value: true,
33
+ });
34
+ }
35
+ };
36
+ }
@@ -1,11 +1,11 @@
1
1
  import {types} from 'putout';
2
+ import {setGoldsteinTry} from '../types/try.js';
2
3
  import {
3
4
  BIND_LEXICAL,
4
5
  BIND_SIMPLE_CATCH,
5
6
  SCOPE_SIMPLE_CATCH,
6
7
  tokTypes as tt,
7
8
  } from '../operator/index.js';
8
- import {setGoldsteinTry} from '../types/try.js';
9
9
 
10
10
  const {
11
11
  isCallExpression,