Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02
core https://github.com/sourcemeta/core 991a4c86b6b22b73aedabe5734cba7108a781953
core https://github.com/sourcemeta/core 4e9d280a8a452885c7cd2bc488799a4f6410f4d8
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SOURCEMETA_CODEGEN_GENERATOR_EXPORT TypeScript {
auto operator()(const IREnumeration &entry) -> void;
auto operator()(const IRObject &entry) -> void;
auto operator()(const IRImpossible &entry) -> void;
auto operator()(const IRAny &entry) -> void;
auto operator()(const IRArray &entry) -> void;
auto operator()(const IRReference &entry) -> void;
auto operator()(const IRTuple &entry) -> void;
Expand Down
6 changes: 6 additions & 0 deletions src/generator/typescript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ auto TypeScript::operator()(const IRImpossible &entry) -> void {
<< " = never;\n";
}

auto TypeScript::operator()(const IRAny &entry) -> void {
this->output << "export type "
<< mangle(this->prefix, entry.pointer, entry.symbol, this->cache)
<< " = unknown;\n";
}

auto TypeScript::operator()(const IRArray &entry) -> void {
this->output << "export type "
<< mangle(this->prefix, entry.pointer, entry.symbol, this->cache)
Expand Down
8 changes: 6 additions & 2 deletions src/ir/include/sourcemeta/codegen/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,18 @@ struct IRTuple : IRType {
/// @ingroup ir
struct IRImpossible : IRType {};

/// @ingroup ir
struct IRAny : IRType {};

/// @ingroup ir
struct IRReference : IRType {
IRType target;
};

/// @ingroup ir
using IREntity = std::variant<IRObject, IRScalar, IREnumeration, IRUnion,
IRArray, IRTuple, IRImpossible, IRReference>;
using IREntity =
std::variant<IRObject, IRScalar, IREnumeration, IRUnion, IRArray, IRTuple,
IRImpossible, IRAny, IRReference>;

/// @ingroup ir
using IRResult = std::vector<IREntity>;
Expand Down
5 changes: 4 additions & 1 deletion src/ir/ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ auto compile(const sourcemeta::core::JSON &input,
// (4) Convert every subschema into a code generation object
// --------------------------------------------------------------------------

std::unordered_set<sourcemeta::core::WeakPointer> visited;
std::unordered_set<sourcemeta::core::WeakPointer,
sourcemeta::core::WeakPointer::Hasher,
sourcemeta::core::WeakPointer::Comparator>
visited;
IRResult result;
for (const auto &[key, location] : frame.locations()) {
if (location.type !=
Expand Down
20 changes: 17 additions & 3 deletions src/ir/ir_default_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ auto handle_impossible(const sourcemeta::core::JSON &,
.symbol = symbol(frame, location)}};
}

auto handle_any(const sourcemeta::core::JSON &,
const sourcemeta::core::SchemaFrame &frame,
const sourcemeta::core::SchemaFrame::Location &location,
const sourcemeta::core::Vocabularies &,
const sourcemeta::core::SchemaResolver &,
const sourcemeta::core::JSON &) -> IRAny {
return IRAny{{.pointer = sourcemeta::core::to_pointer(location.pointer),
.symbol = symbol(frame, location)}};
}

auto handle_string(const sourcemeta::core::JSON &schema,
const sourcemeta::core::SchemaFrame &frame,
const sourcemeta::core::SchemaFrame::Location &location,
Expand Down Expand Up @@ -450,9 +460,13 @@ auto default_compiler(const sourcemeta::core::JSON &schema,
// following shapes

if (subschema.is_boolean()) {
assert(!subschema.to_boolean());
return handle_impossible(schema, frame, location, vocabularies, resolver,
subschema);
if (subschema.to_boolean()) {
return handle_any(schema, frame, location, vocabularies, resolver,
subschema);
} else {
return handle_impossible(schema, frame, location, vocabularies, resolver,
subschema);
}
} else if (subschema.defines("type")) {
const auto &type_value{subschema.at("type")};
if (!type_value.is_string()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,10 @@ export type FlexibleRecordName = string;

export type FlexibleRecordCount = number;

export type FlexibleRecordAdditionalProperties_5 = number;

export type FlexibleRecordAdditionalProperties_4 = string;

export type FlexibleRecordAdditionalProperties_3 = unknown[];

export type FlexibleRecordAdditionalProperties_2 = Record<string, unknown>;

export type FlexibleRecordAdditionalProperties_1 = boolean;

export type FlexibleRecordAdditionalProperties_0 = null;

export type FlexibleRecordAdditionalProperties =
FlexibleRecordAdditionalProperties_0 |
FlexibleRecordAdditionalProperties_1 |
FlexibleRecordAdditionalProperties_2 |
FlexibleRecordAdditionalProperties_3 |
FlexibleRecordAdditionalProperties_4 |
FlexibleRecordAdditionalProperties_5;
export type FlexibleRecordAdditionalProperties = unknown;

export interface FlexibleRecord {
"name": FlexibleRecordName;
"count"?: FlexibleRecordCount;
[key: string]:
// As a notable limitation, TypeScript requires index signatures
// to also include the types of all of its properties, so we must
// match a superset of what JSON Schema allows
FlexibleRecordName |
FlexibleRecordCount |
FlexibleRecordAdditionalProperties |
undefined;
[key: string]: unknown | undefined;
}
Loading