@@ -137,7 +137,7 @@ static SourceKind fromScriptNode(Node n) {
137
137
* @param root The root of the rest of the code to build a namespace for.
138
138
*/
139
139
GlobalNamespace (AbstractCompiler compiler , Node root ) {
140
- this (/* decisionsLog = */ null , compiler , null , root );
140
+ this (/* decisionsLog= */ null , compiler , null , root );
141
141
}
142
142
143
143
/**
@@ -1173,25 +1173,25 @@ private enum DeclaredTypeKind {
1173
1173
*/
1174
1174
enum Inlinability {
1175
1175
INLINE_COMPLETELY (
1176
- /* shouldInlineUsages = */ true ,
1176
+ /* shouldInlineUsages= */ true ,
1177
1177
/* shouldRemoveDeclaration= */ true ,
1178
- /* canCollapse = */ true ),
1178
+ /* canCollapse= */ true ),
1179
1179
INLINE_BUT_KEEP_DECLARATION_ENUM (
1180
- /* shouldInlineUsages = */ true ,
1180
+ /* shouldInlineUsages= */ true ,
1181
1181
/* shouldRemoveDeclaration= */ false ,
1182
- /* canCollapse = */ true ),
1182
+ /* canCollapse= */ true ),
1183
1183
INLINE_BUT_KEEP_DECLARATION_INTERFACE (
1184
- /* shouldInlineUsages = */ true ,
1184
+ /* shouldInlineUsages= */ true ,
1185
1185
/* shouldRemoveDeclaration= */ false ,
1186
- /* canCollapse = */ true ),
1186
+ /* canCollapse= */ true ),
1187
1187
INLINE_BUT_KEEP_DECLARATION_CLASS (
1188
- /* shouldInlineUsages = */ true ,
1188
+ /* shouldInlineUsages= */ true ,
1189
1189
/* shouldRemoveDeclaration= */ false ,
1190
- /* canCollapse = */ true ),
1190
+ /* canCollapse= */ true ),
1191
1191
DO_NOT_INLINE (
1192
- /* shouldInlineUsages = */ false ,
1192
+ /* shouldInlineUsages= */ false ,
1193
1193
/* shouldRemoveDeclaration= */ false ,
1194
- /* canCollapse = */ false );
1194
+ /* canCollapse= */ false );
1195
1195
1196
1196
private final boolean shouldInlineUsages ;
1197
1197
private final boolean shouldRemoveDeclaration ;
@@ -1771,8 +1771,10 @@ Inlinability canCollapseOrInline() {
1771
1771
logDecision (Inlinability .DO_NOT_INLINE , "obj lit property followed by spread" );
1772
1772
return Inlinability .DO_NOT_INLINE ;
1773
1773
}
1774
- Node grandparent = declaration .getGrandparent ();
1775
- if (grandparent .isOr () || grandparent .isHook ()) {
1774
+ // We may be in a deeply nested object literal like, `{a: {b: {c: 1}}}`, so find the
1775
+ // outermost object literal node in order to determine whether it is used conditionally.
1776
+ final Node objectLitParent = getOutermostObjectLit (declaration ).getParent ();
1777
+ if (objectLitParent .isOr () || objectLitParent .isHook ()) {
1776
1778
// Case: `var x = y || {a: b}` or `var x = cond ? y : {a: b}`.
1777
1779
logDecision (Inlinability .DO_NOT_INLINE , "conditional definition" );
1778
1780
return Inlinability .DO_NOT_INLINE ;
@@ -2191,6 +2193,26 @@ boolean isModuleExport() {
2191
2193
}
2192
2194
}
2193
2195
2196
+ /**
2197
+ * Given something like the `'c'` STRING_KEY node in `x = {a: {b: {c: 0}}};`, return the Node for
2198
+ * the outermost object literal.
2199
+ *
2200
+ * @param objLitKey Must be the child of an OBJECT_LIT node
2201
+ * @return The first ancestor that is an OBJECT_LIT and whose grandparent is not an OBJECT_LIT
2202
+ */
2203
+ private Node getOutermostObjectLit (Node objLitKey ) {
2204
+ Node outermostObjectLit = objLitKey .getParent ();
2205
+ checkState (outermostObjectLit .isObjectLit (), outermostObjectLit );
2206
+ while (true ) {
2207
+ final Node objLitGrandparent = outermostObjectLit .getGrandparent ();
2208
+ if (objLitGrandparent != null && objLitGrandparent .isObjectLit ()) {
2209
+ outermostObjectLit = objLitGrandparent ;
2210
+ } else {
2211
+ return outermostObjectLit ;
2212
+ }
2213
+ }
2214
+ }
2215
+
2194
2216
/**
2195
2217
* True if the given Node is the GETPROP in a statement like `some.q.name;`
2196
2218
*
@@ -2400,7 +2422,7 @@ static ObjLitStringKeyAnalysis forObjLitAssignment(String nameString, NameType n
2400
2422
/** The object literal key does not represent a qualified name assignment. */
2401
2423
static ObjLitStringKeyAnalysis forNonReference () {
2402
2424
return new AutoValue_GlobalNamespace_ObjLitStringKeyAnalysis (
2403
- /* nameString = */ null , NameType .OTHER );
2425
+ /* nameString= */ null , NameType .OTHER );
2404
2426
}
2405
2427
}
2406
2428
}
0 commit comments