@@ -16,16 +16,6 @@ import type {
16
16
ValidationDataMap ,
17
17
} from "./validation.types" ;
18
18
19
- function mapWidgetIdsToEmptyScore ( widgetIds : ReadonlyArray < string > ) : {
20
- [ widgetId : string ] : PerseusScore ;
21
- } {
22
- const emptyResult : { [ widgetId : string ] : PerseusScore } = { } ;
23
- widgetIds . forEach ( ( widgetId ) => {
24
- emptyResult [ widgetId ] = { type : "invalid" , message : null } ;
25
- } ) ;
26
- return emptyResult ;
27
- }
28
-
29
19
export function getUpgradedWidgetOptions (
30
20
oldWidgetOptions : PerseusWidgetsMap ,
31
21
) : PerseusWidgetsMap {
@@ -118,18 +108,6 @@ export function scoreWidgetsFunctional(
118
108
) : { [ widgetId : string ] : PerseusScore } {
119
109
const upgradedWidgets = getUpgradedWidgetOptions ( widgets ) ;
120
110
121
- // Do empty check first
122
- const emptyWidgets = emptyWidgetsFunctional (
123
- widgets ,
124
- widgetIds ,
125
- userInputMap ,
126
- strings ,
127
- locale ,
128
- ) ;
129
- if ( emptyWidgets . length > 0 ) {
130
- return mapWidgetIdsToEmptyScore ( emptyWidgets ) ;
131
- }
132
-
133
111
const gradedWidgetIds = widgetIds . filter ( ( id ) => {
134
112
const props = upgradedWidgets [ id ] ;
135
113
const widgetIsGraded : boolean = props ?. graded == null || props . graded ;
@@ -146,13 +124,14 @@ export function scoreWidgetsFunctional(
146
124
}
147
125
148
126
const userInput = userInputMap [ id ] ;
127
+ const validator = getWidgetValidator ( widget . type ) ;
149
128
const scorer = getWidgetScorer ( widget . type ) ;
150
- const score = scorer ?. (
151
- userInput as UserInput ,
152
- widget . options ,
153
- strings ,
154
- locale ,
155
- ) ;
129
+
130
+ // We do validation (empty checks) first and then scoring. If
131
+ // validation fails, it's result is itself a PerseusScore.
132
+ const score =
133
+ validator ?. ( userInput , widget . options , strings , locale ) ??
134
+ scorer ?. ( userInput , widget . options , strings , locale ) ;
156
135
if ( score != null ) {
157
136
widgetScores [ id ] = score ;
158
137
}
0 commit comments