Skip to content

Commit c636edd

Browse files
committed
Legalize casting object literals to classes when linting
1 parent 29081b6 commit c636edd

File tree

6 files changed

+78
-10
lines changed

6 files changed

+78
-10
lines changed

dist/asc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/asc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/lint/base.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@
7373
"no-misused-new": {
7474
"severity": "error"
7575
},
76-
"no-object-literal-type-assertion": {
77-
"severity": "error"
78-
},
7976
"no-require-imports": {
8077
"severity": "error"
8178
},

tests/compiler/object-literal.optimized.wat

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,33 @@
275275
(call $~lib/env/abort
276276
(i32.const 0)
277277
(i32.const 36)
278-
(i32.const 23)
278+
(i32.const 26)
279279
(i32.const 2)
280280
)
281281
(unreachable)
282282
)
283283
)
284284
)
285-
(func $start (; 6 ;) (type $v)
285+
(func $object-literal/Foo2#test (; 6 ;) (type $iv) (param $0 i32)
286+
(if
287+
(i32.ne
288+
(i32.load
289+
(get_local $0)
290+
)
291+
(i32.const 3)
292+
)
293+
(block
294+
(call $~lib/env/abort
295+
(i32.const 0)
296+
(i32.const 36)
297+
(i32.const 21)
298+
(i32.const 4)
299+
)
300+
(unreachable)
301+
)
302+
)
303+
)
304+
(func $start (; 7 ;) (type $v)
286305
(local $0 i32)
287306
(set_global $~lib/allocator/arena/startOffset
288307
(i32.and
@@ -322,5 +341,16 @@
322341
(call $object-literal/bar2
323342
(get_local $0)
324343
)
344+
(i32.store
345+
(tee_local $0
346+
(call $~lib/allocator/arena/allocate_memory
347+
(i32.const 4)
348+
)
349+
)
350+
(i32.const 3)
351+
)
352+
(call $object-literal/Foo2#test
353+
(get_local $0)
354+
)
325355
)
326356
)

tests/compiler/object-literal.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ class Foo2 {
1717
constructor() {
1818
this.bar = 1;
1919
}
20+
test(): void {
21+
assert(this.bar == 3);
22+
}
2023
}
2124

2225
function bar2(foo: Foo2): void {
2326
assert(foo.bar == 2);
2427
}
2528

26-
bar2({ bar: 2 });
29+
bar2(<Foo2>{ bar: 2 });
30+
31+
(<Foo2>{ bar: 3 }).test();

tests/compiler/object-literal.untouched.wat

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,38 @@
308308
(call $~lib/env/abort
309309
(i32.const 0)
310310
(i32.const 36)
311-
(i32.const 23)
311+
(i32.const 26)
312312
(i32.const 2)
313313
)
314314
(unreachable)
315315
)
316316
)
317317
)
318-
(func $start (; 6 ;) (type $v)
318+
(func $object-literal/Foo2#test (; 6 ;) (type $iv) (param $0 i32)
319+
(if
320+
(i32.eqz
321+
(i32.eq
322+
(i32.load
323+
(get_local $0)
324+
)
325+
(i32.const 3)
326+
)
327+
)
328+
(block
329+
(call $~lib/env/abort
330+
(i32.const 0)
331+
(i32.const 36)
332+
(i32.const 21)
333+
(i32.const 4)
334+
)
335+
(unreachable)
336+
)
337+
)
338+
)
339+
(func $start (; 7 ;) (type $v)
319340
(local $0 i32)
320341
(local $1 i32)
342+
(local $2 i32)
321343
(set_global $~lib/allocator/arena/startOffset
322344
(i32.and
323345
(i32.add
@@ -365,5 +387,19 @@
365387
(get_local $1)
366388
)
367389
)
390+
(call $object-literal/Foo2#test
391+
(block (result i32)
392+
(set_local $2
393+
(call $~lib/allocator/arena/allocate_memory
394+
(i32.const 4)
395+
)
396+
)
397+
(i32.store
398+
(get_local $2)
399+
(i32.const 3)
400+
)
401+
(get_local $2)
402+
)
403+
)
368404
)
369405
)

0 commit comments

Comments
 (0)