Skip to content

Commit

Permalink
Simplify some built-in cases of $dotCall
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdz committed Aug 14, 2024
1 parent 932f73b commit ab69e13
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 355 deletions.
319 changes: 46 additions & 273 deletions src/normalize/normalize.mjs

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions tests/cases/function/apply/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ $(

`````js filename=intro
const tmpCallCallee = $;
const tmpCalleeParam$1 = {};
const tmpCalleeParam$3 = [`x`];
const tmpCallObj = function () {
const tmpPrevalAliasArgumentsAny = arguments;
debugger;
$(...tmpPrevalAliasArgumentsAny);
return undefined;
};
const tmpCallVal = tmpCallObj.apply;
const tmpCalleeParam$1 = {};
const tmpCalleeParam$3 = [`x`];
const tmpCalleeParam = $dotCall(tmpCallVal, tmpCallObj, tmpCalleeParam$1, tmpCalleeParam$3);
const tmpCalleeParam = tmpCallObj.apply(tmpCalleeParam$1, tmpCalleeParam$3);
tmpCallCallee(tmpCalleeParam);
`````

Expand Down
21 changes: 6 additions & 15 deletions tests/cases/function/apply/excessive_args.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,18 @@ $(

`````js filename=intro
const tmpCallCallee = $;
const tmpCalleeParam$1 = {};
const tmpCalleeParam$3 = [`x`];
const tmpCalleeParam$5 = 1;
const tmpCalleeParam$7 = 2;
const tmpCalleeParam$9 = 3;
const tmpCallObj = function () {
const tmpPrevalAliasArgumentsAny = arguments;
debugger;
$(...tmpPrevalAliasArgumentsAny);
return undefined;
};
const tmpCallVal = tmpCallObj.apply;
const tmpCalleeParam$1 = {};
const tmpCalleeParam$3 = [`x`];
const tmpCalleeParam$5 = 1;
const tmpCalleeParam$7 = 2;
const tmpCalleeParam$9 = 3;
const tmpCalleeParam = $dotCall(
tmpCallVal,
tmpCallObj,
tmpCalleeParam$1,
tmpCalleeParam$3,
tmpCalleeParam$5,
tmpCalleeParam$7,
tmpCalleeParam$9,
);
const tmpCalleeParam = tmpCallObj.apply(tmpCalleeParam$1, tmpCalleeParam$3, tmpCalleeParam$5, tmpCalleeParam$7, tmpCalleeParam$9);
tmpCallCallee(tmpCalleeParam);
`````

Expand Down
99 changes: 99 additions & 0 deletions tests/cases/function/apply/with_context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Preval test case

# with_context.md

> Function > Apply > With context
>
> Function apply blabla
## Input

`````js filename=intro
// Intentially craft to try and proc the dot call transform
// Show that it keeps the apply when context is used (unless/until we can eliminate that too heh)
$(function(){ $(this.x); }.apply({x: 15}, ['x']));
`````

## Pre Normal


`````js filename=intro
$(
function () {
const tmpPrevalAliasThis = this;
debugger;
$(tmpPrevalAliasThis.x);
}.apply({ x: 15 }, [`x`]),
);
`````

## Normalized


`````js filename=intro
const tmpCallCallee = $;
const tmpCalleeParam$1 = { x: 15 };
const tmpCalleeParam$3 = [`x`];
const tmpCallObj = function () {
const tmpPrevalAliasThis = this;
debugger;
const tmpCallCallee$1 = $;
const tmpCalleeParam$5 = tmpPrevalAliasThis.x;
tmpCallCallee$1(tmpCalleeParam$5);
return undefined;
};
const tmpCalleeParam = tmpCallObj.apply(tmpCalleeParam$1, tmpCalleeParam$3);
tmpCallCallee(tmpCalleeParam);
`````

## Output


`````js filename=intro
const tmpCalleeParam$1 = { x: 15 };
const tmpCalleeParam$3 = [`x`];
const tmpCallObj = function () {
const tmpPrevalAliasThis = this;
debugger;
const tmpCalleeParam$5 = tmpPrevalAliasThis.x;
$(tmpCalleeParam$5);
return undefined;
};
const tmpCalleeParam = tmpCallObj.apply(tmpCalleeParam$1, tmpCalleeParam$3);
$(tmpCalleeParam);
`````

## PST Output

With rename=true

`````js filename=intro
const a = { x: 15 };
const b = [ "x" ];
const c = function() {
const d = this;
debugger;
const e = d.x;
$( e );
return undefined;
};
const f = c.apply( a, b );
$( f );
`````

## Globals

None

## Result

Should call `$` with:
- 1: 15
- 2: undefined
- eval returned: undefined

Pre normalization calls: Same

Normalized calls: Same

Final output calls: Same
16 changes: 6 additions & 10 deletions tests/cases/object_literal/prop_write/mutation_in_closure_proof.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ let f = function () {
delete x.y;
} else {
}
const tmpCallObj = Object;
const tmpCallVal = tmpCallObj.defineProperty;
const tmpCalleeParam = x;
const tmpCalleeParam$1 = `y`;
const tmpCalleeParam$3 = {
Expand All @@ -87,7 +85,7 @@ let f = function () {
return `intercepted`;
},
};
$dotCall(tmpCallVal, tmpCallObj, tmpCalleeParam, tmpCalleeParam$1, tmpCalleeParam$3);
Object.defineProperty(tmpCalleeParam, tmpCalleeParam$1, tmpCalleeParam$3);
$(`b`);
return undefined;
};
Expand Down Expand Up @@ -115,7 +113,6 @@ const f = function () {
delete x.y;
} else {
}
const tmpCallVal = Object.defineProperty;
const tmpCalleeParam$3 = {
set($$0) {
debugger;
Expand All @@ -126,7 +123,7 @@ const f = function () {
return `intercepted`;
},
};
$dotCall(tmpCallVal, Object, x, `y`, tmpCalleeParam$3);
Object.defineProperty(x, `y`, tmpCalleeParam$3);
$(`b`);
return undefined;
};
Expand All @@ -153,8 +150,7 @@ const a = function() {
$( "yeeting" );
delete c.y;
}
const d = Object.defineProperty;
const e = {
const d = {
set( $$0 ) {
debugger;
return undefined;
Expand All @@ -164,7 +160,7 @@ const a = function() {
return "intercepted";
},
};
$dotCall( d, Object, c, "y", e );
Object.defineProperty( c, "y", d );
$( "b" );
return undefined;
};
Expand All @@ -173,8 +169,8 @@ a();
c.y = 10;
a();
$( c );
const f = c.y;
$( f );
const e = c.y;
$( e );
$( a );
`````

Expand Down
67 changes: 32 additions & 35 deletions tests/cases/random/map_to_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ $(
`````js filename=intro
const tmpCallCallee = $;
const tmpNewCallee = Map;
const tmpCalleeParam$3 = function ($$0) {
let k = $$0;
debugger;
const tmpReturnArg = [k, k];
return tmpReturnArg;
};
const tmpNewCallee$1 = Map;
const tmpArrElement = [`clearInterval`, `global.clearInterval`];
const tmpArrElement$1 = [`clearTimeout`, `global.clearTimeout`];
Expand All @@ -70,14 +76,7 @@ const tmpCalleeParam$5 = [tmpArrElement, tmpArrElement$1, tmpArrElement$3, tmpAr
const tmpCallObj$3 = new tmpNewCallee$1(tmpCalleeParam$5);
const tmpArrSpread = tmpCallObj$3.keys();
const tmpCallObj$1 = [...tmpArrSpread, `module`];
const tmpCallVal = tmpCallObj$1.map;
const tmpCalleeParam$3 = function ($$0) {
let k = $$0;
debugger;
const tmpReturnArg = [k, k];
return tmpReturnArg;
};
const tmpCalleeParam$1 = $dotCall(tmpCallVal, tmpCallObj$1, tmpCalleeParam$3);
const tmpCalleeParam$1 = tmpCallObj$1.map(tmpCalleeParam$3);
const tmpCallObj = new tmpNewCallee(tmpCalleeParam$1);
const tmpCalleeParam = tmpCallObj.get(`\$`);
tmpCallCallee(tmpCalleeParam);
Expand All @@ -87,6 +86,12 @@ tmpCallCallee(tmpCalleeParam);


`````js filename=intro
const tmpCalleeParam$3 = function ($$0) {
const k = $$0;
debugger;
const tmpReturnArg = [k, k];
return tmpReturnArg;
};
const tmpArrElement = [`clearInterval`, `global.clearInterval`];
const tmpArrElement$1 = [`clearTimeout`, `global.clearTimeout`];
const tmpArrElement$3 = [`console`, `global.console`];
Expand All @@ -97,14 +102,7 @@ const tmpCalleeParam$5 = [tmpArrElement, tmpArrElement$1, tmpArrElement$3, tmpAr
const tmpCallObj$3 = new Map(tmpCalleeParam$5);
const tmpArrSpread = tmpCallObj$3.keys();
const tmpCallObj$1 = [...tmpArrSpread, `module`];
const tmpCallVal = tmpCallObj$1.map;
const tmpCalleeParam$3 = function ($$0) {
const k = $$0;
debugger;
const tmpReturnArg = [k, k];
return tmpReturnArg;
};
const tmpCalleeParam$1 = $dotCall(tmpCallVal, tmpCallObj$1, tmpCalleeParam$3);
const tmpCalleeParam$1 = tmpCallObj$1.map(tmpCalleeParam$3);
const tmpCallObj = new Map(tmpCalleeParam$1);
const tmpCalleeParam = tmpCallObj.get(`\$`);
$(tmpCalleeParam);
Expand All @@ -115,27 +113,26 @@ $(tmpCalleeParam);
With rename=true

`````js filename=intro
const a = [ "clearInterval", "global.clearInterval" ];
const b = [ "clearTimeout", "global.clearTimeout" ];
const c = [ "console", "global.console" ];
const d = [ "false", "boolean" ];
const e = [ "null", "null" ];
const f = [ "$", "$" ];
const g = [ a, b, c, d, e, f ];
const h = new Map( g );
const i = h.keys();
const j = [ ... i, "module" ];
const k = j.map;
const l = function($$0 ) {
const m = n;
const a = function($$0 ) {
const b = c;
debugger;
const o = [ m, m ];
return o;
const d = [ b, b ];
return d;
};
const p = $dotCall( k, j, l );
const q = new Map( p );
const r = q.get( "$" );
$( r );
const e = [ "clearInterval", "global.clearInterval" ];
const f = [ "clearTimeout", "global.clearTimeout" ];
const g = [ "console", "global.console" ];
const h = [ "false", "boolean" ];
const i = [ "null", "null" ];
const j = [ "$", "$" ];
const k = [ e, f, g, h, i, j ];
const l = new Map( k );
const m = l.keys();
const n = [ ... m, "module" ];
const o = n.map( a );
const p = new Map( o );
const q = p.get( "$" );
$( q );
`````

## Globals
Expand Down
4 changes: 1 addition & 3 deletions tests/cases/tofix/_regressions
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@
// Apply type analysis for our $forIn and $forOf symbols
// Consider whether tests/cases/regex/dotcall/simple.md should be allowed to inline the regex as the callee or smth
// tests/cases/type_tracked/if/base_undefined.md -> why does that leave a label?


check even of deze nog goed if-tail hoist normalize/dce/return/fence_at_loop_forin_if.md
// when a function does not use _this_ and is used in a $dotCall and we know which function it is, we dont need the dotcall
4 changes: 1 addition & 3 deletions tests/cases/type_tracked/string_method/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ $(`hello world`.replace(/ /g, `, `));

`````js filename=intro
const tmpCallCallee = $;
const tmpCallObj = `hello world`;
const tmpCallVal = tmpCallObj.replace;
const tmpCalleeParam$1 = / /g;
const tmpCalleeParam$3 = `, `;
const tmpCalleeParam = $dotCall(tmpCallVal, tmpCallObj, tmpCalleeParam$1, tmpCalleeParam$3);
const tmpCalleeParam = `hello world`.replace(tmpCalleeParam$1, tmpCalleeParam$3);
tmpCallCallee(tmpCalleeParam);
`````

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ $(`hello world`.replace(/ /g, `.`));

`````js filename=intro
const tmpCallCallee = $;
const tmpCallObj = `hello world`;
const tmpCallVal = tmpCallObj.replace;
const tmpCalleeParam$1 = / /g;
const tmpCalleeParam$3 = `.`;
const tmpCalleeParam = $dotCall(tmpCallVal, tmpCallObj, tmpCalleeParam$1, tmpCalleeParam$3);
const tmpCalleeParam = `hello world`.replace(tmpCalleeParam$1, tmpCalleeParam$3);
tmpCallCallee(tmpCalleeParam);
`````

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ $(`hello world`.replace(/ /g, `, `, $, unknown));

`````js filename=intro
const tmpCallCallee = $;
const tmpCallObj = `hello world`;
const tmpCallVal = tmpCallObj.replace;
const tmpCalleeParam$1 = / /g;
const tmpCalleeParam$3 = `, `;
const tmpCalleeParam$5 = $;
const tmpCalleeParam$7 = unknown;
const tmpCalleeParam = $dotCall(tmpCallVal, tmpCallObj, tmpCalleeParam$1, tmpCalleeParam$3, tmpCalleeParam$5, tmpCalleeParam$7);
const tmpCalleeParam = `hello world`.replace(tmpCalleeParam$1, tmpCalleeParam$3, tmpCalleeParam$5, tmpCalleeParam$7);
tmpCallCallee(tmpCalleeParam);
`````

Expand Down
4 changes: 1 addition & 3 deletions tests/cases/type_tracked/string_method/string_split_regex.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ $(`hello world`.split(/o/g));

`````js filename=intro
const tmpCallCallee = $;
const tmpCallObj = `hello world`;
const tmpCallVal = tmpCallObj.split;
const tmpCalleeParam$1 = /o/g;
const tmpCalleeParam = $dotCall(tmpCallVal, tmpCallObj, tmpCalleeParam$1);
const tmpCalleeParam = `hello world`.split(tmpCalleeParam$1);
tmpCallCallee(tmpCalleeParam);
`````

Expand Down
5 changes: 2 additions & 3 deletions tests/cases/typed_comparison/regex_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ $(/x/g.test($(`x`)));

`````js filename=intro
const tmpCallCallee = $;
const tmpCallObj = /x/g;
const tmpCallVal = tmpCallObj.test;
const tmpCalleeParam$1 = $(`x`);
const tmpCalleeParam = $dotCall(tmpCallVal, tmpCallObj, tmpCalleeParam$1);
const tmpCallObj = /x/g;
const tmpCalleeParam = tmpCallObj.test(tmpCalleeParam$1);
tmpCallCallee(tmpCalleeParam);
`````

Expand Down

0 comments on commit ab69e13

Please sign in to comment.