goldstein 4.2.0 → 4.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 +10 -0
- package/build/parser.cjs +7 -6
- package/package.json +1 -1
- package/packages/convert/apply-try/index.js +23 -0
- package/packages/convert/index.js +21 -0
- package/packages/goldstein/index.js +1 -1
- package/packages/keyword-if/index.js +2 -0
- package/packages/keyword-try/index.js +6 -6
- package/packages/printer/index.js +3 -2
- package/packages/printer/visitors/if-statement.js +19 -0
- package/packages/printer/visitors/try-statement.js +1 -0
package/ChangeLog
CHANGED
package/build/parser.cjs
CHANGED
|
@@ -5499,19 +5499,19 @@ function keywordTry(Parser3) {
|
|
|
5499
5499
|
expression.callee,
|
|
5500
5500
|
...expression.arguments
|
|
5501
5501
|
],
|
|
5502
|
-
goldstein:
|
|
5502
|
+
goldstein: createGoldsteinTry({
|
|
5503
5503
|
await: false,
|
|
5504
5504
|
callee: expression.callee,
|
|
5505
|
-
|
|
5505
|
+
args: expression.arguments
|
|
5506
5506
|
})
|
|
5507
5507
|
};
|
|
5508
5508
|
else if (isAwaitExpression(expression))
|
|
5509
5509
|
node.expression = {
|
|
5510
5510
|
type: "AwaitExpression",
|
|
5511
|
-
goldstein:
|
|
5511
|
+
goldstein: createGoldsteinTry({
|
|
5512
5512
|
await: true,
|
|
5513
5513
|
callee: expression.argument.callee,
|
|
5514
|
-
|
|
5514
|
+
args: expression.argument.arguments
|
|
5515
5515
|
}),
|
|
5516
5516
|
argument: {
|
|
5517
5517
|
type: "CallExpression",
|
|
@@ -5556,7 +5556,7 @@ function keywordTry(Parser3) {
|
|
|
5556
5556
|
}
|
|
5557
5557
|
};
|
|
5558
5558
|
}
|
|
5559
|
-
function
|
|
5559
|
+
function createGoldsteinTry(args) {
|
|
5560
5560
|
return {
|
|
5561
5561
|
type: "TryStatement",
|
|
5562
5562
|
expression: true,
|
|
@@ -5564,7 +5564,7 @@ function createGoldsteinNode(args) {
|
|
|
5564
5564
|
argument: {
|
|
5565
5565
|
type: "CallExpression",
|
|
5566
5566
|
callee: args.callee,
|
|
5567
|
-
arguments: args.
|
|
5567
|
+
arguments: args.args
|
|
5568
5568
|
}
|
|
5569
5569
|
};
|
|
5570
5570
|
}
|
|
@@ -5801,6 +5801,7 @@ function fn2(Parser3) {
|
|
|
5801
5801
|
this.raise(this.start, `Use both parens ('(', ')') or none`);
|
|
5802
5802
|
node.consequent = this.parseStatement("if");
|
|
5803
5803
|
node.alternate = this.eat(types$1._else) ? this.parseStatement("if") : null;
|
|
5804
|
+
node.goldsteinIf = true;
|
|
5804
5805
|
return this.finishNode(node, "IfStatement");
|
|
5805
5806
|
}
|
|
5806
5807
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {createGoldsteinTry} from '../../keyword-try/index.js';
|
|
2
|
+
|
|
3
|
+
export const report = () => `Use 'try' instead of 'tryCatch/tryToCatch'`;
|
|
4
|
+
export const replace = () => ({
|
|
5
|
+
'tryCatch(__args)': createTry({
|
|
6
|
+
awaitType: false,
|
|
7
|
+
}),
|
|
8
|
+
'await tryToCatch(__args)': createTry({
|
|
9
|
+
awaitType: true,
|
|
10
|
+
}),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const createTry = ({awaitType}) => ({__args}, path) => {
|
|
14
|
+
const [callee, ...args] = __args;
|
|
15
|
+
|
|
16
|
+
path.node.goldstein = createGoldsteinTry({
|
|
17
|
+
await: awaitType,
|
|
18
|
+
callee,
|
|
19
|
+
args,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return path;
|
|
23
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import estreeToBabel from 'estree-to-babel';
|
|
2
|
+
import {transform} from 'putout';
|
|
3
|
+
import {print} from '../printer/index.js';
|
|
4
|
+
import * as applyTry from './apply-try/index.js';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
fixEmpty,
|
|
8
|
+
parse,
|
|
9
|
+
} from '../goldstein/index.js';
|
|
10
|
+
export const convert = (source) => {
|
|
11
|
+
const ast = estreeToBabel(parse(source));
|
|
12
|
+
|
|
13
|
+
transform(ast, source, {
|
|
14
|
+
plugins: [
|
|
15
|
+
['apply-try', applyTry],
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return fixEmpty(print(ast));
|
|
20
|
+
};
|
|
21
|
+
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {transform} from 'putout';
|
|
2
2
|
import {print} from '@putout/printer';
|
|
3
|
-
import {parse} from './parser.js';
|
|
4
3
|
import estreeToBabel from 'estree-to-babel';
|
|
5
4
|
import tryCatchPlugin from '@putout/plugin-try-catch';
|
|
6
5
|
import declarePlugin from '@putout/plugin-declare';
|
|
7
6
|
import logicalExpressionsPlugin from '@putout/plugin-logical-expressions';
|
|
7
|
+
import {parse} from './parser.js';
|
|
8
8
|
|
|
9
9
|
export * from './parser.js';
|
|
10
10
|
export const compile = (source, options = {}) => {
|
|
@@ -43,19 +43,19 @@ export default function keywordTry(Parser) {
|
|
|
43
43
|
expression.callee,
|
|
44
44
|
...expression.arguments,
|
|
45
45
|
],
|
|
46
|
-
goldstein:
|
|
46
|
+
goldstein: createGoldsteinTry({
|
|
47
47
|
await: false,
|
|
48
48
|
callee: expression.callee,
|
|
49
|
-
|
|
49
|
+
args: expression.arguments,
|
|
50
50
|
}),
|
|
51
51
|
};
|
|
52
52
|
else if (isAwaitExpression(expression))
|
|
53
53
|
node.expression = {
|
|
54
54
|
type: 'AwaitExpression',
|
|
55
|
-
goldstein:
|
|
55
|
+
goldstein: createGoldsteinTry({
|
|
56
56
|
await: true,
|
|
57
57
|
callee: expression.argument.callee,
|
|
58
|
-
|
|
58
|
+
args: expression.argument.arguments,
|
|
59
59
|
}),
|
|
60
60
|
argument: {
|
|
61
61
|
type: 'CallExpression',
|
|
@@ -110,7 +110,7 @@ export default function keywordTry(Parser) {
|
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
function
|
|
113
|
+
export function createGoldsteinTry(args) {
|
|
114
114
|
return {
|
|
115
115
|
type: 'TryStatement',
|
|
116
116
|
expression: true,
|
|
@@ -118,7 +118,7 @@ function createGoldsteinNode(args) {
|
|
|
118
118
|
argument: {
|
|
119
119
|
type: 'CallExpression',
|
|
120
120
|
callee: args.callee,
|
|
121
|
-
arguments: args.
|
|
121
|
+
arguments: args.args,
|
|
122
122
|
},
|
|
123
123
|
};
|
|
124
124
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {print as printJS} from '@putout/printer';
|
|
2
|
-
|
|
2
|
+
import {fixEmpty} from '../goldstein/index.js';
|
|
3
3
|
import {AwaitExpression} from './visitors/await-expression.js';
|
|
4
4
|
import {CallExpression} from './visitors/call-expression.js';
|
|
5
5
|
import {TryStatement} from './visitors/try-statement.js';
|
|
6
|
-
import {
|
|
6
|
+
import {IfStatement} from './visitors/if-statement.js';
|
|
7
7
|
|
|
8
8
|
export const print = (ast) => {
|
|
9
9
|
const code = printJS(ast, {
|
|
@@ -11,6 +11,7 @@ export const print = (ast) => {
|
|
|
11
11
|
CallExpression,
|
|
12
12
|
TryStatement,
|
|
13
13
|
AwaitExpression,
|
|
14
|
+
IfStatement,
|
|
14
15
|
},
|
|
15
16
|
});
|
|
16
17
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {visitors as v} from '@putout/printer';
|
|
2
|
+
|
|
3
|
+
export const IfStatement = (path, printer, semantics) => {
|
|
4
|
+
const {print} = printer;
|
|
5
|
+
const {node} = path;
|
|
6
|
+
|
|
7
|
+
if (!node.goldsteinIf)
|
|
8
|
+
return v.IfStatement(path, printer, semantics);
|
|
9
|
+
|
|
10
|
+
print('if ');
|
|
11
|
+
print('__test');
|
|
12
|
+
print(' ');
|
|
13
|
+
print('__consequent');
|
|
14
|
+
|
|
15
|
+
if (node.alternate) {
|
|
16
|
+
print(' else ');
|
|
17
|
+
print('__alternate');
|
|
18
|
+
}
|
|
19
|
+
};
|