goldstein 3.0.0 → 3.2.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 +11 -0
- package/README.md +68 -4
- package/build/parser.cjs +5492 -0
- package/package.json +9 -4
- package/packages/goldstein/index.js +11 -32
- package/packages/goldstein/parser.js +33 -0
- package/packages/keyword-arrow/index.js +43 -0
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goldstein",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "JavaScript with no limits",
|
|
7
|
-
"
|
|
7
|
+
"exports": {
|
|
8
|
+
"import": "./packages/goldstein/index.js",
|
|
9
|
+
"require": "./build/parser.cjs"
|
|
10
|
+
},
|
|
8
11
|
"bin": {
|
|
9
12
|
"gs": "bin/gs.js"
|
|
10
13
|
},
|
|
11
|
-
"exports": "./packages/goldstein/index.js",
|
|
12
14
|
"repository": {
|
|
13
15
|
"type": "git",
|
|
14
16
|
"url": "git://github.com/coderaiser/goldstein.git"
|
|
@@ -22,12 +24,15 @@
|
|
|
22
24
|
"test": "madrun test",
|
|
23
25
|
"coverage": "madrun coverage",
|
|
24
26
|
"lint": "madrun lint",
|
|
25
|
-
"fix:lint": "madrun fix:lint"
|
|
27
|
+
"fix:lint": "madrun fix:lint",
|
|
28
|
+
"build": "madrun build",
|
|
29
|
+
"prepublish": "madrun prepublish"
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"@putout/printer": "^1.16.0",
|
|
29
33
|
"acorn": "^8.7.1",
|
|
30
34
|
"esbuild": "^0.17.14",
|
|
35
|
+
"esbuild-node-builtins": "^0.1.0",
|
|
31
36
|
"estree-to-babel": "^5.0.1",
|
|
32
37
|
"putout": "^29.1.11",
|
|
33
38
|
"try-catch": "^3.0.1"
|
|
@@ -1,41 +1,17 @@
|
|
|
1
1
|
import {transform} from 'putout';
|
|
2
|
-
|
|
3
2
|
import {print} from '@putout/printer';
|
|
4
|
-
import {
|
|
5
|
-
import keywordFn from '../keyword-fn/index.js';
|
|
6
|
-
import keywordGuard from '../keyword-guard/index.js';
|
|
7
|
-
import keywordTry from '../keyword-try/index.js';
|
|
8
|
-
import keywordShould from '../keyword-should/index.js';
|
|
9
|
-
import keywordThrow from '../keyword-throw/index.js';
|
|
10
|
-
import stringInterpolation from '../string-interpolation/index.js';
|
|
11
|
-
import keywordCurry from '../keyword-curry/index.js';
|
|
12
|
-
import keywordFreeze from '../keyword-freeze/index.js';
|
|
13
|
-
import keywordIf from '../keyword-if/index.js';
|
|
14
|
-
import keywordImport from '../keyword-import/index.js';
|
|
15
|
-
|
|
3
|
+
import {parse} from './parser.js';
|
|
16
4
|
import estreeToBabel from 'estree-to-babel';
|
|
17
5
|
|
|
18
|
-
export
|
|
19
|
-
const {parse} = extendParser([
|
|
20
|
-
keywordFn,
|
|
21
|
-
keywordGuard,
|
|
22
|
-
keywordTry,
|
|
23
|
-
keywordShould,
|
|
24
|
-
keywordThrow,
|
|
25
|
-
keywordCurry,
|
|
26
|
-
keywordFreeze,
|
|
27
|
-
keywordIf,
|
|
28
|
-
keywordImport,
|
|
29
|
-
stringInterpolation,
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
return estreeToBabel(parse(source));
|
|
33
|
-
};
|
|
6
|
+
export * from './parser.js';
|
|
34
7
|
|
|
35
|
-
export const compile = (source) => {
|
|
36
|
-
const ast = parse(source);
|
|
8
|
+
export const compile = (source, options = {}) => {
|
|
9
|
+
const ast = estreeToBabel(parse(source));
|
|
37
10
|
|
|
38
11
|
transform(ast, source, {
|
|
12
|
+
rules: {
|
|
13
|
+
...options.rules,
|
|
14
|
+
},
|
|
39
15
|
plugins: [
|
|
40
16
|
'try-catch',
|
|
41
17
|
'declare',
|
|
@@ -43,9 +19,12 @@ export const compile = (source) => {
|
|
|
43
19
|
],
|
|
44
20
|
});
|
|
45
21
|
|
|
46
|
-
|
|
22
|
+
const {keywords} = options;
|
|
23
|
+
|
|
24
|
+
return fixEmpty(print(ast, {keywords}));
|
|
47
25
|
};
|
|
48
26
|
|
|
49
27
|
const fixEmpty = (source) => {
|
|
50
28
|
return source.replace(';;', ';');
|
|
51
29
|
};
|
|
30
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {extendParser} from '../parser/index.js';
|
|
2
|
+
import keywordFn from '../keyword-fn/index.js';
|
|
3
|
+
import keywordGuard from '../keyword-guard/index.js';
|
|
4
|
+
import keywordTry from '../keyword-try/index.js';
|
|
5
|
+
import keywordShould from '../keyword-should/index.js';
|
|
6
|
+
import keywordThrow from '../keyword-throw/index.js';
|
|
7
|
+
import stringInterpolation from '../string-interpolation/index.js';
|
|
8
|
+
import keywordCurry from '../keyword-curry/index.js';
|
|
9
|
+
import keywordFreeze from '../keyword-freeze/index.js';
|
|
10
|
+
import keywordIf from '../keyword-if/index.js';
|
|
11
|
+
import keywordImport from '../keyword-import/index.js';
|
|
12
|
+
import keywordArrow from '../keyword-arrow/index.js';
|
|
13
|
+
|
|
14
|
+
const defaultKeywords = {
|
|
15
|
+
keywordFn,
|
|
16
|
+
keywordGuard,
|
|
17
|
+
keywordTry,
|
|
18
|
+
keywordShould,
|
|
19
|
+
keywordThrow,
|
|
20
|
+
keywordCurry,
|
|
21
|
+
keywordFreeze,
|
|
22
|
+
keywordIf,
|
|
23
|
+
keywordImport,
|
|
24
|
+
keywordArrow,
|
|
25
|
+
stringInterpolation,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const keywords = defaultKeywords;
|
|
29
|
+
|
|
30
|
+
export const parse = (source, keywords = defaultKeywords) => {
|
|
31
|
+
const {parse} = extendParser(Object.values(keywords));
|
|
32
|
+
return parse(source);
|
|
33
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tokTypes as tt,
|
|
3
|
+
} from 'acorn';
|
|
4
|
+
|
|
5
|
+
export default function fn(Parser) {
|
|
6
|
+
return class extends Parser {
|
|
7
|
+
parseBlock(createNewLexicalScope, node, exitStrict) {
|
|
8
|
+
if (createNewLexicalScope === void 0)
|
|
9
|
+
createNewLexicalScope = true;
|
|
10
|
+
|
|
11
|
+
if (node === void 0)
|
|
12
|
+
node = this.startNode();
|
|
13
|
+
|
|
14
|
+
node.body = [];
|
|
15
|
+
|
|
16
|
+
// optionally parse arrow
|
|
17
|
+
this.eat(tt.arrow);
|
|
18
|
+
this.expect(tt.braceL);
|
|
19
|
+
|
|
20
|
+
if (createNewLexicalScope) {
|
|
21
|
+
this.enterScope(0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
while (this.type !== tt.braceR) {
|
|
25
|
+
const stmt = this.parseStatement(null);
|
|
26
|
+
node.body.push(stmt);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (exitStrict) {
|
|
30
|
+
this.strict = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.next();
|
|
34
|
+
|
|
35
|
+
if (createNewLexicalScope) {
|
|
36
|
+
this.exitScope();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return this.finishNode(node, 'BlockStatement');
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|