diff --git a/.flowconfig b/.flowconfig index 91961148..cacdd9a7 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,5 +1,5 @@ [version] -0.133.0 +0.134.0 [ignore] /dist diff --git a/.yarn/sdks/flow-bin/package.json b/.yarn/sdks/flow-bin/package.json index 87f02652..d1434259 100644 --- a/.yarn/sdks/flow-bin/package.json +++ b/.yarn/sdks/flow-bin/package.json @@ -1,5 +1,5 @@ { "name": "flow-bin", - "version": "0.133.0-pnpify", + "version": "0.134.0-pnpify", "type": "commonjs" } diff --git a/contrib/render-a11y-string/render-a11y-string.js b/contrib/render-a11y-string/render-a11y-string.js index b04c4eaf..3ec0bc6f 100644 --- a/contrib/render-a11y-string/render-a11y-string.js +++ b/contrib/render-a11y-string/render-a11y-string.js @@ -710,7 +710,10 @@ const flatten = function(array) { return result; }; -const renderA11yString = function(text: string, settings?: SettingsOptions) { +const renderA11yString = function( + text: string, + settings?: SettingsOptions, +): string { const tree = katex.__parse(text, settings); const a11yStrings = buildA11yStrings(tree, [], "normal"); diff --git a/katex.js b/katex.js index 7840ae69..9824c2db 100644 --- a/katex.js +++ b/katex.js @@ -25,6 +25,7 @@ import { import type {SettingsOptions} from "./src/Settings"; import type {AnyParseNode} from "./src/parseNode"; +import type {DomSpan} from "./src/domTree"; import {defineSymbol} from './src/symbols'; import {defineMacro} from './src/macros'; @@ -36,7 +37,7 @@ declare var __VERSION__: string; * Parse and build an expression, and place that expression in the DOM node * given. */ -let render = function( +let render: (string, Node, SettingsOptions) => void = function( expression: string, baseNode: Node, options: SettingsOptions, @@ -109,7 +110,7 @@ const renderError = function( const renderToDomTree = function( expression: string, options: SettingsOptions, -) { +): DomSpan { const settings = new Settings(options); try { const tree = parseTree(expression, settings); @@ -126,7 +127,7 @@ const renderToDomTree = function( const renderToHTMLTree = function( expression: string, options: SettingsOptions, -) { +): DomSpan { const settings = new Settings(options); try { const tree = parseTree(expression, settings); diff --git a/package.json b/package.json index 1b0320bf..c22b862c 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "eslint-plugin-flowtype": "^5.2.0", "eslint-plugin-react": "^7.20.3", "file-loader": "^6.0.0", - "flow-bin": "^0.133.0", + "flow-bin": "^0.134.0", "fs-extra": "^9.0.1", "husky": "^4.2.5", "istanbul-lib-coverage": "^3.0.0", diff --git a/src/Lexer.js b/src/Lexer.js index c7f2180d..c9271c1f 100644 --- a/src/Lexer.js +++ b/src/Lexer.js @@ -42,7 +42,7 @@ const controlWordWhitespaceRegexString = const controlWordWhitespaceRegex = new RegExp( `^(${controlWordRegexString})${spaceRegexString}*$`); const combiningDiacriticalMarkString = "[\u0300-\u036f]"; -export const combiningDiacriticalMarksEndRegex = +export const combiningDiacriticalMarksEndRegex: RegExp = new RegExp(`${combiningDiacriticalMarkString}+$`); const tokenRegexString = `(${spaceRegexString}+)|` + // whitespace "([!-\\[\\]-\u2027\u202A-\uD7FF\uF900-\uFFFF]" + // single codepoint diff --git a/src/Options.js b/src/Options.js index 8f20ae02..060b9222 100644 --- a/src/Options.js +++ b/src/Options.js @@ -83,7 +83,7 @@ class Options { /** * The base size index. */ - static BASESIZE = 6; + static BASESIZE: number = 6; constructor(data: OptionsData) { this.style = data.style; @@ -242,7 +242,7 @@ class Options { /** * Create a new options objects with the given fontFamily. */ - withTextFontFamily(fontFamily: string) { + withTextFontFamily(fontFamily: string): Options { return this.extend({ fontFamily, font: "", diff --git a/src/ParseError.js b/src/ParseError.js index 49118be1..f0c62613 100644 --- a/src/ParseError.js +++ b/src/ParseError.js @@ -18,7 +18,7 @@ class ParseError { constructor( message: string, // The error message token?: ?Token | AnyParseNode, // An object providing position information - ) { + ): Error { let error = "KaTeX parse error: " + message; let start; diff --git a/src/Parser.js b/src/Parser.js index a5ce3a87..c5448740 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -143,7 +143,7 @@ export default class Parser { return parse; } - static endOfExpression = ["}", "\\endgroup", "\\end", "\\right", "&"]; + static endOfExpression: string[] = ["}", "\\endgroup", "\\end", "\\right", "&"]; /** * Parses an "expression", which is a list of atoms. diff --git a/src/Settings.js b/src/Settings.js index 5e258c2e..c29271ae 100644 --- a/src/Settings.js +++ b/src/Settings.js @@ -158,7 +158,7 @@ export default class Settings { * This is for the second category of `errorCode`s listed in the README. */ useStrictBehavior(errorCode: string, errorMsg: string, - token?: Token | AnyParseNode) { + token?: Token | AnyParseNode): boolean { let strict = this.strict; if (typeof strict === "function") { // Allow return value of strict function to be boolean or string @@ -196,7 +196,7 @@ export default class Settings { * If `context` has a `url` field, a `protocol` field will automatically * get added by this function (changing the specified object). */ - isTrusted(context: AnyTrustContext) { + isTrusted(context: AnyTrustContext): boolean { if (context.url && !context.protocol) { context.protocol = utils.protocolFromUrl(context.url); } diff --git a/src/Style.js b/src/Style.js index 6304c472..b77d6456 100644 --- a/src/Style.js +++ b/src/Style.js @@ -123,8 +123,8 @@ const text = [D, Dc, T, Tc, T, Tc, T, Tc]; // We only export some of the styles. export default { - DISPLAY: styles[D], - TEXT: styles[T], - SCRIPT: styles[S], - SCRIPTSCRIPT: styles[SS], + DISPLAY: (styles[D]: Style), + TEXT: (styles[T]: Style), + SCRIPT: (styles[S]: Style), + SCRIPTSCRIPT: (styles[SS]: Style), }; diff --git a/src/Token.js b/src/Token.js index 5ceaf168..2a84b4e7 100644 --- a/src/Token.js +++ b/src/Token.js @@ -41,7 +41,7 @@ export class Token { range( endToken: Token, // last token of the range, inclusive text: string, // the text of the newly constructed token - ) { + ): Token { return new Token(text, SourceLocation.range(this, endToken)); } } diff --git a/src/buildCommon.js b/src/buildCommon.js index 0f8c309c..6d26beed 100644 --- a/src/buildCommon.js +++ b/src/buildCommon.js @@ -349,7 +349,7 @@ const makeLineSpan = function( className: string, options: Options, thickness?: number, -) { +): DomSpan { const line = makeSpan([className], [], options); line.height = Math.max( thickness || options.fontMetrics().defaultRuleThickness, @@ -369,7 +369,7 @@ const makeAnchor = function( classes: string[], children: HtmlDomNode[], options: Options, -) { +): Anchor { const anchor = new Anchor(href, classes, children, options); sizeElementFromChildren(anchor); diff --git a/src/functions/color.js b/src/functions/color.js index 5c557451..ad658387 100644 --- a/src/functions/color.js +++ b/src/functions/color.js @@ -4,6 +4,8 @@ import buildCommon from "../buildCommon"; import mathMLTree from "../mathMLTree"; import {assertNodeType} from "../parseNode"; +import type {AnyParseNode} from '../parseNode'; + import * as html from "../buildHTML"; import * as mml from "../buildMathML"; @@ -47,7 +49,7 @@ defineFunction({ type: "color", mode: parser.mode, color, - body: ordargument(body), + body: (ordargument(body): AnyParseNode[]), }; }, htmlBuilder, @@ -72,7 +74,7 @@ defineFunction({ parser.gullet.macros.set("\\current@color", color); // Parse out the implicit body that should be colored. - const body = parser.parseExpression(true, breakOnTokenText); + const body: AnyParseNode[] = parser.parseExpression(true, breakOnTokenText); return { type: "color", diff --git a/webpack.analyze.js b/webpack.analyze.js index 76aaa7ae..02590d64 100644 --- a/webpack.analyze.js +++ b/webpack.analyze.js @@ -3,8 +3,8 @@ const {targets, createConfig} = require('./webpack.common'); // $FlowIgnore const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; -// dev minify -const katexConfig = createConfig(targets.shift(), false, false); +// dev minify +const katexConfig /*: Object */ = createConfig(targets.shift(), false, false); katexConfig.plugins.push(new BundleAnalyzerPlugin()); diff --git a/webpack.common.js b/webpack.common.js index 75e52af9..480d7421 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -172,6 +172,7 @@ function createConfig(target /*: Target */, dev /*: boolean */, plugins: [PnpWebpackPlugin], }, resolveLoader: { + // $FlowIgnore plugins: [PnpWebpackPlugin.moduleLoader(module)], }, }; diff --git a/webpack.config.js b/webpack.config.js index 74fd18de..0b95027a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,7 @@ // @flow const {targets, createConfig} = require('./webpack.common'); -module.exports = [ // dev minify +module.exports = ([ // dev minify ...targets.map(target => createConfig(target, false, false)), ...targets.map(target => createConfig(target, false, true)), -]; +] /*: Array */); diff --git a/webpack.dev.js b/webpack.dev.js index 11e927b4..74d2f2f2 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -3,8 +3,8 @@ const {targets, createConfig} = require('./webpack.common'); const path = require('path'); const PORT = 7936; -// dev minify -const katexConfig = createConfig(targets.shift(), true, false); +// dev minify +const katexConfig /*: Object*/ = createConfig(targets.shift(), true, false); // add the entry point for test page katexConfig.entry.main = './static/main.js'; @@ -24,7 +24,7 @@ katexConfig.devServer = { }, }; -module.exports = [ +module.exports = ([ katexConfig, ...targets.map(target => createConfig(target, true, false)), -]; +] /*: Array */); diff --git a/yarn.lock b/yarn.lock index fa91b0d5..f454ef68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5345,12 +5345,12 @@ __metadata: languageName: node linkType: hard -"flow-bin@npm:^0.133.0": - version: 0.133.0 - resolution: "flow-bin@npm:0.133.0" +"flow-bin@npm:^0.134.0": + version: 0.134.0 + resolution: "flow-bin@npm:0.134.0" bin: flow: cli.js - checksum: b767946fb8763372127d7c7fd013a8c39de2066e59e19210aba17e6e7bb772bdd19f225b90466ca02bcdb2523463d59eb10d15f671d1ea024612219ed9f44fb2 + checksum: 8858ccda62b4e7d30c1672cb48dfcd43c9421c89c692f295224090032573b1488a07abbd7cabdd9d4e2acd8792467d67e7fbeaeb0792191af772e4eae70c4010 languageName: node linkType: hard @@ -7657,7 +7657,7 @@ fsevents@^1.2.7: eslint-plugin-flowtype: ^5.2.0 eslint-plugin-react: ^7.20.3 file-loader: ^6.0.0 - flow-bin: ^0.133.0 + flow-bin: ^0.134.0 fs-extra: ^9.0.1 husky: ^4.2.5 istanbul-lib-coverage: ^3.0.0