Skip to content

Commit

Permalink
feat(compiler): Implement constant string concat propagation (#29621)
Browse files Browse the repository at this point in the history
## Summary

Resolves #29617

## How did you test this change?
I verified the implementation using the test.
  • Loading branch information
nikeee committed May 28, 2024
1 parent 1816476 commit a9a0106
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ function evaluateInstruction(
case "+": {
if (typeof lhs === "number" && typeof rhs === "number") {
result = { kind: "Primitive", value: lhs + rhs, loc: value.loc };
} else if (typeof lhs === "string" && typeof rhs === "string") {
result = { kind: "Primitive", value: lhs + rhs, loc: value.loc };
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

## Input

```javascript
function foo() {
const a = "a" + "b";
const c = "c";
return a + c;
}

export const FIXTURE_ENTRYPOINT = {
fn: foo,
params: [],
isComponent: false,
};

```

## Code

```javascript
function foo() {
return "abc";
}

export const FIXTURE_ENTRYPOINT = {
fn: foo,
params: [],
isComponent: false,
};

```
### Eval output
(kind: ok) "abc"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function foo() {
const a = "a" + "b";
const c = "c";
return a + c;
}

export const FIXTURE_ENTRYPOINT = {
fn: foo,
params: [],
isComponent: false,
};

0 comments on commit a9a0106

Please sign in to comment.