MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

class expr

+31 -17
+2 -4
examples/spec/typeof.js
··· 6 6 test('typeof float', typeof 3.14, 'number'); 7 7 test('typeof NaN', typeof NaN, 'number'); 8 8 test('typeof Infinity', typeof Infinity, 'number'); 9 + test('typeof bigint', typeof 123n, 'bigint'); 9 10 10 11 test('typeof string', typeof 'hello', 'string'); 11 12 test('typeof empty string', typeof '', 'string'); ··· 24 25 test('typeof date', typeof new Date(), 'object'); 25 26 test('typeof regexp', typeof /test/, 'object'); 26 27 27 - test('typeof function', typeof function(){}, 'function'); 28 + test('typeof function', typeof function () {}, 'function'); 28 29 test('typeof arrow', typeof (() => {}), 'function'); 29 30 test('typeof class', typeof class {}, 'function'); 30 - 31 31 test('typeof symbol', typeof Symbol('test'), 'symbol'); 32 - 33 - test('typeof bigint', typeof 123n, 'bigint'); 34 32 35 33 summary();
+1 -1
meson.build
··· 74 74 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 75 75 76 76 version_conf = configuration_data() 77 - version_conf.set('ANT_VERSION', '0.1.1.3') 77 + version_conf.set('ANT_VERSION', '0.1.1.4') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+28 -12
src/ant.c
··· 5301 5301 } \ 5302 5302 return res; 5303 5303 5304 + static jsval_t js_class_expr(struct js *js, bool is_expression); 5305 + 5304 5306 static jsval_t js_literal(struct js *js) { 5305 5307 next(js); 5306 5308 setlwm(js); ··· 5321 5323 case TOK_LBRACE: return js_obj_literal(js); 5322 5324 case TOK_LBRACKET: return js_arr_literal(js); 5323 5325 case TOK_DIV: return js_regex_literal(js); 5326 + case TOK_CLASS: return js_class_expr(js, true); 5324 5327 case TOK_FUNC: return js_func_literal(js, false); 5325 5328 case TOK_ASYNC: { 5326 5329 js->consumed = 1; ··· 5455 5458 case TOK_IDENTIFIER: 5456 5459 case TOK_CATCH: 5457 5460 case TOK_TRY: 5458 - case TOK_CLASS: 5459 5461 case TOK_FINALLY: return mkcoderef((jsoff_t) js->toff, (jsoff_t) js->tlen); 5460 5462 5461 5463 default: return js_mkerr_typed(js, JS_ERR_SYNTAX, "bad expr"); ··· 7844 7846 return res; 7845 7847 } 7846 7848 7847 - static jsval_t js_class_decl(struct js *js) { 7849 + static jsval_t js_class_expr(struct js *js, bool is_expression); 7850 + static jsval_t js_class_decl(struct js *js) { return js_class_expr(js, false); } 7851 + 7852 + static jsval_t js_class_expr(struct js *js, bool is_expression) { 7848 7853 uint8_t exe = !(js->flags & F_NOEXEC); 7849 7854 js->consumed = 1; 7850 - EXPECT(TOK_IDENTIFIER, ); 7851 - js->consumed = 0; 7852 7855 7853 - jsoff_t class_name_off = js->toff, class_name_len = js->tlen; 7854 - char *class_name = (char *) &js->code[class_name_off]; 7855 - js->consumed = 1; 7856 + jsoff_t class_name_off = 0, class_name_len = 0; 7857 + char *class_name = NULL; 7858 + 7859 + if (next(js) == TOK_IDENTIFIER) { 7860 + if (!(js->tlen == 7 && streq(&js->code[js->toff], js->tlen, "extends", 7))) { 7861 + class_name_off = js->toff; 7862 + class_name_len = js->tlen; 7863 + class_name = (char *) &js->code[class_name_off]; 7864 + js->consumed = 1; 7865 + } 7866 + } else if (!is_expression) { 7867 + return js_mkerr_typed(js, JS_ERR_SYNTAX, "class name expected"); 7868 + } 7856 7869 7857 7870 jsoff_t super_off = 0, super_len = 0; 7858 7871 if (next(js) == TOK_IDENTIFIER && js->tlen == 7 && ··· 8177 8190 8178 8191 jsval_t name_key = js_mkstr(js, "name", 4); 8179 8192 if (is_err(name_key)) return name_key; 8180 - jsval_t name_val = js_mkstr(js, class_name, class_name_len); 8193 + jsval_t name_val = class_name_len > 0 ? js_mkstr(js, class_name, class_name_len) : js_mkstr(js, "", 0); 8181 8194 if (is_err(name_val)) return name_val; 8182 8195 jsval_t res_name = setprop(js, func_obj, name_key, name_val); 8183 8196 if (is_err(res_name)) return res_name; ··· 8188 8201 if (is_err(proto_res)) return proto_res; 8189 8202 8190 8203 jsval_t constructor = mkval(T_FUNC, (unsigned long) vdata(func_obj)); 8191 - if (lkp(js, js->scope, class_name, class_name_len) > 0) { 8192 - return js_mkerr(js, "'%.*s' already declared", (int) class_name_len, class_name); 8204 + 8205 + if (class_name_len > 0) { 8206 + if (lkp(js, js->scope, class_name, class_name_len) > 0) { 8207 + return js_mkerr(js, "'%.*s' already declared", (int) class_name_len, class_name); 8208 + } 8209 + jsval_t x = mkprop(js, js->scope, js_mkstr(js, class_name, class_name_len), constructor, false); 8210 + if (is_err(x)) return x; 8193 8211 } 8194 - jsval_t x = mkprop(js, js->scope, js_mkstr(js, class_name, class_name_len), constructor, false); 8195 - if (is_err(x)) return x; 8196 8212 8197 8213 for (int i = 0; i < method_count; i++) { 8198 8214 if (!methods[i].is_static) continue;