-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#76, decorators for stage 3, part 4.
- Loading branch information
Showing
13 changed files
with
217 additions
and
53 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
stage_3_generation/build/fieldStatements/ArrayBooleanAndString.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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import assert from "node:assert/strict"; | ||
|
||
import { | ||
ClassFieldStatementsMap, | ||
LiteralTypeStructureImpl, | ||
type MemberedStatementsKey, | ||
type stringWriterOrStatementImpl, | ||
TypeStructureKind, | ||
} from "#stage_two/snapshot/source/exports.js"; | ||
import { StructureKind } from "ts-morph"; | ||
|
||
import GetterFilter from "./GetterFilter.js"; | ||
|
||
const booleanType = LiteralTypeStructureImpl.get("boolean"); | ||
const stringType = LiteralTypeStructureImpl.get("string"); | ||
|
||
export default | ||
class ArrayBooleanAndString extends GetterFilter | ||
{ | ||
accept( | ||
key: MemberedStatementsKey | ||
): boolean | ||
{ | ||
if (key.statementGroupKey !== ClassFieldStatementsMap.GROUP_INITIALIZER_OR_PROPERTY) | ||
return false; | ||
if (key.fieldType?.kind !== StructureKind.PropertySignature) | ||
return false; | ||
if (key.fieldType.hasQuestionToken) | ||
return false; | ||
|
||
const { typeStructure } = key.fieldType; | ||
return ( | ||
typeStructure === booleanType || | ||
typeStructure === stringType || | ||
typeStructure?.kind === TypeStructureKind.Array | ||
); | ||
} | ||
|
||
getStatements( | ||
key: MemberedStatementsKey | ||
): stringWriterOrStatementImpl[] | ||
{ | ||
assert(key.fieldType?.kind === StructureKind.PropertySignature); | ||
if (key.fieldType.typeStructure === booleanType) | ||
return ["false"]; | ||
|
||
if (key.fieldType.typeStructure === stringType) | ||
return [`""`]; | ||
|
||
return ["[]"]; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { | ||
ClassStatementsGetter, | ||
ImportManager, | ||
MemberedStatementsKey, | ||
stringWriterOrStatementImpl, | ||
} from "#stage_two/snapshot/source/exports.js"; | ||
|
||
export default | ||
abstract class StatementGetterBase | ||
implements ClassStatementsGetter | ||
{ | ||
protected readonly importManager: ImportManager; | ||
|
||
constructor( | ||
importManager: ImportManager | ||
) | ||
{ | ||
this.importManager = importManager; | ||
} | ||
|
||
abstract getStatements( | ||
key: MemberedStatementsKey | ||
): stringWriterOrStatementImpl[]; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { | ||
MemberedStatementsKey | ||
} from "#stage_two/snapshot/source/exports.js"; | ||
import StatementGetterBase from "./GetterBase.js"; | ||
|
||
export default | ||
abstract class GetterFilter extends StatementGetterBase | ||
{ | ||
abstract accept( | ||
key: MemberedStatementsKey | ||
): boolean; | ||
} |
38 changes: 38 additions & 0 deletions
38
stage_3_generation/build/fieldStatements/StatementsRouter.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
ImportManager, | ||
MemberedStatementsKey, | ||
stringWriterOrStatementImpl | ||
} from "#stage_two/snapshot/source/exports.js"; | ||
import StatementGetterBase from "./GetterBase.js"; | ||
import GetterFilter from "./GetterFilter.js"; | ||
|
||
import ArrayBooleanAndString from "./ArrayBooleanAndString.js"; | ||
|
||
export default | ||
class StatementsRouter extends StatementGetterBase | ||
{ | ||
readonly filters: GetterFilter[]; | ||
|
||
constructor( | ||
importManager: ImportManager | ||
) | ||
{ | ||
super(importManager); | ||
this.filters = [ | ||
new ArrayBooleanAndString(importManager), | ||
]; | ||
} | ||
|
||
getStatements( | ||
key: MemberedStatementsKey | ||
): stringWriterOrStatementImpl[] | ||
{ | ||
for (const filter of this.filters) { | ||
if (filter.accept(key)) { | ||
return filter.getStatements(key); | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
} |
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
Oops, something went wrong.