Skip to content

Commit 51d34eb

Browse files
authored
[record_use] Support unsupported constants (dart-lang#3056)
1 parent 0819678 commit 51d34eb

21 files changed

Lines changed: 750 additions & 221 deletions

File tree

‎pkgs/hooks_runner/test_data/pirate_speak/hook/link.dart‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ Set<String> _extractUsedPhrases(Recordings recordings) {
5959

6060
for (final call in usages.constArgumentsFor(pirateSpeakId)) {
6161
if (call.positional.isNotEmpty) {
62-
final phrase = call.positional.first;
63-
if (phrase is String) {
64-
usedPhrases.add(phrase);
62+
if (call.positional.first case StringConstant(:final value)) {
63+
usedPhrases.add(value);
6564
}
6665
}
6766
}

‎pkgs/json_syntax_generator/lib/src/parser/schema_analyzer.dart‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,12 @@ class SchemaAnalyzer {
339339
isNullable: false,
340340
pattern: schemas.patternPropertiesSchemas.keys.firstOrNull,
341341
);
342-
final additionalPropertiesType = additionalPropertiesSchema.type;
342+
final (additionalPropertiesType, additionalNullable) =
343+
additionalPropertiesSchema.typeAndNullable;
343344
switch (additionalPropertiesType) {
344345
case SchemaType.array:
345346
final items = additionalPropertiesSchema.items;
346-
final itemType = items.type;
347+
final (itemType, itemNullable) = items.typeAndNullable;
347348
switch (itemType) {
348349
case SchemaType.object:
349350
_analyzeClass(items);
@@ -353,9 +354,9 @@ class SchemaAnalyzer {
353354
valueType: ListDartType(
354355
itemType: ClassDartType(
355356
classInfo: itemClass,
356-
isNullable: false,
357+
isNullable: itemNullable,
357358
),
358-
isNullable: false,
359+
isNullable: additionalNullable,
359360
),
360361
isNullable: isNullable,
361362
);
@@ -370,15 +371,18 @@ class SchemaAnalyzer {
370371
final clazz = _classes[additionalPropertiesSchema.className]!;
371372
dartType = MapDartType(
372373
keyType: keyDartType,
373-
valueType: ClassDartType(classInfo: clazz, isNullable: false),
374+
valueType: ClassDartType(
375+
classInfo: clazz,
376+
isNullable: additionalNullable,
377+
),
374378
isNullable: isNullable,
375379
);
376380
} else {
377381
dartType = MapDartType(
378382
keyType: keyDartType,
379-
valueType: const MapDartType(
380-
valueType: ObjectDartType(isNullable: true),
381-
isNullable: false,
383+
valueType: MapDartType(
384+
valueType: const ObjectDartType(isNullable: true),
385+
isNullable: additionalNullable,
382386
),
383387
isNullable: isNullable,
384388
);
@@ -431,13 +435,13 @@ class SchemaAnalyzer {
431435
case SchemaType.string:
432436
dartType = MapDartType(
433437
keyType: keyDartType,
434-
valueType: const StringDartType(isNullable: false),
438+
valueType: StringDartType(isNullable: additionalNullable),
435439
isNullable: isNullable,
436440
);
437441
case SchemaType.integer:
438442
dartType = MapDartType(
439443
keyType: keyDartType,
440-
valueType: const IntDartType(isNullable: false),
444+
valueType: IntDartType(isNullable: additionalNullable),
441445
isNullable: isNullable,
442446
);
443447
default:

‎pkgs/record_use/doc/schema/record_use.schema.json‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
"named": {
4040
"type": "object",
4141
"additionalProperties": {
42-
"type": "integer"
42+
"type": [
43+
"integer",
44+
"null"
45+
]
4346
}
4447
},
4548
"positional": {
@@ -68,7 +71,8 @@
6871
"list",
6972
"map",
7073
"null",
71-
"string"
74+
"string",
75+
"unsupported"
7276
]
7377
},
7478
{
@@ -211,6 +215,25 @@
211215
"value"
212216
]
213217
}
218+
},
219+
{
220+
"if": {
221+
"properties": {
222+
"type": {
223+
"const": "unsupported"
224+
}
225+
}
226+
},
227+
"then": {
228+
"properties": {
229+
"message": {
230+
"type": "string"
231+
}
232+
},
233+
"required": [
234+
"message"
235+
]
236+
}
214237
}
215238
]
216239
},
@@ -291,7 +314,10 @@
291314
"named": {
292315
"type": "object",
293316
"additionalProperties": {
294-
"type": "integer"
317+
"type": [
318+
"integer",
319+
"null"
320+
]
295321
}
296322
},
297323
"positional": {

‎pkgs/record_use/lib/record_use.dart‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
export 'src/constant.dart'
6+
show
7+
BoolConstant,
8+
Constant,
9+
InstanceConstant,
10+
IntConstant,
11+
ListConstant,
12+
MapConstant,
13+
MaybeConstant,
14+
NonConstant,
15+
NullConstant,
16+
StringConstant,
17+
UnsupportedConstant;
518
export 'src/identifier.dart' show Identifier;
619
export 'src/metadata.dart' show Metadata;
7-
export 'src/record_use.dart' show ConstantInstance, RecordedUsages;
20+
export 'src/record_use.dart' show RecordedUsages;
821
export 'src/recorded_usage_from_file.dart' show parseFromFile;

‎pkgs/record_use/lib/record_use_internal.dart‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ export 'src/constant.dart'
1010
IntConstant,
1111
ListConstant,
1212
MapConstant,
13+
MaybeConstant,
14+
NonConstant,
1315
NullConstant,
14-
PrimitiveConstant,
15-
StringConstant;
16+
StringConstant,
17+
UnsupportedConstant;
1618
export 'src/definition.dart' show Definition;
1719
export 'src/identifier.dart' show Identifier;
1820
export 'src/metadata.dart' show Metadata;

0 commit comments

Comments
 (0)