Merge pull request #139 from ColinEberhardt/eslint

Eslint - enforces many more rules.
This commit is contained in:
Colin Eberhardt
2015-10-07 22:26:04 +01:00
13 changed files with 143 additions and 135 deletions

View File

@@ -1,6 +1,5 @@
{ {
"browser": true, "extends": "./node_modules/fbjs-scripts/eslint/.eslintrc",
"shadow": true,
"globals": { "globals": {
"jasmine": true, "jasmine": true,
"describe": true, "describe": true,
@@ -17,8 +16,5 @@
"console": true, "console": true,
"setTimeout": true, "setTimeout": true,
"define": true "define": true
},
"rules": {
"quotes": [2, "single"]
} }
} }

View File

@@ -1,9 +1,8 @@
'use strict'; 'use strict';
module.exports = function(grunt) { module.exports = function(grunt) {
var fs = require('fs');
var path = require('path'); var path = require('path');
var isWindows = /^win/.test(process.platform); var isWindows = (/^win/).test(process.platform);
require('load-grunt-tasks')(grunt); require('load-grunt-tasks')(grunt);
@@ -25,9 +24,8 @@ module.exports = function(grunt) {
config.cTestOutput = 'c_test.exe'; config.cTestOutput = 'c_test.exe';
config.cTestCompile = 'cl -nologo -Zi -Tpsrc/__tests__/Layout-test.c -Tpsrc/Layout.c -Tpsrc/Layout-test-utils.c -link -incremental:no -out:"<%= config.cTestOutput %>"'; config.cTestCompile = 'cl -nologo -Zi -Tpsrc/__tests__/Layout-test.c -Tpsrc/Layout.c -Tpsrc/Layout-test-utils.c -link -incremental:no -out:"<%= config.cTestOutput %>"';
config.cTestExecute = '<%= config.cTestOutput %>'; config.cTestExecute = '<%= config.cTestOutput %>';
config.cTestClean = ['<%= config.cTestOutput %>','*.obj','*.pdb']; config.cTestClean = ['<%= config.cTestOutput %>', '*.obj', '*.pdb'];
} } else {
else {
// GCC build (OSX, Linux, ...), assumes gcc is in the path. // GCC build (OSX, Linux, ...), assumes gcc is in the path.
config.cTestOutput = 'c_test'; config.cTestOutput = 'c_test';
config.cTestCompile = 'gcc -std=c99 -Werror -Wno-padded src/__tests__/Layout-test.c src/Layout.c src/Layout-test-utils.c -lm -o "./<%= config.cTestOutput %>"'; config.cTestCompile = 'gcc -std=c99 -Werror -Wno-padded src/__tests__/Layout-test.c src/Layout.c src/Layout-test-utils.c -lm -o "./<%= config.cTestOutput %>"';
@@ -42,8 +40,8 @@ module.exports = function(grunt) {
dist: { dist: {
options: { options: {
create: ['<%= config.distFolder %>'] create: ['<%= config.distFolder %>']
}, }
}, }
}, },
clean: { clean: {
@@ -56,12 +54,12 @@ module.exports = function(grunt) {
options: { options: {
configFile: '.eslintrc' configFile: '.eslintrc'
}, },
target: ['<%= config.srcFolder %>/Layout.js'] target: ['<%= config.srcFolder %>/**/*.js', './Gruntfile.js']
}, },
includereplace: { includereplace: {
options: { options: {
prefix: '// @@', prefix: '// @@'
}, },
main: { main: {
src: '<%= config.srcFolder %>/<%= config.libName %>.js', src: '<%= config.srcFolder %>/<%= config.libName %>.js',
@@ -120,17 +118,16 @@ module.exports = function(grunt) {
'#ifdef CSS_LAYOUT_IMPLEMENTATION', '#ifdef CSS_LAYOUT_IMPLEMENTATION',
src, src,
'#endif // CSS_LAYOUT_IMPLEMENTATION' '#endif // CSS_LAYOUT_IMPLEMENTATION'
].join('\n') ].join('\n');
} } else {
else {
return src; return src;
} }
}, }
}, },
dist: { dist: {
src: ['<%= config.srcFolder %>/Layout.h', '<%= config.srcFolder %>/Layout.c'], src: ['<%= config.srcFolder %>/Layout.h', '<%= config.srcFolder %>/Layout.c'],
dest: '<%= config.distFolder %>/css-layout.h', dest: '<%= config.distFolder %>/css-layout.h'
}, }
}, },
shell: { shell: {
@@ -153,8 +150,8 @@ module.exports = function(grunt) {
watch: { watch: {
files: ['src/Layout.js'], files: ['src/Layout.js'],
tasks: ['ci'], tasks: ['ci']
}, }
}); });
// Compiles and runs the Java tests // Compiles and runs the Java tests

