@auto-engineer/narrative 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +11 -0
- package/dist/src/commands/export-schema-runner.js +1 -1
- package/dist/src/commands/export-schema-runner.js.map +1 -1
- package/dist/src/fluent-builder.js +3 -3
- package/dist/src/fluent-builder.js.map +1 -1
- package/dist/src/getNarratives.specs.js +149 -153
- package/dist/src/getNarratives.specs.js.map +1 -1
- package/dist/src/id/addAutoIds.d.ts.map +1 -1
- package/dist/src/id/addAutoIds.js +23 -10
- package/dist/src/id/addAutoIds.js.map +1 -1
- package/dist/src/id/addAutoIds.specs.js +54 -45
- package/dist/src/id/addAutoIds.specs.js.map +1 -1
- package/dist/src/id/hasAllIds.d.ts.map +1 -1
- package/dist/src/id/hasAllIds.js +8 -3
- package/dist/src/id/hasAllIds.js.map +1 -1
- package/dist/src/id/hasAllIds.specs.js +142 -215
- package/dist/src/id/hasAllIds.specs.js.map +1 -1
- package/dist/src/index.d.ts +6 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/loader/graph.d.ts.map +1 -1
- package/dist/src/loader/graph.js +13 -6
- package/dist/src/loader/graph.js.map +1 -1
- package/dist/src/loader/ts-utils.d.ts +1 -0
- package/dist/src/loader/ts-utils.d.ts.map +1 -1
- package/dist/src/loader/ts-utils.js +95 -16
- package/dist/src/loader/ts-utils.js.map +1 -1
- package/dist/src/model-to-narrative.specs.js +531 -449
- package/dist/src/model-to-narrative.specs.js.map +1 -1
- package/dist/src/narrative-context.d.ts +8 -8
- package/dist/src/narrative-context.d.ts.map +1 -1
- package/dist/src/narrative-context.js +111 -301
- package/dist/src/narrative-context.js.map +1 -1
- package/dist/src/narrative-context.specs.js +15 -55
- package/dist/src/narrative-context.specs.js.map +1 -1
- package/dist/src/narrative.d.ts +19 -22
- package/dist/src/narrative.d.ts.map +1 -1
- package/dist/src/narrative.js +42 -71
- package/dist/src/narrative.js.map +1 -1
- package/dist/src/samples/test-with-ids.narrative.js +13 -29
- package/dist/src/samples/test-with-ids.narrative.js.map +1 -1
- package/dist/src/schema.d.ts +2704 -8293
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/schema.js +26 -47
- package/dist/src/schema.js.map +1 -1
- package/dist/src/slice-builder.js +3 -3
- package/dist/src/slice-builder.js.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/flow.d.ts.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/flow.js +118 -74
- package/dist/src/transformers/model-to-narrative/generators/flow.js.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/gwt.d.ts +9 -1
- package/dist/src/transformers/model-to-narrative/generators/gwt.d.ts.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/gwt.js +112 -112
- package/dist/src/transformers/model-to-narrative/generators/gwt.js.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/imports.d.ts +1 -1
- package/dist/src/transformers/model-to-narrative/generators/imports.d.ts.map +1 -1
- package/dist/src/transformers/model-to-narrative/generators/imports.js +13 -9
- package/dist/src/transformers/model-to-narrative/generators/imports.js.map +1 -1
- package/dist/src/transformers/narrative-to-model/index.d.ts.map +1 -1
- package/dist/src/transformers/narrative-to-model/index.js +50 -23
- package/dist/src/transformers/narrative-to-model/index.js.map +1 -1
- package/dist/src/transformers/narrative-to-model/type-inference.specs.js +100 -90
- package/dist/src/transformers/narrative-to-model/type-inference.specs.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/commands/export-schema-runner.ts +3 -1
- package/src/fluent-builder.ts +3 -3
- package/src/getNarratives.specs.ts +168 -176
- package/src/id/addAutoIds.specs.ts +54 -47
- package/src/id/addAutoIds.ts +28 -11
- package/src/id/hasAllIds.specs.ts +147 -245
- package/src/id/hasAllIds.ts +11 -4
- package/src/index.ts +9 -12
- package/src/loader/graph.ts +23 -6
- package/src/loader/ts-utils.ts +169 -26
- package/src/model-to-narrative.specs.ts +531 -449
- package/src/narrative-context.specs.ts +73 -116
- package/src/narrative-context.ts +127 -374
- package/src/narrative.ts +70 -120
- package/src/samples/test-with-ids.narrative.ts +23 -31
- package/src/schema.ts +33 -52
- package/src/slice-builder.ts +3 -3
- package/src/transformers/model-to-narrative/generators/flow.ts +191 -85
- package/src/transformers/model-to-narrative/generators/gwt.ts +195 -178
- package/src/transformers/model-to-narrative/generators/imports.ts +13 -9
- package/src/transformers/narrative-to-model/index.ts +87 -26
- package/src/transformers/narrative-to-model/type-inference.specs.ts +100 -90
package/src/index.ts
CHANGED
|
@@ -44,7 +44,8 @@ export type { FieldSelector } from './data-narrative-builders';
|
|
|
44
44
|
|
|
45
45
|
// Narrative language functions
|
|
46
46
|
export { narrative, narrative as flow } from './narrative';
|
|
47
|
-
export { client, server, specs, describe, it, should, request, data, rule, example } from './narrative';
|
|
47
|
+
export { client, server, specs, describe, it, should, request, data, rule, example, thenError } from './narrative';
|
|
48
|
+
export type { ExampleBuilder, GivenBuilder, WhenBuilder, ThenBuilder } from './narrative';
|
|
48
49
|
export type { SliceTypeValueInterface } from './narrative';
|
|
49
50
|
export { SliceType } from './narrative';
|
|
50
51
|
|
|
@@ -55,7 +56,7 @@ export { modelToNarrative } from './transformers/model-to-narrative';
|
|
|
55
56
|
export type { ExportSchemaEvents } from './commands/export-schema';
|
|
56
57
|
|
|
57
58
|
// Testing helpers
|
|
58
|
-
export { createNarrativeSpec, given, when } from './testing';
|
|
59
|
+
export { createNarrativeSpec, given as testGiven, when as testWhen } from './testing';
|
|
59
60
|
|
|
60
61
|
// Schema definitions for progressive narrative creation
|
|
61
62
|
export {
|
|
@@ -76,21 +77,19 @@ export {
|
|
|
76
77
|
SliceSchema,
|
|
77
78
|
NarrativeSchema,
|
|
78
79
|
modelSchema,
|
|
79
|
-
EventExampleSchema,
|
|
80
|
-
CommandExampleSchema,
|
|
81
80
|
ExampleSchema,
|
|
82
81
|
RuleSchema,
|
|
83
82
|
SpecSchema,
|
|
83
|
+
StepSchema,
|
|
84
|
+
StepErrorSchema,
|
|
85
|
+
StepWithDocStringSchema,
|
|
86
|
+
StepWithErrorSchema,
|
|
84
87
|
} from './schema';
|
|
85
88
|
|
|
86
89
|
import {
|
|
87
|
-
CommandExampleSchema,
|
|
88
|
-
ErrorExampleSchema,
|
|
89
|
-
EventExampleSchema,
|
|
90
90
|
NarrativeSchema,
|
|
91
91
|
SliceSchema,
|
|
92
92
|
modelSchema,
|
|
93
|
-
StateExampleSchema,
|
|
94
93
|
QuerySliceSchema,
|
|
95
94
|
ReactSliceSchema,
|
|
96
95
|
ExperienceSliceSchema,
|
|
@@ -100,14 +99,11 @@ import {
|
|
|
100
99
|
ExampleSchema,
|
|
101
100
|
RuleSchema,
|
|
102
101
|
SpecSchema,
|
|
102
|
+
StepSchema,
|
|
103
103
|
} from './schema';
|
|
104
104
|
export type Model = z.infer<typeof modelSchema>;
|
|
105
105
|
export type Narrative = z.infer<typeof NarrativeSchema>;
|
|
106
|
-
export type CommandExample = z.infer<typeof CommandExampleSchema>;
|
|
107
|
-
export type EventExample = z.infer<typeof EventExampleSchema>;
|
|
108
106
|
export type Slice = z.infer<typeof SliceSchema>;
|
|
109
|
-
export type StateExample = z.infer<typeof StateExampleSchema>;
|
|
110
|
-
export type ErrorExample = z.infer<typeof ErrorExampleSchema>;
|
|
111
107
|
export type QuerySlice = z.infer<typeof QuerySliceSchema>;
|
|
112
108
|
export type ReactSlice = z.infer<typeof ReactSliceSchema>;
|
|
113
109
|
export type CommandSlice = z.infer<typeof CommandSliceSchema>;
|
|
@@ -117,6 +113,7 @@ export type Example = z.infer<typeof ExampleSchema>;
|
|
|
117
113
|
export type MessageField = z.infer<typeof MessageFieldSchema>;
|
|
118
114
|
export type Rule = z.infer<typeof RuleSchema>;
|
|
119
115
|
export type Spec = z.infer<typeof SpecSchema>;
|
|
116
|
+
export type Step = z.infer<typeof StepSchema>;
|
|
120
117
|
export type { ClientSpecNode } from './schema';
|
|
121
118
|
|
|
122
119
|
// ID assignment utilities
|
package/src/loader/graph.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
parseIntegrationImports,
|
|
9
9
|
parseGivenTypeArguments,
|
|
10
10
|
parseWhenTypeArguments,
|
|
11
|
+
parseThenTypeArguments,
|
|
11
12
|
patchImportMeta,
|
|
12
13
|
transpileToCjs,
|
|
13
14
|
TypeInfo,
|
|
@@ -312,8 +313,12 @@ export async function buildGraph(
|
|
|
312
313
|
function extractTypeInfoFromProgram(
|
|
313
314
|
program: import('typescript').Program,
|
|
314
315
|
checker: import('typescript').TypeChecker,
|
|
315
|
-
):
|
|
316
|
+
): {
|
|
317
|
+
whenTypes: Map<string, import('./ts-utils').GivenTypeInfo[]>;
|
|
318
|
+
thenTypes: Map<string, import('./ts-utils').GivenTypeInfo[]>;
|
|
319
|
+
} {
|
|
316
320
|
const whenTypesByFile: Map<string, import('./ts-utils').GivenTypeInfo[]> = new Map();
|
|
321
|
+
const thenTypesByFile: Map<string, import('./ts-utils').GivenTypeInfo[]> = new Map();
|
|
317
322
|
|
|
318
323
|
for (const sourceFile of program.getSourceFiles()) {
|
|
319
324
|
const posixPath = toPosix(sourceFile.fileName);
|
|
@@ -322,24 +327,35 @@ export async function buildGraph(
|
|
|
322
327
|
const fileTypeMap = typesByFile.get(posixPath) || new Map();
|
|
323
328
|
const extractedGivenTypes = parseGivenTypeArguments(ts, checker, sourceFile, fileTypeMap, typesByFile);
|
|
324
329
|
const extractedWhenTypes = parseWhenTypeArguments(ts, checker, sourceFile, fileTypeMap, typesByFile);
|
|
330
|
+
const extractedThenTypes = parseThenTypeArguments(ts, checker, sourceFile, fileTypeMap, typesByFile);
|
|
325
331
|
|
|
326
332
|
if (extractedGivenTypes.length > 0) {
|
|
327
333
|
givenTypesByFile.set(posixPath, extractedGivenTypes);
|
|
328
|
-
debug('[given-types] extracted %d
|
|
334
|
+
debug('[given-types] extracted %d given<T>() calls from %s', extractedGivenTypes.length, posixPath);
|
|
329
335
|
}
|
|
330
336
|
|
|
331
337
|
if (extractedWhenTypes.length > 0) {
|
|
332
338
|
whenTypesByFile.set(posixPath, extractedWhenTypes);
|
|
333
339
|
debug(
|
|
334
|
-
'[when-types] extracted %d
|
|
340
|
+
'[when-types] extracted %d when<T>() calls from %s: %o',
|
|
335
341
|
extractedWhenTypes.length,
|
|
336
342
|
posixPath,
|
|
337
343
|
extractedWhenTypes.map((t) => ({ typeName: t.typeName, classification: t.classification })),
|
|
338
344
|
);
|
|
339
345
|
}
|
|
346
|
+
|
|
347
|
+
if (extractedThenTypes.length > 0) {
|
|
348
|
+
thenTypesByFile.set(posixPath, extractedThenTypes);
|
|
349
|
+
debug(
|
|
350
|
+
'[then-types] extracted %d then<T>() calls from %s: %o',
|
|
351
|
+
extractedThenTypes.length,
|
|
352
|
+
posixPath,
|
|
353
|
+
extractedThenTypes.map((t) => ({ typeName: t.typeName, classification: t.classification })),
|
|
354
|
+
);
|
|
355
|
+
}
|
|
340
356
|
}
|
|
341
357
|
|
|
342
|
-
return whenTypesByFile;
|
|
358
|
+
return { whenTypes: whenTypesByFile, thenTypes: thenTypesByFile };
|
|
343
359
|
}
|
|
344
360
|
|
|
345
361
|
for (const entry of entryFiles) {
|
|
@@ -352,9 +368,10 @@ export async function buildGraph(
|
|
|
352
368
|
const program = ts.createProgram([...sourceFiles.keys()], compilerOptions, host);
|
|
353
369
|
const checker = program.getTypeChecker();
|
|
354
370
|
|
|
355
|
-
const
|
|
371
|
+
const { whenTypes, thenTypes } = extractTypeInfoFromProgram(program, checker);
|
|
356
372
|
|
|
357
|
-
givenTypesByFile.set('__whenTypes',
|
|
373
|
+
givenTypesByFile.set('__whenTypes', whenTypes as unknown as import('./ts-utils').GivenTypeInfo[]);
|
|
374
|
+
givenTypesByFile.set('__thenTypes', thenTypes as unknown as import('./ts-utils').GivenTypeInfo[]);
|
|
358
375
|
|
|
359
376
|
const result: BuildGraphResult = {
|
|
360
377
|
graph,
|
package/src/loader/ts-utils.ts
CHANGED
|
@@ -660,14 +660,13 @@ export function parseWhenTypeArguments(
|
|
|
660
660
|
const whenTypes: GivenTypeInfo[] = [];
|
|
661
661
|
|
|
662
662
|
const visit = (node: import('typescript').Node): void => {
|
|
663
|
-
if (ts.isCallExpression(node)
|
|
664
|
-
|
|
665
|
-
if (method === 'when') {
|
|
663
|
+
if (ts.isCallExpression(node)) {
|
|
664
|
+
if (ts.isIdentifier(node.expression) && node.expression.text === 'when') {
|
|
666
665
|
if (node.typeArguments && node.typeArguments.length > 0) {
|
|
667
666
|
const typeArg = node.typeArguments[0];
|
|
668
667
|
const typeArgText = typeArg.getText(sourceFile);
|
|
669
668
|
debug(
|
|
670
|
-
'[when-types] found
|
|
669
|
+
'[when-types] found when<%s> at line %d, will process as ordinal %d',
|
|
671
670
|
typeArgText,
|
|
672
671
|
sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1,
|
|
673
672
|
whenTypes.length,
|
|
@@ -676,7 +675,7 @@ export function parseWhenTypeArguments(
|
|
|
676
675
|
} else {
|
|
677
676
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
678
677
|
debug(
|
|
679
|
-
'[when-types] found
|
|
678
|
+
'[when-types] found when() without type argument at line %d, adding placeholder at ordinal %d',
|
|
680
679
|
line + 1,
|
|
681
680
|
whenTypes.length,
|
|
682
681
|
);
|
|
@@ -690,6 +689,38 @@ export function parseWhenTypeArguments(
|
|
|
690
689
|
});
|
|
691
690
|
}
|
|
692
691
|
}
|
|
692
|
+
// Handle property access (fluent API): .when<T>({...})
|
|
693
|
+
else if (ts.isPropertyAccessExpression(node.expression)) {
|
|
694
|
+
const method = node.expression.name.getText();
|
|
695
|
+
if (method === 'when') {
|
|
696
|
+
if (node.typeArguments && node.typeArguments.length > 0) {
|
|
697
|
+
const typeArg = node.typeArguments[0];
|
|
698
|
+
const typeArgText = typeArg.getText(sourceFile);
|
|
699
|
+
debug(
|
|
700
|
+
'[when-types] found .when<%s> at line %d, will process as ordinal %d',
|
|
701
|
+
typeArgText,
|
|
702
|
+
sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1,
|
|
703
|
+
whenTypes.length,
|
|
704
|
+
);
|
|
705
|
+
processWhenCallExpression(ts, node, checker, sourceFile, typeMap, typesByFile, whenTypes, whenTypes.length);
|
|
706
|
+
} else {
|
|
707
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
708
|
+
debug(
|
|
709
|
+
'[when-types] found .when() without type argument at line %d, adding placeholder at ordinal %d',
|
|
710
|
+
line + 1,
|
|
711
|
+
whenTypes.length,
|
|
712
|
+
);
|
|
713
|
+
whenTypes.push({
|
|
714
|
+
fileName: sourceFile.fileName,
|
|
715
|
+
line: line + 1,
|
|
716
|
+
column: character + 1,
|
|
717
|
+
ordinal: whenTypes.length,
|
|
718
|
+
typeName: '',
|
|
719
|
+
classification: 'command',
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
693
724
|
}
|
|
694
725
|
ts.forEachChild(node, visit);
|
|
695
726
|
};
|
|
@@ -699,6 +730,43 @@ export function parseWhenTypeArguments(
|
|
|
699
730
|
return whenTypes;
|
|
700
731
|
}
|
|
701
732
|
|
|
733
|
+
function processStandaloneGivenCall(
|
|
734
|
+
ts: typeof import('typescript'),
|
|
735
|
+
node: import('typescript').CallExpression,
|
|
736
|
+
checker: import('typescript').TypeChecker,
|
|
737
|
+
sourceFile: import('typescript').SourceFile,
|
|
738
|
+
typeMap: Map<string, TypeInfo>,
|
|
739
|
+
typesByFile: Map<string, Map<string, TypeInfo>>,
|
|
740
|
+
givenTypes: GivenTypeInfo[],
|
|
741
|
+
processedNodes: Set<import('typescript').CallExpression>,
|
|
742
|
+
): void {
|
|
743
|
+
if (node.typeArguments !== undefined && node.typeArguments.length > 0) {
|
|
744
|
+
processGivenOrAndCallExpression(ts, node, checker, sourceFile, typeMap, typesByFile, givenTypes, givenTypes.length);
|
|
745
|
+
processedNodes.add(node);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
function processFluentGivenChain(
|
|
750
|
+
ts: typeof import('typescript'),
|
|
751
|
+
node: import('typescript').CallExpression,
|
|
752
|
+
checker: import('typescript').TypeChecker,
|
|
753
|
+
sourceFile: import('typescript').SourceFile,
|
|
754
|
+
typeMap: Map<string, TypeInfo>,
|
|
755
|
+
typesByFile: Map<string, Map<string, TypeInfo>>,
|
|
756
|
+
givenTypes: GivenTypeInfo[],
|
|
757
|
+
processedNodes: Set<import('typescript').CallExpression>,
|
|
758
|
+
): void {
|
|
759
|
+
const chain = collectChainFromStart(ts, node);
|
|
760
|
+
let ordinal = givenTypes.length;
|
|
761
|
+
|
|
762
|
+
for (const chainNode of chain) {
|
|
763
|
+
if (chainNode.typeArguments !== undefined && chainNode.typeArguments.length > 0) {
|
|
764
|
+
processGivenOrAndCallExpression(ts, chainNode, checker, sourceFile, typeMap, typesByFile, givenTypes, ordinal++);
|
|
765
|
+
processedNodes.add(chainNode);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
702
770
|
export function parseGivenTypeArguments(
|
|
703
771
|
ts: typeof import('typescript'),
|
|
704
772
|
checker: import('typescript').TypeChecker,
|
|
@@ -709,31 +777,14 @@ export function parseGivenTypeArguments(
|
|
|
709
777
|
const givenTypes: GivenTypeInfo[] = [];
|
|
710
778
|
const processedNodes = new Set<import('typescript').CallExpression>();
|
|
711
779
|
|
|
712
|
-
// First pass: find all given/and chain starts
|
|
713
780
|
const visit = (node: import('typescript').Node): void => {
|
|
714
781
|
if (ts.isCallExpression(node) && !processedNodes.has(node)) {
|
|
715
|
-
if (ts.
|
|
782
|
+
if (ts.isIdentifier(node.expression) && node.expression.text === 'given') {
|
|
783
|
+
processStandaloneGivenCall(ts, node, checker, sourceFile, typeMap, typesByFile, givenTypes, processedNodes);
|
|
784
|
+
} else if (ts.isPropertyAccessExpression(node.expression)) {
|
|
716
785
|
const method = node.expression.name.getText();
|
|
717
786
|
if (method === 'given' && isChainStart(ts, node)) {
|
|
718
|
-
|
|
719
|
-
const chain = collectChainFromStart(ts, node);
|
|
720
|
-
let ordinal = givenTypes.length;
|
|
721
|
-
|
|
722
|
-
for (const chainNode of chain) {
|
|
723
|
-
if (chainNode.typeArguments !== undefined && chainNode.typeArguments.length > 0) {
|
|
724
|
-
processGivenOrAndCallExpression(
|
|
725
|
-
ts,
|
|
726
|
-
chainNode,
|
|
727
|
-
checker,
|
|
728
|
-
sourceFile,
|
|
729
|
-
typeMap,
|
|
730
|
-
typesByFile,
|
|
731
|
-
givenTypes,
|
|
732
|
-
ordinal++,
|
|
733
|
-
);
|
|
734
|
-
processedNodes.add(chainNode);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
787
|
+
processFluentGivenChain(ts, node, checker, sourceFile, typeMap, typesByFile, givenTypes, processedNodes);
|
|
737
788
|
}
|
|
738
789
|
}
|
|
739
790
|
}
|
|
@@ -744,6 +795,98 @@ export function parseGivenTypeArguments(
|
|
|
744
795
|
return givenTypes;
|
|
745
796
|
}
|
|
746
797
|
|
|
798
|
+
function processThenCallWithTypeArg(
|
|
799
|
+
ts: typeof import('typescript'),
|
|
800
|
+
node: import('typescript').CallExpression,
|
|
801
|
+
checker: import('typescript').TypeChecker,
|
|
802
|
+
sourceFile: import('typescript').SourceFile,
|
|
803
|
+
typeMap: Map<string, TypeInfo>,
|
|
804
|
+
typesByFile: Map<string, Map<string, TypeInfo>>,
|
|
805
|
+
thenTypes: GivenTypeInfo[],
|
|
806
|
+
debugPrefix: string,
|
|
807
|
+
): void {
|
|
808
|
+
const typeArg = node.typeArguments![0];
|
|
809
|
+
const typeArgText = typeArg.getText(sourceFile);
|
|
810
|
+
debug(
|
|
811
|
+
'[then-types] found %s<%s> at line %d, will process as ordinal %d',
|
|
812
|
+
debugPrefix,
|
|
813
|
+
typeArgText,
|
|
814
|
+
sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1,
|
|
815
|
+
thenTypes.length,
|
|
816
|
+
);
|
|
817
|
+
const genericResult = tryUnwrapGeneric(ts, typeArg, checker, typeMap, typesByFile);
|
|
818
|
+
if (genericResult !== undefined && genericResult !== null) {
|
|
819
|
+
thenTypes.push(
|
|
820
|
+
createGivenTypeInfo(sourceFile, node, thenTypes.length, genericResult.typeName, genericResult.classification),
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
function processThenCallWithoutTypeArg(
|
|
826
|
+
sourceFile: import('typescript').SourceFile,
|
|
827
|
+
node: import('typescript').CallExpression,
|
|
828
|
+
thenTypes: GivenTypeInfo[],
|
|
829
|
+
debugPrefix: string,
|
|
830
|
+
): void {
|
|
831
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
832
|
+
debug(
|
|
833
|
+
'[then-types] found %s without type argument at line %d, adding placeholder at ordinal %d',
|
|
834
|
+
debugPrefix,
|
|
835
|
+
line + 1,
|
|
836
|
+
thenTypes.length,
|
|
837
|
+
);
|
|
838
|
+
thenTypes.push({
|
|
839
|
+
fileName: sourceFile.fileName,
|
|
840
|
+
line: line + 1,
|
|
841
|
+
column: character + 1,
|
|
842
|
+
ordinal: thenTypes.length,
|
|
843
|
+
typeName: '',
|
|
844
|
+
classification: 'event',
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
function processThenCall(
|
|
849
|
+
ts: typeof import('typescript'),
|
|
850
|
+
node: import('typescript').CallExpression,
|
|
851
|
+
checker: import('typescript').TypeChecker,
|
|
852
|
+
sourceFile: import('typescript').SourceFile,
|
|
853
|
+
typeMap: Map<string, TypeInfo>,
|
|
854
|
+
typesByFile: Map<string, Map<string, TypeInfo>>,
|
|
855
|
+
thenTypes: GivenTypeInfo[],
|
|
856
|
+
debugPrefix: string,
|
|
857
|
+
): void {
|
|
858
|
+
if (node.typeArguments !== undefined && node.typeArguments.length > 0) {
|
|
859
|
+
processThenCallWithTypeArg(ts, node, checker, sourceFile, typeMap, typesByFile, thenTypes, debugPrefix);
|
|
860
|
+
} else {
|
|
861
|
+
processThenCallWithoutTypeArg(sourceFile, node, thenTypes, debugPrefix);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
export function parseThenTypeArguments(
|
|
866
|
+
ts: typeof import('typescript'),
|
|
867
|
+
checker: import('typescript').TypeChecker,
|
|
868
|
+
sourceFile: import('typescript').SourceFile,
|
|
869
|
+
typeMap: Map<string, TypeInfo>,
|
|
870
|
+
typesByFile: Map<string, Map<string, TypeInfo>>,
|
|
871
|
+
): GivenTypeInfo[] {
|
|
872
|
+
const thenTypes: GivenTypeInfo[] = [];
|
|
873
|
+
|
|
874
|
+
const visit = (node: import('typescript').Node): void => {
|
|
875
|
+
if (ts.isCallExpression(node)) {
|
|
876
|
+
if (ts.isIdentifier(node.expression) && node.expression.text === 'then') {
|
|
877
|
+
processThenCall(ts, node, checker, sourceFile, typeMap, typesByFile, thenTypes, 'then');
|
|
878
|
+
} else if (ts.isPropertyAccessExpression(node.expression) && node.expression.name.getText() === 'then') {
|
|
879
|
+
processThenCall(ts, node, checker, sourceFile, typeMap, typesByFile, thenTypes, '.then');
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
ts.forEachChild(node, visit);
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
visit(sourceFile);
|
|
886
|
+
debug('[then-types] total then types extracted: %d', thenTypes.length);
|
|
887
|
+
return thenTypes;
|
|
888
|
+
}
|
|
889
|
+
|
|
747
890
|
export function transpileToCjs(ts: typeof import('typescript'), fileName: string, source: string): string {
|
|
748
891
|
const out = ts.transpileModule(source, {
|
|
749
892
|
compilerOptions: {
|