babel-plugin-react-compiler 19.0.0-beta-37ed2a7-20241206 → 19.0.0-beta-201e55d-20241215
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +115 -79
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -125850,6 +125850,9 @@ function isPrimitiveType(id) {
|
|
125850
125850
|
function isArrayType(id) {
|
125851
125851
|
return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInArray';
|
125852
125852
|
}
|
125853
|
+
function isPropsType(id) {
|
125854
|
+
return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInProps';
|
125855
|
+
}
|
125853
125856
|
function isRefValueType(id) {
|
125854
125857
|
return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInRefValue';
|
125855
125858
|
}
|
@@ -129921,9 +129924,7 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
129921
129924
|
_26,
|
129922
129925
|
_27,
|
129923
129926
|
_28,
|
129924
|
-
_29
|
129925
|
-
_30,
|
129926
|
-
_31;
|
129927
|
+
_29;
|
129927
129928
|
const stmtNode = stmtPath.node;
|
129928
129929
|
switch (stmtNode.type) {
|
129929
129930
|
case 'ThrowStatement': {
|
@@ -130765,6 +130766,12 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130765
130766
|
? _14
|
130766
130767
|
: GeneratedSource;
|
130767
130768
|
let test;
|
130769
|
+
const advanceIterator = lowerValueToTemporary(builder, {
|
130770
|
+
kind: 'IteratorNext',
|
130771
|
+
loc: leftLoc,
|
130772
|
+
iterator: Object.assign({}, iterator),
|
130773
|
+
collection: Object.assign({}, value),
|
130774
|
+
});
|
130768
130775
|
if (left.isVariableDeclaration()) {
|
130769
130776
|
const declarations = left.get('declarations');
|
130770
130777
|
CompilerError.invariant(declarations.length === 1, {
|
@@ -130774,12 +130781,6 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130774
130781
|
suggestions: null,
|
130775
130782
|
});
|
130776
130783
|
const id = declarations[0].get('id');
|
130777
|
-
const advanceIterator = lowerValueToTemporary(builder, {
|
130778
|
-
kind: 'IteratorNext',
|
130779
|
-
loc: leftLoc,
|
130780
|
-
iterator: Object.assign({}, iterator),
|
130781
|
-
collection: Object.assign({}, value),
|
130782
|
-
});
|
130783
130784
|
const assign = lowerAssignment(
|
130784
130785
|
builder,
|
130785
130786
|
leftLoc,
|
@@ -130790,13 +130791,19 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130790
130791
|
);
|
130791
130792
|
test = lowerValueToTemporary(builder, assign);
|
130792
130793
|
} else {
|
130793
|
-
|
130794
|
-
|
130795
|
-
|
130796
|
-
loc: (_16 = left.node.loc) !== null && _16 !== void 0 ? _16 : null,
|
130797
|
-
suggestions: null,
|
130794
|
+
CompilerError.invariant(left.isLVal(), {
|
130795
|
+
loc: leftLoc,
|
130796
|
+
reason: 'Expected ForOf init to be a variable declaration or lval',
|
130798
130797
|
});
|
130799
|
-
|
130798
|
+
const assign = lowerAssignment(
|
130799
|
+
builder,
|
130800
|
+
leftLoc,
|
130801
|
+
InstructionKind.Reassign,
|
130802
|
+
left,
|
130803
|
+
advanceIterator,
|
130804
|
+
'Assignment'
|
130805
|
+
);
|
130806
|
+
test = lowerValueToTemporary(builder, assign);
|
130800
130807
|
}
|
130801
130808
|
builder.terminateWithContinuation(
|
130802
130809
|
{
|
@@ -130806,8 +130813,8 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130806
130813
|
consequent: loopBlock,
|
130807
130814
|
alternate: continuationBlock.id,
|
130808
130815
|
loc:
|
130809
|
-
(
|
130810
|
-
?
|
130816
|
+
(_16 = stmt.node.loc) !== null && _16 !== void 0
|
130817
|
+
? _16
|
130811
130818
|
: GeneratedSource,
|
130812
130819
|
fallthrough: continuationBlock.id,
|
130813
130820
|
},
|
@@ -130837,8 +130844,8 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130837
130844
|
})
|
130838
130845
|
);
|
130839
130846
|
const loc =
|
130840
|
-
(
|
130841
|
-
?
|
130847
|
+
(_17 = stmt.node.loc) !== null && _17 !== void 0
|
130848
|
+
? _17
|
130842
130849
|
: GeneratedSource;
|
130843
130850
|
const value = lowerExpressionToTemporary(builder, stmt.get('right'));
|
130844
130851
|
builder.terminateWithContinuation(
|
@@ -130854,24 +130861,24 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130854
130861
|
);
|
130855
130862
|
const left = stmt.get('left');
|
130856
130863
|
const leftLoc =
|
130857
|
-
(
|
130858
|
-
?
|
130864
|
+
(_18 = left.node.loc) !== null && _18 !== void 0
|
130865
|
+
? _18
|
130859
130866
|
: GeneratedSource;
|
130860
130867
|
let test;
|
130868
|
+
const nextPropertyTemp = lowerValueToTemporary(builder, {
|
130869
|
+
kind: 'NextPropertyOf',
|
130870
|
+
loc: leftLoc,
|
130871
|
+
value: value,
|
130872
|
+
});
|
130861
130873
|
if (left.isVariableDeclaration()) {
|
130862
130874
|
const declarations = left.get('declarations');
|
130863
130875
|
CompilerError.invariant(declarations.length === 1, {
|
130864
130876
|
reason: `Expected only one declaration in the init of a ForInStatement, got ${declarations.length}`,
|
130865
130877
|
description: null,
|
130866
|
-
loc: (
|
130878
|
+
loc: (_19 = left.node.loc) !== null && _19 !== void 0 ? _19 : null,
|
130867
130879
|
suggestions: null,
|
130868
130880
|
});
|
130869
130881
|
const id = declarations[0].get('id');
|
130870
|
-
const nextPropertyTemp = lowerValueToTemporary(builder, {
|
130871
|
-
kind: 'NextPropertyOf',
|
130872
|
-
loc: leftLoc,
|
130873
|
-
value: value,
|
130874
|
-
});
|
130875
130882
|
const assign = lowerAssignment(
|
130876
130883
|
builder,
|
130877
130884
|
leftLoc,
|
@@ -130882,13 +130889,19 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130882
130889
|
);
|
130883
130890
|
test = lowerValueToTemporary(builder, assign);
|
130884
130891
|
} else {
|
130885
|
-
|
130886
|
-
|
130887
|
-
|
130888
|
-
loc: (_21 = left.node.loc) !== null && _21 !== void 0 ? _21 : null,
|
130889
|
-
suggestions: null,
|
130892
|
+
CompilerError.invariant(left.isLVal(), {
|
130893
|
+
loc: leftLoc,
|
130894
|
+
reason: 'Expected ForIn init to be a variable declaration or lval',
|
130890
130895
|
});
|
130891
|
-
|
130896
|
+
const assign = lowerAssignment(
|
130897
|
+
builder,
|
130898
|
+
leftLoc,
|
130899
|
+
InstructionKind.Reassign,
|
130900
|
+
left,
|
130901
|
+
nextPropertyTemp,
|
130902
|
+
'Assignment'
|
130903
|
+
);
|
130904
|
+
test = lowerValueToTemporary(builder, assign);
|
130892
130905
|
}
|
130893
130906
|
builder.terminateWithContinuation(
|
130894
130907
|
{
|
@@ -130899,8 +130912,8 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130899
130912
|
alternate: continuationBlock.id,
|
130900
130913
|
fallthrough: continuationBlock.id,
|
130901
130914
|
loc:
|
130902
|
-
(
|
130903
|
-
?
|
130915
|
+
(_20 = stmt.node.loc) !== null && _20 !== void 0
|
130916
|
+
? _20
|
130904
130917
|
: GeneratedSource,
|
130905
130918
|
},
|
130906
130919
|
continuationBlock
|
@@ -130910,8 +130923,8 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130910
130923
|
case 'DebuggerStatement': {
|
130911
130924
|
const stmt = stmtPath;
|
130912
130925
|
const loc =
|
130913
|
-
(
|
130914
|
-
?
|
130926
|
+
(_21 = stmt.node.loc) !== null && _21 !== void 0
|
130927
|
+
? _21
|
130915
130928
|
: GeneratedSource;
|
130916
130929
|
builder.push({
|
130917
130930
|
id: makeInstructionId(0),
|
@@ -130932,7 +130945,7 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130932
130945
|
builder.errors.push({
|
130933
130946
|
reason: `(BuildHIR::lowerStatement) Handle TryStatement without a catch clause`,
|
130934
130947
|
severity: exports.ErrorSeverity.Todo,
|
130935
|
-
loc: (
|
130948
|
+
loc: (_22 = stmt.node.loc) !== null && _22 !== void 0 ? _22 : null,
|
130936
130949
|
suggestions: null,
|
130937
130950
|
});
|
130938
130951
|
return;
|
@@ -130941,7 +130954,7 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130941
130954
|
builder.errors.push({
|
130942
130955
|
reason: `(BuildHIR::lowerStatement) Handle TryStatement with a finalizer ('finally') clause`,
|
130943
130956
|
severity: exports.ErrorSeverity.Todo,
|
130944
|
-
loc: (
|
130957
|
+
loc: (_23 = stmt.node.loc) !== null && _23 !== void 0 ? _23 : null,
|
130945
130958
|
suggestions: null,
|
130946
130959
|
});
|
130947
130960
|
}
|
@@ -130951,15 +130964,15 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130951
130964
|
const place = {
|
130952
130965
|
kind: 'Identifier',
|
130953
130966
|
identifier: builder.makeTemporary(
|
130954
|
-
(
|
130955
|
-
?
|
130967
|
+
(_24 = handlerBindingPath.node.loc) !== null && _24 !== void 0
|
130968
|
+
? _24
|
130956
130969
|
: GeneratedSource
|
130957
130970
|
),
|
130958
130971
|
effect: exports.Effect.Unknown,
|
130959
130972
|
reactive: false,
|
130960
130973
|
loc:
|
130961
|
-
(
|
130962
|
-
?
|
130974
|
+
(_25 = handlerBindingPath.node.loc) !== null && _25 !== void 0
|
130975
|
+
? _25
|
130963
130976
|
: GeneratedSource,
|
130964
130977
|
};
|
130965
130978
|
promoteTemporary(place.identifier);
|
@@ -130971,8 +130984,8 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
130971
130984
|
},
|
130972
130985
|
type: null,
|
130973
130986
|
loc:
|
130974
|
-
(
|
130975
|
-
?
|
130987
|
+
(_26 = handlerBindingPath.node.loc) !== null && _26 !== void 0
|
130988
|
+
? _26
|
130976
130989
|
: GeneratedSource,
|
130977
130990
|
});
|
130978
130991
|
handlerBinding = {path: handlerBindingPath, place: place};
|
@@ -131032,8 +131045,8 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
131032
131045
|
fallthrough: continuationBlock.id,
|
131033
131046
|
id: makeInstructionId(0),
|
131034
131047
|
loc:
|
131035
|
-
(
|
131036
|
-
?
|
131048
|
+
(_27 = stmt.node.loc) !== null && _27 !== void 0
|
131049
|
+
? _27
|
131037
131050
|
: GeneratedSource,
|
131038
131051
|
},
|
131039
131052
|
continuationBlock
|
@@ -131073,14 +131086,14 @@ function lowerStatement(builder, stmtPath, label = null) {
|
|
131073
131086
|
builder.errors.push({
|
131074
131087
|
reason: `(BuildHIR::lowerStatement) Handle ${stmtPath.type} statements`,
|
131075
131088
|
severity: exports.ErrorSeverity.Todo,
|
131076
|
-
loc: (
|
131089
|
+
loc: (_28 = stmtPath.node.loc) !== null && _28 !== void 0 ? _28 : null,
|
131077
131090
|
suggestions: null,
|
131078
131091
|
});
|
131079
131092
|
lowerValueToTemporary(builder, {
|
131080
131093
|
kind: 'UnsupportedNode',
|
131081
131094
|
loc:
|
131082
|
-
(
|
131083
|
-
?
|
131095
|
+
(_29 = stmtPath.node.loc) !== null && _29 !== void 0
|
131096
|
+
? _29
|
131084
131097
|
: GeneratedSource,
|
131085
131098
|
node: stmtPath.node,
|
131086
131099
|
});
|
@@ -141722,15 +141735,14 @@ function createPropsProperties(
|
|
141722
141735
|
let refProperty;
|
141723
141736
|
let keyProperty;
|
141724
141737
|
const props = [];
|
141725
|
-
const
|
141726
|
-
p => p.kind === 'JsxAttribute' && p.name !== 'key'
|
141738
|
+
const jsxAttributesWithoutKey = propAttributes.filter(
|
141739
|
+
p => p.kind === 'JsxAttribute' && p.name !== 'key'
|
141727
141740
|
);
|
141728
141741
|
const jsxSpreadAttributes = propAttributes.filter(
|
141729
141742
|
p => p.kind === 'JsxSpreadAttribute'
|
141730
141743
|
);
|
141731
141744
|
const spreadPropsOnly =
|
141732
|
-
|
141733
|
-
jsxSpreadAttributes.length === 1;
|
141745
|
+
jsxAttributesWithoutKey.length === 0 && jsxSpreadAttributes.length === 1;
|
141734
141746
|
propAttributes.forEach(prop => {
|
141735
141747
|
switch (prop.kind) {
|
141736
141748
|
case 'JsxAttribute': {
|
@@ -145203,19 +145215,6 @@ function codegenInstructionNullable(cx, instr) {
|
|
145203
145215
|
}
|
145204
145216
|
function codegenForInit(cx, init) {
|
145205
145217
|
if (init.kind === 'SequenceExpression') {
|
145206
|
-
for (const instr of init.instructions) {
|
145207
|
-
if (instr.value.kind === 'DeclareContext') {
|
145208
|
-
CompilerError.throwTodo({
|
145209
|
-
reason: `Support for loops where the index variable is a context variable`,
|
145210
|
-
loc: instr.loc,
|
145211
|
-
description:
|
145212
|
-
instr.value.lvalue.place.identifier.name != null
|
145213
|
-
? `\`${instr.value.lvalue.place.identifier.name.value}\` is a context variable`
|
145214
|
-
: null,
|
145215
|
-
suggestions: null,
|
145216
|
-
});
|
145217
|
-
}
|
145218
|
-
}
|
145219
145218
|
const body = codegenBlock(
|
145220
145219
|
cx,
|
145221
145220
|
init.instructions.map(instruction => ({
|
@@ -145226,20 +145225,37 @@ function codegenForInit(cx, init) {
|
|
145226
145225
|
const declarators = [];
|
145227
145226
|
let kind = 'const';
|
145228
145227
|
body.forEach(instr => {
|
145229
|
-
|
145230
|
-
|
145231
|
-
|
145232
|
-
|
145233
|
-
|
145234
|
-
|
145235
|
-
|
145236
|
-
|
145228
|
+
var _a;
|
145229
|
+
let top = undefined;
|
145230
|
+
if (
|
145231
|
+
instr.type === 'ExpressionStatement' &&
|
145232
|
+
instr.expression.type === 'AssignmentExpression' &&
|
145233
|
+
instr.expression.operator === '=' &&
|
145234
|
+
instr.expression.left.type === 'Identifier' &&
|
145235
|
+
((_a = top = declarators.at(-1)) === null || _a === void 0
|
145236
|
+
? void 0
|
145237
|
+
: _a.id.type) === 'Identifier' &&
|
145238
|
+
(top === null || top === void 0 ? void 0 : top.id.name) ===
|
145239
|
+
instr.expression.left.name &&
|
145240
|
+
(top === null || top === void 0 ? void 0 : top.init) == null
|
145241
|
+
) {
|
145242
|
+
top.init = instr.expression.right;
|
145243
|
+
} else {
|
145244
|
+
CompilerError.invariant(
|
145245
|
+
instr.type === 'VariableDeclaration' &&
|
145246
|
+
(instr.kind === 'let' || instr.kind === 'const'),
|
145247
|
+
{
|
145248
|
+
reason: 'Expected a variable declaration',
|
145249
|
+
loc: init.loc,
|
145250
|
+
description: `Got ${instr.type}`,
|
145251
|
+
suggestions: null,
|
145252
|
+
}
|
145253
|
+
);
|
145254
|
+
if (instr.kind === 'let') {
|
145255
|
+
kind = 'let';
|
145237
145256
|
}
|
145238
|
-
|
145239
|
-
if (instr.kind === 'let') {
|
145240
|
-
kind = 'let';
|
145257
|
+
declarators.push(...instr.declarations);
|
145241
145258
|
}
|
145242
|
-
declarators.push(...instr.declarations);
|
145243
145259
|
});
|
145244
145260
|
CompilerError.invariant(declarators.length > 0, {
|
145245
145261
|
reason: 'Expected a variable declaration',
|
@@ -157256,6 +157272,24 @@ function emitDestructureProps(env, propsObj, oldToNewProps) {
|
|
157256
157272
|
};
|
157257
157273
|
return destructurePropsInstr;
|
157258
157274
|
}
|
157275
|
+
function optimizePropsMethodCalls(fn) {
|
157276
|
+
for (const [, block] of fn.body.blocks) {
|
157277
|
+
for (let i = 0; i < block.instructions.length; i++) {
|
157278
|
+
const instr = block.instructions[i];
|
157279
|
+
if (
|
157280
|
+
instr.value.kind === 'MethodCall' &&
|
157281
|
+
isPropsType(instr.value.receiver.identifier)
|
157282
|
+
) {
|
157283
|
+
instr.value = {
|
157284
|
+
kind: 'CallExpression',
|
157285
|
+
callee: instr.value.property,
|
157286
|
+
args: instr.value.args,
|
157287
|
+
loc: instr.value.loc,
|
157288
|
+
};
|
157289
|
+
}
|
157290
|
+
}
|
157291
|
+
}
|
157292
|
+
}
|
157259
157293
|
function* run(
|
157260
157294
|
func,
|
157261
157295
|
config,
|
@@ -157327,6 +157361,8 @@ function* runWithEnvironment(func, env) {
|
|
157327
157361
|
if (env.config.lowerContextAccess) {
|
157328
157362
|
lowerContextAccess(hir, env.config.lowerContextAccess);
|
157329
157363
|
}
|
157364
|
+
optimizePropsMethodCalls(hir);
|
157365
|
+
yield log({kind: 'hir', name: 'OptimizePropsMethodCalls', value: hir});
|
157330
157366
|
analyseFunctions(hir);
|
157331
157367
|
yield log({kind: 'hir', name: 'AnalyseFunctions', value: hir});
|
157332
157368
|
inferReferenceEffects(hir);
|