View File

@@ -24,6 +24,8 @@
}, },
"homepage": "https://github.com/facebook/css-layout", "homepage": "https://github.com/facebook/css-layout",
"devDependencies": { "devDependencies": {
"babel-eslint": "^4.1.3",
"fbjs-scripts": "^0.2.2",
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-cli": "^0.1.13", "grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.6.0", "grunt-contrib-clean": "^0.6.0",

View File

@@ -56,8 +56,8 @@ function __transpileToCSharpCommon(code) {
// additional case conversions // additional case conversions
.replace(/(CSSConstants|CSSWrap|CSSJustify|CSSAlign|CSSPositionType)\.([_A-Z]+)/g, .replace(/(CSSConstants|CSSWrap|CSSJustify|CSSAlign|CSSPositionType)\.([_A-Z]+)/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + "." + constantToPascalCase(match2); return match1 + '.' + constantToPascalCase(match2);
}); });
} }
@@ -67,54 +67,54 @@ function __transpileSingleTestToCSharp(code) {
.replace(/CSS_FLEX_DIRECTION_/g, 'CSSFlexDirection.') .replace(/CSS_FLEX_DIRECTION_/g, 'CSSFlexDirection.')
.replace(/CSS_WRAP/g, 'CSSWrap.WRAP') .replace(/CSS_WRAP/g, 'CSSWrap.WRAP')
.replace(/new_test_css_node/g, 'new TestCSSNode') .replace(/new_test_css_node/g, 'new TestCSSNode')
.replace( // style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP] .replace(// style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP]
/(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g, /(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + '.position[POSITION_' + match2 + ']'; return match1 + '.position[POSITION_' + match2 + ']';
}) })
.replace( // style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH] .replace(// style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH]
/(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g, /(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + '.dimensions[DIMENSION_' + match2 + ']'; return match1 + '.dimensions[DIMENSION_' + match2 + ']';
}) })
.replace( // style.maxDimensions[CSS_WIDTH] => style.maxWidth .replace(// style.maxDimensions[CSS_WIDTH] => style.maxWidth
/(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g, /(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase();
}) })
.replace( // style.minDimensions[CSS_WIDTH] => style.minWidth .replace(// style.minDimensions[CSS_WIDTH] => style.minWidth
/(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g, /(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + '.min' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); return match1 + '.min' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase();
}) })
.replace( // style.margin[CSS_TOP] = 12.3 => style.margin[Spacing.TOP].set(12.3) .replace(// style.margin[CSS_TOP] = 12.3 => style.margin[Spacing.TOP].set(12.3)
/style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g, /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g,
function (str, match1, match2, match3) { function(str, match1, match2, match3) {
var propertyCap = match1.charAt(0).toUpperCase() + match1.slice(1); var propertyCap = match1.charAt(0).toUpperCase() + match1.slice(1);
return 'set' + propertyCap + '(Spacing.' + match2 + ', ' + match3 + ')'; return 'set' + propertyCap + '(Spacing.' + match2 + ', ' + match3 + ')';
}) })
.replace( // style.margin[CSS_TOP] => style.margin[Spacing.TOP] .replace(// style.margin[CSS_TOP] => style.margin[Spacing.TOP]
/style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]/g, /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return 'style.' + match1 + '.get(Spacing.' + match2 + ')'; return 'style.' + match1 + '.get(Spacing.' + match2 + ')';
}) })
.replace(/get_child\(.*context\,\s([^\)]+)\)/g, 'getChildAt($1)') .replace(/get_child\(.*context\,\s([^\)]+)\)/g, 'getChildAt($1)')
.replace(/init_css_node_children/g, 'addChildren') .replace(/init_css_node_children/g, 'addChildren')
.replace(/css_node_t(\s)\*/g, 'TestCSSNode$1') .replace(/css_node_t(\s)\*/g, 'TestCSSNode$1')
.replace(/\->/g, '.') .replace(/\->/g, '.')
.replace(/(\d+\.\d+)/g, '$1f') .replace(/(\d+\.\d+)/g, '$1f')
.replace( // style.flex_direction => style.flexDirection .replace(// style.flex_direction => style.flexDirection
/style\.([^_\[\]\s]+)_(\w)(\w+)/g, /style\.([^_\[\]\s]+)_(\w)(\w+)/g,
function (str, match1, match2, match3) { function(str, match1, match2, match3) {
return 'style.' + match1 + match2.toUpperCase() + match3; return 'style.' + match1 + match2.toUpperCase() + match3;
}) })
.replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);') .replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);')
// additional case conversions // additional case conversions
.replace(/(CSSWrap|CSSFlexDirection)\.([_A-Z]+)/g, .replace(/(CSSWrap|CSSFlexDirection)\.([_A-Z]+)/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + "." + constantToPascalCase(match2); return match1 + '.' + constantToPascalCase(match2);
}); });
} }
@@ -129,7 +129,7 @@ function constantToPascalCase(str) {
return str[0] + str.substr(1) return str[0] + str.substr(1)
.toLowerCase() .toLowerCase()
.replace(/_(.)/g, .replace(/_(.)/g,
function (_, m) { return m.toUpperCase(); }); function(_, m) { return m.toUpperCase(); });
} }
var CSharpTranspiler = { var CSharpTranspiler = {
@@ -162,13 +162,13 @@ var CSharpTranspiler = {
var allTestsInCSharp = []; var allTestsInCSharp = [];
for (var i = 0; i < allTestsInC.length; i++) { for (var i = 0; i < allTestsInC.length; i++) {
allTestsInCSharp[i] = allTestsInCSharp[i] =
" [Test]\n" + ' [Test]\n' +
" public void TestCase" + i + "()\n" + ' public void TestCase' + i + '()\n' +
__transpileSingleTestToCSharp(allTestsInC[i]); __transpileSingleTestToCSharp(allTestsInC[i]);
} }
return allTestsInCSharp.join('\n\n'); return allTestsInCSharp.join('\n\n');
} }
} };
if (typeof module !== 'undefined') { if (typeof module !== 'undefined') {
module.exports = CSharpTranspiler; module.exports = CSharpTranspiler;

View File

@@ -51,7 +51,7 @@ function __transpileToJavaCommon(code) {
.replace(/isUndefined\((.+?)\)/g, 'Float.isNaN\($1\)') .replace(/isUndefined\((.+?)\)/g, 'Float.isNaN\($1\)')
.replace(/\/\*\(c\)!([^*]+)\*\//g, '') .replace(/\/\*\(c\)!([^*]+)\*\//g, '')
.replace(/var\/\*\(java\)!([^*]+)\*\//g, '$1') .replace(/var\/\*\(java\)!([^*]+)\*\//g, '$1')
.replace(/\/\*\(java\)!([^*]+)\*\//g, '$1') .replace(/\/\*\(java\)!([^*]+)\*\//g, '$1');
} }
function __transpileSingleTestToJava(code) { function __transpileSingleTestToJava(code) {
@@ -60,35 +60,35 @@ function __transpileSingleTestToJava(code) {
.replace(/CSS_FLEX_DIRECTION_/g, 'CSSFlexDirection.') .replace(/CSS_FLEX_DIRECTION_/g, 'CSSFlexDirection.')
.replace(/CSS_WRAP/g, 'CSSWrap.WRAP') .replace(/CSS_WRAP/g, 'CSSWrap.WRAP')
.replace(/new_test_css_node/g, 'new TestCSSNode') .replace(/new_test_css_node/g, 'new TestCSSNode')
.replace( // style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP] .replace(// style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP]
/(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g, /(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + '.position[POSITION_' + match2 + ']'; return match1 + '.position[POSITION_' + match2 + ']';
}) })
.replace( // style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH] .replace(// style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH]
/(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g, /(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + '.dimensions[DIMENSION_' + match2 + ']'; return match1 + '.dimensions[DIMENSION_' + match2 + ']';
}) })
.replace( // style.maxDimensions[CSS_WIDTH] => style.maxWidth .replace(// style.maxDimensions[CSS_WIDTH] => style.maxWidth
/(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g, /(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase();
}) })
.replace( // style.minDimensions[CSS_WIDTH] => style.minWidth .replace(// style.minDimensions[CSS_WIDTH] => style.minWidth
/(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g, /(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return match1 + '.min' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); return match1 + '.min' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase();
}) })
.replace( // style.margin[CSS_TOP] = 12.3 => style.margin[Spacing.TOP].set(12.3) .replace(// style.margin[CSS_TOP] = 12.3 => style.margin[Spacing.TOP].set(12.3)
/style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g, /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g,
function (str, match1, match2, match3) { function(str, match1, match2, match3) {
var propertyCap = match1.charAt(0).toUpperCase() + match1.slice(1); var propertyCap = match1.charAt(0).toUpperCase() + match1.slice(1);
return 'set' + propertyCap + '(Spacing.' + match2 + ', ' + match3 + ')'; return 'set' + propertyCap + '(Spacing.' + match2 + ', ' + match3 + ')';
}) })
.replace( // style.margin[CSS_TOP] => style.margin[Spacing.TOP] .replace(// style.margin[CSS_TOP] => style.margin[Spacing.TOP]
/style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]/g, /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]/g,
function (str, match1, match2) { function(str, match1, match2) {
return 'style.' + match1 + '.get(Spacing.' + match2 + ')'; return 'style.' + match1 + '.get(Spacing.' + match2 + ')';
}) })
.replace(/get_child\(.*context\,\s([^\)]+)\)/g, 'getChildAt($1)') .replace(/get_child\(.*context\,\s([^\)]+)\)/g, 'getChildAt($1)')
@@ -96,10 +96,10 @@ function __transpileSingleTestToJava(code) {
.replace(/css_node_t(\s)\*/g, 'TestCSSNode$1') .replace(/css_node_t(\s)\*/g, 'TestCSSNode$1')
.replace(/\->/g, '.') .replace(/\->/g, '.')
.replace(/(\d+\.\d+)/g, '$1f') .replace(/(\d+\.\d+)/g, '$1f')
.replace( // style.flex_direction => style.flexDirection .replace(// style.flex_direction => style.flexDirection
/style\.([^_\[\]\s]+)_(\w)(\w+)/g, /style\.([^_\[\]\s]+)_(\w)(\w+)/g,
function (str, match1, match2, match3) { function(str, match1, match2, match3) {
return 'style.' + match1 + match2.toUpperCase() + match3; return 'style.' + match1 + match2.toUpperCase() + match3;
}) })
.replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);'); .replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);');
} }

