Match xplat/yoga/javascript prettier conventions

Summary:
Match Prettier config to match other Meta OSS projects

Didn't update the test generator to use this form yet.

Reviewed By: yungsters

Differential Revision: D45570415

fbshipit-source-id: d5fd791b047debf41c28aecac75fb8dde16da3e3
This commit is contained in:
Nick Gerleman
2023-05-09 15:35:42 -07:00
committed by Facebook GitHub Bot
parent 0cb4a49d38
commit 0a6a581936
29 changed files with 197 additions and 199 deletions

View File

@@ -8,8 +8,9 @@
*/ */
module.exports = { module.exports = {
trailingComma: "es5", arrowParens: 'avoid',
tabWidth: 2, bracketSameLine: true,
semi: true, bracketSpacing: false,
singleQuote: false, singleQuote: true,
trailingComma: 'all',
}; };

View File

@@ -7,11 +7,11 @@
* @format * @format
*/ */
import type { Config } from "jest"; import type {Config} from 'jest';
const config: Config = { const config: Config = {
setupFiles: ["./jest.setup.ts"], setupFiles: ['./jest.setup.ts'],
testRegex: "/tests/.*\\.test\\.[jt]s$", testRegex: '/tests/.*\\.test\\.[jt]s$',
}; };
export default config; export default config;

View File

@@ -8,17 +8,17 @@
*/ */
module.exports = async () => { module.exports = async () => {
if (process.env["SYNC"] === "1" && process.env["WASM"] === "1") { if (process.env['SYNC'] === '1' && process.env['WASM'] === '1') {
globalThis.Yoga = require("./dist/entrypoint/wasm-sync"); globalThis.Yoga = require('./dist/entrypoint/wasm-sync');
} else if (process.env["SYNC"] === "1") { } else if (process.env['SYNC'] === '1') {
globalThis.Yoga = require("./dist/entrypoint/asmjs-sync"); globalThis.Yoga = require('./dist/entrypoint/asmjs-sync');
} else if (process.env["WASM"] === "1") { } else if (process.env['WASM'] === '1') {
globalThis.Yoga = await require("./dist/entrypoint/wasm-async").loadYoga(); globalThis.Yoga = await require('./dist/entrypoint/wasm-async').loadYoga();
} else { } else {
globalThis.Yoga = await require("./dist/entrypoint/asmjs-async").loadYoga(); globalThis.Yoga = await require('./dist/entrypoint/asmjs-async').loadYoga();
} }
}; };
Object.defineProperty(globalThis, "YGBENCHMARK", { Object.defineProperty(globalThis, 'YGBENCHMARK', {
get: () => globalThis.test, get: () => globalThis.test,
}); });

View File

