goldstein 5.7.2 → 5.8.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,10 @@
1
+ 2024.05.22, v5.8.0
2
+
3
+ feature:
4
+ - 2bd6e8c test: do not fail when update tests
5
+ - f4fb1d6 goldstein: broken strings
6
+ - e80d132 goldstein: check-dts v0.8.0
7
+
1
8
  2024.05.11, v5.7.2
2
9
 
3
10
  fix:
package/README.md CHANGED
@@ -408,6 +408,23 @@ 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
+ Golstein will fix it to:
421
+
422
+ ```js
423
+ const a = 'hello';
424
+ const b = 'world';
425
+ ```
426
+
427
+
411
428
  ## How to contribute?
412
429
 
413
430
  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.7.2",
3
+ "version": "5.8.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.7.1",
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,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 keywordBrokenString from '../keyword-broken-string/index.js';
15
16
 
16
17
  const {values} = Object;
17
18
 
@@ -27,6 +28,7 @@ const defaultKeywords = {
27
28
  keywordImport,
28
29
  keywordArrow,
29
30
  keywordAddArray,
31
+ keywordBrokenString,
30
32
  stringInterpolation,
31
33
  };
32
34
 
@@ -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;
@@ -22,9 +22,11 @@ export default function fn(Parser) {
22
22
  node.body.push(stmt);
23
23
  }
24
24
 
25
+ /* c8 ignore start */
25
26
  if (exitStrict)
26
27
  this.strict = false;
27
28
 
29
+ /* c8 ignore end */
28
30
  this.next();
29
31
 
30
32
  if (createNewLexicalScope)
@@ -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');
@@ -80,8 +80,6 @@ export default function newSpeak(Parser) {
80
80
  },
81
81
  },
82
82
  };
83
- else
84
- this.raise(this.start, `After 'should' only 'await' and 'function call' can come`);
85
83
 
86
84
  return super.finishNode(node, 'ExpressionStatement');
87
85
  }
@@ -1,12 +1,7 @@
1
- import {visitors as v} from '@putout/printer';
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