katex 0.16.32 → 0.16.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +3 -3
  2. package/contrib/auto-render/{auto-render.js → auto-render.ts} +41 -19
  3. package/contrib/auto-render/{splitAtDelimiters.js → splitAtDelimiters.ts} +18 -4
  4. package/contrib/auto-render/test/{auto-render-spec.js → auto-render-spec.ts} +10 -2
  5. package/contrib/copy-tex/README.md +2 -2
  6. package/contrib/copy-tex/{copy-tex.js → copy-tex.ts} +4 -6
  7. package/contrib/copy-tex/{katex2tex.js → katex2tex.ts} +2 -3
  8. package/contrib/mathtex-script-type/README.md +5 -5
  9. package/contrib/mhchem/README.md +1 -1
  10. package/contrib/render-a11y-string/{render-a11y-string.js → render-a11y-string.ts} +18 -33
  11. package/contrib/render-a11y-string/test/{render-a11y-string-spec.js → render-a11y-string-spec.ts} +0 -1
  12. package/dist/README.md +3 -3
  13. package/dist/contrib/auto-render.js +24 -57
  14. package/dist/contrib/auto-render.min.js +1 -1
  15. package/dist/contrib/auto-render.mjs +16586 -210
  16. package/dist/contrib/copy-tex.js +23 -37
  17. package/dist/contrib/copy-tex.min.js +1 -1
  18. package/dist/contrib/copy-tex.mjs +77 -95
  19. package/dist/contrib/mathtex-script-type.js +0 -3
  20. package/dist/contrib/mathtex-script-type.mjs +16427 -4
  21. package/dist/contrib/mhchem.js +55 -303
  22. package/dist/contrib/mhchem.mjs +12884 -723
  23. package/dist/contrib/render-a11y-string.js +13 -108
  24. package/dist/contrib/render-a11y-string.min.js +1 -1
  25. package/dist/contrib/render-a11y-string.mjs +17020 -760
  26. package/dist/katex-swap.css +2 -1
  27. package/dist/katex-swap.min.css +1 -1
  28. package/dist/katex.css +2 -1
  29. package/dist/katex.js +4547 -5680
  30. package/dist/katex.min.css +1 -1
  31. package/dist/katex.min.js +1 -1
  32. package/dist/katex.mjs +11854 -13828
  33. package/{katex.js → katex.ts} +8 -5
  34. package/package.json +34 -31
  35. package/src/{Lexer.js → Lexer.ts} +1 -2
  36. package/src/{MacroExpander.js → MacroExpander.ts} +11 -15
  37. package/src/{Namespace.js → Namespace.ts} +4 -6
  38. package/src/{Options.js → Options.ts} +7 -12
  39. package/src/{ParseError.js → ParseError.ts} +16 -26
  40. package/src/{Parser.js → Parser.ts} +68 -56
  41. package/src/{Settings.js → Settings.ts} +70 -70
  42. package/src/{SourceLocation.js → SourceLocation.ts} +6 -7
  43. package/src/{Style.js → Style.ts} +4 -5
  44. package/src/{Token.js → Token.ts} +8 -6
  45. package/src/{buildCommon.js → buildCommon.ts} +62 -55
  46. package/src/{buildHTML.js → buildHTML.ts} +29 -25
  47. package/src/{buildMathML.js → buildMathML.ts} +15 -13
  48. package/src/{buildTree.js → buildTree.ts} +1 -2
  49. package/src/{defineEnvironment.js → defineEnvironment.ts} +26 -27
  50. package/src/{defineFunction.js → defineFunction.ts} +54 -56
  51. package/src/{defineMacro.js → defineMacro.ts} +12 -13
  52. package/src/{delimiter.js → delimiter.ts} +19 -17
  53. package/src/{domTree.js → domTree.ts} +94 -103
  54. package/src/environments/{array.js → array.ts} +109 -99
  55. package/src/environments/{cd.js → cd.ts} +9 -11
  56. package/src/{environments.js → environments.ts} +0 -1
  57. package/src/{fontMetrics.js → fontMetrics.ts} +10 -12
  58. package/src/fontMetricsData.d.ts +3 -0
  59. package/src/functions/{accent.js → accent.ts} +1 -2
  60. package/src/functions/{accentunder.js → accentunder.ts} +0 -1
  61. package/src/functions/{arrow.js → arrow.ts} +4 -6
  62. package/src/functions/{char.js → char.ts} +0 -1
  63. package/src/functions/{color.js → color.ts} +5 -6
  64. package/src/functions/{cr.js → cr.ts} +0 -1
  65. package/src/functions/{def.js → def.ts} +9 -7
  66. package/src/functions/{delimsizing.js → delimsizing.ts} +11 -9
  67. package/src/functions/{enclose.js → enclose.ts} +3 -4
  68. package/src/functions/{environment.js → environment.ts} +2 -3
  69. package/src/functions/{font.js → font.ts} +4 -4
  70. package/src/functions/{genfrac.js → genfrac.ts} +14 -15
  71. package/src/functions/{hbox.js → hbox.ts} +0 -1
  72. package/src/functions/{horizBrace.js → horizBrace.ts} +4 -5
  73. package/src/functions/{href.js → href.ts} +4 -4
  74. package/src/functions/{html.js → html.ts} +3 -3
  75. package/src/functions/{htmlmathml.js → htmlmathml.ts} +0 -1
  76. package/src/functions/{includegraphics.js → includegraphics.ts} +0 -1
  77. package/src/functions/{kern.js → kern.ts} +0 -1
  78. package/src/functions/{lap.js → lap.ts} +0 -1
  79. package/src/functions/{math.js → math.ts} +0 -1
  80. package/src/functions/{mathchoice.js → mathchoice.ts} +2 -2
  81. package/src/functions/{mclass.js → mclass.ts} +5 -6
  82. package/src/functions/{op.js → op.ts} +9 -11
  83. package/src/functions/{operatorname.js → operatorname.ts} +4 -7
  84. package/src/functions/{ordgroup.js → ordgroup.ts} +0 -2
  85. package/src/functions/{overline.js → overline.ts} +0 -1
  86. package/src/functions/{phantom.js → phantom.ts} +0 -1
  87. package/src/functions/{pmb.js → pmb.ts} +0 -1
  88. package/src/functions/{raisebox.js → raisebox.ts} +0 -1
  89. package/src/functions/{relax.js → relax.ts} +0 -1
  90. package/src/functions/{rule.js → rule.ts} +0 -1
  91. package/src/functions/{sizing.js → sizing.ts} +0 -1
  92. package/src/functions/{smash.js → smash.ts} +2 -4
  93. package/src/functions/{sqrt.js → sqrt.ts} +0 -1
  94. package/src/functions/{styling.js → styling.ts} +3 -3
  95. package/src/functions/{supsub.js → supsub.ts} +6 -8
  96. package/src/functions/{symbolsOp.js → symbolsOp.ts} +0 -2
  97. package/src/functions/{symbolsOrd.js → symbolsOrd.ts} +1 -2
  98. package/src/functions/{symbolsSpacing.js → symbolsSpacing.ts} +2 -3
  99. package/src/functions/{tag.js → tag.ts} +0 -2
  100. package/src/functions/{text.js → text.ts} +7 -6
  101. package/src/functions/{underline.js → underline.ts} +0 -1
  102. package/src/functions/utils/{assembleSupSub.js → assembleSupSub.ts} +2 -3
  103. package/src/functions/{vcenter.js → vcenter.ts} +0 -2
  104. package/src/functions/{verb.js → verb.ts} +0 -1
  105. package/src/{functions.js → functions.ts} +0 -1
  106. package/src/{macros.js → macros.ts} +10 -8
  107. package/src/{mathMLTree.js → mathMLTree.ts} +5 -6
  108. package/src/parseNode.ts +522 -0
  109. package/src/{parseTree.js → parseTree.ts} +5 -3
  110. package/src/{spacingData.js → spacingData.ts} +11 -12
  111. package/src/{stretchy.js → stretchy.ts} +7 -7
  112. package/src/styles/katex-swap.scss +1 -4
  113. package/src/styles/katex.scss +9 -0
  114. package/src/{svgGeometry.js → svgGeometry.ts} +1 -2
  115. package/src/{symbols.js → symbols.ts} +6 -6
  116. package/src/{tree.js → tree.ts} +5 -7
  117. package/src/{types.js → types.ts} +1 -2
  118. package/src/unicodeAccents.js +4 -1
  119. package/src/{unicodeScripts.js → unicodeScripts.ts} +1 -3
  120. package/src/{unicodeSupOrSub.js → unicodeSupOrSub.ts} +1 -1
  121. package/src/unicodeSymbols.js +4 -3
  122. package/src/{units.js → units.ts} +2 -4
  123. package/src/{utils.js → utils.ts} +2 -3
  124. package/src/{wide-character.js → wide-character.ts} +8 -10
  125. package/types/katex.d.ts +13 -12
  126. package/src/parseNode.js +0 -523
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /* eslint no-console:0 */
3
2
  /**
4
3
  * This is the main entry point for KaTeX. Here, we expose functions for
@@ -32,13 +31,17 @@ import defineFunction from './src/defineFunction';
32
31
  import defineMacro from './src/defineMacro';
33
32
  import {setFontMetrics} from './src/fontMetrics';
34
33
 
35
- declare var __VERSION__: string;
34
+ declare let __VERSION__: string;
36
35
 
37
36
  /**
38
37
  * Parse and build an expression, and place that expression in the DOM node
39
38
  * given.
40
39
  */
