Skip to content

Commit f1c1cc5

Browse files
authored
Upgrade Core to 4e9d280a8a452885c7cd2bc488799a4f6410f4d8 (#17)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 10466c0 commit f1c1cc5

File tree

137 files changed

+3110
-1085
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+3110
-1085
lines changed

DEPENDENCIES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02
2-
core https://github.com/sourcemeta/core 991a4c86b6b22b73aedabe5734cba7108a781953
2+
core https://github.com/sourcemeta/core 4e9d280a8a452885c7cd2bc488799a4f6410f4d8

src/generator/include/sourcemeta/codegen/generator_typescript.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class SOURCEMETA_CODEGEN_GENERATOR_EXPORT TypeScript {
2424
auto operator()(const IREnumeration &entry) -> void;
2525
auto operator()(const IRObject &entry) -> void;
2626
auto operator()(const IRImpossible &entry) -> void;
27+
auto operator()(const IRAny &entry) -> void;
2728
auto operator()(const IRArray &entry) -> void;
2829
auto operator()(const IRReference &entry) -> void;
2930
auto operator()(const IRTuple &entry) -> void;

src/generator/typescript.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ auto TypeScript::operator()(const IRImpossible &entry) -> void {
172172
<< " = never;\n";
173173
}
174174

175+
auto TypeScript::operator()(const IRAny &entry) -> void {
176+
this->output << "export type "
177+
<< mangle(this->prefix, entry.pointer, entry.symbol, this->cache)
178+
<< " = unknown;\n";
179+
}
180+
175181
auto TypeScript::operator()(const IRArray &entry) -> void {
176182
this->output << "export type "
177183
<< mangle(this->prefix, entry.pointer, entry.symbol, this->cache)

src/ir/include/sourcemeta/codegen/ir.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,18 @@ struct IRTuple : IRType {
8383
/// @ingroup ir
8484
struct IRImpossible : IRType {};
8585

86+
/// @ingroup ir
87+
struct IRAny : IRType {};
88+
8689
/// @ingroup ir
8790
struct IRReference : IRType {
8891
IRType target;
8992
};
9093

9194
/// @ingroup ir
92-
using IREntity = std::variant<IRObject, IRScalar, IREnumeration, IRUnion,
93-
IRArray, IRTuple, IRImpossible, IRReference>;
95+
using IREntity =
96+
std::variant<IRObject, IRScalar, IREnumeration, IRUnion, IRArray, IRTuple,
97+
IRImpossible, IRAny, IRReference>;
9498

9599
/// @ingroup ir
96100
using IRResult = std::vector<IREntity>;

src/ir/ir.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ auto compile(const sourcemeta::core::JSON &input,
4646
// (4) Convert every subschema into a code generation object
4747
// --------------------------------------------------------------------------
4848

49-
std::unordered_set<sourcemeta::core::WeakPointer> visited;
49+
std::unordered_set<sourcemeta::core::WeakPointer,
50+
sourcemeta::core::WeakPointer::Hasher,
51+
sourcemeta::core::WeakPointer::Comparator>
52+
visited;
5053
IRResult result;
5154
for (const auto &[key, location] : frame.locations()) {
5255
if (location.type !=

src/ir/ir_default_compiler.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ auto handle_impossible(const sourcemeta::core::JSON &,
3737
.symbol = symbol(frame, location)}};
3838
}
3939

40+
auto handle_any(const sourcemeta::core::JSON &,
41+
const sourcemeta::core::SchemaFrame &frame,
42+
const sourcemeta::core::SchemaFrame::Location &location,
43+
const sourcemeta::core::Vocabularies &,
44+
const sourcemeta::core::SchemaResolver &,
45+
const sourcemeta::core::JSON &) -> IRAny {
46+
return IRAny{{.pointer = sourcemeta::core::to_pointer(location.pointer),
47+
.symbol = symbol(frame, location)}};
48+
}
49+
4050
auto handle_string(const sourcemeta::core::JSON &schema,
4151
const sourcemeta::core::SchemaFrame &frame,
4252
const sourcemeta::core::SchemaFrame::Location &location,
@@ -450,9 +460,13 @@ auto default_compiler(const sourcemeta::core::JSON &schema,
450460
// following shapes
451461

452462
if (subschema.is_boolean()) {
453-
assert(!subschema.to_boolean());
454-
return handle_impossible(schema, frame, location, vocabularies, resolver,
455-
subschema);
463+
if (subschema.to_boolean()) {
464+
return handle_any(schema, frame, location, vocabularies, resolver,
465+
subschema);
466+
} else {
467+
return handle_impossible(schema, frame, location, vocabularies, resolver,
468+
subschema);
469+
}
456470
} else if (subschema.defines("type")) {
457471
const auto &type_value{subschema.at("type")};
458472
if (!type_value.is_string()) {

test/e2e/typescript/2020-12/additional_properties_true/expected.d.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,10 @@ export type FlexibleRecordName = string;
22

33
export type FlexibleRecordCount = number;
44

5-
export type FlexibleRecordAdditionalProperties_5 = number;
6-
7-
export type FlexibleRecordAdditionalProperties_4 = string;
8-
9-
export type FlexibleRecordAdditionalProperties_3 = unknown[];
10-
11-
export type FlexibleRecordAdditionalProperties_2 = Record<string, unknown>;
12-
13-
export type FlexibleRecordAdditionalProperties_1 = boolean;
14-
15-
export type FlexibleRecordAdditionalProperties_0 = null;
16-
17-
export type FlexibleRecordAdditionalProperties =
18-
FlexibleRecordAdditionalProperties_0 |
19-
FlexibleRecordAdditionalProperties_1 |
20-
FlexibleRecordAdditionalProperties_2 |
21-
FlexibleRecordAdditionalProperties_3 |
22-
FlexibleRecordAdditionalProperties_4 |
23-
FlexibleRecordAdditionalProperties_5;
5+
export type FlexibleRecordAdditionalProperties = unknown;
246

257
export interface FlexibleRecord {
268
"name": FlexibleRecordName;
279
"count"?: FlexibleRecordCount;
28-
[key: string]:
29-
// As a notable limitation, TypeScript requires index signatures
30-
// to also include the types of all of its properties, so we must
31-
// match a superset of what JSON Schema allows
32-
FlexibleRecordName |
33-
FlexibleRecordCount |
34-
FlexibleRecordAdditionalProperties |
35-
undefined;
10+
[key: string]: unknown | undefined;
3611
}

0 commit comments

Comments
 (0)