aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/js_lexer.zig8
-rw-r--r--src/js_lexer_tables.zig6
-rw-r--r--src/js_parser/js_parser.zig80
-rw-r--r--src/js_parser/js_parser_test.zig588
4 files changed, 369 insertions, 313 deletions
diff --git a/src/js_lexer.zig b/src/js_lexer.zig
index be3befa61..3f221d3c5 100644
--- a/src/js_lexer.zig
+++ b/src/js_lexer.zig
@@ -1120,6 +1120,7 @@ pub const Lexer = struct {
}
pub fn init(log: *logger.Log, source: *logger.Source, allocator: *std.mem.Allocator) !LexerType {
+ try tables.initJSXEntityMap();
var empty_string_literal: JavascriptString = &emptyJavaScriptString;
var lex = LexerType{
.log = log,
@@ -1475,9 +1476,8 @@ pub const Lexer = struct {
while (i < text.len) {
const width = try std.unicode.utf8ByteSequenceLength(text[i]);
const i_0 = i;
- i += width;
var buf = [4]u8{ 0, 0, 0, 0 };
- std.mem.copy(u8, &buf, text[i_0..width]);
+ std.mem.copy(u8, &buf, text[i_0 .. i_0 + width]);
var c = std.mem.readIntNative(i32, &buf);
switch (c) {
@@ -1493,7 +1493,7 @@ pub const Lexer = struct {
}
// Reset for the next line
- first_non_whitespace = 0;
+ first_non_whitespace = null;
},
'\t', ' ' => {},
else => {
@@ -1533,7 +1533,7 @@ pub const Lexer = struct {
width = try std.unicode.utf8ByteSequenceLength(text[i]);
i_0 = i;
i += width;
- std.mem.copy(u8, buf_ptr, text[i_0..width]);
+ std.mem.copy(u8, buf_ptr, text[i_0..i]);
c = std.mem.readIntNative(i32, buf_ptr);
if (c == '&') {
diff --git a/src/js_lexer_tables.zig b/src/js_lexer_tables.zig
index 7a1bf705e..ef4b13e8c 100644
--- a/src/js_lexer_tables.zig
+++ b/src/js_lexer_tables.zig
@@ -536,9 +536,15 @@ pub const TypescriptStmtKeyword = enum {
pub const JSXEntityMap = std.StringHashMap(CodePoint);
pub var jsxEntity: JSXEntityMap = undefined;
+var has_loaded_jsx_map = false;
// There's probably a way to move this to comptime
pub fn initJSXEntityMap() !void {
+ if (has_loaded_jsx_map) {
+ return;
+ }
+
+ has_loaded_jsx_map = true;
jsxEntity = JSXEntityMap.init(alloc.dynamic);
// return jsxEntity;
jsxEntity.ensureCapacity(255) catch unreachable;
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index 7c8b25019..8fed3f736 100644
--- a/src/js_parser/js_parser.zig
+++ b/src/js_parser/js_parser.zig
@@ -1305,13 +1305,43 @@ pub const Parser = struct {
const jsx_factory_symbol: Symbol = p.symbols.items[p.jsx_factory_ref.inner_index];
if (jsx_symbol.use_count_estimate > 0 or jsx_fragment_symbol.use_count_estimate > 0 or jsx_factory_symbol.use_count_estimate > 0) {
- var jsx_imports = [_]string{ p.options.jsx.jsx, p.options.jsx.fragment, p.options.jsx.factory };
+ var jsx_imports = [_]string{ "", "", "" };
var symbols = StringRefMap.init(p.allocator);
defer symbols.deinit();
- try symbols.put(p.options.jsx.jsx, p.jsx_runtime_ref);
- try symbols.put(p.options.jsx.fragment, p.jsx_fragment_ref);
- try symbols.put(p.options.jsx.factory, p.jsx_factory_ref);
- try p.generateImportStmt(p.options.jsx.import_source, &jsx_imports, &parts, symbols);
+ var i: usize = 0;
+ var additional_stmt: ?Stmt = null;
+ if (jsx_factory_symbol.use_count_estimate > 0) {
+ jsx_imports[i] = p.options.jsx.factory;
+ try symbols.put(p.options.jsx.factory, p.jsx_factory_ref);
+ i += 1;
+ }
+
+ if (jsx_symbol.use_count_estimate > 0) {
+ jsx_imports[i] = p.options.jsx.jsx;
+ i += 1;
+ try symbols.put(p.options.jsx.jsx, p.jsx_runtime_ref);
+ // While we are here, add the __jsxFilename declaration
+ }
+
+ if (p.options.jsx.development) {
+ const jsx_filename_symbol = p.symbols.items[p.jsx_filename_ref.inner_index];
+ if (jsx_filename_symbol.use_count_estimate > 0) {
+ var decls = try p.allocator.alloc(G.Decl, 1);
+ var filename_str = try strings.toUTF16Alloc(p.source.path.pretty, p.allocator);
+ decls[0] = G.Decl{ .binding = p.b(B.Identifier{ .ref = p.jsx_filename_ref }, logger.Loc{}), .value = p.e(E.String{ .value = filename_str }, logger.Loc{}) };
+ additional_stmt = p.s(S.Local{ .kind = .k_var, .decls = decls }, logger.Loc{});
+ try symbols.put(Prefill.Runtime.JSXFilename, p.jsx_filename_ref);
+ }
+ }
+
+ if (jsx_fragment_symbol.use_count_estimate > 0) {
+ jsx_imports[i] = p.options.jsx.fragment;
+
+ try symbols.put(p.options.jsx.fragment, p.jsx_fragment_ref);
+ i += 1;
+ }
+
+ try p.generateImportStmt(p.options.jsx.import_source, jsx_imports[0..i], &before, symbols, additional_stmt);
}
}
@@ -1480,7 +1510,7 @@ pub const Prefill = struct {
pub var ColumnNumber = Expr.Data{ .e_string = &Prefill.String.ColumnNumber };
};
pub const Runtime = struct {
- pub var JSXFilename = "JSX_fIlEnAmE";
+ pub var JSXFilename = "__jsxFilename";
pub var JSXDevelopmentImportName = "jsxDEV";
pub var JSXImportName = "jsx";
};
@@ -1573,6 +1603,8 @@ pub const P = struct {
jsx_factory_ref: js_ast.Ref = Ref.None,
jsx_fragment_ref: js_ast.Ref = Ref.None,
+ jsx_source_list_ref: js_ast.Ref = Ref.None,
+
// Imports (both ES6 and CommonJS) are tracked at the top level
import_records: List(ImportRecord),
import_records_for_current_part: List(u32),
@@ -2093,19 +2125,19 @@ pub const P = struct {
return p.e(ident, loc);
}
- pub fn generateImportStmt(p: *P, import_path: string, imports: []string, parts: *List(js_ast.Part), symbols: StringRefMap) !void {
- const import_record_i = p.addImportRecord(.stmt, logger.Loc.Empty, import_path);
+ pub fn generateImportStmt(p: *P, import_path: string, imports: []string, parts: *List(js_ast.Part), symbols: StringRefMap, additional_stmt: ?Stmt) !void {
+ const import_record_i = p.addImportRecordByRange(.stmt, logger.Range.None, import_path);
var import_record = p.import_records.items[import_record_i];
var import_path_identifier = try import_record.path.name.nonUniqueNameString(p.allocator);
var namespace_identifier = try p.allocator.alloc(u8, import_path_identifier.len + "import_".len);
var clause_items = try p.allocator.alloc(js_ast.ClauseItem, imports.len);
- var stmts = try p.allocator.alloc(Stmt, 1);
+ var stmts = try p.allocator.alloc(Stmt, 1 + if (additional_stmt != null) @as(usize, 1) else @as(usize, 0));
var declared_symbols = try p.allocator.alloc(js_ast.DeclaredSymbol, imports.len);
std.mem.copy(u8, namespace_identifier[0.."import_".len], "import_");
std.mem.copy(
u8,
- namespace_identifier["import_".len..import_path_identifier.len],
- import_path_identifier,
+ namespace_identifier["import_".len..namespace_identifier.len],
+ import_path_identifier[0..import_path_identifier.len],
);
const namespace_ref = try p.newSymbol(.other, namespace_identifier);
@@ -2129,13 +2161,21 @@ pub const P = struct {
.items = clause_items,
.import_record_index = import_record_i,
}, logger.Loc{});
+ if (additional_stmt) |add| {
+ stmts[1] = add;
+ }
var import_records = try p.allocator.alloc(@TypeOf(import_record_i), 1);
import_records[0] = import_record_i;
// Append a single import to the end of the file (ES6 imports are hoisted
// so we don't need to worry about where the import statement goes)
- parts.append(js_ast.Part{ .stmts = stmts, .declared_symbols = declared_symbols, .import_record_indices = import_records }) catch unreachable;
+ parts.append(js_ast.Part{
+ .stmts = stmts,
+ .declared_symbols = declared_symbols,
+ .import_record_indices = import_records,
+ .symbol_uses = SymbolUseMap.init(p.allocator),
+ }) catch unreachable;
}
pub fn prepareForVisitPass(p: *P) !void {
@@ -5136,10 +5176,14 @@ pub const P = struct {
}
pub fn addImportRecord(p: *P, kind: ImportKind, loc: logger.Loc, name: string) u32 {
+ return p.addImportRecordByRange(kind, p.source.rangeOfString(loc), name);
+ }
+
+ pub fn addImportRecordByRange(p: *P, kind: ImportKind, range: logger.Range, name: string) u32 {
var index = p.import_records.items.len;
const record = ImportRecord{
.kind = kind,
- .range = p.source.rangeOfString(loc),
+ .range = range,
.path = fs.Path.init(name),
};
p.import_records.append(record) catch unreachable;
@@ -7497,7 +7541,13 @@ pub const P = struct {
p.lexer.expected(.t_greater_than);
}
- return p.e(E.JSXElement{ .tag = end_tag.data.asExpr(), .children = children.toOwnedSlice() }, loc);
+ return p.e(E.JSXElement{
+ .tag = end_tag.data.asExpr(),
+ .children = children.toOwnedSlice(),
+ .properties = properties,
+ .key = key_prop,
+ .flags = flags,
+ }, loc);
},
else => {
p.lexer.unexpected();
@@ -8849,7 +8899,7 @@ pub const P = struct {
exprs[1] = p.e(E.String{
.value = p.lexer.stringToUTF16(name),
}, _value.loc);
- var value = p.callRuntime(_value.loc, "__name", exprs);
+ var value = p.callRuntime(_value.loc, "ℹ", exprs);
// Make sure tree shaking removes this if the function is never used
value.data.e_call.can_be_unwrapped_if_unused = true;
diff --git a/src/js_parser/js_parser_test.zig b/src/js_parser/js_parser_test.zig
index e2fec5390..936f8864f 100644
--- a/src/js_parser/js_parser_test.zig
+++ b/src/js_parser/js_parser_test.zig
@@ -337,7 +337,7 @@ fn expectPrinted(t: *Tester, contents: string, expected: string, src: anytype) !
debugl("INIT TEST");
- const opts = try options.TransformOptions.initUncached(alloc.dynamic, "file.js", contents);
+ const opts = try options.TransformOptions.initUncached(alloc.dynamic, "file.jsx", contents);
var log = logger.Log.init(alloc.dynamic);
var source = logger.Source.initFile(opts.entry_point, alloc.dynamic);
var ast: js_ast.Ast = undefined;
@@ -380,298 +380,298 @@ const PRINT_AST = false;
test "expectPrint" {
var t_ = Tester.t(std.heap.page_allocator);
var t = &t_;
-
- try expectPrinted(t, "if (true) { console.log(\"hi\"); }", "if (true) { console.log(\"hi\"); }", @src());
-
- try expectPrinted(t, "try { console.log(\"hi\"); }\ncatch(er) { console.log('noooo'); }", "class Foo {\n foo() {\n }\n}\n", @src());
-
- try expectPrinted(t, "try { console.log(\"hi\"); }\ncatch(er) { console.log('noooo'); }", "class Foo {\n foo() {\n }\n}\n", @src());
-
- try expectPrinted(t, "class Foo { foo() {} }", "class Foo {\n foo() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { *foo() {} }", "class Foo {\n *foo() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { get foo() {} }", "class Foo {\n get foo() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { set foo(x) {} }", "class Foo {\n set foo(x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static foo() {} }", "class Foo {\n static foo() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static *foo() {} }", "class Foo {\n static *foo() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static get foo() {} }", "class Foo {\n static get foo() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static set foo(x) {} }", "class Foo {\n static set foo(x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { async foo() {} }", "class Foo {\n async foo() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static async foo() {} }", "class Foo {\n static async foo() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static async *foo() {} }", "class Foo {\n static async *foo() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static async *foo() {}\n hey = true; }", "class Foo {\n static async *foo() {\n }\n hey = true;\n}\n", @src());
-
- try expectPrinted(t, "class Foo { if() {} }", "class Foo {\n if() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { *if() {} }", "class Foo {\n *if() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { get if() {} }", "class Foo {\n get if() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { set if(x) {} }", "class Foo {\n set if(x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static if() {} }", "class Foo {\n static if() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static *if() {} }", "class Foo {\n static *if() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static get if() {} }", "class Foo {\n static get if() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static set if(x) {} }", "class Foo {\n static set if(x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { async if() {} }", "class Foo {\n async if() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static async if() {} }", "class Foo {\n static async if() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static async *if() {} }", "class Foo {\n static async *if() {\n }\n}\n", @src());
-
- try expectPrinted(t, "class Foo { a() {} b() {} }", "class Foo {\n a() {\n }\n b() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { a() {} get b() {} }", "class Foo {\n a() {\n }\n get b() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { a() {} set b(x) {} }", "class Foo {\n a() {\n }\n set b(x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { a() {} static b() {} }", "class Foo {\n a() {\n }\n static b() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { a() {} static *b() {} }", "class Foo {\n a() {\n }\n static *b() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { a() {} static get b() {} }", "class Foo {\n a() {\n }\n static get b() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { a() {} static set b(x) {} }", "class Foo {\n a() {\n }\n static set b(x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { a() {} async b() {} }", "class Foo {\n a() {\n }\n async b() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { a() {} static async b() {} }", "class Foo {\n a() {\n }\n static async b() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { a() {} static async *b() {} }", "class Foo {\n a() {\n }\n static async *b() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { [arguments] }", "class Foo {\n [arguments];\n}\n", @src());
- try expectPrinted(t, "class Foo { [arguments] = 1 }", "class Foo {\n [arguments] = 1;\n}\n", @src());
- try expectPrinted(t, "class Foo { arguments = 1 }", "class Foo {\n arguments = 1;\n}\n", @src());
- try expectPrinted(t, "class Foo { x = class { arguments = 1 } }", "class Foo {\n x = class {\n arguments = 1;\n };\n}\n", @src());
- try expectPrinted(t, "class Foo { x = function() { arguments } }", "class Foo {\n x = function() {\n arguments;\n };\n}\n", @src());
- try expectPrinted(t, "class Foo { get ['constructor']() {} }", "class Foo {\n get [\"constructor\"]() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { set ['constructor'](x) {} }", "class Foo {\n set [\"constructor\"](x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { *['constructor']() {} }", "class Foo {\n *[\"constructor\"]() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { async ['constructor']() {} }", "class Foo {\n async [\"constructor\"]() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { async *['constructor']() {} }", "class Foo {\n async *[\"constructor\"]() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { get prototype() {} }", "class Foo {\n get prototype() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { get 'prototype'() {} }", "class Foo {\n get prototype() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { set prototype(x) {} }", "class Foo {\n set prototype(x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { set 'prototype'(x) {} }", "class Foo {\n set prototype(x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { *prototype() {} }", "class Foo {\n *prototype() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { *'prototype'() {} }", "class Foo {\n *prototype() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { async prototype() {} }", "class Foo {\n async prototype() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { async 'prototype'() {} }", "class Foo {\n async prototype() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { async *prototype() {} }", "class Foo {\n async *prototype() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { async *'prototype'() {} }", "class Foo {\n async *prototype() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static get ['prototype']() {} }", "class Foo {\n static get [\"prototype\"]() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static set ['prototype'](x) {} }", "class Foo {\n static set [\"prototype\"](x) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static *['prototype']() {} }", "class Foo {\n static *[\"prototype\"]() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static async ['prototype']() {} }", "class Foo {\n static async [\"prototype\"]() {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo { static async *['prototype']() {} }", "class Foo {\n static async *[\"prototype\"]() {\n }\n}\n", @src());
-
- try expectPrinted(t, "class Foo extends Bar { constructor() { super() } }", "class Foo extends Bar {\n constructor() {\n super();\n }\n}\n", @src());
- try expectPrinted(t, "class Foo extends Bar { constructor() { () => super() } }", "class Foo extends Bar {\n constructor() {\n () => super();\n }\n}\n", @src());
- try expectPrinted(t, "class Foo extends Bar { constructor() { () => { super() } } }", "class Foo extends Bar {\n constructor() {\n () => {\n super();\n };\n }\n}\n", @src());
- try expectPrinted(t, "class Foo extends Bar { constructor(x = super()) {} }", "class Foo extends Bar {\n constructor(x = super()) {\n }\n}\n", @src());
- try expectPrinted(t, "class Foo extends Bar { constructor(x = () => super()) {} }", "class Foo extends Bar {\n constructor(x = () => super()) {\n }\n}\n", @src());
-
- try expectPrinted(t, "class Foo { a }", "class Foo {\n a;\n}\n", @src());
- try expectPrinted(t, "class Foo { a = 1 }", "class Foo {\n a = 1;\n}\n", @src());
- try expectPrinted(t, "class Foo { static a }", "class Foo {\n static a;\n}\n", @src());
- try expectPrinted(t, "class Foo { static a = 1 }", "class Foo {\n static a = 1;\n}\n", @src());
- try expectPrinted(t, "class Foo { static a = 1; b }", "class Foo {\n static a = 1;\n b;\n}\n", @src());
- try expectPrinted(t, "class Foo { static [a] }", "class Foo {\n static [a];\n}\n", @src());
- try expectPrinted(t, "class Foo { static [a] = 1 }", "class Foo {\n static [a] = 1;\n}\n", @src());
- try expectPrinted(t, "class Foo { static [a] = 1; [b] }", "class Foo {\n static [a] = 1;\n [b];\n}\n", @src());
-
- try expectPrinted(t, "class Foo { prototype }", "class Foo {\n prototype;\n}\n", @src());
- try expectPrinted(t, "class Foo { 'prototype' }", "class Foo {\n prototype;\n}\n", @src());
- try expectPrinted(t, "class Foo { prototype = 1 }", "class Foo {\n prototype = 1;\n}\n", @src());
- try expectPrinted(t, "class Foo { 'prototype' = 1 }", "class Foo {\n prototype = 1;\n}\n", @src());
- try expectPrinted(t, "function* foo() { -(yield 100) }", "function* foo() {\n -(yield 100);\n}\n", @src());
-
- try expectPrinted(t, "function *foo() { (x = yield y) }", "function* foo() {\n x = yield y;\n}\n", @src());
- try expectPrinted(t, "yield\n100", "yield;\n100;\n", @src());
- try expectPrinted(t, "let x = {yield}", "let x = {yield};\n", @src());
- try expectPrinted(t, "function foo() { ({yield} = x) }", "function foo() {\n ({yield} = x);\n}\n", @src());
- try expectPrinted(t, "({ *yield() {} })", "({*yield() {\n}});\n", @src());
- try expectPrinted(t, "(class { *yield() {} })", "(class {\n *yield() {\n }\n});\n", @src());
- try expectPrinted(t, "class Foo { *yield() {} }", "class Foo {\n *yield() {\n }\n}\n", @src());
- try expectPrinted(t, "function* yield() {}", "function* yield() {\n}\n", @src());
- try expectPrinted(t, "({ async *yield() {} })", "({async *yield() {\n}});\n", @src());
- try expectPrinted(t, "(class { async *yield() {} })", "(class {\n async *yield() {\n }\n});\n", @src());
- try expectPrinted(t, "class Foo { async *yield() {} }", "class Foo {\n async *yield() {\n }\n}\n", @src());
- try expectPrinted(t, "async function* yield() {}", "async function* yield() {\n}\n", @src());
- try expectPrinted(t, "-async function foo() { await 0 }", "-async function foo() {\n await 0;\n};\n", @src());
- try expectPrinted(t, "-async function() { await 0 }", "-async function() {\n await 0;\n};\n", @src());
- try expectPrinted(t, "1 - async function foo() { await 0 }", "1 - async function foo() {\n await 0;\n};\n", @src());
- try expectPrinted(t, "1 - async function() { await 0 }", "1 - async function() {\n await 0;\n};\n", @src());
- try expectPrinted(t, "(async function foo() { await 0 })", "(async function foo() {\n await 0;\n});\n", @src());
- try expectPrinted(t, "(async function() { await 0 })", "(async function() {\n await 0;\n});\n", @src());
- try expectPrinted(t, "(x, async function foo() { await 0 })", "x, async function foo() {\n await 0;\n};\n", @src());
- try expectPrinted(t, "(x, async function() { await 0 })", "x, async function() {\n await 0;\n};\n", @src());
- try expectPrinted(t, "new async function() { await 0 }", "new async function() {\n await 0;\n}();\n", @src());
- try expectPrinted(t, "new async function() { await 0 }.x", "new async function() {\n await 0;\n}.x();\n", @src());
-
- try expectPrinted(t, "function foo() { await }", "function foo() {\n await;\n}\n", @src());
- try expectPrinted(t, "async function foo() { await 0 }", "async function foo() {\n await 0;\n}\n", @src());
-
- try expectPrinted(t, "(async x => y), z", "async (x) => y, z;\n", @src());
- try expectPrinted(t, "(async x => y, z)", "async (x) => y, z;\n", @src());
- try expectPrinted(t, "(async x => (y, z))", "async (x) => (y, z);\n", @src());
- try expectPrinted(t, "(async (x) => y), z", "async (x) => y, z;\n", @src());
- try expectPrinted(t, "(async (x) => y, z)", "async (x) => y, z;\n", @src());
- try expectPrinted(t, "(async (x) => (y, z))", "async (x) => (y, z);\n", @src());
- try expectPrinted(t, "async x => y, z", "async (x) => y, z;\n", @src());
- try expectPrinted(t, "async x => (y, z)", "async (x) => (y, z);\n", @src());
- try expectPrinted(t, "async (x) => y, z", "async (x) => y, z;\n", @src());
- try expectPrinted(t, "async (x) => (y, z)", "async (x) => (y, z);\n", @src());
- try expectPrinted(t, "export default async x => (y, z)", "export default async (x) => (y, z);\n", @src());
- try expectPrinted(t, "export default async (x) => (y, z)", "export default async (x) => (y, z);\n", @src());
-
- try expectPrinted(t, "(class { async \n foo() {} })", "(class {\n async;\n foo() {\n }\n});\n", @src());
- try expectPrinted(t, "(class { async \n *foo() {} })", "(class {\n async;\n *foo() {\n }\n});\n", @src());
- try expectPrinted(t, "async function foo(){for await(x of y);}", "async function foo() {\n for await (x of y)\n ;\n}\n", @src());
- try expectPrinted(t, "async function foo(){for await(let x of y);}", "async function foo() {\n for await (let x of y)\n ;\n}\n", @src());
-
- // Await as a declaration
- try expectPrinted(t, "({ async await() {} })", "({async await() {\n}});\n", @src());
- try expectPrinted(t, "(class { async await() {} })", "(class {\n async await() {\n }\n});\n", @src());
- try expectPrinted(t, "class Foo { async await() {} }", "class Foo {\n async await() {\n }\n}\n", @src());
-
- try expectPrinted(t, "({ async *await() {} })", "({async *await() {\n}});\n", @src());
- try expectPrinted(t, "(class { async *await() {} })", "(class {\n async *await() {\n }\n});\n", @src());
- try expectPrinted(t, "class Foo { async *await() {} }", "class Foo {\n async *await() {\n }\n}\n", @src());
-
- try expectPrinted(t, "(x) => function() {}", "(x) => function() {\n};\n", @src());
-
- try expectPrinted(t, "x => function() {}", "(x) => function() {\n};\n", @src());
-
- try expectPrinted(t, "(x => function() {})", "(x) => function() {\n};\n", @src());
-
- try expectPrinted(t, "(x = () => {}) => {}", "(x = () => {\n}) => {\n};\n", @src());
- try expectPrinted(t, "async (x = () => {}) => {}", "async (x = () => {\n}) => {\n};\n", @src());
-
- try expectPrinted(t, "(() => {}) ? a : b", "(() => {\n}) ? a : b;\n", @src());
- try expectPrinted(t, "1 < (() => {})", "1 < (() => {\n});\n", @src());
- try expectPrinted(t, "y = x => {}", "y = (x) => {\n};\n", @src());
- try expectPrinted(t, "y = () => {}", "y = () => {\n};\n", @src());
- try expectPrinted(t, "y = (x) => {}", "y = (x) => {\n};\n", @src());
- try expectPrinted(t, "y = async x => {}", "y = async (x) => {\n};\n", @src());
- try expectPrinted(t, "y = async () => {}", "y = async () => {\n};\n", @src());
- try expectPrinted(t, "y = async (x) => {}", "y = async (x) => {\n};\n", @src());
- try expectPrinted(t, "1 + function () {}", "1 + function() {\n};\n", @src());
- try expectPrinted(t, "1 + async function () {}", "1 + async function() {\n};\n", @src());
- try expectPrinted(t, "class Foo extends function () {} {}", "class Foo extends function() {\n} {\n}\n", @src());
- try expectPrinted(t, "class Foo extends async function () {} {}", "class Foo extends async function() {\n} {\n}\n", @src());
-
- try expectPrinted(t, "() => {}\n(0)", "() => {\n};\n0;\n", @src());
- try expectPrinted(t, "x => {}\n(0)", "(x) => {\n};\n0;\n", @src());
- try expectPrinted(t, "async () => {}\n(0)", "async () => {\n};\n0;\n", @src());
- try expectPrinted(t, "async x => {}\n(0)", "async (x) => {\n};\n0;\n", @src());
- try expectPrinted(t, "async (x) => {}\n(0)", "async (x) => {\n};\n0;\n", @src());
-
- try expectPrinted(t, "() => {}\n,0", "() => {\n}, 0;\n", @src());
- try expectPrinted(t, "x => {}\n,0", "(x) => {\n}, 0;\n", @src());
- try expectPrinted(t, "async () => {}\n,0", "async () => {\n}, 0;\n", @src());
- try expectPrinted(t, "async x => {}\n,0", "async (x) => {\n}, 0;\n", @src());
- try expectPrinted(t, "async (x) => {}\n,0", "async (x) => {\n}, 0;\n", @src());
-
- try expectPrinted(t, "(() => {})\n(0)", "(() => {\n})(0);\n", @src());
- try expectPrinted(t, "(x => {})\n(0)", "((x) => {\n})(0);\n", @src());
- try expectPrinted(t, "(async () => {})\n(0)", "(async () => {\n})(0);\n", @src());
- try expectPrinted(t, "(async x => {})\n(0)", "(async (x) => {\n})(0);\n", @src());
- try expectPrinted(t, "(async (x) => {})\n(0)", "(async (x) => {\n})(0);\n", @src());
- try expectPrinted(t, "y = () => {}\n(0)", "y = () => {\n};\n0;\n", @src());
- try expectPrinted(t, "y = x => {}\n(0)", "y = (x) => {\n};\n0;\n", @src());
- try expectPrinted(t, "y = async () => {}\n(0)", "y = async () => {\n};\n0;\n", @src());
- try expectPrinted(t, "y = async x => {}\n(0)", "y = async (x) => {\n};\n0;\n", @src());
- try expectPrinted(t, "y = async (x) => {}\n(0)", "y = async (x) => {\n};\n0;\n", @src());
-
- try expectPrinted(t, "y = () => {}\n,0", "y = () => {\n}, 0;\n", @src());
- try expectPrinted(t, "y = x => {}\n,0", "y = (x) => {\n}, 0;\n", @src());
- try expectPrinted(t, "y = async () => {}\n,0", "y = async () => {\n}, 0;\n", @src());
- try expectPrinted(t, "y = async x => {}\n,0", "y = async (x) => {\n}, 0;\n", @src());
- try expectPrinted(t, "y = async (x) => {}\n,0", "y = async (x) => {\n}, 0;\n", @src());
-
- try expectPrinted(t, "y = (() => {})\n(0)", "y = (() => {\n})(0);\n", @src());
- try expectPrinted(t, "y = (x => {})\n(0)", "y = ((x) => {\n})(0);\n", @src());
- try expectPrinted(t, "y = (async () => {})\n(0)", "y = (async () => {\n})(0);\n", @src());
- try expectPrinted(t, "y = (async x => {})\n(0)", "y = (async (x) => {\n})(0);\n", @src());
- try expectPrinted(t, "y = (async (x) => {})\n(0)", "y = (async (x) => {\n})(0);\n", @src());
- try expectPrinted(t, "(() => {}\n,0)", "() => {\n}, 0;\n", @src());
- try expectPrinted(t, "(x => {}\n,0)", "(x) => {\n}, 0;\n", @src());
- try expectPrinted(t, "(async () => {}\n,0)", "async () => {\n}, 0;\n", @src());
- try expectPrinted(t, "(async x => {}\n,0)", "async (x) => {\n}, 0;\n", @src());
- try expectPrinted(t, "(async (x) => {}\n,0)", "async (x) => {\n}, 0;\n", @src());
-
- try expectPrinted(t, "((() => {})\n(0))", "(() => {\n})(0);\n", @src());
- try expectPrinted(t, "((x => {})\n(0))", "((x) => {\n})(0);\n", @src());
- try expectPrinted(t, "((async () => {})\n(0))", "(async () => {\n})(0);\n", @src());
- try expectPrinted(t, "((async x => {})\n(0))", "(async (x) => {\n})(0);\n", @src());
- try expectPrinted(t, "((async (x) => {})\n(0))", "(async (x) => {\n})(0);\n", @src());
-
- try expectPrinted(t, "y = (() => {}\n,0)", "y = (() => {\n}, 0);\n", @src());
- try expectPrinted(t, "y = (x => {}\n,0)", "y = ((x) => {\n}, 0);\n", @src());
- try expectPrinted(t, "y = (async () => {}\n,0)", "y = (async () => {\n}, 0);\n", @src());
- try expectPrinted(t, "y = (async x => {}\n,0)", "y = (async (x) => {\n}, 0);\n", @src());
- try expectPrinted(t, "y = (async (x) => {}\n,0)", "y = (async (x) => {\n}, 0);\n", @src());
-
- try expectPrinted(t, "y = ((() => {})\n(0))", "y = (() => {\n})(0);\n", @src());
- try expectPrinted(t, "y = ((x => {})\n(0))", "y = ((x) => {\n})(0);\n", @src());
- try expectPrinted(t, "y = ((async () => {})\n(0))", "y = (async () => {\n})(0);\n", @src());
- try expectPrinted(t, "y = ((async x => {})\n(0))", "y = (async (x) => {\n})(0);\n", @src());
- try expectPrinted(t, "y = ((async (x) => {})\n(0))", "y = (async (x) => {\n})(0);\n", @src());
-
- try expectPrinted(t, "(-x) ** 2", "(-x) ** 2;\n", @src());
- try expectPrinted(t, "(+x) ** 2", "(+x) ** 2;\n", @src());
- try expectPrinted(t, "(~x) ** 2", "(~x) ** 2;\n", @src());
- try expectPrinted(t, "(!x) ** 2", "(!x) ** 2;\n", @src());
- try expectPrinted(t, "(-1) ** 2", "(-1) ** 2;\n", @src());
- try expectPrinted(t, "(+1) ** 2", "1 ** 2;\n", @src());
- try expectPrinted(t, "(~1) ** 2", "(~1) ** 2;\n", @src());
- try expectPrinted(t, "(!1) ** 2", "false ** 2;\n", @src());
- try expectPrinted(t, "(void x) ** 2", "(void x) ** 2;\n", @src());
- try expectPrinted(t, "(delete x) ** 2", "(delete x) ** 2;\n", @src());
- try expectPrinted(t, "(typeof x) ** 2", "(typeof x) ** 2;\n", @src());
- try expectPrinted(t, "undefined ** 2", "(void 0) ** 2;\n", @src());
-
- try expectPrinted(t, "({ prototype: 1 })", "({prototype: 1});\n", @src());
- try expectPrinted(t, "({ get prototype() {} })", "({get prototype() {\n}});\n", @src());
- try expectPrinted(t, "({ set prototype(x) {} })", "({set prototype(x) {\n}});\n", @src());
- try expectPrinted(t, "({ *prototype() {} })", "({*prototype() {\n}});\n", @src());
- try expectPrinted(t, "({ async prototype() {} })", "({async prototype() {\n}});\n", @src());
- try expectPrinted(t, "({ async* prototype() {} })", "({async *prototype() {\n}});\n", @src());
-
- try expectPrinted(t, "({foo})", "({foo});\n", @src());
- try expectPrinted(t, "({foo:0})", "({foo: 0});\n", @src());
- try expectPrinted(t, "({1e9:0})", "({1e9: 0});\n", @src());
- try expectPrinted(t, "({1_2_3n:0})", "({123n: 0});\n", @src());
- try expectPrinted(t, "({0x1_2_3n:0})", "({0x123n: 0});\n", @src());
- try expectPrinted(t, "({foo() {}})", "({foo() {\n}});\n", @src());
- try expectPrinted(t, "({*foo() {}})", "({*foo() {\n}});\n", @src());
- try expectPrinted(t, "({get foo() {}})", "({get foo() {\n}});\n", @src());
- try expectPrinted(t, "({set foo(x) {}})", "({set foo(x) {\n}});\n", @src());
-
- try expectPrinted(t, "({if:0})", "({if: 0});\n", @src());
- try expectPrinted(t, "({if() {}})", "({if() {\n}});\n", @src());
- try expectPrinted(t, "({*if() {}})", "({*if() {\n}});\n", @src());
- try expectPrinted(t, "({get if() {}})", "({get if() {\n}});\n", @src());
- try expectPrinted(t, "({set if(x) {}})", "({set if(x) {\n}});\n", @src());
-
- try expectPrinted(t, "async function foo() { await x; }", "await x;\n", @src());
- try expectPrinted(t, "async function foo() { await +x; }", "await +x;\n", @src());
- try expectPrinted(t, "async function foo() { await -x; }", "await -x;\n", @src());
- try expectPrinted(t, "async function foo() { await ~x; }", "await ~x;\n", @src());
- try expectPrinted(t, "async function foo() { await !x; }", "await !x;\n", @src());
- try expectPrinted(t, "async function foo() { await --x; }", "await --x;\n", @src());
- try expectPrinted(t, "async function foo() { await ++x; }", "await ++x;\n", @src());
- try expectPrinted(t, "async function foo() { await x--; }", "await x--;\n", @src());
- try expectPrinted(t, "async function foo() { await x++; }", "await x++;\n", @src());
- try expectPrinted(t, "async function foo() { await void x; }", "await void x;\n", @src());
- try expectPrinted(t, "async function foo() { await typeof x; }", "await typeof x;\n", @src());
- try expectPrinted(t, "async function foo() { await (x * y); }", "await (x * y);\n", @src());
- try expectPrinted(t, "async function foo() { await (x ** y); }", "await (x ** y);\n", @src());
-
- try expectPrinted(t, "export default (1, 2)", "export default (1, 2);\n", @src());
- try expectPrinted(t, "export default async", "export default async;\n", @src());
- try expectPrinted(t, "export default async()", "export default async();\n", @src());
- try expectPrinted(t, "export default async + 1", "export default async + 1;\n", @src());
- try expectPrinted(t, "export default async => {}", "export default (async) => {\n};\n", @src());
- try expectPrinted(t, "export default async x => {}", "export default async (x) => {\n};\n", @src());
- try expectPrinted(t, "export default async () => {}", "export default async () => {\n};\n", @src());
-
- // This is a corner case in the ES6 grammar. The "export default" statement
- // normally takes an expression except for the function and class keywords
- // which behave sort of like their respective declarations instead.
- try expectPrinted(t, "export default function() {} - after", "export default function() {\n}\n-after;\n", @src());
- try expectPrinted(t, "export default function*() {} - after", "export default function* () {\n}\n-after;\n", @src());
- try expectPrinted(t, "export default function foo() {} - after", "export default function foo() {\n}\n-after;\n", @src());
- try expectPrinted(t, "export default function* foo() {} - after", "export default function* foo() {\n}\n-after;\n", @src());
- try expectPrinted(t, "export default async function() {} - after", "export default async function() {\n}\n-after;\n", @src());
- try expectPrinted(t, "export default async function*() {} - after", "export default async function* () {\n}\n-after;\n", @src());
- try expectPrinted(t, "export default async function foo() {} - after", "export default async function foo() {\n}\n-after;\n", @src());
- try expectPrinted(t, "export default async function* foo() {} - after", "export default async function* foo() {\n}\n-after;\n", @src());
- try expectPrinted(t, "export default class {} - after", "export default class {\n}\n-after;\n", @src());
- try expectPrinted(t, "export default class Foo {} - after", "export default class Foo {\n}\n-after;\n", @src());
+ try expectPrinted(t, "if (true) { console.log(<div>true</div>); }", "if (true) { console.log(\"hi\"); }", @src());
+ // try expectPrinted(t, "if (true) { console.log(\"hi\"); }", "if (true) { console.log(\"hi\"); }", @src());
+
+ // try expectPrinted(t, "try { console.log(\"hi\"); }\ncatch(er) { console.log('noooo'); }", "class Foo {\n foo() {\n }\n}\n", @src());
+
+ // try expectPrinted(t, "try { console.log(\"hi\"); }\ncatch(er) { console.log('noooo'); }", "class Foo {\n foo() {\n }\n}\n", @src());
+
+ // try expectPrinted(t, "class Foo { foo() {} }", "class Foo {\n foo() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { *foo() {} }", "class Foo {\n *foo() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { get foo() {} }", "class Foo {\n get foo() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { set foo(x) {} }", "class Foo {\n set foo(x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static foo() {} }", "class Foo {\n static foo() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static *foo() {} }", "class Foo {\n static *foo() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static get foo() {} }", "class Foo {\n static get foo() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static set foo(x) {} }", "class Foo {\n static set foo(x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { async foo() {} }", "class Foo {\n async foo() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static async foo() {} }", "class Foo {\n static async foo() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static async *foo() {} }", "class Foo {\n static async *foo() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static async *foo() {}\n hey = true; }", "class Foo {\n static async *foo() {\n }\n hey = true;\n}\n", @src());
+
+ // try expectPrinted(t, "class Foo { if() {} }", "class Foo {\n if() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { *if() {} }", "class Foo {\n *if() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { get if() {} }", "class Foo {\n get if() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { set if(x) {} }", "class Foo {\n set if(x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static if() {} }", "class Foo {\n static if() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static *if() {} }", "class Foo {\n static *if() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static get if() {} }", "class Foo {\n static get if() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static set if(x) {} }", "class Foo {\n static set if(x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { async if() {} }", "class Foo {\n async if() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static async if() {} }", "class Foo {\n static async if() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static async *if() {} }", "class Foo {\n static async *if() {\n }\n}\n", @src());
+
+ // try expectPrinted(t, "class Foo { a() {} b() {} }", "class Foo {\n a() {\n }\n b() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a() {} get b() {} }", "class Foo {\n a() {\n }\n get b() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a() {} set b(x) {} }", "class Foo {\n a() {\n }\n set b(x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a() {} static b() {} }", "class Foo {\n a() {\n }\n static b() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a() {} static *b() {} }", "class Foo {\n a() {\n }\n static *b() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a() {} static get b() {} }", "class Foo {\n a() {\n }\n static get b() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a() {} static set b(x) {} }", "class Foo {\n a() {\n }\n static set b(x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a() {} async b() {} }", "class Foo {\n a() {\n }\n async b() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a() {} static async b() {} }", "class Foo {\n a() {\n }\n static async b() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a() {} static async *b() {} }", "class Foo {\n a() {\n }\n static async *b() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { [arguments] }", "class Foo {\n [arguments];\n}\n", @src());
+ // try expectPrinted(t, "class Foo { [arguments] = 1 }", "class Foo {\n [arguments] = 1;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { arguments = 1 }", "class Foo {\n arguments = 1;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { x = class { arguments = 1 } }", "class Foo {\n x = class {\n arguments = 1;\n };\n}\n", @src());
+ // try expectPrinted(t, "class Foo { x = function() { arguments } }", "class Foo {\n x = function() {\n arguments;\n };\n}\n", @src());
+ // try expectPrinted(t, "class Foo { get ['constructor']() {} }", "class Foo {\n get [\"constructor\"]() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { set ['constructor'](x) {} }", "class Foo {\n set [\"constructor\"](x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { *['constructor']() {} }", "class Foo {\n *[\"constructor\"]() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { async ['constructor']() {} }", "class Foo {\n async [\"constructor\"]() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { async *['constructor']() {} }", "class Foo {\n async *[\"constructor\"]() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { get prototype() {} }", "class Foo {\n get prototype() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { get 'prototype'() {} }", "class Foo {\n get prototype() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { set prototype(x) {} }", "class Foo {\n set prototype(x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { set 'prototype'(x) {} }", "class Foo {\n set prototype(x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { *prototype() {} }", "class Foo {\n *prototype() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { *'prototype'() {} }", "class Foo {\n *prototype() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { async prototype() {} }", "class Foo {\n async prototype() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { async 'prototype'() {} }", "class Foo {\n async prototype() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { async *prototype() {} }", "class Foo {\n async *prototype() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { async *'prototype'() {} }", "class Foo {\n async *prototype() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static get ['prototype']() {} }", "class Foo {\n static get [\"prototype\"]() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static set ['prototype'](x) {} }", "class Foo {\n static set [\"prototype\"](x) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static *['prototype']() {} }", "class Foo {\n static *[\"prototype\"]() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static async ['prototype']() {} }", "class Foo {\n static async [\"prototype\"]() {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static async *['prototype']() {} }", "class Foo {\n static async *[\"prototype\"]() {\n }\n}\n", @src());
+
+ // try expectPrinted(t, "class Foo extends Bar { constructor() { super() } }", "class Foo extends Bar {\n constructor() {\n super();\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo extends Bar { constructor() { () => super() } }", "class Foo extends Bar {\n constructor() {\n () => super();\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo extends Bar { constructor() { () => { super() } } }", "class Foo extends Bar {\n constructor() {\n () => {\n super();\n };\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo extends Bar { constructor(x = super()) {} }", "class Foo extends Bar {\n constructor(x = super()) {\n }\n}\n", @src());
+ // try expectPrinted(t, "class Foo extends Bar { constructor(x = () => super()) {} }", "class Foo extends Bar {\n constructor(x = () => super()) {\n }\n}\n", @src());
+
+ // try expectPrinted(t, "class Foo { a }", "class Foo {\n a;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { a = 1 }", "class Foo {\n a = 1;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static a }", "class Foo {\n static a;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static a = 1 }", "class Foo {\n static a = 1;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static a = 1; b }", "class Foo {\n static a = 1;\n b;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static [a] }", "class Foo {\n static [a];\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static [a] = 1 }", "class Foo {\n static [a] = 1;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { static [a] = 1; [b] }", "class Foo {\n static [a] = 1;\n [b];\n}\n", @src());
+
+ // try expectPrinted(t, "class Foo { prototype }", "class Foo {\n prototype;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { 'prototype' }", "class Foo {\n prototype;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { prototype = 1 }", "class Foo {\n prototype = 1;\n}\n", @src());
+ // try expectPrinted(t, "class Foo { 'prototype' = 1 }", "class Foo {\n prototype = 1;\n}\n", @src());
+ // try expectPrinted(t, "function* foo() { -(yield 100) }", "function* foo() {\n -(yield 100);\n}\n", @src());
+
+ // try expectPrinted(t, "function *foo() { (x = yield y) }", "function* foo() {\n x = yield y;\n}\n", @src());
+ // try expectPrinted(t, "yield\n100", "yield;\n100;\n", @src());
+ // try expectPrinted(t, "let x = {yield}", "let x = {yield};\n", @src());
+ // try expectPrinted(t, "function foo() { ({yield} = x) }", "function foo() {\n ({yield} = x);\n}\n", @src());
+ // try expectPrinted(t, "({ *yield() {} })", "({*yield() {\n}});\n", @src());
+ // try expectPrinted(t, "(class { *yield() {} })", "(class {\n *yield() {\n }\n});\n", @src());
+ // try expectPrinted(t, "class Foo { *yield() {} }", "class Foo {\n *yield() {\n }\n}\n", @src());
+ // try expectPrinted(t, "function* yield() {}", "function* yield() {\n}\n", @src());
+ // try expectPrinted(t, "({ async *yield() {} })", "({async *yield() {\n}});\n", @src());
+ // try expectPrinted(t, "(class { async *yield() {} })", "(class {\n async *yield() {\n }\n});\n", @src());
+ // try expectPrinted(t, "class Foo { async *yield() {} }", "class Foo {\n async *yield() {\n }\n}\n", @src());
+ // try expectPrinted(t, "async function* yield() {}", "async function* yield() {\n}\n", @src());
+ // try expectPrinted(t, "-async function foo() { await 0 }", "-async function foo() {\n await 0;\n};\n", @src());
+ // try expectPrinted(t, "-async function() { await 0 }", "-async function() {\n await 0;\n};\n", @src());
+ // try expectPrinted(t, "1 - async function foo() { await 0 }", "1 - async function foo() {\n await 0;\n};\n", @src());
+ // try expectPrinted(t, "1 - async function() { await 0 }", "1 - async function() {\n await 0;\n};\n", @src());
+ // try expectPrinted(t, "(async function foo() { await 0 })", "(async function foo() {\n await 0;\n});\n", @src());
+ // try expectPrinted(t, "(async function() { await 0 })", "(async function() {\n await 0;\n});\n", @src());
+ // try expectPrinted(t, "(x, async function foo() { await 0 })", "x, async function foo() {\n await 0;\n};\n", @src());
+ // try expectPrinted(t, "(x, async function() { await 0 })", "x, async function() {\n await 0;\n};\n", @src());
+ // try expectPrinted(t, "new async function() { await 0 }", "new async function() {\n await 0;\n}();\n", @src());
+ // try expectPrinted(t, "new async function() { await 0 }.x", "new async function() {\n await 0;\n}.x();\n", @src());
+
+ // try expectPrinted(t, "function foo() { await }", "function foo() {\n await;\n}\n", @src());
+ // try expectPrinted(t, "async function foo() { await 0 }", "async function foo() {\n await 0;\n}\n", @src());
+
+ // try expectPrinted(t, "(async x => y), z", "async (x) => y, z;\n", @src());
+ // try expectPrinted(t, "(async x => y, z)", "async (x) => y, z;\n", @src());
+ // try expectPrinted(t, "(async x => (y, z))", "async (x) => (y, z);\n", @src());
+ // try expectPrinted(t, "(async (x) => y), z", "async (x) => y, z;\n", @src());
+ // try expectPrinted(t, "(async (x) => y, z)", "async (x) => y, z;\n", @src());
+ // try expectPrinted(t, "(async (x) => (y, z))", "async (x) => (y, z);\n", @src());
+ // try expectPrinted(t, "async x => y, z", "async (x) => y, z;\n", @src());
+ // try expectPrinted(t, "async x => (y, z)", "async (x) => (y, z);\n", @src());
+ // try expectPrinted(t, "async (x) => y, z", "async (x) => y, z;\n", @src());
+ // try expectPrinted(t, "async (x) => (y, z)", "async (x) => (y, z);\n", @src());
+ // try expectPrinted(t, "export default async x => (y, z)", "export default async (x) => (y, z);\n", @src());
+ // try expectPrinted(t, "export default async (x) => (y, z)", "export default async (x) => (y, z);\n", @src());
+
+ // try expectPrinted(t, "(class { async \n foo() {} })", "(class {\n async;\n foo() {\n }\n});\n", @src());
+ // try expectPrinted(t, "(class { async \n *foo() {} })", "(class {\n async;\n *foo() {\n }\n});\n", @src());
+ // try expectPrinted(t, "async function foo(){for await(x of y);}", "async function foo() {\n for await (x of y)\n ;\n}\n", @src());
+ // try expectPrinted(t, "async function foo(){for await(let x of y);}", "async function foo() {\n for await (let x of y)\n ;\n}\n", @src());
+
+ // // Await as a declaration
+ // try expectPrinted(t, "({ async await() {} })", "({async await() {\n}});\n", @src());
+ // try expectPrinted(t, "(class { async await() {} })", "(class {\n async await() {\n }\n});\n", @src());
+ // try expectPrinted(t, "class Foo { async await() {} }", "class Foo {\n async await() {\n }\n}\n", @src());
+
+ // try expectPrinted(t, "({ async *await() {} })", "({async *await() {\n}});\n", @src());
+ // try expectPrinted(t, "(class { async *await() {} })", "(class {\n async *await() {\n }\n});\n", @src());
+ // try expectPrinted(t, "class Foo { async *await() {} }", "class Foo {\n async *await() {\n }\n}\n", @src());
+
+ // try expectPrinted(t, "(x) => function() {}", "(x) => function() {\n};\n", @src());
+
+ // try expectPrinted(t, "x => function() {}", "(x) => function() {\n};\n", @src());
+
+ // try expectPrinted(t, "(x => function() {})", "(x) => function() {\n};\n", @src());
+
+ // try expectPrinted(t, "(x = () => {}) => {}", "(x = () => {\n}) => {\n};\n", @src());
+ // try expectPrinted(t, "async (x = () => {}) => {}", "async (x = () => {\n}) => {\n};\n", @src());
+
+ // try expectPrinted(t, "(() => {}) ? a : b", "(() => {\n}) ? a : b;\n", @src());
+ // try expectPrinted(t, "1 < (() => {})", "1 < (() => {\n});\n", @src());
+ // try expectPrinted(t, "y = x => {}", "y = (x) => {\n};\n", @src());
+ // try expectPrinted(t, "y = () => {}", "y = () => {\n};\n", @src());
+ // try expectPrinted(t, "y = (x) => {}", "y = (x) => {\n};\n", @src());
+ // try expectPrinted(t, "y = async x => {}", "y = async (x) => {\n};\n", @src());
+ // try expectPrinted(t, "y = async () => {}", "y = async () => {\n};\n", @src());
+ // try expectPrinted(t, "y = async (x) => {}", "y = async (x) => {\n};\n", @src());
+ // try expectPrinted(t, "1 + function () {}", "1 + function() {\n};\n", @src());
+ // try expectPrinted(t, "1 + async function () {}", "1 + async function() {\n};\n", @src());
+ // try expectPrinted(t, "class Foo extends function () {} {}", "class Foo extends function() {\n} {\n}\n", @src());
+ // try expectPrinted(t, "class Foo extends async function () {} {}", "class Foo extends async function() {\n} {\n}\n", @src());
+
+ // try expectPrinted(t, "() => {}\n(0)", "() => {\n};\n0;\n", @src());
+ // try expectPrinted(t, "x => {}\n(0)", "(x) => {\n};\n0;\n", @src());
+ // try expectPrinted(t, "async () => {}\n(0)", "async () => {\n};\n0;\n", @src());
+ // try expectPrinted(t, "async x => {}\n(0)", "async (x) => {\n};\n0;\n", @src());
+ // try expectPrinted(t, "async (x) => {}\n(0)", "async (x) => {\n};\n0;\n", @src());
+
+ // try expectPrinted(t, "() => {}\n,0", "() => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "x => {}\n,0", "(x) => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "async () => {}\n,0", "async () => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "async x => {}\n,0", "async (x) => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "async (x) => {}\n,0", "async (x) => {\n}, 0;\n", @src());
+
+ // try expectPrinted(t, "(() => {})\n(0)", "(() => {\n})(0);\n", @src());
+ // try expectPrinted(t, "(x => {})\n(0)", "((x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "(async () => {})\n(0)", "(async () => {\n})(0);\n", @src());
+ // try expectPrinted(t, "(async x => {})\n(0)", "(async (x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "(async (x) => {})\n(0)", "(async (x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "y = () => {}\n(0)", "y = () => {\n};\n0;\n", @src());
+ // try expectPrinted(t, "y = x => {}\n(0)", "y = (x) => {\n};\n0;\n", @src());
+ // try expectPrinted(t, "y = async () => {}\n(0)", "y = async () => {\n};\n0;\n", @src());
+ // try expectPrinted(t, "y = async x => {}\n(0)", "y = async (x) => {\n};\n0;\n", @src());
+ // try expectPrinted(t, "y = async (x) => {}\n(0)", "y = async (x) => {\n};\n0;\n", @src());
+
+ // try expectPrinted(t, "y = () => {}\n,0", "y = () => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "y = x => {}\n,0", "y = (x) => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "y = async () => {}\n,0", "y = async () => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "y = async x => {}\n,0", "y = async (x) => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "y = async (x) => {}\n,0", "y = async (x) => {\n}, 0;\n", @src());
+
+ // try expectPrinted(t, "y = (() => {})\n(0)", "y = (() => {\n})(0);\n", @src());
+ // try expectPrinted(t, "y = (x => {})\n(0)", "y = ((x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "y = (async () => {})\n(0)", "y = (async () => {\n})(0);\n", @src());
+ // try expectPrinted(t, "y = (async x => {})\n(0)", "y = (async (x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "y = (async (x) => {})\n(0)", "y = (async (x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "(() => {}\n,0)", "() => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "(x => {}\n,0)", "(x) => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "(async () => {}\n,0)", "async () => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "(async x => {}\n,0)", "async (x) => {\n}, 0;\n", @src());
+ // try expectPrinted(t, "(async (x) => {}\n,0)", "async (x) => {\n}, 0;\n", @src());
+
+ // try expectPrinted(t, "((() => {})\n(0))", "(() => {\n})(0);\n", @src());
+ // try expectPrinted(t, "((x => {})\n(0))", "((x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "((async () => {})\n(0))", "(async () => {\n})(0);\n", @src());
+ // try expectPrinted(t, "((async x => {})\n(0))", "(async (x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "((async (x) => {})\n(0))", "(async (x) => {\n})(0);\n", @src());
+
+ // try expectPrinted(t, "y = (() => {}\n,0)", "y = (() => {\n}, 0);\n", @src());
+ // try expectPrinted(t, "y = (x => {}\n,0)", "y = ((x) => {\n}, 0);\n", @src());
+ // try expectPrinted(t, "y = (async () => {}\n,0)", "y = (async () => {\n}, 0);\n", @src());
+ // try expectPrinted(t, "y = (async x => {}\n,0)", "y = (async (x) => {\n}, 0);\n", @src());
+ // try expectPrinted(t, "y = (async (x) => {}\n,0)", "y = (async (x) => {\n}, 0);\n", @src());
+
+ // try expectPrinted(t, "y = ((() => {})\n(0))", "y = (() => {\n})(0);\n", @src());
+ // try expectPrinted(t, "y = ((x => {})\n(0))", "y = ((x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "y = ((async () => {})\n(0))", "y = (async () => {\n})(0);\n", @src());
+ // try expectPrinted(t, "y = ((async x => {})\n(0))", "y = (async (x) => {\n})(0);\n", @src());
+ // try expectPrinted(t, "y = ((async (x) => {})\n(0))", "y = (async (x) => {\n})(0);\n", @src());
+
+ // try expectPrinted(t, "(-x) ** 2", "(-x) ** 2;\n", @src());
+ // try expectPrinted(t, "(+x) ** 2", "(+x) ** 2;\n", @src());
+ // try expectPrinted(t, "(~x) ** 2", "(~x) ** 2;\n", @src());
+ // try expectPrinted(t, "(!x) ** 2", "(!x) ** 2;\n", @src());
+ // try expectPrinted(t, "(-1) ** 2", "(-1) ** 2;\n", @src());
+ // try expectPrinted(t, "(+1) ** 2", "1 ** 2;\n", @src());
+ // try expectPrinted(t, "(~1) ** 2", "(~1) ** 2;\n", @src());
+ // try expectPrinted(t, "(!1) ** 2", "false ** 2;\n", @src());
+ // try expectPrinted(t, "(void x) ** 2", "(void x) ** 2;\n", @src());
+ // try expectPrinted(t, "(delete x) ** 2", "(delete x) ** 2;\n", @src());
+ // try expectPrinted(t, "(typeof x) ** 2", "(typeof x) ** 2;\n", @src());
+ // try expectPrinted(t, "undefined ** 2", "(void 0) ** 2;\n", @src());
+
+ // try expectPrinted(t, "({ prototype: 1 })", "({prototype: 1});\n", @src());
+ // try expectPrinted(t, "({ get prototype() {} })", "({get prototype() {\n}});\n", @src());
+ // try expectPrinted(t, "({ set prototype(x) {} })", "({set prototype(x) {\n}});\n", @src());
+ // try expectPrinted(t, "({ *prototype() {} })", "({*prototype() {\n}});\n", @src());
+ // try expectPrinted(t, "({ async prototype() {} })", "({async prototype() {\n}});\n", @src());
+ // try expectPrinted(t, "({ async* prototype() {} })", "({async *prototype() {\n}});\n", @src());
+
+ // try expectPrinted(t, "({foo})", "({foo});\n", @src());
+ // try expectPrinted(t, "({foo:0})", "({foo: 0});\n", @src());
+ // try expectPrinted(t, "({1e9:0})", "({1e9: 0});\n", @src());
+ // try expectPrinted(t, "({1_2_3n:0})", "({123n: 0});\n", @src());
+ // try expectPrinted(t, "({0x1_2_3n:0})", "({0x123n: 0});\n", @src());
+ // try expectPrinted(t, "({foo() {}})", "({foo() {\n}});\n", @src());
+ // try expectPrinted(t, "({*foo() {}})", "({*foo() {\n}});\n", @src());
+ // try expectPrinted(t, "({get foo() {}})", "({get foo() {\n}});\n", @src());
+ // try expectPrinted(t, "({set foo(x) {}})", "({set foo(x) {\n}});\n", @src());
+
+ // try expectPrinted(t, "({if:0})", "({if: 0});\n", @src());
+ // try expectPrinted(t, "({if() {}})", "({if() {\n}});\n", @src());
+ // try expectPrinted(t, "({*if() {}})", "({*if() {\n}});\n", @src());
+ // try expectPrinted(t, "({get if() {}})", "({get if() {\n}});\n", @src());
+ // try expectPrinted(t, "({set if(x) {}})", "({set if(x) {\n}});\n", @src());
+
+ // try expectPrinted(t, "async function foo() { await x; }", "await x;\n", @src());
+ // try expectPrinted(t, "async function foo() { await +x; }", "await +x;\n", @src());
+ // try expectPrinted(t, "async function foo() { await -x; }", "await -x;\n", @src());
+ // try expectPrinted(t, "async function foo() { await ~x; }", "await ~x;\n", @src());
+ // try expectPrinted(t, "async function foo() { await !x; }", "await !x;\n", @src());
+ // try expectPrinted(t, "async function foo() { await --x; }", "await --x;\n", @src());
+ // try expectPrinted(t, "async function foo() { await ++x; }", "await ++x;\n", @src());
+ // try expectPrinted(t, "async function foo() { await x--; }", "await x--;\n", @src());
+ // try expectPrinted(t, "async function foo() { await x++; }", "await x++;\n", @src());
+ // try expectPrinted(t, "async function foo() { await void x; }", "await void x;\n", @src());
+ // try expectPrinted(t, "async function foo() { await typeof x; }", "await typeof x;\n", @src());
+ // try expectPrinted(t, "async function foo() { await (x * y); }", "await (x * y);\n", @src());
+ // try expectPrinted(t, "async function foo() { await (x ** y); }", "await (x ** y);\n", @src());
+
+ // try expectPrinted(t, "export default (1, 2)", "export default (1, 2);\n", @src());
+ // try expectPrinted(t, "export default async", "export default async;\n", @src());
+ // try expectPrinted(t, "export default async()", "export default async();\n", @src());
+ // try expectPrinted(t, "export default async + 1", "export default async + 1;\n", @src());
+ // try expectPrinted(t, "export default async => {}", "export default (async) => {\n};\n", @src());
+ // try expectPrinted(t, "export default async x => {}", "export default async (x) => {\n};\n", @src());
+ // try expectPrinted(t, "export default async () => {}", "export default async () => {\n};\n", @src());
+
+ // // This is a corner case in the ES6 grammar. The "export default" statement
+ // // normally takes an expression except for the function and class keywords
+ // // which behave sort of like their respective declarations instead.
+ // try expectPrinted(t, "export default function() {} - after", "export default function() {\n}\n-after;\n", @src());
+ // try expectPrinted(t, "export default function*() {} - after", "export default function* () {\n}\n-after;\n", @src());
+ // try expectPrinted(t, "export default function foo() {} - after", "export default function foo() {\n}\n-after;\n", @src());
+ // try expectPrinted(t, "export default function* foo() {} - after", "export default function* foo() {\n}\n-after;\n", @src());
+ // try expectPrinted(t, "export default async function() {} - after", "export default async function() {\n}\n-after;\n", @src());
+ // try expectPrinted(t, "export default async function*() {} - after", "export default async function* () {\n}\n-after;\n", @src());
+ // try expectPrinted(t, "export default async function foo() {} - after", "export default async function foo() {\n}\n-after;\n", @src());
+ // try expectPrinted(t, "export default async function* foo() {} - after", "export default async function* foo() {\n}\n-after;\n", @src());
+ // try expectPrinted(t, "export default class {} - after", "export default class {\n}\n-after;\n", @src());
+ // try expectPrinted(t, "export default class Foo {} - after", "export default class Foo {\n}\n-after;\n", @src());
t.report(@src());
}