Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sunset the value namespace #1720

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions gentest/fixtures/YGAutoTest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div id="auto_width" style="width: auto; height: 50px; flex-direction: row;">
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
</div>

<div id="auto_height" style="width: 50px; height: auto;">
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
</div>

<div id="auto_flex_basis" style="width: 50px; flex-basis: auto;">
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
</div>

<div id="auto_position" style="width: 50px; height: 50px;">
<div style="width: 25px; height: 25px; right: auto"></div>
</div>

<div id="auto_margin" style="width: 50px; height: 50px;">
<div style="width: 25px; height: 25px; margin-left: auto"></div>
</div>
87 changes: 40 additions & 47 deletions gentest/gentest-cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function toValueCpp(value) {
return n + (Number(n) == n && n % 1 !== 0 ? 'f' : '');
}

function toFunctionName(value) {
function toFunctionNameCpp(value) {
if (value.indexOf('%') >= 0) {
return 'Percent';
} else if (value.indexOf('Auto') >= 0) {
Expand All @@ -21,6 +21,23 @@ function toFunctionName(value) {
return '';
}

function keywordFunctionCpp(functionPrefix, nodeName, value) {
const functionSuffix = toFunctionNameCpp(value);
if (functionSuffix == 'Auto') {
return functionPrefix + functionSuffix + '(' + nodeName + ');';
} else {
return (
functionPrefix +
functionSuffix +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');'
);
}
}

const CPPEmitter = function () {
Emitter.call(this, 'cpp', ' ');
};
Expand Down Expand Up @@ -231,7 +248,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetAspectRatio' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
Expand Down Expand Up @@ -273,15 +290,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {

YGNodeStyleSetFlexBasis: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetFlexBasis' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
this.push(keywordFunctionCpp('YGNodeStyleSetFlexBasis', nodeName, value));
},
},

Expand Down Expand Up @@ -325,20 +334,6 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
},
},

YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetHeight' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},

YGNodeStyleSetJustifyContent: {
value: function (nodeName, value) {
this.push(
Expand All @@ -361,7 +356,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
}
this.push(
'YGNodeStyleSetMargin' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
Expand All @@ -372,11 +367,23 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
},
},

YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(keywordFunctionCpp('YGNodeStyleSetHeight', nodeName, value));
},
},

YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(keywordFunctionCpp('YGNodeStyleSetWidth', nodeName, value));
},
},

YGNodeStyleSetMaxHeight: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMaxHeight' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
Expand All @@ -390,7 +397,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMaxWidth' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
Expand All @@ -404,7 +411,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMinHeight' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
Expand All @@ -418,7 +425,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMinWidth' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
Expand All @@ -440,7 +447,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, edge, value) {
this.push(
'YGNodeStyleSetPadding' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
Expand All @@ -462,7 +469,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
}
this.push(
'YGNodeStyleSetPosition' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
Expand All @@ -485,25 +492,11 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
},
},

YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetWidth' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},

YGNodeStyleSetGap: {
value: function (nodeName, gap, value) {
this.push(
'YGNodeStyleSetGap' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
Expand Down
12 changes: 9 additions & 3 deletions gentest/gentest-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,21 @@ for (const fileName of fixtures) {
await driver.get('file://' + process.cwd() + '/test.html');
const logs = await driver.manage().logs().get(logging.Type.BROWSER);

const testLogs = logs.filter(
log => !log.message.replace(/^[^"]*/, '').startsWith('"gentest-log:'),
);

await fs.writeFile(
`${yogaDir}/tests/generated/${fileNameNoExtension}.cpp`,
addSignatureToSourceCode(JSON.parse(logs[0].message.replace(/^[^"]*/, ''))),
addSignatureToSourceCode(
JSON.parse(testLogs[0].message.replace(/^[^"]*/, '')),
),
);

await fs.writeFile(
`${yogaDir}/java/tests/generated/com/facebook/yoga/${fileNameNoExtension}.java`,
addSignatureToSourceCode(
JSON.parse(logs[1].message.replace(/^[^"]*/, '')).replace(
JSON.parse(testLogs[1].message.replace(/^[^"]*/, '')).replace(
'YogaTest',
fileNameNoExtension,
),
Expand All @@ -118,7 +124,7 @@ for (const fileName of fixtures) {
await fs.writeFile(
`${yogaDir}/javascript/tests/generated/${fileNameNoExtension}.test.ts`,
addSignatureToSourceCode(
JSON.parse(logs[2].message.replace(/^[^"]*/, '')).replace(
JSON.parse(testLogs[2].message.replace(/^[^"]*/, '')).replace(
'YogaTest',
fileNameNoExtension,
),
Expand Down
64 changes: 30 additions & 34 deletions gentest/gentest-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ function toMethodName(value) {
return '';
}

function keywordMethod(methodPrefix, nodeName, value) {
const methodSuffix = toMethodName(value);
if (methodSuffix == 'Auto') {
return nodeName + '.' + methodPrefix + methodSuffix + '();';
} else {
return (
nodeName +
'.' +
methodPrefix +
methodSuffix +
'(' +
toValueJava(value) +
'f);'
);
}
}

const JavaEmitter = function () {
Emitter.call(this, 'java', ' ');
};
Expand Down Expand Up @@ -273,14 +290,7 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {

YGNodeStyleSetFlexBasis: {
value: function (nodeName, value) {
this.push(
nodeName +
'.setFlexBasis' +
toMethodName(value) +
'(' +
toValueJava(value) +
'f);',
);
this.push(keywordMethod('setFlexBasis', nodeName, value));
},
},

Expand Down Expand Up @@ -308,19 +318,6 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
},
},

YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(
nodeName +
'.setHeight' +
toMethodName(value) +
'(' +
toValueJava(value) +
'f);',
);
},
},

YGNodeStyleSetJustifyContent: {
value: function (nodeName, value) {
this.push(nodeName + '.setJustifyContent(' + toValueJava(value) + ');');
Expand Down Expand Up @@ -348,6 +345,18 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
},
},

YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(keywordMethod('setHeight', nodeName, value));
},
},

YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(keywordMethod('setWidth', nodeName, value));
},
},

YGNodeStyleSetMaxHeight: {
value: function (nodeName, value) {
this.push(
Expand Down Expand Up @@ -448,19 +457,6 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
},
},

YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(
nodeName +
'.setWidth' +
toMethodName(value) +
'(' +
toValueJava(value) +
'f);',
);
},
},

YGNodeStyleSetGap: {
value: function (nodeName, gap, value) {
this.push(
Expand Down
11 changes: 11 additions & 0 deletions gentest/gentest-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// eslint-disable-next-line no-unused-vars
function gentestLog(message) {
console.log('gentest-log: ', message);
}
1 change: 1 addition & 0 deletions gentest/test-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="gentest-cpp.js"></script>
<script src="gentest-java.js"></script>
<script src="gentest-javascript.js"></script>
<script src="gentest-log.js"></script>

<style>
@font-face {
Expand Down
Loading
Loading