goldstein 5.2.0 → 5.3.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 +12 -0
- package/README.md +19 -9
- package/build/parser.cjs +44 -10
- package/package.json +6 -4
- package/packages/convert/index.js +1 -4
- package/packages/goldstein/index.js +2 -0
- package/packages/goldstein/parser.js +2 -0
- package/packages/keyword-fn/index.js +1 -4
- package/packages/keyword-freeze/index.js +1 -4
- package/packages/keyword-if/index.js +2 -1
- package/packages/keyword-no-async/index.js +36 -0
- package/packages/keyword-try/index.js +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2024.05.06, v5.3.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 98f3048 goldstein: add ability to parse no async code with await
|
|
5
|
+
- 45c7363 @putout/plugin-goldstein: eslint-plugin-putout v22.7.0
|
|
6
|
+
- 3964832 @putout/plugin-goldstein: @putout/test v9.1.0
|
|
7
|
+
- aa689c7 @putout/plugin-goldstein: eslint v9.2.0
|
|
8
|
+
- 1399854 @putout/plugin-goldstein: c8 v9.1.0
|
|
9
|
+
- a728422 goldstein: redlint v3.14.1
|
|
10
|
+
- 6f03127 goldstein: eslint v9.2.0
|
|
11
|
+
- 23c8eb3 goldstein: @putout/plugin-declare v4.0.0
|
|
12
|
+
|
|
1
13
|
2024.02.20, v5.2.0
|
|
2
14
|
|
|
3
15
|
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(
|
|
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/build/parser.cjs
CHANGED
|
@@ -1134,6 +1134,7 @@ pp$8.parseLabeledStatement = function(node, maybeName, expr, context) {
|
|
|
1134
1134
|
};
|
|
1135
1135
|
pp$8.parseExpressionStatement = function(node, expr) {
|
|
1136
1136
|
node.expression = expr;
|
|
1137
|
+
console.log(expr);
|
|
1137
1138
|
this.semicolon();
|
|
1138
1139
|
return this.finishNode(node, "ExpressionStatement");
|
|
1139
1140
|
};
|
|
@@ -5948,15 +5949,18 @@ function createIfLet({ isParenL }) {
|
|
|
5948
5949
|
const node = {
|
|
5949
5950
|
loc: {},
|
|
5950
5951
|
range: [],
|
|
5951
|
-
body: [
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5952
|
+
body: [
|
|
5953
|
+
{
|
|
5954
|
+
type: "VariableDeclaration",
|
|
5955
|
+
kind: "let",
|
|
5956
|
+
declarations: [{
|
|
5957
|
+
type: "VariableDeclarator",
|
|
5958
|
+
id: assignmentExpression.left,
|
|
5959
|
+
init: assignmentExpression.right
|
|
5960
|
+
}]
|
|
5961
|
+
},
|
|
5962
|
+
ifNode
|
|
5963
|
+
]
|
|
5960
5964
|
};
|
|
5961
5965
|
return this.finishNode(node, "BlockStatement");
|
|
5962
5966
|
}
|
|
@@ -6109,6 +6113,35 @@ function createAppendNode(context, node) {
|
|
|
6109
6113
|
return context.finishNode(node, "CallExpression");
|
|
6110
6114
|
}
|
|
6111
6115
|
|
|
6116
|
+
// packages/keyword-no-async/index.js
|
|
6117
|
+
var { defineProperty } = Object;
|
|
6118
|
+
function fn4(Parser3) {
|
|
6119
|
+
return class extends Parser3 {
|
|
6120
|
+
parseFunction(node, statement, allowExpressionBody, isAsync, forInit) {
|
|
6121
|
+
return super.parseFunction(node, statement, allowExpressionBody, true, forInit);
|
|
6122
|
+
}
|
|
6123
|
+
checkUnreserved({ start, end, name }) {
|
|
6124
|
+
if (this.inGenerator && name === "yield")
|
|
6125
|
+
this.raiseRecoverable(start, `Cannot use 'yield' as identifier inside a generator`);
|
|
6126
|
+
if (this.inAsync && name === "await")
|
|
6127
|
+
this.raiseRecoverable(start, `Cannot use 'await' as identifier inside an async function`);
|
|
6128
|
+
if (this.currentThisScope().inClassFieldInit && name === "arguments")
|
|
6129
|
+
this.raiseRecoverable(start, `Cannot use 'arguments' in class field initializer`);
|
|
6130
|
+
if (this.inClassStaticBlock && (name === "arguments" || name === "await"))
|
|
6131
|
+
this.raise(start, `Cannot use ${name} in class static initialization block`);
|
|
6132
|
+
if (this.keywords.test(name))
|
|
6133
|
+
this.raise(start, `Unexpected keyword '` + name + `'`);
|
|
6134
|
+
if (this.options.ecmaVersion < 6 && this.input.slice(start, end).includes("\\"))
|
|
6135
|
+
return;
|
|
6136
|
+
const re = this.strict ? this.reservedWordsStrict : this.reservedWords;
|
|
6137
|
+
if (re.test(name) && !this.inAsync && name === "await")
|
|
6138
|
+
defineProperty(this, "inAsync", {
|
|
6139
|
+
value: true
|
|
6140
|
+
});
|
|
6141
|
+
}
|
|
6142
|
+
};
|
|
6143
|
+
}
|
|
6144
|
+
|
|
6112
6145
|
// packages/goldstein/parser.js
|
|
6113
6146
|
var defaultKeywords = {
|
|
6114
6147
|
keywordFn: fn,
|
|
@@ -6122,7 +6155,8 @@ var defaultKeywords = {
|
|
|
6122
6155
|
keywordImport,
|
|
6123
6156
|
keywordArrow: fn3,
|
|
6124
6157
|
keywordAddArray,
|
|
6125
|
-
stringInterpolation
|
|
6158
|
+
stringInterpolation,
|
|
6159
|
+
keywordNoAsync: fn4
|
|
6126
6160
|
};
|
|
6127
6161
|
var keywords2 = defaultKeywords;
|
|
6128
6162
|
var parse3 = (source, options = {}, keywords3 = defaultKeywords) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goldstein",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "JavaScript with no limits",
|
|
@@ -29,9 +29,10 @@
|
|
|
29
29
|
"wisdom": "madrun wisdom"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@putout/plugin-declare": "^
|
|
32
|
+
"@putout/plugin-declare": "^4.0.0",
|
|
33
33
|
"@putout/plugin-logical-expressions": "^5.0.0",
|
|
34
34
|
"@putout/plugin-try-catch": "^3.0.0",
|
|
35
|
+
"@putout/plugin-promises": "^14.1.0",
|
|
35
36
|
"@putout/printer": "^8.0.1",
|
|
36
37
|
"acorn": "^8.7.1",
|
|
37
38
|
"esbuild": "^0.20.1",
|
|
@@ -45,17 +46,18 @@
|
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@babel/core": "^8.0.0-alpha.5",
|
|
47
48
|
"@cloudcmd/stub": "^4.0.1",
|
|
49
|
+
"@putout/plugin-goldstein": "./rules/goldstein",
|
|
48
50
|
"@putout/test": "^9.0.1",
|
|
49
51
|
"c8": "^9.1.0",
|
|
50
52
|
"check-dts": "^0.7.1",
|
|
51
53
|
"escover": "^4.0.1",
|
|
52
|
-
"eslint": "^
|
|
53
|
-
"eslint-plugin-n": "^16.0.1",
|
|
54
|
+
"eslint": "^9.2.0",
|
|
54
55
|
"eslint-plugin-putout": "^22.0.0",
|
|
55
56
|
"madrun": "^10.0.0",
|
|
56
57
|
"mock-require": "^3.0.3",
|
|
57
58
|
"montag": "^1.2.1",
|
|
58
59
|
"nodemon": "^3.0.1",
|
|
60
|
+
"redlint": "^3.14.1",
|
|
59
61
|
"runsome": "^1.0.0",
|
|
60
62
|
"supertape": "^10.1.0",
|
|
61
63
|
"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;
|
|
@@ -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,
|