goldstein 4.2.0 → 4.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
CHANGED
package/build/parser.cjs
CHANGED
|
@@ -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
|
@@ -6,7 +6,6 @@ export default function fn(Parser) {
|
|
|
6
6
|
this.next();
|
|
7
7
|
|
|
8
8
|
const isParenL = this.eat(tt.parenL);
|
|
9
|
-
|
|
10
9
|
node.test = this.parseExpression();
|
|
11
10
|
const isParenR = this.eat(tt.parenR);
|
|
12
11
|
|
|
@@ -19,8 +18,9 @@ export default function fn(Parser) {
|
|
|
19
18
|
node.consequent = this.parseStatement('if');
|
|
20
19
|
node.alternate = this.eat(tt._else) ? this.parseStatement('if') : null;
|
|
21
20
|
|
|
21
|
+
node.goldsteinIf = true;
|
|
22
|
+
|
|
22
23
|
return this.finishNode(node, 'IfStatement');
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {print as printJS} from '@putout/printer';
|
|
2
2
|
|
|
3
|
+
import {fixEmpty} from '../goldstein/index.js';
|
|
3
4
|
import {AwaitExpression} from './visitors/await-expression.js';
|
|
4
5
|
import {CallExpression} from './visitors/call-expression.js';
|
|
5
6
|
import {TryStatement} from './visitors/try-statement.js';
|
|
6
|
-
import {
|
|
7
|
+
import {IfStatement} from './visitors/if-statement.js';
|
|
7
8
|
|
|
8
9
|
export const print = (ast) => {
|
|
9
10
|
const code = printJS(ast, {
|
|
@@ -11,6 +12,7 @@ export const print = (ast) => {
|
|
|
11
12
|
CallExpression,
|
|
12
13
|
TryStatement,
|
|
13
14
|
AwaitExpression,
|
|
15
|
+
IfStatement,
|
|
14
16
|
},
|
|
15
17
|
});
|
|
16
18
|
|
|
@@ -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
|
+
};
|