rapydscript-ng 0.7.23 → 0.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +72 -26
  3. package/bin/package.json +1 -0
  4. package/bin/rapydscript +65 -62
  5. package/editor-plugins/nvim/rapydscript/README.md +184 -0
  6. package/editor-plugins/nvim/rapydscript/bin/rapydscript.so +0 -0
  7. package/editor-plugins/nvim/rapydscript/ftdetect/rapydscript.lua +10 -0
  8. package/editor-plugins/nvim/rapydscript/lua/rapydscript/health.lua +88 -0
  9. package/editor-plugins/nvim/rapydscript/lua/rapydscript/init.lua +279 -0
  10. package/local-agent.md +28 -0
  11. package/package.json +4 -5
  12. package/release/baselib-plain-pretty.js +448 -326
  13. package/release/baselib-plain-ugly.js +3 -3
  14. package/release/compiler.js +2528 -1672
  15. package/release/signatures.json +17 -17
  16. package/src/ast.pyj +73 -25
  17. package/src/baselib-builtins.pyj +2 -2
  18. package/src/baselib-containers.pyj +153 -151
  19. package/src/baselib-internal.pyj +3 -3
  20. package/src/baselib-str.pyj +5 -5
  21. package/src/lib/aes.pyj +1 -1
  22. package/src/lib/encodings.pyj +1 -1
  23. package/src/lib/pythonize.pyj +1 -1
  24. package/src/lib/re.pyj +2 -2
  25. package/src/lib/traceback.pyj +165 -28
  26. package/src/lib/uuid.pyj +1 -1
  27. package/src/output/codegen.pyj +10 -3
  28. package/src/output/functions.pyj +31 -40
  29. package/src/output/literals.pyj +11 -14
  30. package/src/output/loops.pyj +25 -87
  31. package/src/output/modules.pyj +5 -47
  32. package/src/output/statements.pyj +1 -1
  33. package/src/output/stream.pyj +58 -31
  34. package/src/parse.pyj +777 -427
  35. package/src/tokenizer.pyj +16 -4
  36. package/src/utils.pyj +1 -1
  37. package/test/_treeshake_mod.pyj +30 -0
  38. package/test/_treeshake_side_effect.pyj +9 -0
  39. package/test/ast_serialization.pyj +392 -0
  40. package/test/async.pyj +95 -0
  41. package/test/baselib.pyj +1 -2
  42. package/test/embedded_compiler.pyj +57 -0
  43. package/test/fmt.pyj +201 -0
  44. package/test/generic.pyj +7 -3
  45. package/test/imports.pyj +8 -6
  46. package/test/internationalization.pyj +38 -37
  47. package/test/lint.pyj +120 -115
  48. package/test/lsp.pyj +222 -0
  49. package/test/repl.pyj +70 -65
  50. package/test/sourcemaps.pyj +315 -0
  51. package/test/starargs.pyj +46 -39
  52. package/test/traceback.pyj +263 -0
  53. package/test/treeshaking.pyj +181 -0
  54. package/test/web_repl_export.pyj +88 -0
  55. package/tools/ast_serialize.mjs +557 -0
  56. package/tools/cli.mjs +510 -0
  57. package/tools/compile.mjs +201 -0
  58. package/tools/compiler.mjs +127 -0
  59. package/tools/{completer.js → completer.mjs} +6 -6
  60. package/tools/{embedded_compiler.js → embedded_compiler.mjs} +17 -13
  61. package/tools/export.js +109 -56
  62. package/tools/fmt.mjs +735 -0
  63. package/tools/{gettext.js → gettext.mjs} +46 -53
  64. package/tools/{ini.js → ini.mjs} +9 -10
  65. package/tools/{lint.js → lint.mjs} +107 -56
  66. package/tools/lsp.mjs +914 -0
  67. package/tools/lsp_protocol.mjs +259 -0
  68. package/tools/lsp_symbols.mjs +418 -0
  69. package/tools/{msgfmt.js → msgfmt.mjs} +18 -18
  70. package/tools/{repl.js → repl.mjs} +52 -41
  71. package/tools/{self.js → self.mjs} +56 -46
  72. package/tools/sourcemap.mjs +123 -0
  73. package/tools/test.mjs +152 -0
  74. package/tools/treeshake.mjs +400 -0
  75. package/tools/{utils.js → utils.mjs} +26 -23
  76. package/tools/{web_repl.js → web_repl.mjs} +15 -13
  77. package/tools/web_repl_export.mjs +93 -0
  78. package/tree-sitter/README.md +101 -0
  79. package/tree-sitter/grammar.js +992 -0
  80. package/tree-sitter/package.json +43 -0
  81. package/tree-sitter/queries/rapydscript/highlights.scm +232 -0
  82. package/tree-sitter/queries/rapydscript/indents.scm +64 -0
  83. package/tree-sitter/queries/rapydscript/injections.scm +14 -0
  84. package/tree-sitter/queries/rapydscript/locals.scm +108 -0
  85. package/tree-sitter/src/grammar.json +4976 -0
  86. package/tree-sitter/src/node-types.json +2901 -0
  87. package/tree-sitter/src/parser.c +196465 -0
  88. package/tree-sitter/src/scanner.c +294 -0
  89. package/tree-sitter/src/tree_sitter/alloc.h +54 -0
  90. package/tree-sitter/src/tree_sitter/array.h +330 -0
  91. package/tree-sitter/src/tree_sitter/parser.h +286 -0
  92. package/tree-sitter/test/corpus/chaining.txt +99 -0
  93. package/tree-sitter/test/corpus/classes.txt +147 -0
  94. package/tree-sitter/test/corpus/comprehensions.txt +155 -0
  95. package/tree-sitter/test/corpus/containers.txt +242 -0
  96. package/tree-sitter/test/corpus/control_flow.txt +361 -0
  97. package/tree-sitter/test/corpus/decorators.txt +64 -0
  98. package/tree-sitter/test/corpus/existential.txt +102 -0
  99. package/tree-sitter/test/corpus/functions.txt +293 -0
  100. package/tree-sitter/test/corpus/imports.txt +117 -0
  101. package/tree-sitter/test/corpus/literals.txt +135 -0
  102. package/tree-sitter/test/corpus/operators.txt +296 -0
  103. package/tree-sitter/test/corpus/statements.txt +189 -0
  104. package/tree-sitter/test/corpus/strings.txt +90 -0
  105. package/tree-sitter/test/corpus/subscripts.txt +227 -0
  106. package/tree-sitter/tree-sitter.json +36 -0
  107. package/web-repl/env.js +35 -23
  108. package/web-repl/main.js +8 -8
  109. package/bin/export +0 -75
  110. package/bin/web-repl-export +0 -102
  111. package/tools/cli.js +0 -523
  112. package/tools/compile.js +0 -184
  113. package/tools/compiler.js +0 -84
  114. package/tools/test.js +0 -110