@@ -20,81 +20,78 @@ import {
spawn, spawn,
task, task,
tscTask, tscTask,
} from "just-scripts"; } from 'just-scripts';
import glob from "glob"; import glob from 'glob';
import path from "path"; import path from 'path';
import which from "which"; import which from 'which';
const node = process.execPath; const node = process.execPath;
option("fix"); option('fix');
task("clean", cleanTask({ paths: ["build", "dist"] })); task('clean', cleanTask({paths: ['build', 'dist']}));
task( task(
"prepare-for-build", 'prepare-for-build',
parallel( parallel(
babelTransformTask({ paths: ["src_js"], dest: "dist" }), babelTransformTask({paths: ['src_js'], dest: 'dist'}),
copyTask({ paths: ["src_js/**/*.d.ts"], dest: "dist" }), copyTask({paths: ['src_js/**/*.d.ts'], dest: 'dist'}),
emcmakeGenerateTask() emcmakeGenerateTask(),
) ),
); );
function defineFlavor(flavor: string, env: NodeJS.ProcessEnv) { function defineFlavor(flavor: string, env: NodeJS.ProcessEnv) {
task(`cmake-build:${flavor}`, cmakeBuildTask({ targets: [flavor] })); task(`cmake-build:${flavor}`, cmakeBuildTask({targets: [flavor]}));
task( task(
`jest:${flavor}`, `jest:${flavor}`,
jestTask({ config: path.join(__dirname, "jest.config.ts"), env }) jestTask({config: path.join(__dirname, 'jest.config.ts'), env}),
); );
task( task(
`test:${flavor}`, `test:${flavor}`,
series("prepare-for-build", `cmake-build:${flavor}`, `jest:${flavor}`) series('prepare-for-build', `cmake-build:${flavor}`, `jest:${flavor}`),
); );
} }
defineFlavor("asmjs-async", { WASM: "0", SYNC: "0" }); defineFlavor('asmjs-async', {WASM: '0', SYNC: '0'});
defineFlavor("asmjs-sync", { WASM: "0", SYNC: "1" }); defineFlavor('asmjs-sync', {WASM: '0', SYNC: '1'});
defineFlavor("wasm-async", { WASM: "1", SYNC: "0" }); defineFlavor('wasm-async', {WASM: '1', SYNC: '0'});
defineFlavor("wasm-sync", { WASM: "1", SYNC: "1" }); defineFlavor('wasm-sync', {WASM: '1', SYNC: '1'});
task("cmake-build:all", cmakeBuildTask()); task('cmake-build:all', cmakeBuildTask());
task( task(
"cmake-build:async", 'cmake-build:async',
cmakeBuildTask({ targets: ["asmjs-async", "wasm-async"] }) cmakeBuildTask({targets: ['asmjs-async', 'wasm-async']}),
); );
task( task(
"cmake-build:sync", 'cmake-build:sync',
cmakeBuildTask({ targets: ["asmjs-sync", "wasm-sync"] }) cmakeBuildTask({targets: ['asmjs-sync', 'wasm-sync']}),
); );
task("build", series("prepare-for-build", "cmake-build:all")); task('build', series('prepare-for-build', 'cmake-build:all'));
task( task(
"test", 'test',
series( series(
"prepare-for-build", 'prepare-for-build',
series("cmake-build:asmjs-async", "jest:asmjs-async"), series('cmake-build:asmjs-async', 'jest:asmjs-async'),
series("cmake-build:asmjs-sync", "jest:asmjs-sync"), series('cmake-build:asmjs-sync', 'jest:asmjs-sync'),
series("cmake-build:wasm-async", "jest:wasm-async"), series('cmake-build:wasm-async', 'jest:wasm-async'),
series("cmake-build:wasm-sync", "jest:wasm-sync") series('cmake-build:wasm-sync', 'jest:wasm-sync'),
) ),
); );
task( task(
"benchmark", 'benchmark',
series("prepare-for-build", "cmake-build:sync", runBenchTask()) series('prepare-for-build', 'cmake-build:sync', runBenchTask()),
); );
task( task(
"lint", 'lint',
parallel( parallel(
tscTask(), tscTask(),
series( series(eslintTask({fix: argv().fix}), clangFormatTask({fix: argv().fix})),
eslintTask({ fix: argv().fix }), ),
clangFormatTask({ fix: argv().fix })
)
)
); );
function babelTransformTask(opts: { function babelTransformTask(opts: {
@@ -102,68 +99,68 @@ function babelTransformTask(opts: {
dest: string; dest: string;
}) { }) {
return () => { return () => {
const args = [...opts.paths, "--source-maps", "--out-dir", opts.dest]; const args = [...opts.paths, '--source-maps', '--out-dir', opts.dest];
logger.info(`Transforming [${opts.paths.join(",")}] to '${opts.dest}'`); logger.info(`Transforming [${opts.paths.join(',')}] to '${opts.dest}'`);
return spawn(node, [require.resolve("@babel/cli/bin/babel"), ...args]); return spawn(node, [require.resolve('@babel/cli/bin/babel'), ...args]);
}; };
} }
function runBenchTask() { function runBenchTask() {
return () => { return () => {
const files = glob.sync("./tests/Benchmarks/**/*"); const files = glob.sync('./tests/Benchmarks/**/*');
const args = ["./tests/bin/run-bench.ts", ...files]; const args = ['./tests/bin/run-bench.ts', ...files];
logger.info(args.join(" ")); logger.info(args.join(' '));
return spawn(node, args, { return spawn(node, args, {
stdio: "inherit", stdio: 'inherit',
env: { NODE_OPTIONS: "-r ts-node/register" }, env: {NODE_OPTIONS: '-r ts-node/register'},
}); });
}; };
} }
function emcmakeGenerateTask() { function emcmakeGenerateTask() {
return () => { return () => {
const emcmake = which.sync("emcmake"); const emcmake = which.sync('emcmake');
const ninja = which.sync("ninja", { nothrow: true }); const ninja = which.sync('ninja', {nothrow: true});
const args = [ const args = [
"cmake", 'cmake',
"-S", '-S',
".", '.',
"-B", '-B',
"build", 'build',
...(ninja ? ["-G", "Ninja"] : []), ...(ninja ? ['-G', 'Ninja'] : []),
]; ];
logger.info(["emcmake", ...args].join(" ")); logger.info(['emcmake', ...args].join(' '));
return spawn(emcmake, args); return spawn(emcmake, args);
}; };
} }
function cmakeBuildTask(opts?: { targets?: ReadonlyArray<string> }) { function cmakeBuildTask(opts?: {targets?: ReadonlyArray<string>}) {
return () => { return () => {
const cmake = which.sync("cmake"); const cmake = which.sync('cmake');
const args = [ const args = [
"--build", '--build',
"build", 'build',
...(opts?.targets ? ["--target", ...opts.targets] : []), ...(opts?.targets ? ['--target', ...opts.targets] : []),
]; ];
logger.info(["cmake", ...args].join(" ")); logger.info(['cmake', ...args].join(' '));
return spawn(cmake, args, { stdio: "inherit" }); return spawn(cmake, args, {stdio: 'inherit'});
}; };
} }
function clangFormatTask(opts?: { fix?: boolean }) { function clangFormatTask(opts?: {fix?: boolean}) {
return () => { return () => {
const args = [ const args = [
...(opts?.fix ? ["-i"] : ["--dry-run", "--Werror"]), ...(opts?.fix ? ['-i'] : ['--dry-run', '--Werror']),
...glob.sync("**/*.{h,hh,hpp,c,cpp,cc,m,mm}"), ...glob.sync('**/*.{h,hh,hpp,c,cpp,cc,m,mm}'),
]; ];
logger.info(["clang-format", ...args].join(" ")); logger.info(['clang-format', ...args].join(' '));
return spawn(node, [require.resolve("clang-format"), ...args], { return spawn(node, [require.resolve('clang-format'), ...args], {
stdio: "inherit", stdio: 'inherit',
}); });
}; };
} }

View File

@@ -7,9 +7,9 @@
* @format * @format
*/ */
const wrapAsm = require("../wrapAsm"); const wrapAsm = require('../wrapAsm');
module.exports = (loadAsm) => ({ module.exports = loadAsm => ({
loadYoga: () => loadAsm().then(wrapAsm), loadYoga: () => loadAsm().then(wrapAsm),
...require("../generated/YGEnums"), ...require('../generated/YGEnums'),
}); });

View File

@@ -7,5 +7,5 @@
* @format * @format
*/ */
const wrapAsm = require("../wrapAsm"); const wrapAsm = require('../wrapAsm');
module.exports = (asm) => wrapAsm(asm()); module.exports = asm => wrapAsm(asm());

View File

@@ -7,5 +7,5 @@
* @format * @format
*/ */
const asm = require("../build/asmjs-async"); const asm = require('../build/asmjs-async');
module.exports = require("./_entryAsync")(asm); module.exports = require('./_entryAsync')(asm);

View File

@@ -7,5 +7,5 @@
* @format * @format
*/ */
const asm = require("../build/asmjs-sync"); const asm = require('../build/asmjs-sync');
module.exports = require("./_entrySync")(asm); module.exports = require('./_entrySync')(asm);

View File

@@ -7,5 +7,5 @@
* @format * @format
*/ */
const asm = require("../build/wasm-async"); const asm = require('../build/wasm-async');
module.exports = require("./_entryAsync")(asm); module.exports = require('./_entryAsync')(asm);

View File

@@ -7,5 +7,5 @@
* @format * @format
*/ */
const asm = require("../build/wasm-sync"); const asm = require('../build/wasm-sync');
module.exports = require("./_entrySync")(asm); module.exports = require('./_entrySync')(asm);

View File

@@ -7,9 +7,9 @@
* @format * @format
*/ */
import type { Yoga } from "./wrapAsm"; import type {Yoga} from './wrapAsm';
export * from "./generated/YGEnums"; export * from './generated/YGEnums';
export * from "./wrapAsm"; export * from './wrapAsm';
export function loadYoga(): Promise<Yoga>; export function loadYoga(): Promise<Yoga>;

View File

@@ -8,4 +8,4 @@
*/ */
// Fallback for when the export map is not followed // Fallback for when the export map is not followed
module.exports = require("./entrypoint/asmjs-async"); module.exports = require('./entrypoint/asmjs-async');

View File

@@ -7,10 +7,10 @@
* @format * @format
*/ */
import type { Yoga } from "./wrapAsm"; import type {Yoga} from './wrapAsm';
export * from "./generated/YGEnums"; export * from './generated/YGEnums';
export * from "./wrapAsm"; export * from './wrapAsm';
declare const yoga: Yoga; declare const yoga: Yoga;
export default yoga; export default yoga;

View File

@@ -8,4 +8,4 @@
*/ */
// Fallback for when the export map is not followed // Fallback for when the export map is not followed
module.exports = require("./entrypoint/asmjs-sync"); module.exports = require('./entrypoint/asmjs-sync');

View File

@@ -22,9 +22,9 @@ import type {
PositionType, PositionType,
Unit, Unit,
Wrap, Wrap,
} from "./generated/YGEnums"; } from './generated/YGEnums';
import type * as YGEnums from "./generated/YGEnums"; import type * as YGEnums from './generated/YGEnums';
type Layout = { type Layout = {
left: number; left: number;
@@ -50,7 +50,7 @@ export type Config = {
isExperimentalFeatureEnabled(feature: ExperimentalFeature): boolean; isExperimentalFeatureEnabled(feature: ExperimentalFeature): boolean;
setExperimentalFeatureEnabled( setExperimentalFeatureEnabled(
feature: ExperimentalFeature, feature: ExperimentalFeature,
enabled: boolean enabled: boolean,
): void; ): void;
setPointScaleFactor(factor: number): void; setPointScaleFactor(factor: number): void;
/** /**
@@ -77,7 +77,7 @@ export type MeasureFunction = (
width: number, width: number,
widthMode: MeasureMode, widthMode: MeasureMode,
height: number, height: number,
heightMode: MeasureMode heightMode: MeasureMode,
) => Size; ) => Size;
export type Node = { export type Node = {
@@ -135,20 +135,20 @@ export type Node = {
setBorder(edge: Edge, borderWidth: number): void; setBorder(edge: Edge, borderWidth: number): void;
setDisplay(display: Display): void; setDisplay(display: Display): void;
setFlex(flex: number): void; setFlex(flex: number): void;
setFlexBasis(flexBasis: number | "auto" | `${number}%`): void; setFlexBasis(flexBasis: number | 'auto' | `${number}%`): void;
setFlexBasisPercent(flexBasis: number): void; setFlexBasisPercent(flexBasis: number): void;
setFlexBasisAuto(): void; setFlexBasisAuto(): void;
setFlexDirection(flexDirection: FlexDirection): void; setFlexDirection(flexDirection: FlexDirection): void;
setFlexGrow(flexGrow: number): void; setFlexGrow(flexGrow: number): void;
setFlexShrink(flexShrink: number): void; setFlexShrink(flexShrink: number): void;
setFlexWrap(flexWrap: Wrap): void; setFlexWrap(flexWrap: Wrap): void;
setHeight(height: number | "auto" | `${number}%`): void; setHeight(height: number | 'auto' | `${number}%`): void;
setIsReferenceBaseline(isReferenceBaseline: boolean): void; setIsReferenceBaseline(isReferenceBaseline: boolean): void;
setHeightAuto(): void; setHeightAuto(): void;
setHeightPercent(height: number): void; setHeightPercent(height: number): void;
setJustifyContent(justifyContent: Justify): void; setJustifyContent(justifyContent: Justify): void;
setGap(gutter: Gutter, gapLength: number): Value; setGap(gutter: Gutter, gapLength: number): Value;
setMargin(edge: Edge, margin: number | "auto" | `${number}%`): void; setMargin(edge: Edge, margin: number | 'auto' | `${number}%`): void;
setMarginAuto(edge: Edge): void; setMarginAuto(edge: Edge): void;
setMarginPercent(edge: Edge, margin: number): void; setMarginPercent(edge: Edge, margin: number): void;
setMaxHeight(maxHeight: number | `${number}%`): void; setMaxHeight(maxHeight: number | `${number}%`): void;
@@ -167,7 +167,7 @@ export type Node = {
setPosition(edge: Edge, position: number | `${number}%`): void; setPosition(edge: Edge, position: number | `${number}%`): void;
setPositionPercent(edge: Edge, position: number): void; setPositionPercent(edge: Edge, position: number): void;
setPositionType(positionType: PositionType): void; setPositionType(positionType: PositionType): void;
setWidth(width: number | "auto" | `${number}%`): void; setWidth(width: number | 'auto' | `${number}%`): void;
setWidthAuto(): void; setWidthAuto(): void;
setWidthPercent(width: number): void; setWidthPercent(width: number): void;
unsetDirtiedFunc(): void; unsetDirtiedFunc(): void;

View File

@@ -7,9 +7,9 @@
* @format * @format
*/ */
const CONSTANTS = require("./generated/YGEnums"); const CONSTANTS = require('./generated/YGEnums');
module.exports = (lib) => { module.exports = lib => {
function patch(prototype, name, fn) { function patch(prototype, name, fn) {
const original = prototype[name]; const original = prototype[name];
@@ -19,16 +19,16 @@ module.exports = (lib) => {
} }
for (const fnName of [ for (const fnName of [
"setPosition", 'setPosition',
"setMargin", 'setMargin',
"setFlexBasis", 'setFlexBasis',
"setWidth", 'setWidth',
"setHeight", 'setHeight',
"setMinWidth", 'setMinWidth',
"setMinHeight", 'setMinHeight',
"setMaxWidth", 'setMaxWidth',
"setMaxHeight", 'setMaxHeight',
"setPadding", 'setPadding',
]) { ]) {
const methods = { const methods = {
[CONSTANTS.UNIT_POINT]: lib.Node.prototype[fnName], [CONSTANTS.UNIT_POINT]: lib.Node.prototype[fnName],
@@ -43,15 +43,15 @@ module.exports = (lib) => {
const value = args.pop(); const value = args.pop();
let unit, asNumber; let unit, asNumber;
if (value === "auto") { if (value === 'auto') {
unit = CONSTANTS.UNIT_AUTO; unit = CONSTANTS.UNIT_AUTO;
asNumber = undefined; asNumber = undefined;
} else if (typeof value === "object") { } else if (typeof value === 'object') {
unit = value.unit; unit = value.unit;
asNumber = value.valueOf(); asNumber = value.valueOf();
} else { } else {
unit = unit =
typeof value === "string" && value.endsWith("%") typeof value === 'string' && value.endsWith('%')
? CONSTANTS.UNIT_PERCENT ? CONSTANTS.UNIT_PERCENT
: CONSTANTS.UNIT_POINT; : CONSTANTS.UNIT_POINT;
asNumber = parseFloat(value); asNumber = parseFloat(value);
@@ -62,7 +62,7 @@ module.exports = (lib) => {
if (!methods[unit]) if (!methods[unit])
throw new Error( throw new Error(
`Failed to execute "${fnName}": Unsupported unit '${value}'` `Failed to execute "${fnName}": Unsupported unit '${value}'`,
); );
if (asNumber !== undefined) { if (asNumber !== undefined) {
@@ -76,7 +76,7 @@ module.exports = (lib) => {
function wrapMeasureFunction(measureFunction) { function wrapMeasureFunction(measureFunction) {
return lib.MeasureCallback.implement({ return lib.MeasureCallback.implement({
measure: (...args) => { measure: (...args) => {
const { width, height } = measureFunction(...args); const {width, height} = measureFunction(...args);
return { return {
width: width ?? NaN, width: width ?? NaN,
height: height ?? NaN, height: height ?? NaN,
@@ -85,7 +85,7 @@ module.exports = (lib) => {
}); });
} }
patch(lib.Node.prototype, "setMeasureFunc", function (original, measureFunc) { patch(lib.Node.prototype, 'setMeasureFunc', function (original, measureFunc) {
// This patch is just a convenience patch, since it helps write more // This patch is just a convenience patch, since it helps write more
// idiomatic source code (such as .setMeasureFunc(null)) // idiomatic source code (such as .setMeasureFunc(null))
if (measureFunc) { if (measureFunc) {
@@ -96,33 +96,33 @@ module.exports = (lib) => {
}); });
function wrapDirtiedFunc(dirtiedFunction) { function wrapDirtiedFunc(dirtiedFunction) {
return lib.DirtiedCallback.implement({ dirtied: dirtiedFunction }); return lib.DirtiedCallback.implement({dirtied: dirtiedFunction});
} }
patch(lib.Node.prototype, "setDirtiedFunc", function (original, dirtiedFunc) { patch(lib.Node.prototype, 'setDirtiedFunc', function (original, dirtiedFunc) {
original.call(this, wrapDirtiedFunc(dirtiedFunc)); original.call(this, wrapDirtiedFunc(dirtiedFunc));
}); });
patch(lib.Config.prototype, "free", function () { patch(lib.Config.prototype, 'free', function () {
// Since we handle the memory allocation ourselves (via lib.Config.create), // Since we handle the memory allocation ourselves (via lib.Config.create),
// we also need to handle the deallocation // we also need to handle the deallocation
lib.Config.destroy(this); lib.Config.destroy(this);
}); });
patch(lib.Node, "create", (_, config) => { patch(lib.Node, 'create', (_, config) => {
// We decide the constructor we want to call depending on the parameters // We decide the constructor we want to call depending on the parameters
return config return config
? lib.Node.createWithConfig(config) ? lib.Node.createWithConfig(config)
: lib.Node.createDefault(); : lib.Node.createDefault();
}); });
patch(lib.Node.prototype, "free", function () { patch(lib.Node.prototype, 'free', function () {
// Since we handle the memory allocation ourselves (via lib.Node.create), // Since we handle the memory allocation ourselves (via lib.Node.create),
// we also need to handle the deallocation // we also need to handle the deallocation
lib.Node.destroy(this); lib.Node.destroy(this);
}); });
patch(lib.Node.prototype, "freeRecursive", function () { patch(lib.Node.prototype, 'freeRecursive', function () {
for (let t = 0, T = this.getChildCount(); t < T; ++t) { for (let t = 0, T = this.getChildCount(); t < T; ++t) {
this.getChild(0).freeRecursive(); this.getChild(0).freeRecursive();
} }
@@ -131,16 +131,16 @@ module.exports = (lib) => {
patch( patch(
lib.Node.prototype, lib.Node.prototype,
"calculateLayout", 'calculateLayout',
function ( function (
original, original,
width = NaN, width = NaN,
height = NaN, height = NaN,
direction = CONSTANTS.DIRECTION_LTR direction = CONSTANTS.DIRECTION_LTR,
) { ) {
// Just a small patch to add support for the function default parameters // Just a small patch to add support for the function default parameters
return original.call(this, width, height, direction); return original.call(this, width, height, direction);
} },
); );
return { return {

View File

@@ -5,12 +5,12 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { getMeasureCounter } from "../tools/MeasureCounter"; import {getMeasureCounter} from '../tools/MeasureCounter';
import { Yoga, YGBENCHMARK } from "../tools/globals"; import {Yoga, YGBENCHMARK} from '../tools/globals';
const ITERATIONS = 2000; const ITERATIONS = 2000;
YGBENCHMARK("Stack with flex", () => { YGBENCHMARK('Stack with flex', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setWidth(100); root.setWidth(100);
root.setHeight(100); root.setHeight(100);
@@ -28,7 +28,7 @@ YGBENCHMARK("Stack with flex", () => {
root.freeRecursive(); root.freeRecursive();
}); });
YGBENCHMARK("Align stretch in undefined axis", () => { YGBENCHMARK('Align stretch in undefined axis', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
const measureCounter = getMeasureCounter(); const measureCounter = getMeasureCounter();
@@ -44,7 +44,7 @@ YGBENCHMARK("Align stretch in undefined axis", () => {
root.freeRecursive(); root.freeRecursive();
}); });
YGBENCHMARK("Nested flex", () => { YGBENCHMARK('Nested flex', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
const measureCounter = getMeasureCounter(); const measureCounter = getMeasureCounter();
@@ -68,7 +68,7 @@ YGBENCHMARK("Nested flex", () => {
root.freeRecursive(); root.freeRecursive();
}); });
YGBENCHMARK("Huge nested layout", () => { YGBENCHMARK('Huge nested layout', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
const iterations = Math.pow(ITERATIONS, 1 / 4); const iterations = Math.pow(ITERATIONS, 1 / 4);

View File

@@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { Yoga } from "./tools/globals"; import {Yoga} from './tools/globals';
test("align_baseline_parent_using_child_in_column_as_reference", () => { test('align_baseline_parent_using_child_in_column_as_reference', () => {
const config = Yoga.Config.create(); const config = Yoga.Config.create();
let root; let root;
@@ -57,7 +57,7 @@ test("align_baseline_parent_using_child_in_column_as_reference", () => {
expect(root_child1_child1.getComputedLeft()).toBe(0); expect(root_child1_child1.getComputedLeft()).toBe(0);
expect(root_child1_child1.getComputedTop()).toBe(300); expect(root_child1_child1.getComputedTop()).toBe(300);
} finally { } finally {
if (typeof root !== "undefined") { if (typeof root !== 'undefined') {
root.freeRecursive(); root.freeRecursive();
} }
@@ -65,7 +65,7 @@ test("align_baseline_parent_using_child_in_column_as_reference", () => {
} }
}); });
test("align_baseline_parent_using_child_in_row_as_reference", () => { test('align_baseline_parent_using_child_in_row_as_reference', () => {
const config = Yoga.Config.create(); const config = Yoga.Config.create();
let root; let root;
@@ -115,7 +115,7 @@ test("align_baseline_parent_using_child_in_row_as_reference", () => {
expect(root_child1_child1.getComputedLeft()).toBe(500); expect(root_child1_child1.getComputedLeft()).toBe(500);
expect(root_child1_child1.getComputedTop()).toBe(0); expect(root_child1_child1.getComputedTop()).toBe(0);
} finally { } finally {
if (typeof root !== "undefined") { if (typeof root !== 'undefined') {
root.freeRecursive(); root.freeRecursive();
} }

View File

@@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { Yoga } from "./tools/globals"; import {Yoga} from './tools/globals';
test("border_start", () => { test('border_start', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setWidth(100); root.setWidth(100);
root.setHeight(100); root.setHeight(100);

View File

@@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { Yoga } from "./tools/globals"; import {Yoga} from './tools/globals';
test("margin_start", () => { test('margin_start', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setWidth(100); root.setWidth(100);
root.setHeight(100); root.setHeight(100);

View File

@@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { Yoga } from "./tools/globals"; import {Yoga} from './tools/globals';
test("padding_start", () => { test('padding_start', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setWidth(100); root.setWidth(100);
root.setHeight(100); root.setHeight(100);

View File

@@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { Yoga } from "./tools/globals"; import {Yoga} from './tools/globals';
test("dirtied", () => { test('dirtied', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100); root.setWidth(100);
@@ -21,7 +21,7 @@ test("dirtied", () => {
}); });
// only nodes with a measure function can be marked dirty // only nodes with a measure function can be marked dirty
root.setMeasureFunc(() => ({ width: 0, height: 0 })); root.setMeasureFunc(() => ({width: 0, height: 0}));
expect(dirtied).toBe(0); expect(dirtied).toBe(0);
@@ -36,7 +36,7 @@ test("dirtied", () => {
root.freeRecursive(); root.freeRecursive();
}); });
test("dirtied_propagation", () => { test('dirtied_propagation', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100); root.setWidth(100);
@@ -46,7 +46,7 @@ test("dirtied_propagation", () => {
root_child0.setAlignItems(Yoga.ALIGN_FLEX_START); root_child0.setAlignItems(Yoga.ALIGN_FLEX_START);
root_child0.setWidth(50); root_child0.setWidth(50);
root_child0.setHeight(20); root_child0.setHeight(20);
root_child0.setMeasureFunc(() => ({ width: 0, height: 0 })); root_child0.setMeasureFunc(() => ({width: 0, height: 0}));
root.insertChild(root_child0, 0); root.insertChild(root_child0, 0);
const root_child1 = Yoga.Node.create(); const root_child1 = Yoga.Node.create();
@@ -75,7 +75,7 @@ test("dirtied_propagation", () => {
root.freeRecursive(); root.freeRecursive();
}); });
test("dirtied_hierarchy", () => { test('dirtied_hierarchy', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100); root.setWidth(100);
@@ -85,14 +85,14 @@ test("dirtied_hierarchy", () => {
root_child0.setAlignItems(Yoga.ALIGN_FLEX_START); root_child0.setAlignItems(Yoga.ALIGN_FLEX_START);
root_child0.setWidth(50); root_child0.setWidth(50);
root_child0.setHeight(20); root_child0.setHeight(20);
root_child0.setMeasureFunc(() => ({ width: 0, height: 0 })); root_child0.setMeasureFunc(() => ({width: 0, height: 0}));
root.insertChild(root_child0, 0); root.insertChild(root_child0, 0);
const root_child1 = Yoga.Node.create(); const root_child1 = Yoga.Node.create();
root_child1.setAlignItems(Yoga.ALIGN_FLEX_START); root_child1.setAlignItems(Yoga.ALIGN_FLEX_START);
root_child1.setWidth(50); root_child1.setWidth(50);
root_child1.setHeight(20); root_child1.setHeight(20);
root_child0.setMeasureFunc(() => ({ width: 0, height: 0 })); root_child0.setMeasureFunc(() => ({width: 0, height: 0}));
root.insertChild(root_child1, 0); root.insertChild(root_child1, 0);
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
@@ -118,12 +118,12 @@ test("dirtied_hierarchy", () => {
root.freeRecursive(); root.freeRecursive();
}); });
test("dirtied_reset", () => { test('dirtied_reset', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100); root.setWidth(100);
root.setHeight(100); root.setHeight(100);
root.setMeasureFunc(() => ({ width: 0, height: 0 })); root.setMeasureFunc(() => ({width: 0, height: 0}));
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
@@ -145,7 +145,7 @@ test("dirtied_reset", () => {
root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100); root.setWidth(100);
root.setHeight(100); root.setHeight(100);
root.setMeasureFunc(() => ({ width: 0, height: 0 })); root.setMeasureFunc(() => ({width: 0, height: 0}));
root.markDirty(); root.markDirty();

View File

@@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { Yoga } from "./tools/globals"; import {Yoga} from './tools/globals';
test("errata_all_contains_example_errata", () => { test('errata_all_contains_example_errata', () => {
const config = Yoga.Config.create(); const config = Yoga.Config.create();
config.setErrata(Yoga.ERRATA_ALL); config.setErrata(Yoga.ERRATA_ALL);
@@ -17,7 +17,7 @@ test("errata_all_contains_example_errata", () => {
config.free(); config.free();
}); });
test("errata_none_omits_example_errata", () => { test('errata_none_omits_example_errata', () => {
const config = Yoga.Config.create(); const config = Yoga.Config.create();
config.setErrata(Yoga.ERRATA_NONE); config.setErrata(Yoga.ERRATA_NONE);
@@ -27,7 +27,7 @@ test("errata_none_omits_example_errata", () => {
config.free(); config.free();
}); });
test("errata_is_settable", () => { test('errata_is_settable', () => {
const config = Yoga.Config.create(); const config = Yoga.Config.create();
config.setErrata(Yoga.ERRATA_ALL); config.setErrata(Yoga.ERRATA_ALL);

View File

@@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { Yoga } from "./tools/globals"; import {Yoga} from './tools/globals';
test("flex_basis_auto", () => { test('flex_basis_auto', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
expect(root.getFlexBasis().unit).toBe(Yoga.UNIT_AUTO); expect(root.getFlexBasis().unit).toBe(Yoga.UNIT_AUTO);

View File

@@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { Yoga } from "./tools/globals"; import {Yoga} from './tools/globals';
import { getMeasureCounterMax } from "./tools/MeasureCounter"; import {getMeasureCounterMax} from './tools/MeasureCounter';
test("measure_once_single_flexible_child", () => { test('measure_once_single_flexible_child', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setAlignItems(Yoga.ALIGN_FLEX_START);

View File

@@ -5,10 +5,10 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { Yoga } from "./tools/globals"; import {Yoga} from './tools/globals';
import { getMeasureCounter } from "./tools/MeasureCounter"; import {getMeasureCounter} from './tools/MeasureCounter';
test("dont_measure_single_grow_shrink_child", () => { test('dont_measure_single_grow_shrink_child', () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();
root.setWidth(100); root.setWidth(100);
root.setHeight(100); root.setHeight(100);
@@ -27,11 +27,11 @@ test("dont_measure_single_grow_shrink_child", () => {
root.freeRecursive(); root.freeRecursive();
}); });
test("dont_fail_with_incomplete_measure_dimensions", () => { test('dont_fail_with_incomplete_measure_dimensions', () => {
// @ts-expect-error Testing bad usage // @ts-expect-error Testing bad usage
const heightOnlyCallback = getMeasureCounter(() => ({ height: 10 })); const heightOnlyCallback = getMeasureCounter(() => ({height: 10}));
// @ts-expect-error Testing bad usage // @ts-expect-error Testing bad usage
const widthOnlyCallback = getMeasureCounter(() => ({ width: 10 })); const widthOnlyCallback = getMeasureCounter(() => ({width: 10}));
// @ts-expect-error Testing bad usage // @ts-expect-error Testing bad usage
const emptyCallback = getMeasureCounter(() => ({})); const emptyCallback = getMeasureCounter(() => ({}));

View File

@@ -8,7 +8,7 @@
* @format * @format
*/ */
import path from "path"; import path from 'path';
const WARMUP_ITERATIONS = 3; const WARMUP_ITERATIONS = 3;
const BENCHMARK_ITERATIONS = 10; const BENCHMARK_ITERATIONS = 10;
@@ -17,10 +17,10 @@ const testFiles = process.argv.slice(2);
const testResults = new Map<string, Map<string, number>>(); const testResults = new Map<string, Map<string, number>>();
for (const type of ["asmjs", "wasm"]) { for (const type of ['asmjs', 'wasm']) {
globalThis.Yoga = require(type === "asmjs" globalThis.Yoga = require(type === 'asmjs'
? "../../dist/entrypoint/asmjs-sync" ? '../../dist/entrypoint/asmjs-sync'
: "../../dist/entrypoint/wasm-sync"); : '../../dist/entrypoint/wasm-sync');
for (const file of testFiles) { for (const file of testFiles) {
globalThis.YGBENCHMARK = (name: string, fn: () => void) => { globalThis.YGBENCHMARK = (name: string, fn: () => void) => {
@@ -42,14 +42,14 @@ for (const type of ["asmjs", "wasm"]) {
const modulePath = path.resolve(file); const modulePath = path.resolve(file);
delete require.cache[require.resolve("../tools/globals")]; delete require.cache[require.resolve('../tools/globals')];
delete require.cache[modulePath]; delete require.cache[modulePath];
require(modulePath); require(modulePath);
} }
} }
console.log( console.log(
`Note: those tests are independants; there is no time relation to be expected between them` `Note: those tests are independants; there is no time relation to be expected between them`,
); );
for (const [name, results] of testResults) { for (const [name, results] of testResults) {
@@ -61,7 +61,7 @@ for (const [name, results] of testResults) {
for (const [type, result] of results) { for (const [type, result] of results) {
console.log( console.log(
` - ${type}: ${result}ms (${Math.round((result / min) * 10000) / 100}%)` ` - ${type}: ${result}ms (${Math.round((result / min) * 10000) / 100}%)`,
); );
} }
} }

View File

@@ -7,8 +7,8 @@
* @format * @format
*/ */
import type { MeasureFunction } from "yoga-layout"; import type {MeasureFunction} from 'yoga-layout';
import { Yoga } from "./globals"; import {Yoga} from './globals';
export type MeasureCounter = { export type MeasureCounter = {
inc: MeasureFunction; inc: MeasureFunction;
@@ -18,7 +18,7 @@ export type MeasureCounter = {
export function getMeasureCounter( export function getMeasureCounter(
cb?: MeasureFunction | null, cb?: MeasureFunction | null,
staticWidth = 0, staticWidth = 0,
staticHeight = 0 staticHeight = 0,
): MeasureCounter { ): MeasureCounter {
let counter = 0; let counter = 0;
@@ -28,7 +28,7 @@ export function getMeasureCounter(
return cb return cb
? cb(width, widthMode, height, heightMode) ? cb(width, widthMode, height, heightMode)
: { width: staticWidth, height: staticHeight }; : {width: staticWidth, height: staticHeight};
}, },
get: function () { get: function () {
@@ -44,7 +44,7 @@ export function getMeasureCounterMax(): MeasureCounter {
const measuredHeight = const measuredHeight =
heightMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : height; heightMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : height;
return { width: measuredWidth, height: measuredHeight }; return {width: measuredWidth, height: measuredHeight};
}); });
} }
@@ -61,6 +61,6 @@ export function getMeasureCounterMin(): MeasureCounter {
? 10 ? 10
: height; : height;
return { width: measuredWidth, height: measuredHeight }; return {width: measuredWidth, height: measuredHeight};
}); });
} }

View File

@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type { Yoga } from "yoga-layout"; import type {Yoga} from 'yoga-layout';
declare global { declare global {
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
@@ -24,4 +24,4 @@ if (globalThis.YGBENCHMARK === undefined) {
const yoga = globalThis.Yoga; const yoga = globalThis.Yoga;
const benchmark = globalThis.YGBENCHMARK; const benchmark = globalThis.YGBENCHMARK;
export { yoga as Yoga, benchmark as YGBENCHMARK }; export {yoga as Yoga, benchmark as YGBENCHMARK};