-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing intersection types and heritage clauses
- Loading branch information
1 parent
097f70e
commit e28c92e
Showing
8 changed files
with
339 additions
and
53 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/core/src/code-gen/__snapshots__/parser.interface.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 21 additions & 3 deletions
24
packages/core/src/code-gen/parsers/generateIntersectionParser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
import ts from "typescript" | ||
import * as tsx from "../../tsx" | ||
import generateParserFromModel from "./generateParserFromModel" | ||
import { IntersectionParserModel } from "./generateParserModel" | ||
import Pointer from "./Pointer" | ||
|
||
export default function generateIntersectionParser( | ||
pointer: Pointer<IntersectionParserModel>, | ||
): ts.Statement { | ||
return ts.factory.createBlock( | ||
pointer.model.parsers.map((parser) => | ||
return ts.factory.createBlock([ | ||
tsx.const({ | ||
name: "intersectionResult", | ||
init: tsx.literal.object(), | ||
type: tsx.type.any, | ||
}), | ||
...pointer.model.parsers.flatMap((parser) => [ | ||
generateParserFromModel(parser, pointer.path), | ||
tsx.statement.expression( | ||
tsx.expression.call(tsx.expression.propertyAccess("Object", "assign"), { | ||
args: ["intersectionResult", "result"], | ||
}), | ||
), | ||
]), | ||
tsx.statement.expression( | ||
tsx.expression.binary( | ||
tsx.expression.identifier("result"), | ||
"=", | ||
tsx.expression.identifier("intersectionResult"), | ||
), | ||
), | ||
) | ||
]) | ||
} |
Oops, something went wrong.