@@ -0,0 +1,201 @@
1
+ /*
2
+ * compile.js
3
+ * Copyright (C) 2015 Kovid Goyal <kovid at kovidgoyal.net>
4
+ *
5
+ * Distributed under terms of the BSD license.
6
+ */
7
+
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import vm from 'vm';
11
+ import { createRequire } from 'module';
12
+ import { create_compiler } from './compiler.mjs';
13
+ import * as utils from './utils.mjs';
14
+ import { generate_source_map } from './sourcemap.mjs';
15
+ import tree_shake from './treeshake.mjs';
16
+
17
+ const require = createRequire(import.meta.url);
18
+ const RapydScript = await create_compiler();
19
+
20
+ async function read_whole_file(filename) {
21
+ if (!filename) {
22
+ var chunks = [];
23
+ process.stdin.setEncoding('utf-8');
24
+ await new Promise((resolve, reject) => {
25
+ process.stdin.on('data', chunk => chunks.push(chunk));
26
+ process.stdin.on('end', resolve);
27
+ process.stdin.on('error', reject);
28
+ });
29
+ process.openStdin();
30
+ return chunks.join('');
31
+ } else {
32
+ return await fs.promises.readFile(filename, 'utf-8');
33
+ }
34
+ }
35
+
36
+ async function makedirs(dir) {
37
+ try {
38
+ await fs.promises.mkdir(dir);
39
+ } catch(e) {
40
+ if (e.code == 'EEXIST') return;
41
+ if (e.code == 'ENOENT') { await makedirs(path.dirname(dir)); await fs.promises.mkdir(dir); }
42
+ else throw e;
43
+ }
44
+ }
45
+
46
+ async function process_cache_dir(dir) {
47
+ dir = path.resolve(path.normalize(dir));
48
+ await makedirs(dir);
49
+ return dir;
50
+ }
51
+
52
+ export default async function(start_time, argv, base_path, src_path, lib_path) {
53
+ // configure settings for the output
54
+ var cache_dir = argv.cache_dir ? await process_cache_dir(argv.cache_dir) : '';
55
+ var OUTPUT_OPTIONS = {
56
+ beautify: !argv.uglify,
57
+ private_scope: !argv.bare,
58
+ omit_baselib: argv.omit_baselib,
59
+ js_version: parseInt(argv.js_version),
60
+ keep_docstrings: argv.keep_docstrings,
61
+ discard_asserts: argv.discard_asserts,
62
+ module_cache_dir: cache_dir,
63
+ source_map: !!argv.source_map,
64
+ source_map_line_offset: parseInt(argv.source_map_line_offset) || 0,
65
+ };
66
+
67
+ if (argv.comments) {
68
+ if (/^\//.test(argv.comments)) {
69
+ OUTPUT_OPTIONS.comments = new Function("return(" + argv.comments + ")")(); // jshint ignore:line
70
+ } else if (argv.comments == "all") {
71
+ OUTPUT_OPTIONS.comments = true;
72
+ } else {
73
+ OUTPUT_OPTIONS.comments = function(node, comment) {
74
+ var text = comment.value;
75
+ var type = comment.type;
76
+ if (type == "comment2") {
77
+ // multiline comment
78
+ return /@preserve|@license|@cc_on/i.test(text);
79
+ }
80
+ };
81
+ }
82
+ }
83
+
84
+ if (!argv.omit_baselib) {
85
+ var which = (OUTPUT_OPTIONS.beautify) ? 'pretty' : 'ugly';
86
+ OUTPUT_OPTIONS.baselib_plain = await fs.promises.readFile(path.join(lib_path, 'baselib-plain-' + which + '.js'), 'utf-8');
87
+ }
88
+
89
+ var files = argv.files.slice();
90
+ var STATS = {}, TOPLEVEL;
91
+ var num_of_files = files.length || 1;
92
+
93
+ if (files.filter(function(el){ return el == "-"; }).length > 1) {
94
+ console.error("ERROR: Can read a single file from STDIN (two or more dashes specified)");
95
+ process.exit(1);
96
+ }
97
+
98
+ async function parse_file(code, file, toplevel) {
99
+ return await RapydScript.parse(code, {
100
+ filename: file,
101
+ toplevel: toplevel,
102
+ basedir: (file !== '<stdin>') ? path.dirname(file) : undefined,
103
+ libdir: path.join(src_path, 'lib'),
104
+ import_dirs: utils.get_import_dirs(argv.import_path),
105
+ discard_asserts: argv.discard_asserts,
106
+ module_cache_dir: cache_dir,
107
+ });
108
+ }
109
+
110
+ async function write_output(js_output, output_stream) {
111
+ if (argv.source_map && output_stream) {
112
+ var segments = output_stream.get_source_map_segments();
113
+ var map_json = generate_source_map(segments, argv.output, '');
114
+ await fs.promises.writeFile(argv.source_map, map_json, 'utf8');
115
+ if (argv.output) {
116
+ var map_url = path.relative(path.dirname(path.resolve(argv.output)), path.resolve(argv.source_map));
117
+ js_output = js_output + '\n//# sourceMappingURL=' + map_url + '\n';
118
+ }
119
+ }
120
+ if (argv.output) {
121
+ // Node's filesystem module cannot write directly to /dev/stdout
122
+ if (argv.output == '/dev/stdout') console.log(js_output);
123
+ else if (argv.output == '/dev/stderr') console.error(js_output);
124
+ else await fs.promises.writeFile(argv.output, js_output, "utf8");
125
+ } else if (!argv.execute){
126
+ console.log(js_output);
127
+ }
128
+ if (argv.execute) {
129
+ vm.runInNewContext(js_output, {'console':console, 'require':require}, {'filename':files[0]});
130
+ }
131
+ }
132
+
133
+ async function time_it(name, cont) {
134
+ var t1 = new Date().getTime();
135
+ var ret = await cont();
136
+ if (argv.stats) {
137
+ var spent = new Date().getTime() - t1;
138
+ if (STATS[name]) STATS[name] += spent;
139
+ else STATS[name] = spent;
140
+ }
141
+ return ret;
142
+ }
143
+
144
+ var filenames = files.length ? files : [null];
145
+ for (var i = 0; i < filenames.length; i++) {
146
+ var filename = filenames[i];
147
+ var code;
148
+ try {
149
+ code = await read_whole_file(filename);
150
+ } catch(e) {
151
+ console.error("ERROR: can't read file: " + filename);
152
+ process.exit(1);
153
+ }
154
+
155
+ var output_stream;
156
+ await time_it("parse", async function(){
157
+ var file = filename || argv.filename_for_stdin || '<stdin>';
158
+ try {
159
+ TOPLEVEL = await parse_file(code, file, TOPLEVEL);
160
+ } catch (e) {
161
+ if (!(e instanceof RapydScript.SyntaxError)) throw e;
162
+ console.error(e.toString());
163
+ process.exit(1);
164
+ }
165
+ });
166
+
167
+ try {
168
+ output_stream = new RapydScript.OutputStream(OUTPUT_OPTIONS);
169
+ } catch(ex) {
170
+ if (ex instanceof RapydScript.DefaultsError) {
171
+ console.error(ex.message);
172
+ process.exit(1);
173
+ }
174
+ throw ex;
175
+ }
176
+
177
+ if (argv.tree_shaking) {
178
+ time_it("tree_shaking", function(){
179
+ TOPLEVEL = tree_shake(TOPLEVEL);
180
+ });
181
+ }
182
+
183
+ time_it("generate", function(){
184
+ TOPLEVEL.print(output_stream);
185
+ });
186
+
187
+ await write_output(output_stream.get(), output_stream);
188
+ }
189
+
190
+ if (argv.stats) {
191
+ console.error(RapydScript.string_template("Timing information (compressed {count} files):", {
192
+ count: num_of_files
193
+ }));
194
+ for (var i in STATS) if (Object.prototype.hasOwnProperty.call(STATS, i)) {
195
+ console.error(RapydScript.string_template("- {name}: {time}s", {
196
+ name: i,
197
+ time: (STATS[i] / 1000).toFixed(3)
198
+ }));
199
+ }
200
+ }
201
+ }
@@ -0,0 +1,127 @@
1
+ /* vim:fileencoding=utf-8
2
+ *
3
+ * Copyright (C) 2015 Kovid Goyal <kovid at kovidgoyal.net>
4
+ *
5
+ * Distributed under terms of the BSD license
6
+ */
7
+ "use strict";
8
+
9
+ // Thin wrapper around (release|dev)/compiler.js to setup some global facilities and
10
+ // export the compiler's symbols safely.
11
+
12
+ import path from 'path';
13
+ import fs from 'fs';
14
+ import crypto from 'crypto';
15
+ import vm from 'vm';
16
+ import * as terser from 'terser';
17
+ import { fileURLToPath } from 'url';
18
+ import { createRequire } from 'module';
19
+ import { generate_source_map } from './sourcemap.mjs';
20
+ import embedded_compiler_factory from './embedded_compiler.mjs';
21
+ import tree_shake from './treeshake.mjs';
22
+ import { make_ast_serializer } from './ast_serialize.mjs';
23
+
24
+ const _cjs_require = createRequire(import.meta.url);
25
+
26
+ function sha1sum(data) {
27
+ var h = crypto.createHash('sha1');
28
+ h.update(data);
29
+ return h.digest('hex');
30
+ }
31
+
32
+ async function path_exists(p) {
33
+ try {
34
+ await fs.promises.stat(p);
35
+ return true;
36
+ } catch(e) {
37
+ if (e.code != 'ENOENT') throw e;
38
+ return false;
39
+ }
40
+ }
41
+
42
+ function uglify(code) {
43
+ var ans = terser.minify_sync(code);
44
+ if (ans.error) throw ans.error;
45
+ return ans.code;
46
+ }
47
+
48
+
49
+ async function find_compiler_dir() {
50
+ var base = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
51
+ var compiler_dir = path.join(base, 'dev');
52
+ if (!await path_exists(path.join(compiler_dir, 'compiler.js'))) compiler_dir = path.join(base, 'release');
53
+ return { base, compiler_dir };
54
+ }
55
+
56
+ async function create_compiler(opts) {
57
+ opts = opts || {};
58
+ var vfs = opts.virtual_file_system;
59
+
60
+ const { base, compiler_dir } = await find_compiler_dir();
61
+
62
+ var readfile, writefile, stat_file;
63
+ if (vfs) {
64
+ var stdlib_dir = path.join(base, 'src', 'lib');
65
+ readfile = async (p, enc) => {
66
+ if (p.startsWith('__stdlib__/')) {
67
+ return fs.promises.readFile(path.join(stdlib_dir, p.slice('__stdlib__/'.length)), enc);
68
+ }
69
+ return vfs.read_file(p, enc);
70
+ };
71
+ writefile = async (p, data) => {
72
+ if (p.startsWith('__vfs__/')) {
73
+ if (typeof vfs.write_file === 'function') return vfs.write_file(p, data);
74
+ return;
75
+ }
76
+ if (p.startsWith('__stdlib__/')) return;
77
+ return fs.promises.writeFile(p, data);
78
+ };
79
+ // VFS has no stat; read the file to check existence and return the content
80
+ // so do_import can reuse it without a second read (mtimeMs: null disables
81
+ // the mtime fast-path, but the content avoids a double-read).
82
+ stat_file = async (p) => {
83
+ const content = await readfile(p, 'utf-8');
84
+ return { mtimeMs: null, content };
85
+ };
86
+ } else {
87
+ readfile = async (p, enc) => fs.promises.readFile(p, enc);
88
+ writefile = async (p, data) => fs.promises.writeFile(p, data);
89
+ stat_file = async (p) => {
90
+ const st = await fs.promises.stat(p);
91
+ return { mtimeMs: st.mtimeMs };
92
+ };
93
+ }
94
+
95
+ var compiler_exports = {};
96
+ var compiler_context = vm.createContext({
97
+ console : console,
98
+ readfile : readfile,
99
+ writefile : writefile,
100
+ stat_file : stat_file,
101
+ sha1sum : sha1sum,
102
+ require : _cjs_require,
103
+ exports : compiler_exports,
104
+ });
105
+ var compiler_file = path.join(compiler_dir, 'compiler.js');
106
+ var compilerjs = await fs.promises.readFile(compiler_file, 'utf-8');
107
+ vm.runInContext(compilerjs, compiler_context, path.relative(base, compiler_file));
108
+ const { ast_to_json, ast_from_json, make_lazy_ast_module, encode_cache, decode_cache } = make_ast_serializer(compiler_exports);
109
+ compiler_exports.ast_to_json = ast_to_json;
110
+ compiler_exports.ast_from_json = ast_from_json;
111
+ compiler_exports.make_lazy_ast_module = make_lazy_ast_module;
112
+ compiler_exports.encode_cache = encode_cache;
113
+ compiler_exports.decode_cache = decode_cache;
114
+ // Inject into the VM context so parse.pyj compiled code can call them as globals.
115
+ compiler_context.ast_to_json = ast_to_json;
116
+ compiler_context.ast_from_json = ast_from_json;
117
+ compiler_context.make_lazy_ast_module = make_lazy_ast_module;
118
+ compiler_context.encode_cache = encode_cache;
119
+ compiler_context.decode_cache = decode_cache;
120
+ return compiler_exports;
121
+ }
122
+
123
+ async function create_embedded_compiler(compiler, baselib, runjs, name) {
124
+ return await embedded_compiler_factory(compiler || await create_compiler(), baselib, runjs, name, tree_shake, generate_source_map);
125
+ }
126
+
127
+ export { create_compiler, create_embedded_compiler, generate_source_map };
@@ -1,15 +1,15 @@
1
1
  /* vim:fileencoding=utf-8
2
- *
2
+ *
3
3
  * Copyright (C) 2016 Kovid Goyal <kovid at kovidgoyal.net>
4
4
  *
5
5
  * Distributed under terms of the BSD license
6
6
  */
