goldstein 3.2.3 → 3.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 +19 -0
- package/README.md +6 -4
- package/bin/gs.js +1 -0
- package/build/parser.cjs +486 -160
- package/package.json +10 -10
- package/packages/goldstein/index.js +4 -8
- package/packages/goldstein/parser.js +6 -2
- package/packages/keyword-arrow/index.js +1 -4
- package/packages/keyword-curry/index.js +1 -0
- package/packages/keyword-fn/index.js +2 -0
- package/packages/keyword-freeze/index.js +3 -4
- package/packages/keyword-guard/index.js +2 -0
- package/packages/keyword-should/index.js +2 -2
- package/packages/keyword-try/index.js +1 -2
- package/packages/operator/index.js +1 -1
- package/packages/operator/scopeflags.js +2 -4
- package/packages/parser/index.js +2 -3
- package/packages/string-interpolation/index.js +3 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goldstein",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.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,27 +29,27 @@
|
|
|
29
29
|
"wisdom": "madrun wisdom"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@putout/printer": "^
|
|
32
|
+
"@putout/printer": "^2.61.0",
|
|
33
33
|
"acorn": "^8.7.1",
|
|
34
|
-
"esbuild": "^0.
|
|
34
|
+
"esbuild": "^0.18.11",
|
|
35
35
|
"esbuild-node-builtins": "^0.1.0",
|
|
36
|
-
"estree-to-babel": "^
|
|
37
|
-
"putout": "^
|
|
36
|
+
"estree-to-babel": "^6.0.0",
|
|
37
|
+
"putout": "^30.2.0",
|
|
38
38
|
"try-catch": "^3.0.1"
|
|
39
39
|
},
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@cloudcmd/stub": "^4.0.1",
|
|
43
|
-
"c8": "^
|
|
43
|
+
"c8": "^8.0.0",
|
|
44
44
|
"check-dts": "^0.7.1",
|
|
45
|
-
"escover": "^
|
|
45
|
+
"escover": "^3.4.0",
|
|
46
46
|
"eslint": "^8.0.0-beta.1",
|
|
47
|
-
"eslint-plugin-n": "^
|
|
48
|
-
"eslint-plugin-putout": "^
|
|
47
|
+
"eslint-plugin-n": "^16.0.1",
|
|
48
|
+
"eslint-plugin-putout": "^18.0.0",
|
|
49
49
|
"madrun": "^9.0.0",
|
|
50
50
|
"mock-require": "^3.0.3",
|
|
51
51
|
"montag": "^1.2.1",
|
|
52
|
-
"nodemon": "^
|
|
52
|
+
"nodemon": "^3.0.1",
|
|
53
53
|
"runsome": "^1.0.0",
|
|
54
54
|
"supertape": "^8.0.1",
|
|
55
55
|
"typescript": "^5.0.3",
|
|
@@ -4,9 +4,8 @@ import {parse} from './parser.js';
|
|
|
4
4
|
import estreeToBabel from 'estree-to-babel';
|
|
5
5
|
|
|
6
6
|
export * from './parser.js';
|
|
7
|
-
|
|
8
7
|
export const compile = (source, options = {}) => {
|
|
9
|
-
const ast = estreeToBabel(parse(source));
|
|
8
|
+
const ast = estreeToBabel(parse(source, options));
|
|
10
9
|
|
|
11
10
|
transform(ast, source, {
|
|
12
11
|
rules: {
|
|
@@ -19,12 +18,9 @@ export const compile = (source, options = {}) => {
|
|
|
19
18
|
],
|
|
20
19
|
});
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return fixEmpty(print(ast, {keywords}));
|
|
21
|
+
return fixEmpty(print(ast));
|
|
25
22
|
};
|
|
26
23
|
|
|
27
|
-
const fixEmpty = (source) => {
|
|
28
|
-
return source.replace(
|
|
24
|
+
export const fixEmpty = (source) => {
|
|
25
|
+
return source.replace(/;(\s+)?;/g, ';');
|
|
29
26
|
};
|
|
30
|
-
|
|
@@ -27,7 +27,11 @@ const defaultKeywords = {
|
|
|
27
27
|
|
|
28
28
|
export const keywords = defaultKeywords;
|
|
29
29
|
|
|
30
|
-
export const parse = (source, options, keywords = defaultKeywords) => {
|
|
31
|
-
const {parse} = extendParser(Object.values(
|
|
30
|
+
export const parse = (source, options = {}, keywords = defaultKeywords) => {
|
|
31
|
+
const {parse} = extendParser(Object.values({
|
|
32
|
+
...options.keywords,
|
|
33
|
+
...keywords,
|
|
34
|
+
}));
|
|
35
|
+
|
|
32
36
|
return parse(source);
|
|
33
37
|
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
tokTypes as tt,
|
|
3
|
-
} from 'acorn';
|
|
1
|
+
import {tokTypes as tt} from 'acorn';
|
|
4
2
|
|
|
5
3
|
export default function fn(Parser) {
|
|
6
4
|
return class extends Parser {
|
|
@@ -12,7 +10,6 @@ export default function fn(Parser) {
|
|
|
12
10
|
node = this.startNode();
|
|
13
11
|
|
|
14
12
|
node.body = [];
|
|
15
|
-
|
|
16
13
|
// optionally parse arrow
|
|
17
14
|
this.eat(tt.arrow);
|
|
18
15
|
this.expect(tt.braceL);
|
|
@@ -13,6 +13,7 @@ export default function keywordCurry(Parser) {
|
|
|
13
13
|
|
|
14
14
|
return super.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
|
|
15
15
|
}
|
|
16
|
+
|
|
16
17
|
parseCurry(base, startPos, startLoc) {
|
|
17
18
|
const node = this.startNodeAt(startPos, startLoc);
|
|
18
19
|
const isParenL = this.eat(tt.parenL);
|
|
@@ -14,6 +14,7 @@ export default function fn(Parser) {
|
|
|
14
14
|
|
|
15
15
|
return super.parse();
|
|
16
16
|
}
|
|
17
|
+
|
|
17
18
|
parseStatement(context, topLevel, exports) {
|
|
18
19
|
if (this.type === Parser.acorn.keywordTypes.fn) {
|
|
19
20
|
this.type = Parser.acorn.keywordTypes.function;
|
|
@@ -21,6 +22,7 @@ export default function fn(Parser) {
|
|
|
21
22
|
|
|
22
23
|
return super.parseStatement(context, topLevel, exports);
|
|
23
24
|
}
|
|
25
|
+
|
|
24
26
|
shouldParseExportStatement() {
|
|
25
27
|
if (this.type === Parser.acorn.keywordTypes.fn) {
|
|
26
28
|
return true;
|
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
|
|
12
12
|
export default function keywordFreeze(Parser) {
|
|
13
13
|
const {keywordTypes} = Parser.acorn;
|
|
14
|
+
|
|
14
15
|
keywordTypes.freeze = new TokenType('freeze', {
|
|
15
16
|
keyword: 'freeze',
|
|
16
17
|
});
|
|
@@ -20,6 +21,7 @@ export default function keywordFreeze(Parser) {
|
|
|
20
21
|
this.keywords = addKeyword('freeze', this.keywords);
|
|
21
22
|
return super.parse();
|
|
22
23
|
}
|
|
24
|
+
|
|
23
25
|
parseStatement(context, topLevel, exports) {
|
|
24
26
|
if (this.type === keywordTypes.freeze) {
|
|
25
27
|
return this.parseFreeze();
|
|
@@ -43,12 +45,9 @@ export default function keywordFreeze(Parser) {
|
|
|
43
45
|
type: 'Identifier',
|
|
44
46
|
name: 'freeze',
|
|
45
47
|
},
|
|
46
|
-
arguments: [
|
|
47
|
-
expression,
|
|
48
|
-
],
|
|
48
|
+
arguments: [expression],
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
|
-
|
|
52
51
|
else
|
|
53
52
|
this.raise(this.start, `After 'freeze' only objects and arrays can come`);
|
|
54
53
|
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
export default function newSpeak(Parser) {
|
|
8
8
|
const {keywordTypes} = Parser.acorn;
|
|
9
|
+
|
|
9
10
|
keywordTypes.guard = new TokenType('guard', {
|
|
10
11
|
keyword: 'guard',
|
|
11
12
|
});
|
|
@@ -15,6 +16,7 @@ export default function newSpeak(Parser) {
|
|
|
15
16
|
this.keywords = addKeyword('guard', this.keywords);
|
|
16
17
|
return super.parse();
|
|
17
18
|
}
|
|
19
|
+
|
|
18
20
|
parseStatement(context, topLevel, exports) {
|
|
19
21
|
if (this.type === keywordTypes.guard) {
|
|
20
22
|
return this.parseGuard();
|
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
|
|
13
13
|
export default function newSpeak(Parser) {
|
|
14
14
|
const {keywordTypes} = Parser.acorn;
|
|
15
|
+
|
|
15
16
|
keywordTypes.should = new TokenType('should', {
|
|
16
17
|
keyword: 'should',
|
|
17
18
|
});
|
|
@@ -21,6 +22,7 @@ export default function newSpeak(Parser) {
|
|
|
21
22
|
this.keywords = addKeyword('should', this.keywords);
|
|
22
23
|
return super.parse();
|
|
23
24
|
}
|
|
25
|
+
|
|
24
26
|
parseStatement(context, topLevel, exports) {
|
|
25
27
|
if (this.type === keywordTypes.should) {
|
|
26
28
|
return this.parseShould();
|
|
@@ -61,7 +63,6 @@ export default function newSpeak(Parser) {
|
|
|
61
63
|
},
|
|
62
64
|
},
|
|
63
65
|
};
|
|
64
|
-
|
|
65
66
|
else if (isAwaitExpression(expression))
|
|
66
67
|
node.expression = {
|
|
67
68
|
type: 'TryStatement',
|
|
@@ -80,7 +81,6 @@ export default function newSpeak(Parser) {
|
|
|
80
81
|
},
|
|
81
82
|
},
|
|
82
83
|
};
|
|
83
|
-
|
|
84
84
|
else
|
|
85
85
|
this.raise(this.start, `After 'should' only 'await' and 'function call' can come`);
|
|
86
86
|
|
|
@@ -44,7 +44,6 @@ export default function newSpeak(Parser) {
|
|
|
44
44
|
...expression.arguments,
|
|
45
45
|
],
|
|
46
46
|
};
|
|
47
|
-
|
|
48
47
|
else if (isAwaitExpression(expression))
|
|
49
48
|
node.expression = {
|
|
50
49
|
type: 'AwaitExpression',
|
|
@@ -60,12 +59,12 @@ export default function newSpeak(Parser) {
|
|
|
60
59
|
],
|
|
61
60
|
},
|
|
62
61
|
};
|
|
63
|
-
|
|
64
62
|
else
|
|
65
63
|
this.raise(this.start, `After 'try' only '{', 'await' and 'function call' can come`);
|
|
66
64
|
|
|
67
65
|
return super.finishNode(node, 'ExpressionStatement');
|
|
68
66
|
}
|
|
67
|
+
|
|
69
68
|
parseUglyTry(node) {
|
|
70
69
|
node.block = this.parseBlock();
|
|
71
70
|
node.handler = null;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Each scope gets a bitset that may contain these flags
|
|
2
|
-
export const
|
|
3
|
-
SCOPE_TOP = 1,
|
|
2
|
+
export const SCOPE_TOP = 1,
|
|
4
3
|
SCOPE_FUNCTION = 2,
|
|
5
4
|
SCOPE_ASYNC = 4,
|
|
6
5
|
SCOPE_GENERATOR = 8,
|
|
@@ -12,8 +11,7 @@ export const
|
|
|
12
11
|
SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;
|
|
13
12
|
|
|
14
13
|
// Used in checkLVal* and declareName to determine the type of a binding
|
|
15
|
-
export const
|
|
16
|
-
BIND_NONE = 0, // Not a binding
|
|
14
|
+
export const BIND_NONE = 0, // Not a binding
|
|
17
15
|
BIND_VAR = 1, // Var-style binding
|
|
18
16
|
BIND_LEXICAL = 2, // Let- or const-style binding
|
|
19
17
|
BIND_FUNCTION = 3, // Function declaration
|
package/packages/parser/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {Parser} from 'acorn';
|
|
2
2
|
|
|
3
3
|
export const extendParser = (keywords) => {
|
|
4
|
-
const parser = Parser.extend(
|
|
5
|
-
...keywords,
|
|
6
|
-
);
|
|
4
|
+
const parser = Parser.extend(...keywords);
|
|
7
5
|
|
|
8
6
|
const parse = createParse(parser);
|
|
9
7
|
|
|
@@ -17,6 +15,7 @@ const createParse = (parser) => (source) => {
|
|
|
17
15
|
ecmaVersion: 'latest',
|
|
18
16
|
sourceType: 'module',
|
|
19
17
|
locations: true,
|
|
18
|
+
comment: true,
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
const result = parser.parse(source, options);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {template} from 'putout';
|
|
2
|
+
|
|
2
3
|
const isString = (a) => typeof a === 'string';
|
|
3
4
|
const {assign} = Object;
|
|
4
5
|
|
|
@@ -19,7 +20,6 @@ export default function stringInterpolation(Parser) {
|
|
|
19
20
|
if (char === '(') {
|
|
20
21
|
// keep count of parenthesis
|
|
21
22
|
parenthesis++;
|
|
22
|
-
|
|
23
23
|
// check if previous token was "/" (only if literal is not opened yet)
|
|
24
24
|
const prev = index - 1;
|
|
25
25
|
|
|
@@ -28,7 +28,6 @@ export default function stringInterpolation(Parser) {
|
|
|
28
28
|
out[prev] = '$';
|
|
29
29
|
// set current char to "{"
|
|
30
30
|
char = '{';
|
|
31
|
-
|
|
32
31
|
// set literalOpened to true
|
|
33
32
|
literalOpened = true;
|
|
34
33
|
// match TemplateLiteral instead of StringLiteral
|
|
@@ -37,9 +36,8 @@ export default function stringInterpolation(Parser) {
|
|
|
37
36
|
} else if (char === ')') {
|
|
38
37
|
parenthesis--;
|
|
39
38
|
|
|
40
|
-
if (parenthesis
|
|
39
|
+
if (!parenthesis && literalOpened) {
|
|
41
40
|
char = '}';
|
|
42
|
-
|
|
43
41
|
// reset literalOpened to false
|
|
44
42
|
literalOpened = false;
|
|
45
43
|
}
|
|
@@ -52,7 +50,7 @@ export default function stringInterpolation(Parser) {
|
|
|
52
50
|
const node = this.startNode();
|
|
53
51
|
this.next();
|
|
54
52
|
|
|
55
|
-
const {quasis, expressions} = template.ast(
|
|
53
|
+
const {quasis, expressions} = template.ast(`\`${out.join('')}\``);
|
|
56
54
|
|
|
57
55
|
assign(node, {
|
|
58
56
|
quasis,
|