Skip to content

Commit

Permalink
chore: convert a few functions to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jul 7, 2022
1 parent 67f5790 commit a06e5f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
21 changes: 5 additions & 16 deletions src/lib/components/modes/textmode/TextMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import jsonSourceMap from 'json-source-map'
import StatusBar from './StatusBar.svelte'
import { highlighter } from './codemirror/codemirror-theme'
import { ParseError, RichValidationError, ValidationError } from '../../../types'
export let readOnly = false
export let mainMenuBar = true
Expand Down Expand Up @@ -391,13 +392,10 @@
focus()
}
/**
* @param {ParseError} parseError
**/
function handleSelectParseError(parseError) {
function handleSelectParseError(parseError: ParseError) {
debug('select parse error', parseError)
const richParseError = toRichParseError(parseError)
const richParseError = toRichParseError(parseError, false)
// we take "to" as head, not as anchor, because the scrollIntoView will
// move to the head, and when a large whole object is selected as a whole,
Expand Down Expand Up @@ -499,11 +497,7 @@
return codeMirrorView ? normalization.unescapeValue(codeMirrorView.state.doc.toString()) : ''
}
/**
* @param {ValidationError} validationError
* @returns {RichValidationError}
*/
function toRichValidationError(validationError) {
function toRichValidationError(validationError: ValidationError): RichValidationError {
const { path, message, isChildError } = validationError
const { line, column, from, to } = findTextLocation(text, path)
Expand All @@ -520,12 +514,7 @@
}
}
/**
* @param {ParseError} parseError
* @param {boolean} isRepairable
* @returns {RichValidationError}
*/
function toRichParseError(parseError, isRepairable) {
function toRichParseError(parseError: ParseError, isRepairable: boolean): RichValidationError {
const { line, column, position, message } = parseError
return {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export interface RichValidationError {
to: number
message: string
severity: 'info' | 'warning' | 'error'
actions: Array<string>
actions: Array<{ name: string; apply: () => void }> | null
}

export interface TextLocation {
Expand Down

0 comments on commit a06e5f5

Please sign in to comment.