41
- let render: (string, Node, SettingsOptions) => void = function(
40
+ let render: (
41
+ expression: string,
42
+ baseNode: Node,
43
+ options: SettingsOptions,
44
+ ) => void = function(
42
45
  expression: string,
43
46
  baseNode: Node,
44
47
  options: SettingsOptions,
@@ -78,7 +81,7 @@ const renderToString = function(
78
81
  */
79
82
  const generateParseTree = function(
80
83
  expression: string,
81
- options: SettingsOptions,
84
+ options?: SettingsOptions,
82
85
  ): AnyParseNode[] {
83
86
  const settings = new Settings(options);
84
87
  return parseTree(expression, settings);
@@ -90,7 +93,7 @@ const generateParseTree = function(
90
93
  * error message. Otherwise, simply throws the error.
91
94
  */
92
95
  const renderError = function(
93
- error,
96
+ error: unknown,
94
97
  expression: string,
95
98
  options: Settings,
96
99
  ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.16.32",
3
+ "version": "0.16.34",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "types": "types/katex.d.ts",
@@ -47,7 +47,7 @@
47
47
  "https://github.com/sponsors/katex"
48
48
  ],
49
49
  "files": [
50
- "katex.js",
50
+ "katex.ts",
51
51
  "cli.js",
52
52
  "src/",
53
53
  "contrib/",
@@ -57,22 +57,25 @@
57
57
  "license": "MIT",
58
58
  "packageManager": "yarn@4.1.1",
59
59
  "devDependencies": {
60
- "@babel/core": "^7.18.13",
61
- "@babel/eslint-parser": "^7.18.9",
60
+ "@babel/core": "^7.29.0",
61
+ "@babel/eslint-parser": "^7.28.6",
62
62
  "@babel/plugin-proposal-class-properties": "^7.18.6",
63
- "@babel/plugin-syntax-flow": "^7.18.6",
64
- "@babel/plugin-transform-react-jsx": "^7.18.10",
65
- "@babel/plugin-transform-runtime": "^7.18.10",
66
- "@babel/preset-env": "^7.18.10",
67
- "@babel/preset-flow": "^7.18.6",
68
- "@babel/preset-react": "^7.18.6",
69
- "@babel/register": "^7.18.9",
70
- "@babel/runtime": "^7.18.9",
63
+ "@babel/plugin-transform-react-jsx": "^7.28.6",
64
+ "@babel/plugin-transform-runtime": "^7.29.0",
65
+ "@babel/preset-env": "^7.29.0",
66
+ "@babel/preset-react": "^7.28.5",
67
+ "@babel/preset-typescript": "^7.28.5",
68
+ "@babel/register": "^7.28.6",
69
+ "@babel/runtime": "^7.28.6",
71
70
  "@rollup/plugin-alias": "^3.1.9",
72
71
  "@rollup/plugin-babel": "^5.3.1",
72
+ "@rollup/plugin-commonjs": "^28.0.9",
73
+ "@rollup/plugin-typescript": "^12.3.0",
73
74
  "@semantic-release/changelog": "^6.0.1",
74
75
  "@semantic-release/git": "^10.0.1",
75
- "babel-jest": "^29.0.1",
76
+ "@typescript-eslint/eslint-plugin": "^8.56.0",
77
+ "@typescript-eslint/parser": "^8.56.0",
78
+ "babel-jest": "^30.2.0",
76
79
  "babel-loader": "^8.2.5",
77
80
  "babel-plugin-istanbul": "^6.1.1",
78
81
  "babel-plugin-preval": "^5.1.0",
@@ -84,23 +87,21 @@
84
87
  "css-loader": "^6.7.1",
85
88
  "cssnano": "^5.1.13",
86
89
  "eslint": "^8.23.0",
87
- "eslint-import-resolver-webpack": "^0.13.2",
90
+ "eslint-import-resolver-webpack": "^0.13.10",
88
91
  "eslint-plugin-actions": "^2.0.0",
89
- "eslint-plugin-flowtype": "^8.0.3",
90
92
  "eslint-plugin-import": "^2.26.0",
91
93
  "eslint-plugin-react": "^7.31.1",
92
- "flow-bin": "^0.135.0",
93
94
  "fs-extra": "^10.1.0",
94
95
  "got": "^11.8.5",
95
96
  "husky": "^4.3.8",
96
97
  "istanbul-lib-coverage": "^3.2.0",
97
98
  "istanbul-lib-report": "^3.0.0",
98
99
  "istanbul-reports": "^3.1.5",
99
- "jest": "^29.0.1",
100
- "jest-diff": "^29.0.1",
101
- "jest-environment-jsdom": "^29.0.1",
102
- "jest-matcher-utils": "^29.0.1",
103
- "jest-message-util": "^29.0.1",
100
+ "jest": "^30.2.0",
101
+ "jest-diff": "^30.2.0",
102
+ "jest-environment-jsdom": "^30.2.0",
103
+ "jest-matcher-utils": "^30.2.0",
104
+ "jest-message-util": "^30.2.0",
104
105
  "jest-serializer-html": "^7.1.0",
105
106
  "js-yaml": "^4.1.0",
106
107
  "json-stable-stringify": "^1.0.1",
@@ -126,6 +127,8 @@
126
127
  "stylelint-config-standard": "^28.0.0",
127
128
  "stylelint-scss": "^6.3.2",
128
129
  "terser-webpack-plugin": "^5.3.6",
130
+ "tslib": "^2.8.1",
131
+ "typescript": "^5.9.3",
129
132
  "webpack": "^5.74.0",
130
133
  "webpack-bundle-analyzer": "^4.6.1",
131
134
  "webpack-cli": "^4.10.0",
@@ -134,18 +137,18 @@
134
137
  },
135
138
  "bin": "cli.js",
136
139
  "scripts": {
137
- "test": "yarn test:lint && yarn test:flow && yarn test:jest",
140
+ "test": "yarn test:lint && yarn test:ts && yarn test:jest",
138
141
  "test:lint": "yarn test:lint:js && yarn test:lint:css",
139
142
  "test:lint:js": "eslint .",
140
143
  "test:lint:css": "stylelint src/styles/katex.scss static/main.css website/static/**/*.css",
141
- "test:flow": "flow",
142
144
  "test:jest": "jest",
143
145
  "test:jest:watch": "jest --watch",
144
146
  "test:jest:update": "jest --updateSnapshot",
145
147
  "test:jest:coverage": "jest --coverage",
146
148
  "test:screenshots": "yarn test:screenshots:update --verify",
147
149
  "test:screenshots:update": "dockers/screenshotter/screenshotter.sh",
148
- "test:perf": "NODE_ENV=test node test/perf-test.js",
150
+ "test:perf": "NODE_ENV=test node -e \"require('@babel/register')({extensions:['.js','.ts']}); require('./test/perf-test.ts')\"",
151
+ "test:ts": "tsc --noEmit",
149
152
  "clean": "rm -rf dist/ node_modules/",
150
153
  "clean-install": "yarn clean && yarn",
151
154
  "start": "webpack serve --config webpack.dev.js",
@@ -169,28 +172,28 @@
169
172
  },
170
173
  "jest": {
171
174
  "collectCoverageFrom": [
172
- "src/**/*.js",
173
- "contrib/**/*.js",
174
- "!src/unicodeSymbols.js",
175
+ "src/**/*.{js,ts}",
176
+ "contrib/**/*.{js,ts}",
177
+ "!src/unicodeSymbols.{js,ts}",
175
178
  "!contrib/mhchem/**"
176
179
  ],
177
180
  "setupFilesAfterEnv": [
178
- "<rootDir>/test/setup.js"
181
+ "<rootDir>/test/setup.ts"
179
182
  ],
180
183
  "snapshotSerializers": [
181
184
  "jest-serializer-html"
182
185
  ],
183
186
  "testMatch": [
184
- "**/test/*-spec.js"
187
+ "**/test/*-spec.ts"
185
188
  ],
186
189
  "testEnvironmentOptions": {
187
190
  "url": "http://localhost/"
188
191
  },
189
192
  "transform": {
190
- "^.+\\.js$": "babel-jest"
193
+ "^.+\\.(js|ts)$": "babel-jest"
191
194
  },
192
195
  "moduleNameMapper": {
193
- "^katex$": "<rootDir>/katex.js"
196
+ "^katex$": "<rootDir>/katex.ts"
194
197
  }
195
198
  }
196
199
  }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /**
3
2
  * The Lexer class handles tokenizing the input in various ways. Since our
4
3
  * parser expects us to be able to backtrack, the lexer allows lexing from any
@@ -69,7 +68,7 @@ export default class Lexer implements LexerInterface {
69
68
  tokenRegex: RegExp;
70
69
  // Category codes. The lexer only supports comment characters (14) for now.
71
70
  // MacroExpander additionally distinguishes active (13).
72
- catcodes: {[string]: number};
71
+ catcodes: Record<string, number>;
73
72
 
74
73
  constructor(input: string, settings: Settings) {
75
74
  // Separate accents from characters
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /**
3
2
  * This file contains the “gullet” where macros are expanded
4
3
  * until only non-macro tokens remain.
@@ -30,7 +29,7 @@ export const implicitCommands = {
30
29
  export default class MacroExpander implements MacroContextInterface {
31
30
  settings: Settings;
32
31
  expansionCount: number;
33
- lexer: Lexer;
32
+ lexer!: Lexer;
34
33
  macros: Namespace<MacroDefinition>;
35
34
  stack: Token[];
36
35
  mode: Mode;
@@ -98,7 +97,7 @@ export default class MacroExpander implements MacroContextInterface {
98
97
  */
99
98
  popToken(): Token {
100
99
  this.future(); // ensure non-empty stack
101
- return this.stack.pop();
100
+ return this.stack.pop()!;
102
101
  }
103
102
 
104
103
  /**
@@ -120,7 +119,7 @@ export default class MacroExpander implements MacroContextInterface {
120
119
  * Find an macro argument without expanding tokens and append the array of
121
120
  * tokens to the token stack. Uses Token as a container for the result.
122
121
  */
123
- scanArgument(isOptional: boolean): ?Token {
122
+ scanArgument(isOptional: boolean): Token | null | undefined {
124
123
  let start;
125
124
  let end;
126
125
  let tokens;
@@ -160,7 +159,7 @@ export default class MacroExpander implements MacroContextInterface {
160
159
  * Consume an argument from the token stream, and return the resulting array
161
160
  * of tokens and start/end token.
162
161
  */
163
- consumeArg(delims?: ?string[]): MacroArg {
162
+ consumeArg(delims?: string[] | null | undefined): MacroArg {
164
163
  // The argument for a delimited parameter is the shortest (possibly
165
164
  // empty) sequence of tokens with properly nested {...} groups that is
166
165
  // followed ... by this particular list of non-parameter tokens.
@@ -339,7 +338,7 @@ export default class MacroExpander implements MacroContextInterface {
339
338
  expandNextToken(): Token {
340
339
  for (;;) {
341
340
  if (this.expandOnce() === false) { // fully expanded
342
- const token = this.stack.pop();
341
+ const token = this.stack.pop()!;
343
342
  // the token after \noexpand is interpreted as if its meaning
344
343
  // were ‘\relax’
345
344
  if (token.treatAsRelax) {
@@ -348,17 +347,13 @@ export default class MacroExpander implements MacroContextInterface {
348
347
  return token;
349
348
  }
350
349
  }
351
-
352
- // Flow unable to figure out that this pathway is impossible.
353
- // https://github.com/facebook/flow/issues/4808
354
- throw new Error(); // eslint-disable-line no-unreachable
355
350
  }
356
351
 
357
352
  /**
358
353
  * Fully expand the given macro name and return the resulting list of
359
354
  * tokens, or return `undefined` if no such macro is defined.
360
355
  */
361
- expandMacro(name: string): Token[] | void {
356
+ expandMacro(name: string): Token[] | undefined {
362
357
  return this.macros.has(name)
363
358
  ? this.expandTokens([new Token(name)]) : undefined;
364
359
  }
@@ -369,13 +364,13 @@ export default class MacroExpander implements MacroContextInterface {
369
364
  * output tokens are in forward order.
370
365
  */
371
366
  expandTokens(tokens: Token[]): Token[] {
372
- const output = [];
367
+ const output: Token[] = [];
373
368
  const oldStackLength = this.stack.length;
374
369
  this.pushTokens(tokens);
375
370
  while (this.stack.length > oldStackLength) {
376
371
  // Expand only expandable tokens
377
372
  if (this.expandOnce(true) === false) { // fully expanded
378
- const token = this.stack.pop();
373
+ const token = this.stack.pop()!;
379
374
  if (token.treatAsRelax) {
380
375
  // the expansion of \noexpand is the token itself
381
376
  token.noexpand = false;
@@ -394,7 +389,7 @@ export default class MacroExpander implements MacroContextInterface {
394
389
  * Fully expand the given macro name and return the result as a string,
395
390
  * or return `undefined` if no such macro is defined.
396
391
  */
397
- expandMacroAsText(name: string): string | void {
392
+ expandMacroAsText(name: string): string | undefined {
398
393
  const tokens = this.expandMacro(name);
399
394
  if (tokens) {
400
395
  return tokens.map((token) => token.text).join("");
@@ -407,8 +402,9 @@ export default class MacroExpander implements MacroContextInterface {
407
402
  * Returns the expanded macro as a reversed array of tokens and a macro
408
403
  * argument count. Or returns `null` if no such macro.
409
404
  */
410
- _getExpansion(name: string): ?MacroExpansion {
405
+ _getExpansion(name: string): MacroExpansion | null | undefined {
411
406
  const definition = this.macros.get(name);
407
+
412
408
  if (definition == null) { // mainly checking for undefined here
413
409
  return definition;
414
410
  }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
 
3
2
  /**
4
3
  * A `Namespace` refers to a space of nameable things like macros or lengths,
@@ -9,13 +8,12 @@
9
8
  */
10
9
 
11
10
  import ParseError from "./ParseError";
12
-
13
- export type Mapping<Value> = {[string]: Value};
11
+ export type Mapping<Value> = Record<string, Value>;
14
12
 
15
13
  export default class Namespace<Value> {
16
14
  current: Mapping<Value>;
17
15
  builtins: Mapping<Value>;
18
- undefStack: Mapping<?Value>[];
16
+ undefStack: Mapping<Value | null | undefined>[];
19
17
 
20
18
  /**
21
19
  * Both arguments are optional. The first argument is an object of
@@ -84,7 +82,7 @@ export default class Namespace<Value> {
84
82
  * to `false` in JavaScript. Use `if (namespace.get(...) != null)` or
85
83
  * `if (namespace.has(...))`.
86
84
  */
87
- get(name: string): ?Value {
85
+ get(name: string): Value | null | undefined {
88
86
  if (this.current.hasOwnProperty(name)) {
89
87
  return this.current[name];
90
88
  } else {
@@ -99,7 +97,7 @@ export default class Namespace<Value> {
99
97
  * operation at every level, so takes time linear in their number.
100
98
  * A value of undefined means to delete existing definitions.
101
99
  */
102
- set(name: string, value: ?Value, global: boolean = false) {
100
+ set(name: string, value: Value | null | undefined, global: boolean = false) {
103
101
  if (global) {
104
102
  // Global set is equivalent to setting in all groups. Simulate this
105
103
  // by destroying any undos currently scheduled for this name,
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /**
3
2
  * This file contains information about the options that the Parser carries
4
3
  * around with it while parsing. Data is held in an `Options` object, and when
@@ -42,7 +41,7 @@ export type FontShape = "textit" | "textup" | "";
42
41
 
43
42
  export type OptionsData = {
44
43
  style: StyleInterface;
45
- color?: string | void;
44
+ color?: string | undefined;
46
45
  size?: number;
47
46
  textSize?: number;
48
47
  phantom?: boolean;
@@ -64,7 +63,7 @@ export type OptionsData = {
64
63
  */
65
64
  class Options {
66
65
  style: StyleInterface;
67
- color: string | void;
66
+ color: string | undefined;
68
67
  size: number;
69
68
  textSize: number;
70
69
  phantom: boolean;
@@ -78,7 +77,7 @@ class Options {
78
77
  sizeMultiplier: number;
79
78
  maxSize: number;
80
79
  minRuleThickness: number;
81
- _fontMetrics: FontMetrics | void;
80
+ _fontMetrics: FontMetrics | undefined;
82
81
 
83
82
  /**
84
83
  * The base size index.
@@ -105,8 +104,8 @@ class Options {
105
104
  * Returns a new options object with the same properties as "this". Properties
106
105
  * from "extension" will be copied to the new options object.
107
106
  */
108
- extend(extension: $Shape<OptionsData>): Options {
109
- const data = {
107
+ extend(extension: Partial<OptionsData>): Options {
108
+ const data: OptionsData = {
110
109
  style: this.style,
111
110
  size: this.size,
112
111
  textSize: this.textSize,
@@ -120,11 +119,7 @@ class Options {
120
119
  minRuleThickness: this.minRuleThickness,
121
120
  };
122
121
 
123
- for (const key in extension) {
124
- if (extension.hasOwnProperty(key)) {
125
- data[key] = extension[key];
126
- }
127
- }
122
+ Object.assign(data, extension);
128
123
 
129
124
  return new Options(data);
130
125
  }
@@ -307,7 +302,7 @@ class Options {
307
302
  /**
308
303
  * Gets the CSS color of the current options object
309
304
  */
310
- getColor(): string | void {
305
+ getColor(): string | undefined {
311
306
  if (this.phantom) {
312
307
  return "transparent";
313
308
  } else {
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {Token} from "./Token";
3
2
 
4
3
  import type {AnyParseNode} from "./parseNode";
@@ -11,19 +10,19 @@ import type {AnyParseNode} from "./parseNode";
11
10
  * If possible, a caller should provide a Token or ParseNode with information
12
11
  * about where in the source string the problem occurred.
13
12
  */
14
- class ParseError {
15
- name: "ParseError";
16
- position: number | void;
17
- // Error start position based on passed-in Token or ParseNode.
18
- length: number | void;
19
- // Length of affected text based on passed-in Token or ParseNode.
20
- rawMessage: string | void;
21
- // The underlying error message without any context added.
13
+ class ParseError extends Error {
14
+ override name = "ParseError" as const;
15
+ position: number | undefined;
16
+ // Error start position based on passed-in Token or ParseNode.
17
+ length: number | undefined;
18
+ // Length of affected text based on passed-in Token or ParseNode.
19
+ rawMessage: string;
20
+ // The underlying error message without any context added.
22
21
 
23
22
  constructor(
24
- message: string, // The error message
25
- token?: ?Token | AnyParseNode, // An object providing position information
26
- ): ParseError {
23
+ message: string, // The error message
24
+ token?: Token | null | undefined | AnyParseNode,
25
+ ) {
27
26
  let error = "KaTeX parse error: " + message;
28
27
  let start;
29
28
  let end;
@@ -64,23 +63,14 @@ class ParseError {
64
63
 
65
64
  }
66
65
 
67
- // Some hackery to make ParseError a prototype of Error
68
- // See http://stackoverflow.com/a/8460753
69
- // $FlowFixMe
70
- const self: ParseError = new Error(error);
71
- self.name = "ParseError";
72
- // $FlowFixMe
73
- self.__proto__ = ParseError.prototype;
74
- self.position = start;
66
+ super(error);
67
+ Object.setPrototypeOf(this, ParseError.prototype);
68
+ this.position = start;
75
69
  if (start != null && end != null) {
76
- self.length = end - start;
70
+ this.length = end - start;
77
71
  }
78
- self.rawMessage = message;
79
- return self;
72
+ this.rawMessage = message;
80
73
  }
81
74
  }
82
75
 
83
- // $FlowFixMe More hackery
84
- ParseError.prototype.__proto__ = Error.prototype;
85
-
86
76
  export default ParseError;