goldstein 5.7.2 → 5.9.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 +25 -0
- package/package.json +2 -3
- package/packages/goldstein/parser.js +4 -0
- package/packages/keyword-add-array/index.js +2 -0
- package/packages/keyword-arrow/index.js +2 -0
- package/packages/keyword-broken-string/index.js +61 -0
- package/packages/keyword-import/index.js +2 -1
- package/packages/keyword-missing-initializer/index.js +31 -0
- package/packages/keyword-should/index.js +0 -2
- package/packages/printer/visitors/if-statement.js +1 -6
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2024.05.23, v5.9.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 1a9585b goldstein: missing-initializer: add
|
|
5
|
+
|
|
6
|
+
2024.05.22, v5.8.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 2bd6e8c test: do not fail when update tests
|
|
10
|
+
- f4fb1d6 goldstein: broken strings
|
|
11
|
+
- e80d132 goldstein: check-dts v0.8.0
|
|
12
|
+
|
|
1
13
|
2024.05.11, v5.7.2
|
|
2
14
|
|
|
3
15
|
fix:
|
package/README.md
CHANGED
|
@@ -408,6 +408,31 @@ That absolutely fine, it will be converted to:
|
|
|
408
408
|
function hello() {}
|
|
409
409
|
```
|
|
410
410
|
|
|
411
|
+
### Broken String
|
|
412
|
+
|
|
413
|
+
When you accidentally broke string:
|
|
414
|
+
|
|
415
|
+
```gs
|
|
416
|
+
const a = 'hello
|
|
417
|
+
const b = 'world';
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
Goldstein will fix it to:
|
|
421
|
+
|
|
422
|
+
```js
|
|
423
|
+
const a = 'hello';
|
|
424
|
+
const b = 'world';
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Missing Initializer
|
|
428
|
+
|
|
429
|
+
Forget to add assignment (`=`), not problem!
|
|
430
|
+
|
|
431
|
+
```gs
|
|
432
|
+
-const {code, places} await samadhi(source);
|
|
433
|
+
+const {code, places} = await samadhi(source);
|
|
434
|
+
```
|
|
435
|
+
|
|
411
436
|
## How to contribute?
|
|
412
437
|
|
|
413
438
|
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.
|
|
3
|
+
"version": "5.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "JavaScript with no limits",
|
|
@@ -45,10 +45,9 @@
|
|
|
45
45
|
"@putout/plugin-goldstein": "./rules/goldstein",
|
|
46
46
|
"@putout/test": "^9.0.1",
|
|
47
47
|
"c8": "^9.1.0",
|
|
48
|
-
"check-dts": "^0.
|
|
48
|
+
"check-dts": "^0.8.0",
|
|
49
49
|
"esbuild": "^0.21.1",
|
|
50
50
|
"esbuild-node-builtins": "^0.1.0",
|
|
51
|
-
"escover": "^4.0.1",
|
|
52
51
|
"eslint": "^9.2.0",
|
|
53
52
|
"eslint-plugin-putout": "^22.0.0",
|
|
54
53
|
"madrun": "^10.0.0",
|
|
@@ -12,6 +12,8 @@ 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 keywordBrokenString from '../keyword-broken-string/index.js';
|
|
16
|
+
import keywordMissingInitializer from '../keyword-missing-initializer/index.js';
|
|
15
17
|
|
|
16
18
|
const {values} = Object;
|
|
17
19
|
|
|
@@ -27,7 +29,9 @@ const defaultKeywords = {
|
|
|
27
29
|
keywordImport,
|
|
28
30
|
keywordArrow,
|
|
29
31
|
keywordAddArray,
|
|
32
|
+
keywordBrokenString,
|
|
30
33
|
stringInterpolation,
|
|
34
|
+
keywordMissingInitializer,
|
|
31
35
|
};
|
|
32
36
|
|
|
33
37
|
export const keywords = defaultKeywords;
|
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
export default function keywordAddArray(Parser) {
|
|
15
15
|
return class extends Parser {
|
|
16
16
|
parseMaybeAssign(forInit, refDestructuringErrors, afterLeftParse) {
|
|
17
|
+
/* c8 ignore start */
|
|
17
18
|
if (this.isContextual('yield')) {
|
|
18
19
|
if (this.inGenerator)
|
|
19
20
|
return this.parseYield(forInit);
|
|
@@ -23,6 +24,7 @@ export default function keywordAddArray(Parser) {
|
|
|
23
24
|
this.exprAllowed = false;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/* c8 ignore end */
|
|
26
28
|
let ownDestructuringErrors = false;
|
|
27
29
|
let oldParenAssign = -1;
|
|
28
30
|
let oldTrailingComma = -1;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {tokTypes as tt} from '../operator/index.js';
|
|
2
|
+
|
|
3
|
+
export default function keywordBrokenString(Parser) {
|
|
4
|
+
return class extends Parser {
|
|
5
|
+
parseVarStatement(node, kind, allowMissingInitializer) {
|
|
6
|
+
this.next();
|
|
7
|
+
this.parseVar(node, false, kind, allowMissingInitializer);
|
|
8
|
+
this.eat(tt.semi);
|
|
9
|
+
|
|
10
|
+
return this.finishNode(node, 'VariableDeclaration');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
readString(quote) {
|
|
14
|
+
let out = '';
|
|
15
|
+
let chunkStart = ++this.pos;
|
|
16
|
+
|
|
17
|
+
for (;;) {
|
|
18
|
+
const ch = this.input.charCodeAt(this.pos);
|
|
19
|
+
|
|
20
|
+
if (ch === quote)
|
|
21
|
+
break;
|
|
22
|
+
|
|
23
|
+
/* c8 ignore start */
|
|
24
|
+
if (ch === 92) {
|
|
25
|
+
// '\'
|
|
26
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
27
|
+
out += this.readEscapedChar(false);
|
|
28
|
+
chunkStart = this.pos;
|
|
29
|
+
} else if (ch === 0x2028 || ch === 0x2029) {
|
|
30
|
+
if (this.options.ecmaVersion < 10)
|
|
31
|
+
this.raise(this.start, 'Unterminated string constant');
|
|
32
|
+
|
|
33
|
+
++this.pos;
|
|
34
|
+
|
|
35
|
+
if (this.options.locations) {
|
|
36
|
+
this.curLine++;
|
|
37
|
+
this.lineStart = this.pos;
|
|
38
|
+
}
|
|
39
|
+
/* c8 ignore end */
|
|
40
|
+
} else {
|
|
41
|
+
if (isNewLine(ch)) {
|
|
42
|
+
if (this.input[this.pos - 1] === ';')
|
|
43
|
+
--this.pos;
|
|
44
|
+
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
++this.pos;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
out += this.input.slice(chunkStart, this.pos++);
|
|
53
|
+
|
|
54
|
+
return this.finishToken(tt.string, out);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isNewLine(code) {
|
|
60
|
+
return code === 10 || code === 13 || code === 0x2028 || code === 0x2029;
|
|
61
|
+
}
|
|
@@ -8,9 +8,10 @@ export default function keywordImport(Parser) {
|
|
|
8
8
|
this.next();
|
|
9
9
|
|
|
10
10
|
// import '...'
|
|
11
|
+
/* c8 ignore start */
|
|
11
12
|
if (this.type === tokTypes.string) {
|
|
12
13
|
node.specifiers = empty;
|
|
13
|
-
node.source = this.parseExprAtom();
|
|
14
|
+
node.source = this.parseExprAtom(); /* c8 ignore end */
|
|
14
15
|
} else {
|
|
15
16
|
node.specifiers = this.parseImportSpecifiers();
|
|
16
17
|
this.expectContextual('from');
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {tokTypes as tt} from '../operator/index.js';
|
|
2
|
+
|
|
3
|
+
export default function keywordMissingInitializer(Parser) {
|
|
4
|
+
return class extends Parser {
|
|
5
|
+
parseVar(node, isFor, kind, allowMissingInitializer) {
|
|
6
|
+
node.declarations = [];
|
|
7
|
+
node.kind = kind;
|
|
8
|
+
for (;;) {
|
|
9
|
+
const decl = this.startNode();
|
|
10
|
+
this.parseVarId(decl, kind);
|
|
11
|
+
|
|
12
|
+
if (this.eat(tt.eq)) {
|
|
13
|
+
decl.init = this.parseMaybeAssign(isFor);
|
|
14
|
+
} else if (!allowMissingInitializer && kind === 'const' && !(this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual('of'))) {
|
|
15
|
+
decl.init = this.parseMaybeAssign(isFor); /* c8 ignore start */
|
|
16
|
+
} else if (!allowMissingInitializer && decl.id.type !== 'Identifier' && !(isFor && (this.type === tt._in || this.isContextual('of'))))
|
|
17
|
+
this.raise(this.lastTokEnd, 'Complex binding patterns require an initialization value');
|
|
18
|
+
else
|
|
19
|
+
decl.init = null;
|
|
20
|
+
|
|
21
|
+
/* c8 ignore end */
|
|
22
|
+
node.declarations.push(this.finishNode(decl, 'VariableDeclarator'));
|
|
23
|
+
|
|
24
|
+
if (!this.eat(tt.comma))
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return node;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const IfStatement = (path, printer, semantics) => {
|
|
1
|
+
export const IfStatement = (path, printer) => {
|
|
4
2
|
const {print, indent} = printer;
|
|
5
3
|
const {node} = path;
|
|
6
4
|
|
|
7
|
-
if (!node.goldsteinIf)
|
|
8
|
-
return v.IfStatement(path, printer, semantics);
|
|
9
|
-
|
|
10
5
|
indent();
|
|
11
6
|
print('if ');
|
|
12
7
|
|