From 0ce53e76310fdc2fa93415db23414071bfe18f02 Mon Sep 17 00:00:00 2001 From: Ashish Myles Date: Mon, 5 Mar 2018 23:43:01 -0500 Subject: [PATCH] Port spacingData and unicodeSymbols to @flow. (#1195) * Port spacingData and unicodeSymbols to @flow. * Review fixes. * Made Measurement an exact object type. --- src/spacingData.js | 28 +++++++++++++++++++++++----- src/unicodeMake.js | 1 + src/unicodeSymbols.js | 1 + src/units.js | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/spacingData.js b/src/spacingData.js index a726e645..9a04401a 100644 --- a/src/spacingData.js +++ b/src/spacingData.js @@ -1,22 +1,40 @@ +// @flow /** * Describes spaces between different classes of atoms. */ +import type {Measurement} from "./units"; -const thinspace = { +const thinspace: Measurement = { number: 3, unit: "mu", }; -const mediumspace = { +const mediumspace: Measurement = { number: 4, unit: "mu", }; -const thickspace = { +const thickspace: Measurement = { number: 5, unit: "mu", }; +// Making the type below exact with all optional fields doesn't work due to +// - https://github.com/facebook/flow/issues/4582 +// - https://github.com/facebook/flow/issues/5688 +// However, since *all* fields are optional, $Shape<> works as suggested in 5688 +// above. +export type Spacings = $Shape<{ + mord: Measurement, + mop: Measurement, + mbin: Measurement, + mrel: Measurement, + mopen: Measurement, + mclose: Measurement, + mpunct: Measurement, + minner: Measurement, +}> & {}; + // Spacing relationships for display and text styles -export const spacings = { +export const spacings: {[$Keys]: Spacings} = { mord: { mop: thinspace, mbin: mediumspace, @@ -69,7 +87,7 @@ export const spacings = { }; // Spacing relationships for script and scriptscript styles -export const tightSpacings = { +export const tightSpacings: {[$Keys]: Spacings} = { mord: { mop: thinspace, }, diff --git a/src/unicodeMake.js b/src/unicodeMake.js index 68e2a892..cd7be200 100644 --- a/src/unicodeMake.js +++ b/src/unicodeMake.js @@ -7,6 +7,7 @@ const accents = require('./unicodeAccents'); +console.log("// @flow"); console.log("// This file is GENERATED by unicodeMake.js. DO NOT MODIFY."); console.log(""); diff --git a/src/unicodeSymbols.js b/src/unicodeSymbols.js index 3b100479..846ca73b 100644 --- a/src/unicodeSymbols.js +++ b/src/unicodeSymbols.js @@ -1,3 +1,4 @@ +// @flow // This file is GENERATED by unicodeMake.js. DO NOT MODIFY. export default { diff --git a/src/units.js b/src/units.js index 13bc2683..190e7f8e 100644 --- a/src/units.js +++ b/src/units.js @@ -37,7 +37,7 @@ const relativeUnit = { "mu": true, }; -export type Measurement = {number: number, unit: string}; +export type Measurement = {| number: number, unit: string |}; /** * Determine whether the specified unit (either a string defining the unit