Skip to content

Commit 9d1415b

Browse files
Merge pull request #3757 from DavidANeil:davidneil-no-inline-arrows
PiperOrigin-RevId: 353083185
2 parents 4fe8404 + e3a8f11 commit 9d1415b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/com/google/javascript/jscomp/InlineSimpleMethods.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void visit(NodeTraversal t, Node callNode, Node parent, String callName) {
9999
// Verify this is a trivial return
100100
Node returned = returnedExpression(firstDefinition);
101101
if (returned != null) {
102-
if (isPropertyTree(returned)) {
102+
if (isPropertyTree(returned) && !firstDefinition.isArrowFunction()) {
103103
if (logger.isLoggable(Level.FINE)) {
104104
logger.fine("Inlining property accessor: " + callName);
105105
}

test/com/google/javascript/jscomp/InlineSimpleMethodsTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,23 @@ public void testEs6Issue2() {
386386
"y.foo();"));
387387
}
388388

389+
@Test
390+
public void testArrowFunction() {
391+
// Arrow functions cannot be trivially inlined.
392+
// This is only an issue if ES6+ is being targetted,
393+
// because otherwise the arrow function is removed before this pass.
394+
testSame(
395+
lines(
396+
"class Holder {",
397+
" constructor() {",
398+
" this.val = {internal: true};",
399+
" this.context = {getVal: () => this.val}",
400+
" }",
401+
"}",
402+
"",
403+
"console.log(new Holder().context.getVal().internal);"));
404+
}
405+
389406
@Test
390407
public void testAnonymousGet() {
391408
// Anonymous object definition without side-effect should be removed.

0 commit comments

Comments
 (0)