Skip to content

Commit

Permalink
feat: done
Browse files Browse the repository at this point in the history
  • Loading branch information
GrinZero committed Jun 28, 2024
1 parent 689ff4f commit e0c95e5
Showing 1 changed file with 76 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,66 +176,6 @@ export function codegenFunction(
),
])
);
// preface.push(
// t.ifStatement(
// t.binaryExpression(
// "!==",
// t.memberExpression(
// t.identifier(cx.synthesizeName("$")),
// t.numericLiteral(fastRefreshState.cacheIndex),
// true
// ),
// t.stringLiteral(fastRefreshState.hash)
// ),
// t.blockStatement([
// t.forStatement(
// t.variableDeclaration("let", [
// t.variableDeclarator(t.identifier(index), t.numericLiteral(0)),
// ]),
// t.binaryExpression(
// "<",
// t.identifier(index),
// t.numericLiteral(cacheCount)
// ),
// t.assignmentExpression(
// "+=",
// t.identifier(index),
// t.numericLiteral(1)
// ),
// t.blockStatement([
// t.expressionStatement(
// t.assignmentExpression(
// "=",
// t.memberExpression(
// t.identifier(cx.synthesizeName("$")),
// t.identifier(index),
// true
// ),
// t.callExpression(
// t.memberExpression(
// t.identifier("Symbol"),
// t.identifier("for")
// ),
// [t.stringLiteral(MEMO_CACHE_SENTINEL)]
// )
// )
// ),
// ])
// ),
// t.expressionStatement(
// t.assignmentExpression(
// "=",
// t.memberExpression(
// t.identifier(cx.synthesizeName("$")),
// t.numericLiteral(fastRefreshState.cacheIndex),
// true
// ),
// t.stringLiteral(fastRefreshState.hash)
// )
// ),
// ])
// )
// );
}
compiled.body.body.unshift(...preface);
}
Expand Down Expand Up @@ -548,14 +488,25 @@ function codegenReactiveScope(
if (count === 1) {
const indices: t.NumericLiteral[] = [];

Check failure on line 489 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 't.NumericLiteral[]' is forbidden. Use 'Array<t.NumericLiteral>' instead
const newValues: t.Expression[] = [];

Check failure on line 490 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 't.Expression[]' is forbidden. Use 'Array<t.Expression>' instead
const todo: (t.Expression | null | undefined)[] = [];
const updateIndexs: t.NumericLiteral[] = [];

Check failure on line 491 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 't.NumericLiteral[]' is forbidden. Use 'Array<t.NumericLiteral>' instead
const source: (t.Expression | null | undefined)[] = [];

Check failure on line 492 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 'T[]' is forbidden. Use 'Array<T>' instead

for (const dep of scope.dependencies) {
const index = cx.nextCacheIndex;
indices.push(t.numericLiteral(index));
newValues.push(codegenDependency(cx, dep));

todo.push(codegenDependency(cx, dep));
const comparison = t.binaryExpression(
"!==",
t.memberExpression(
t.identifier(cx.synthesizeName("$")),
t.numericLiteral(index),
true
),
codegenDependency(cx, dep)
);
changeExpressions.push(comparison);
updateIndexs.push(t.numericLiteral(index));
source.push(codegenDependency(cx, dep));
}

const arr: t.Identifier[] = [];

Check failure on line 512 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 't.Identifier[]' is forbidden. Use 'Array<t.Identifier>' instead
Expand All @@ -565,22 +516,64 @@ function codegenReactiveScope(
arr.push(name);
cacheLoads.push({ name, index, value: wrapCacheDep(cx, name) });
}

for (const reassignment of scope.reassignments) {
const index = cx.nextCacheIndex;
const name = convertIdentifier(reassignment);
cacheLoads.push({ name, index, value: wrapCacheDep(cx, name) });
}
// qucik

let testCondition = (changeExpressions as Array<t.Expression>).reduce(
(acc: t.Expression | null, ident: t.Expression) => {
if (acc == null) {
return ident;
}
return t.logicalExpression("||", acc, ident);
},
null as t.Expression | null
);

// quick
let computationBlock = codegenBlock(cx, block);

const [variableDeclaration] = computationBlock.body;
const bd: (t.Expression | t.SpreadElement | null | undefined)[] = [];

Check failure on line 540 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 'T[]' is forbidden. Use 'Array<T>' instead
if ("declarations" in variableDeclaration) {
todo.push(...variableDeclaration.declarations.map((item) => item.init));
for (let i = 0; i < variableDeclaration.declarations.length; i++) {
const declaration = variableDeclaration.declarations[i];
if (declaration.id.type === "ObjectPattern") {
const returnIdentifiers = declaration.id.properties.map((item) => {
if (item.type === "ObjectProperty") {
return item.value;
}
return item.argument;
}) as t.Identifier[];

Check failure on line 550 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 't.Identifier[]' is forbidden. Use 'Array<t.Identifier>' instead
bd.push(
t.spreadElement(
t.callExpression(
t.arrowFunctionExpression(
[],
t.blockStatement([
t.variableDeclaration("const", [
t.variableDeclarator(declaration.id, declaration.init),
]),
t.returnStatement(t.arrayExpression(returnIdentifiers)),
])
),
[]
)
)
);
continue;
}
bd.push(declaration.init);
}
}

const back: t.MemberExpression[] = [];

Check failure on line 573 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 't.MemberExpression[]' is forbidden. Use 'Array<t.MemberExpression>' instead
for (const { index, value } of cacheLoads) {
todo.push(value);
source.push(value);
updateIndexs.push(t.numericLiteral(index));
back.push(
t.memberExpression(
t.identifier(cx.synthesizeName("$")),
Expand All @@ -590,17 +583,31 @@ function codegenReactiveScope(
);
}

const initName = arr.map((item) => item.name);
const elements = t.variableDeclaration("const", [
t.variableDeclarator(
t.arrayPattern(arr),
t.logicalExpression(
"||",
t.callExpression(t.identifier("u"), [
t.identifier(cx.synthesizeName("$")),
t.arrowFunctionExpression(
[],
t.arrayExpression(bd as t.Expression[])

Check failure on line 596 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 't.Expression[]' is forbidden. Use 'Array<t.Expression>' instead
),
t.arrayExpression(indices),
t.arrayExpression(newValues),
t.arrayExpression(
todo.slice(0, -1).filter(Boolean) as t.Expression[]
testCondition ? t.arrayExpression(newValues) : t.nullLiteral(),
t.arrayExpression(updateIndexs),
t.arrowFunctionExpression(
[],
t.arrayExpression(
source.filter((s) => {
if (s?.type === "Identifier") {
return !initName.includes(s.name);
}
return true;
}) as t.Expression[]

Check failure on line 609 in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Array type using 't.Expression[]' is forbidden. Use 'Array<t.Expression>' instead
)
),
]),
t.arrayExpression(back)
Expand Down

0 comments on commit e0c95e5

Please sign in to comment.