View File

@@ -23,13 +23,13 @@ var layoutTestUtils = (function() {
var testMeasurePrecision = 1.0; var testMeasurePrecision = 1.0;
if (typeof jasmine !== 'undefined') { if (typeof jasmine !== 'undefined') {
jasmine.matchersUtil.buildFailureMessage = function () { jasmine.matchersUtil.buildFailureMessage = function() {
var args = Array.prototype.slice.call(arguments, 0), var args = Array.prototype.slice.call(arguments, 0);
matcherName = args[0], var matcherName = args[0];
isNot = args[1], var isNot = args[1];
actual = args[2], var actual = args[2];
expected = args.slice(3), var expected = args.slice(3);
englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
var pp = function(node) { var pp = function(node) {
return jasmine.pp(node) return jasmine.pp(node)
@@ -278,8 +278,7 @@ var layoutTestUtils = (function() {
var val = obj[key]; var val = obj[key];
if (typeof val === 'number') { if (typeof val === 'number') {
obj[key] = Math.floor((val * testMeasurePrecision) + 0.5) / testMeasurePrecision; obj[key] = Math.floor((val * testMeasurePrecision) + 0.5) / testMeasurePrecision;
} } else if (typeof val === 'object') {
else if (typeof val === 'object') {
inplaceRoundNumbersInObject(val); inplaceRoundNumbersInObject(val);
} }
} }
@@ -386,7 +385,7 @@ var layoutTestUtils = (function() {
document.body.appendChild(iframeText); document.body.appendChild(iframeText);
var body = iframeText.contentDocument.body; var body = iframeText.contentDocument.body;
if (width === undefined || width !== width) { if (width === undefined || isNaN(width)) {
width = Infinity; width = Infinity;
} }
@@ -490,7 +489,7 @@ var layoutTestUtils = (function() {
reduceTest: reduceTest, reduceTest: reduceTest,
text: function(text) { text: function(text) {
var fn = function(width) { var fn = function(width) {
if (width === undefined || width !== width) { if (width === undefined || isNaN(width)) {
width = Infinity; width = Infinity;
} }

View File

@@ -989,7 +989,10 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
// For a relative children, we're either using alignItems (parent) or // For a relative children, we're either using alignItems (parent) or
// alignSelf (child) in order to determine the position in the cross axis // alignSelf (child) in order to determine the position in the cross axis
if (child->style.position_type == CSS_POSITION_RELATIVE) { if (child->style.position_type == CSS_POSITION_RELATIVE) {
/*eslint-disable */
// This variable is intentionally re-defined as the code is transpiled to a block scope language
css_align_t alignItem = getAlignItem(node, child); css_align_t alignItem = getAlignItem(node, child);
/*eslint-enable */
if (alignItem == CSS_ALIGN_STRETCH) { if (alignItem == CSS_ALIGN_STRETCH) {
// You can only stretch if the dimension has not already been set // You can only stretch if the dimension has not already been set
// previously. // previously.

View File

@@ -100,7 +100,7 @@ var computeLayout = (function() {
} }
function getLeadingMargin(node, axis) { function getLeadingMargin(node, axis) {
if (node.style.marginStart != null && isRowDirection(axis)) { if (node.style.marginStart !== undefined && isRowDirection(axis)) {
return node.style.marginStart; return node.style.marginStart;
} }
@@ -112,11 +112,11 @@ var computeLayout = (function() {
case 'column-reverse': value = node.style.marginBottom; break; case 'column-reverse': value = node.style.marginBottom; break;
} }
if (value != null) { if (value !== undefined) {
return value; return value;
} }
if (node.style.margin != null) { if (node.style.margin !== undefined) {
return node.style.margin; return node.style.margin;
} }
@@ -124,7 +124,7 @@ var computeLayout = (function() {
} }
function getTrailingMargin(node, axis) { function getTrailingMargin(node, axis) {
if (node.style.marginEnd != null && isRowDirection(axis)) { if (node.style.marginEnd !== undefined && isRowDirection(axis)) {
return node.style.marginEnd; return node.style.marginEnd;
} }
@@ -140,7 +140,7 @@ var computeLayout = (function() {
return value; return value;
} }
if (node.style.margin != null) { if (node.style.margin !== undefined) {
return node.style.margin; return node.style.margin;
} }
@@ -148,7 +148,7 @@ var computeLayout = (function() {
} }
function getLeadingPadding(node, axis) { function getLeadingPadding(node, axis) {
if (node.style.paddingStart != null && node.style.paddingStart >= 0 if (node.style.paddingStart !== undefined && node.style.paddingStart >= 0
&& isRowDirection(axis)) { && isRowDirection(axis)) {
return node.style.paddingStart; return node.style.paddingStart;
} }
@@ -165,7 +165,7 @@ var computeLayout = (function() {
return value; return value;
} }
if (node.style.padding != null && node.style.padding >= 0) { if (node.style.padding !== undefined && node.style.padding >= 0) {
return node.style.padding; return node.style.padding;
} }
@@ -173,7 +173,7 @@ var computeLayout = (function() {
} }
function getTrailingPadding(node, axis) { function getTrailingPadding(node, axis) {
if (node.style.paddingEnd != null && node.style.paddingEnd >= 0 if (node.style.paddingEnd !== undefined && node.style.paddingEnd >= 0
&& isRowDirection(axis)) { && isRowDirection(axis)) {
return node.style.paddingEnd; return node.style.paddingEnd;
} }
@@ -190,7 +190,7 @@ var computeLayout = (function() {
return value; return value;
} }
if (node.style.padding != null && node.style.padding >= 0) { if (node.style.padding !== undefined && node.style.padding >= 0) {
return node.style.padding; return node.style.padding;
} }
@@ -198,7 +198,7 @@ var computeLayout = (function() {
} }
function getLeadingBorder(node, axis) { function getLeadingBorder(node, axis) {
if (node.style.borderStartWidth != null && node.style.borderStartWidth >= 0 if (node.style.borderStartWidth !== undefined && node.style.borderStartWidth >= 0
&& isRowDirection(axis)) { && isRowDirection(axis)) {
return node.style.borderStartWidth; return node.style.borderStartWidth;
} }
@@ -215,7 +215,7 @@ var computeLayout = (function() {
return value; return value;
} }
if (node.style.borderWidth != null && node.style.borderWidth >= 0) { if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
return node.style.borderWidth; return node.style.borderWidth;
} }
@@ -223,7 +223,7 @@ var computeLayout = (function() {
} }
function getTrailingBorder(node, axis) { function getTrailingBorder(node, axis) {
if (node.style.borderEndWidth != null && node.style.borderEndWidth >= 0 if (node.style.borderEndWidth !== undefined && node.style.borderEndWidth >= 0
&& isRowDirection(axis)) { && isRowDirection(axis)) {
return node.style.borderEndWidth; return node.style.borderEndWidth;
} }
@@ -240,13 +240,13 @@ var computeLayout = (function() {
return value; return value;
} }
if (node.style.borderWidth != null && node.style.borderWidth >= 0) { if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
return node.style.borderWidth; return node.style.borderWidth;
} }
return 0; return 0;
} }
function getLeadingPaddingAndBorder(node, axis) { function getLeadingPaddingAndBorder(node, axis) {
return getLeadingPadding(node, axis) + getLeadingBorder(node, axis); return getLeadingPadding(node, axis) + getLeadingBorder(node, axis);
} }
@@ -357,19 +357,19 @@ var computeLayout = (function() {
} }
function isDimDefined(node, axis) { function isDimDefined(node, axis) {
return node.style[dim[axis]] != null && node.style[dim[axis]] >= 0; return node.style[dim[axis]] !== undefined && node.style[dim[axis]] >= 0;
} }
function isPosDefined(node, pos) { function isPosDefined(node, pos) {
return node.style[pos] != null; return node.style[pos] !== undefined;
} }
function isMeasureDefined(node) { function isMeasureDefined(node) {
return node.style.measure != null; return node.style.measure !== undefined;
} }
function getPosition(node, pos) { function getPosition(node, pos) {
if (node.style[pos] != null) { if (node.style[pos] !== undefined) {
return node.style[pos]; return node.style[pos];
} }
return 0; return 0;
@@ -391,10 +391,10 @@ var computeLayout = (function() {
}[axis]; }[axis];
var boundValue = value; var boundValue = value;
if (max != null && max >= 0 && boundValue > max) { if (max !== undefined && max >= 0 && boundValue > max) {
boundValue = max; boundValue = max;
} }
if (min != null && min >= 0 && boundValue < min) { if (min !== undefined && min >= 0 && boundValue < min) {
boundValue = min; boundValue = min;
} }
return boundValue; return boundValue;
@@ -410,7 +410,7 @@ var computeLayout = (function() {
// When the user specifically sets a value for width or height // When the user specifically sets a value for width or height
function setDimensionFromStyle(node, axis) { function setDimensionFromStyle(node, axis) {
// The parent already computed us a width or height. We just skip it // The parent already computed us a width or height. We just skip it
if (node.layout[dim[axis]] != null) { if (node.layout[dim[axis]] !== undefined) {
return; return;
} }
// We only run if there's a width or height defined // We only run if there's a width or height defined
@@ -433,7 +433,7 @@ var computeLayout = (function() {
// If both left and right are defined, then use left. Otherwise return // If both left and right are defined, then use left. Otherwise return
// +left or -right depending on which is defined. // +left or -right depending on which is defined.
function getRelativePosition(node, axis) { function getRelativePosition(node, axis) {
if (node.style[leading[axis]] != null) { if (node.style[leading[axis]] !== undefined) {
return getPosition(node, leading[axis]); return getPosition(node, leading[axis]);
} }
return -getPosition(node, trailing[axis]); return -getPosition(node, trailing[axis]);
@@ -565,8 +565,8 @@ var computeLayout = (function() {
// immediately stacked in the initial loop will not be touched again // immediately stacked in the initial loop will not be touched again
// in <Loop C>. // in <Loop C>.
var/*bool*/ isSimpleStackMain = var/*bool*/ isSimpleStackMain =
(isMainDimDefined && justifyContent == CSS_JUSTIFY_FLEX_START) || (isMainDimDefined && justifyContent === CSS_JUSTIFY_FLEX_START) ||
(!isMainDimDefined && justifyContent != CSS_JUSTIFY_CENTER); (!isMainDimDefined && justifyContent !== CSS_JUSTIFY_CENTER);
var/*int*/ firstComplexMain = (isSimpleStackMain ? childCount : startLine); var/*int*/ firstComplexMain = (isSimpleStackMain ? childCount : startLine);
// Use the initial line loop to position children in the cross axis for // Use the initial line loop to position children in the cross axis for
@@ -704,7 +704,7 @@ var computeLayout = (function() {
// we found a non-trivial child. The remaining children will be laid out // we found a non-trivial child. The remaining children will be laid out
// in <Loop C>. // in <Loop C>.
if (isSimpleStackMain && if (isSimpleStackMain &&
(getPositionType(child) != CSS_POSITION_RELATIVE || isFlex(child))) { (getPositionType(child) !== CSS_POSITION_RELATIVE || isFlex(child))) {
isSimpleStackMain = false; isSimpleStackMain = false;
firstComplexMain = i; firstComplexMain = i;
} }
@@ -713,8 +713,8 @@ var computeLayout = (function() {
// we found a non-trivial child. The remaining children will be laid out // we found a non-trivial child. The remaining children will be laid out
// in <Loop D>. // in <Loop D>.
if (isSimpleStackCross && if (isSimpleStackCross &&
(getPositionType(child) != CSS_POSITION_RELATIVE || (getPositionType(child) !== CSS_POSITION_RELATIVE ||
(alignItem !== CSS_ALIGN_STRETCH && alignItem != CSS_ALIGN_FLEX_START) || (alignItem !== CSS_ALIGN_STRETCH && alignItem !== CSS_ALIGN_FLEX_START) ||
isUndefined(child.layout[dim[crossAxis]]))) { isUndefined(child.layout[dim[crossAxis]]))) {
isSimpleStackCross = false; isSimpleStackCross = false;
firstComplexCross = i; firstComplexCross = i;
@@ -911,7 +911,10 @@ var computeLayout = (function() {
// For a relative children, we're either using alignItems (parent) or // For a relative children, we're either using alignItems (parent) or
// alignSelf (child) in order to determine the position in the cross axis // alignSelf (child) in order to determine the position in the cross axis
if (getPositionType(child) === CSS_POSITION_RELATIVE) { if (getPositionType(child) === CSS_POSITION_RELATIVE) {
/*eslint-disable */
// This variable is intentionally re-defined as the code is transpiled to a block scope language
var/*css_align_t*/ alignItem = getAlignItem(node, child); var/*css_align_t*/ alignItem = getAlignItem(node, child);
/*eslint-enable */
if (alignItem === CSS_ALIGN_STRETCH) { if (alignItem === CSS_ALIGN_STRETCH) {
// You can only stretch if the dimension has not already been set // You can only stretch if the dimension has not already been set
// previously. // previously.
@@ -1048,8 +1051,8 @@ var computeLayout = (function() {
paddingAndBorderAxisMain paddingAndBorderAxisMain
); );
if (mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || if (mainAxis === CSS_FLEX_DIRECTION_ROW_REVERSE ||
mainAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { mainAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
needsMainTrailingPos = true; needsMainTrailingPos = true;
} }
} }
@@ -1063,8 +1066,8 @@ var computeLayout = (function() {
paddingAndBorderAxisCross paddingAndBorderAxisCross
); );
if (crossAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || if (crossAxis === CSS_FLEX_DIRECTION_ROW_REVERSE ||
crossAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { crossAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
needsCrossTrailingPos = true; needsCrossTrailingPos = true;
} }
} }
@@ -1122,19 +1125,19 @@ var computeLayout = (function() {
child.nextAbsoluteChild = null; child.nextAbsoluteChild = null;
} }
} }
function layoutNode(node, parentMaxWidth, parentDirection) { function layoutNode(node, parentMaxWidth, parentDirection) {
node.shouldUpdate = true; node.shouldUpdate = true;
var direction = node.style.direction || CSS_DIRECTION_LTR; var direction = node.style.direction || CSS_DIRECTION_LTR;
var skipLayout = var skipLayout =
!node.isDirty && !node.isDirty &&
node.lastLayout && node.lastLayout &&
node.lastLayout.requestedHeight === node.layout.height && node.lastLayout.requestedHeight === node.layout.height &&
node.lastLayout.requestedWidth === node.layout.width && node.lastLayout.requestedWidth === node.layout.width &&
node.lastLayout.parentMaxWidth === parentMaxWidth && node.lastLayout.parentMaxWidth === parentMaxWidth &&
node.lastLayout.direction === direction; node.lastLayout.direction === direction;
if (skipLayout) { if (skipLayout) {
node.layout.width = node.lastLayout.width; node.layout.width = node.lastLayout.width;
node.layout.height = node.lastLayout.height; node.layout.height = node.lastLayout.height;
@@ -1144,12 +1147,12 @@ var computeLayout = (function() {
if (!node.lastLayout) { if (!node.lastLayout) {
node.lastLayout = {}; node.lastLayout = {};
} }
node.lastLayout.requestedWidth = node.layout.width; node.lastLayout.requestedWidth = node.layout.width;
node.lastLayout.requestedHeight = node.layout.height; node.lastLayout.requestedHeight = node.layout.height;
node.lastLayout.parentMaxWidth = parentMaxWidth; node.lastLayout.parentMaxWidth = parentMaxWidth;
node.lastLayout.direction = direction; node.lastLayout.direction = direction;
// Reset child layouts // Reset child layouts
node.children.forEach(function(child) { node.children.forEach(function(child) {
child.layout.width = undefined; child.layout.width = undefined;
@@ -1157,9 +1160,9 @@ var computeLayout = (function() {
child.layout.top = 0; child.layout.top = 0;
child.layout.left = 0; child.layout.left = 0;
}); });
layoutNodeImpl(node, parentMaxWidth, parentDirection); layoutNodeImpl(node, parentMaxWidth, parentDirection);
node.lastLayout.width = node.layout.width; node.lastLayout.width = node.layout.width;
node.lastLayout.height = node.layout.height; node.lastLayout.height = node.layout.height;
node.lastLayout.top = node.layout.top; node.lastLayout.top = node.layout.top;

View File

@@ -98,13 +98,13 @@ describe('Random layout', function() {
} }
function checkRandomLayout(i, node) { function checkRandomLayout(i, node) {
it('should layout randomly #' + i + '.', function(node) { it('should layout randomly #' + i + '.', function(node) {
if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) { if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) {
node = reduceTest(node); node = reduceTest(node);
} }
testRandomLayout(node, i); testRandomLayout(node, i);
}.bind(this, node)); }.bind(this, node));
} }
for (var i = 0; i < 100; ++i) { for (var i = 0; i < 100; ++i) {

View File

@@ -11,7 +11,6 @@
var testLayout = layoutTestUtils.testLayout; var testLayout = layoutTestUtils.testLayout;
var testLayoutAgainstDomOnly = layoutTestUtils.testLayoutAgainstDomOnly; var testLayoutAgainstDomOnly = layoutTestUtils.testLayoutAgainstDomOnly;
var testFillNodes = layoutTestUtils.testFillNodes; var testFillNodes = layoutTestUtils.testFillNodes;
var testExtractNodes = layoutTestUtils.testExtractNodes;
var text = layoutTestUtils.text; var text = layoutTestUtils.text;
var texts = layoutTestUtils.texts; var texts = layoutTestUtils.texts;
var textSizes = layoutTestUtils.textSizes; var textSizes = layoutTestUtils.textSizes;

View File

@@ -718,7 +718,10 @@ namespace Facebook.CSSLayout
// For a relative children, we're either using alignItems (parent) or // For a relative children, we're either using alignItems (parent) or
// alignSelf (child) in order to determine the position in the cross axis // alignSelf (child) in order to determine the position in the cross axis
if (child.style.positionType == CSSPositionType.Relative) { if (child.style.positionType == CSSPositionType.Relative) {
/*eslint-disable */
// This variable is intentionally re-defined as the code is transpiled to a block scope language
CSSAlign alignItem = getAlignItem(node, child); CSSAlign alignItem = getAlignItem(node, child);
/*eslint-enable */
if (alignItem == CSSAlign.Stretch) { if (alignItem == CSSAlign.Stretch) {
// You can only stretch if the dimension has not already been set // You can only stretch if the dimension has not already been set
// previously. // previously.

View File

@@ -3,7 +3,7 @@
// //
// This file uses the following specific UMD implementation: // This file uses the following specific UMD implementation:
// https://github.com/umdjs/umd/blob/master/returnExports.js // https://github.com/umdjs/umd/blob/master/returnExports.js
(function (root, factory) { (function(root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module. // AMD. Register as an anonymous module.
define([], factory); define([], factory);
@@ -16,11 +16,14 @@
// Browser globals (root is window) // Browser globals (root is window)
root.computeLayout = factory(); root.computeLayout = factory();
} }
}(this, function () { }(this, function() {
// @@include('./Layout.js') // @@include('./Layout.js')
return function(node) { return function(node) {
computeLayout.fillNodes(node); /*eslint-disable */
computeLayout.computeLayout(node); // disabling ESLint because this code relies on the above include
computeLayout.fillNodes(node);
computeLayout.computeLayout(node);
/*eslint-enable */
}; };
})); }));

View File

@@ -692,7 +692,10 @@ public class LayoutEngine {
// For a relative children, we're either using alignItems (parent) or // For a relative children, we're either using alignItems (parent) or
// alignSelf (child) in order to determine the position in the cross axis // alignSelf (child) in order to determine the position in the cross axis
if (child.style.positionType == CSSPositionType.RELATIVE) { if (child.style.positionType == CSSPositionType.RELATIVE) {
/*eslint-disable */
// This variable is intentionally re-defined as the code is transpiled to a block scope language
CSSAlign alignItem = getAlignItem(node, child); CSSAlign alignItem = getAlignItem(node, child);
/*eslint-enable */
if (alignItem == CSSAlign.STRETCH) { if (alignItem == CSSAlign.STRETCH) {
// You can only stretch if the dimension has not already been set // You can only stretch if the dimension has not already been set
// previously. // previously.