@@ -82,7 +82,7 @@ import {
82
82
getNameAsString ,
83
83
getPropertyName ,
84
84
getRuntimeTypeName ,
85
- hasModifier ,
85
+ hasModifier , hasSourceFile ,
86
86
isBuiltType ,
87
87
isNodeWithLocals ,
88
88
NodeConverter ,
@@ -465,7 +465,7 @@ class CompilerProgram {
465
465
return frame . variables . length - 1 ;
466
466
}
467
467
468
- pushTemplateParameter ( name : string , withDefault : boolean = false ) : number {
468
+ pushTemplateParameter ( name : string , withDefault : boolean = false ) : number {
469
469
this . pushOp ( withDefault ? ReflectionOp . typeParameterDefault : ReflectionOp . typeParameter , this . findOrAddStackEntry ( name ) ) ;
470
470
this . frame . variables . push ( {
471
471
index : this . frame . variables . length ,
@@ -1343,11 +1343,11 @@ export class ReflectionTransformer implements CustomTransformer {
1343
1343
const narrowed = node as ClassDeclaration | ClassExpression ;
1344
1344
//class nodes have always their own program, so the start is always fresh, means we don't need a frame
1345
1345
1346
- if ( this . external . isEmbeddingExternalLibraryImport ( ) ) {
1346
+ /* if (this.external.isEmbeddingExternalLibraryImport()) {
1347
1347
const declaration = this.nodeConverter.convertClassToInterface(narrowed);
1348
1348
this.extractPackStructOfType(declaration, program);
1349
1349
break;
1350
- }
1350
+ }*/
1351
1351
1352
1352
if ( node ) {
1353
1353
const members : ClassElement [ ] = [ ] ;
@@ -1363,7 +1363,7 @@ export class ReflectionTransformer implements CustomTransformer {
1363
1363
}
1364
1364
}
1365
1365
1366
- if ( narrowed . heritageClauses ) {
1366
+ if ( ! this . external . isEmbeddingExternalLibraryImport ( ) && narrowed . heritageClauses ) {
1367
1367
for ( const heritage of narrowed . heritageClauses ) {
1368
1368
if ( heritage . token === SyntaxKind . ExtendsKeyword ) {
1369
1369
for ( const extendType of heritage . types ) {
@@ -1394,7 +1394,8 @@ export class ReflectionTransformer implements CustomTransformer {
1394
1394
this . extractPackStructOfType ( member , program ) ;
1395
1395
}
1396
1396
1397
- program . pushOp ( ReflectionOp . class ) ;
1397
+ program . pushOp ( ReflectionOp . class )
1398
+ // program.pushOp(!this.external.isEmbeddingExternalLibraryImport() ? ReflectionOp.class : ReflectionOp.objectLiteral);
1398
1399
1399
1400
if ( narrowed . heritageClauses ) {
1400
1401
for ( const heritageClause of narrowed . heritageClauses ) {
@@ -1416,7 +1417,9 @@ export class ReflectionTransformer implements CustomTransformer {
1416
1417
}
1417
1418
}
1418
1419
1419
- if ( narrowed . name ) this . resolveTypeName ( getIdentifierName ( narrowed . name ) , program ) ;
1420
+ if ( narrowed . name ) {
1421
+ this . resolveTypeName ( getIdentifierName ( narrowed . name ) , program ) ;
1422
+ }
1420
1423
1421
1424
const description = extractJSDocAttribute ( narrowed , 'description' ) ;
1422
1425
if ( description ) program . pushOp ( ReflectionOp . description , program . findOrAddStackEntry ( description ) ) ;
@@ -1696,10 +1699,6 @@ export class ReflectionTransformer implements CustomTransformer {
1696
1699
const narrowed = node as MethodSignature | MethodDeclaration | CallSignatureDeclaration | ConstructorTypeNode
1697
1700
| ConstructSignatureDeclaration | ConstructorDeclaration | ArrowFunction | FunctionExpression | FunctionTypeNode | FunctionDeclaration ;
1698
1701
1699
- if ( this . external . isEmbeddingExternalLibraryImport ( ) && ( isFunctionDeclaration ( node ) || isFunctionExpression ( node ) || isMethodDeclaration ( node ) ) ) {
1700
- console . log ( getNameAsString ( narrowed . name ) ) ;
1701
- }
1702
-
1703
1702
const config = this . findReflectionConfig ( narrowed , program ) ;
1704
1703
if ( config . mode === 'never' ) return ;
1705
1704
@@ -2034,7 +2033,7 @@ export class ReflectionTransformer implements CustomTransformer {
2034
2033
if ( importDeclaration . importClause && importDeclaration . importClause . isTypeOnly ) typeOnly = true ;
2035
2034
declaration = this . resolveImportSpecifier ( typeName . escapedText , importDeclaration , this . sourceFile ) ;
2036
2035
//might be an external library
2037
- if ( ! declaration ) {
2036
+ if ( ! declaration && hasSourceFile ( importDeclaration ) ) {
2038
2037
sourceFile = importDeclaration . getSourceFile ( ) ;
2039
2038
declaration = this . resolveImportSpecifier ( typeName . escapedText , importDeclaration , sourceFile ) ;
2040
2039
}
@@ -2096,6 +2095,7 @@ export class ReflectionTransformer implements CustomTransformer {
2096
2095
// check if the referenced declaration has reflection disabled
2097
2096
const declarationReflection = this . findReflectionConfig ( declaration , program ) ;
2098
2097
if ( declarationReflection . mode !== 'never' ) {
2098
+ if ( ! hasSourceFile ( importDeclaration ) ) return expression ;
2099
2099
const declarationSourceFile = importDeclaration . getSourceFile ( ) ;
2100
2100
2101
2101
const runtimeTypeName = this . getRuntimeTypeName ( typeName ) ;
@@ -2106,10 +2106,11 @@ export class ReflectionTransformer implements CustomTransformer {
2106
2106
2107
2107
if ( isEmbeddingExternalLibraryImport || ( ! builtType && this . external . shouldInlineExternalLibraryImport ( importDeclaration , typeName , declarationReflection ) ) ) {
2108
2108
const { module } = this . external . processExternalLibraryImport ( typeName , declaration , declarationSourceFile , importDeclaration ) ;
2109
- const newExpression = this . f . createPropertyAccessExpression ( this . f . createIdentifier ( getExternalRuntimeTypeName ( module . packageId . name ) ) , typeName ) ;
2110
- return ! isEmbeddingExternalLibraryImport && ( isClassDeclaration ( declaration ) || isFunctionDeclaration ( declaration ) )
2111
- ? this . wrapWithAssignType ( expression , newExpression )
2112
- : newExpression
2109
+ return this . f . createPropertyAccessExpression ( this . f . createIdentifier ( getExternalRuntimeTypeName ( module . packageId . name ) ) , typeName ) ;
2110
+ // const newExpression = this.f.createPropertyAccessExpression(this.f.createIdentifier(getExternalRuntimeTypeName(module.packageId.name)), typeName);
2111
+ // return !isEmbeddingExternalLibraryImport && (isClassDeclaration(declaration) || isFunctionDeclaration(declaration))
2112
+ // ? this.wrapWithAssignType(expression, newExpression)
2113
+ // : newExpression
2113
2114
}
2114
2115
}
2115
2116
@@ -2215,7 +2216,6 @@ export class ReflectionTransformer implements CustomTransformer {
2215
2216
if ( isModuleDeclaration ( declaration ) && resolved . importDeclaration ) {
2216
2217
let expression : Expression = serializeEntityNameAsExpression ( this . f , typeName ) ;
2217
2218
if ( isIdentifier ( typeName ) ) {
2218
- console . log ( 2 , getNameAsString ( typeName ) ) ;
2219
2219
expression = this . resolveImportExpression ( declaration , resolved . importDeclaration , typeName , expression , program )
2220
2220
}
2221
2221
@@ -2309,19 +2309,20 @@ export class ReflectionTransformer implements CustomTransformer {
2309
2309
return ;
2310
2310
}
2311
2311
2312
- const builtType = isBuiltType ( runtimeTypeName , found ) ;
2313
- if ( ! builtType ) {
2314
- if ( ! this . external . shouldInlineExternalLibraryImport ( resolved . importDeclaration , typeName , declarationReflection ) ) return ;
2315
- this . external . processExternalLibraryImport ( typeName , declaration , declarationSourceFile , resolved . importDeclaration ) ;
2312
+ const reflection = this . findReflectionFromPath ( found . fileName ) ;
2313
+ if ( reflection . mode !== 'never' ) {
2314
+ this . addImports . push ( { identifier : runtimeTypeName , from : resolved . importDeclaration . moduleSpecifier } ) ;
2315
+ return ;
2316
2316
} else {
2317
- //check if the referenced file has reflection info emitted. if not, any is emitted for that reference
2318
- const reflection = this . findReflectionFromPath ( found . fileName ) ;
2319
- if ( reflection . mode === 'never' ) {
2320
- program . pushOp ( ReflectionOp . any ) ;
2321
- return ;
2317
+ const builtType = isBuiltType ( runtimeTypeName , found ) ;
2318
+ if ( ! builtType ) {
2319
+ if ( this . external . shouldInlineExternalLibraryImport ( resolved . importDeclaration , typeName , declarationReflection ) ) {
2320
+ this . external . processExternalLibraryImport ( typeName , declaration , declarationSourceFile , resolved . importDeclaration ) ;
2321
+ } else {
2322
+ program . pushOp ( ReflectionOp . any ) ;
2323
+ return ;
2324
+ }
2322
2325
}
2323
-
2324
- this . addImports . push ( { identifier : runtimeTypeName , from : resolved . importDeclaration . moduleSpecifier } ) ;
2325
2326
}
2326
2327
}
2327
2328
} else {
@@ -2384,14 +2385,15 @@ export class ReflectionTransformer implements CustomTransformer {
2384
2385
this . extractPackStructOfType ( typeArgument , program ) ;
2385
2386
}
2386
2387
}
2387
- if ( this . external . isEmbeddingExternalLibraryImport ( ) ) {
2388
+ /* if (this.external.isEmbeddingExternalLibraryImport()) {
2388
2389
if (isClassDeclaration(declaration)) {
2389
2390
program.pushOp(ReflectionOp.objectLiteral);
2390
2391
} else {
2391
2392
const index = program.pushStack(this.f.createArrowFunction(undefined, undefined, [], undefined, undefined, body));
2392
2393
program.pushOp(ReflectionOp.function, index);
2393
2394
}
2394
- } else {
2395
+ this.resolveTypeName(getNameAsString(typeName), program);
2396
+ } else */ {
2395
2397
const index = program . pushStack ( this . f . createArrowFunction ( undefined , undefined , [ ] , undefined , undefined , body ) ) ;
2396
2398
program . pushOp ( isClassDeclaration ( declaration ) ? ReflectionOp . classReference : ReflectionOp . functionReference , index ) ;
2397
2399
}
0 commit comments