7
7
 
8
+ import vm from 'vm';
8
9
 
9
- module.exports = function(compiler, options) {
10
+ export default function(compiler, options) {
10
11
  "use strict";
11
12
  var all_keywords = compiler.ALL_KEYWORDS.split(' ');
12
- var vm = require('vm');
13
13
  options = options || {};
14
14
  if (!options.enum_global) options.enum_global = "var global = Function('return this')(); Object.getOwnPropertyNames(global);";
15
15
 
@@ -19,7 +19,7 @@ module.exports = function(compiler, options) {
19
19
  ans = ans.concat(all_keywords);
20
20
  ans.sort();
21
21
  var seen = {};
22
- ans.filter(function (item) {
22
+ ans.filter(function (item) {
23
23
  if (Object.prototype.hasOwnProperty.call(seen, item)) return false;
24
24
  seen[item] = true;
25
25
  return true;
@@ -45,7 +45,7 @@ module.exports = function(compiler, options) {
45
45
  if (typeof obj === 'object' || typeof obj === 'function') {
46
46
  add(obj);
47
47
  p = Object.getPrototypeOf(obj);
48
- } else p = obj.constructor ? obj.constructor.prototype : null;
48
+ } else p = obj.constructor ? obj.constructor.prototype : null;
49
49
 
50
50
  // Walk the prototype chain
51
51
  try {
@@ -128,4 +128,4 @@ module.exports = function(compiler, options) {
128
128
  }
129
129
 
130
130
  return find_completions;
131
- };
131
+ }
@@ -1,42 +1,47 @@
1
1
  /* vim:fileencoding=utf-8
2
- *
2
+ *
3
3
  * Copyright (C) 2016 Kovid Goyal <kovid at kovidgoyal.net>
4
4
  *
5
5
  * Distributed under terms of the BSD license
6
6
  */
7
- "use strict"; /*jshint node:true */
7
+ "use strict";
8
8
 
9
9
  var has_prop = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
10
10
 
11
- module.exports = function(compiler, baselib, runjs, name) {
11
+ export default async function(compiler, baselib, runjs, name, tree_shake, generate_source_map) {
12
12
  var LINE_CONTINUATION_CHARS = ':\\';
13
13
  runjs = runjs || eval;
14
- runjs(print_ast(compiler.parse(''), true));
14
+ runjs(print_ast(await compiler.parse(''), true));
15
15
  runjs('var __name__ = "' + (name || '__embedded__') + '";');
16
16
 
17
- function print_ast(ast, keep_baselib, keep_docstrings, js_version, private_scope, write_name) {
18
- var output_options = {omit_baselib:!keep_baselib, write_name:!!write_name, private_scope:!!private_scope, beautify:true, js_version: (js_version || 6), keep_docstrings:keep_docstrings};
17
+ function print_ast(ast, keep_baselib, keep_docstrings, js_version, private_scope, write_name, source_map, source_map_line_offset) {
18
+ var output_options = {omit_baselib:!keep_baselib, write_name:!!write_name, private_scope:!!private_scope, beautify:true, js_version: (js_version || 6), keep_docstrings:keep_docstrings, source_map:!!source_map, source_map_line_offset: source_map_line_offset || 0};
19
19
  if (keep_baselib) output_options.baselib_plain = baselib;
20
20
  var output = new compiler.OutputStream(output_options);
21
21
  ast.print(output);
22
+ if (source_map && generate_source_map) return {code: output.get(), source_map: generate_source_map(output.get_source_map_segments(), '', '')};
22
23
  return output.get();
23
24
  }
24
25
 
25
26
  return {
26
27
  'toplevel': null,
27
28
 
28
- 'compile': function streaming_compile(code, opts) {
29
+ 'compile': async function streaming_compile(code, opts) {
29
30
  opts = opts || {};
30
31
  var classes = (this.toplevel) ? this.toplevel.classes : undefined;
31
32
  var scoped_flags = (this.toplevel) ? this.toplevel.scoped_flags: undefined;
32
- this.toplevel = compiler.parse(code, {
33
+ this.toplevel = await compiler.parse(code, {
33
34
  'filename': opts.filename || '<embedded>',
34
- 'basedir': '__stdlib__',
35
+ 'libdir': '__stdlib__',
36
+ 'basedir': '__vfs__',
35
37
  'classes': classes,
36
38
  'scoped_flags': scoped_flags,
37
39
  'discard_asserts': opts.discard_asserts,
38
40
  });
39
- var ans = print_ast(this.toplevel, opts.keep_baselib, opts.keep_docstrings, opts.js_version, opts.private_scope, opts.write_name);
41
+ if (opts.tree_shaking && tree_shake) {
42
+ this.toplevel = tree_shake(this.toplevel);
43
+ }
44
+ var ans = print_ast(this.toplevel, opts.keep_baselib, opts.keep_docstrings, opts.js_version, opts.private_scope, opts.write_name, opts.source_map, opts.source_map_line_offset);
40
45
  if (classes) {
41
46
  var exports = {};
42
47
  var self = this;
@@ -47,10 +52,9 @@ module.exports = function(compiler, baselib, runjs, name) {
47
52
  });
48
53
  }
49
54
  scoped_flags = this.toplevel.scoped_flags;
50
-
55
+
51
56
  return ans;
52
57
  },
53
58
 
54
59
  };
55
- };
56
-
60
+ }