Skip to content
Snippets Groups Projects
Commit ffe8e007 authored by Mofei Zhang's avatar Mofei Zhang
Browse files

[compiler][ez] Add shape for global Object.keys

Add shape / type for global Object.keys. This is useful because
- it has an Effect.Read (not an Effect.Capture) as it cannot alias its argument.
- Object.keys return an array
parent 22902de4
No related merge requests found
......@@ -87,6 +87,21 @@ const UNTYPED_GLOBALS: Set<string> = new Set([
]);
const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
[
'Object',
addObject(DEFAULT_SHAPES, 'Object', [
[
'keys',
addFunction(DEFAULT_SHAPES, [], {
positionalParams: [Effect.Read],
restParam: null,
returnType: {kind: 'Object', shapeId: BuiltInArrayId},
calleeEffect: Effect.Read,
returnValueKind: ValueKind.Mutable,
}),
],
]),
],
[
'Array',
addObject(DEFAULT_SHAPES, 'Array', [
......
## Input
```javascript
import {arrayPush} from 'shared-runtime';
function useFoo({a, b}) {
const obj = {a};
arrayPush(Object.keys(obj), b);
return obj;
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{a: 2, b: 3}],
};
```
## Code
```javascript
import { c as _c } from "react/compiler-runtime";
import { arrayPush } from "shared-runtime";
function useFoo(t0) {
const $ = _c(2);
const { a, b } = t0;
let t1;
if ($[0] !== a) {
t1 = { a };
$[0] = a;
$[1] = t1;
} else {
t1 = $[1];
}
const obj = t1;
arrayPush(Object.keys(obj), b);
return obj;
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{ a: 2, b: 3 }],
};
```
### Eval output
(kind: ok) {"a":2}
\ No newline at end of file
import {arrayPush} from 'shared-runtime';
function useFoo({a, b}) {
const obj = {a};
arrayPush(Object.keys(obj), b);
return obj;
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{a: 2, b: 3}],
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment