@@ -208,7 +208,7 @@ export namespace Compiler {
208
208
const matchingItem =
209
209
typeof location . column === 'number'
210
210
? // Find the next closes column we have, we if cannot find an exact match.
211
- map . get ( location . column ) || map . get ( location . column - 1 ) || map . get ( location . column + 1 )
211
+ map . get ( location . column ) || map . get ( location . column - 1 ) || map . get ( location . column + 1 )
212
212
: map . get ( 0 ) ! ;
213
213
if ( matchingItem ) {
214
214
mappedLocation . line = matchingItem . generatedLine ;
@@ -260,11 +260,12 @@ export namespace Compiler {
260
260
{
261
261
sourceMap : true ,
262
262
inlineSourceMap : true ,
263
- sourceRoot : path . dirname ( details . sourceFilename ) ,
263
+ jsx : ts . JsxEmit . None ,
264
+ sourceRoot : path . dirname ( details . sourceTsFilename ) ,
264
265
noImplicitUseStrict : true ,
265
266
importsNotUsedAsValues : ts . ImportsNotUsedAsValues . Remove ,
266
267
strict : false , // No way.
267
- fileName : details . sourceFilename ,
268
+ fileName : details . sourceTsFilename ,
268
269
resolveJsonModule : true ,
269
270
removeComments : true ,
270
271
target : ts . ScriptTarget . ESNext , // Minimum Node12 (but let users use what ever they want). Lets look into user defined tsconfig.json.
@@ -282,7 +283,7 @@ export namespace Compiler {
282
283
allowSyntheticDefaultImports : true ,
283
284
skipLibCheck : true // We expect users to rely on VS Code to let them know if they have issues in their code.
284
285
} ,
285
- details . sourceFilename
286
+ details . sourceTsFilename
286
287
) ;
287
288
// let transpiledCode = result;
288
289
// let transpiledCode = result.replace(
@@ -522,6 +523,7 @@ function createCodeObject(cell: NotebookCell) {
522
523
const codeObject : CodeObject = {
523
524
code : '' ,
524
525
sourceFilename : '' ,
526
+ sourceTsFilename : '' ,
525
527
sourceMapFilename : '' ,
526
528
friendlyName : cwd
527
529
? `${ path . relative ( cwd , cell . notebook . uri . fsPath ) } ?cell=${ cell . index + 1 } `
@@ -535,10 +537,16 @@ function createCodeObject(cell: NotebookCell) {
535
537
// codeObject.sourceFilename = codeObject.sourceFilename || cell.document.uri.toString();
536
538
codeObject . sourceFilename =
537
539
codeObject . sourceFilename || path . join ( tmpDirectory , `notebook_cell_${ cell . document . uri . fragment } .js` ) ;
540
+ codeObject . sourceTsFilename =
541
+ codeObject . sourceTsFilename || path . join ( tmpDirectory , `notebook_cell_${ cell . document . uri . fragment } .ts` ) ;
538
542
codeObject . sourceMapFilename = codeObject . sourceMapFilename || `${ codeObject . sourceFilename } .map` ;
539
543
mapOfSourceFilesToNotebookUri . set ( codeObject . sourceFilename , cell . document . uri ) ;
540
544
mapOfSourceFilesToNotebookUri . set ( cell . document . uri . toString ( ) , cell . document . uri ) ;
541
545
mapFromCellToPath . set ( cell , codeObject ) ;
546
+ // For some reason if the file is empty, then generics don't work
547
+ // To fix this issue (https://github.com/DonJayamanne/typescript-notebook/issues/40) we must have code in the file.
548
+ // Even tried locally by manullay importing typescript and using compiler, same problem.
549
+ fs . writeFileSync ( codeObject . sourceTsFilename , cell . document . getText ( ) ) ;
542
550
return codeObject ;
543
551
}
544
552
function updateCodeObject ( codeObject : CodeObject , cell : NotebookCell , sourceCode : string , sourceMapText : string ) {
@@ -549,6 +557,7 @@ function updateCodeObject(codeObject: CodeObject, cell: NotebookCell, sourceCode
549
557
550
558
if ( codeObject . textDocumentVersion !== cell . document . version ) {
551
559
fs . writeFileSync ( codeObject . sourceFilename , sourceCode ) ;
560
+ fs . writeFileSync ( codeObject . sourceTsFilename , sourceCode ) ;
552
561
// if (sourceMapText) {
553
562
// fs.writeFileSync(codeObject.sourceMapFilename, sourceMapText);
554
563
// }
@@ -655,15 +664,15 @@ export type VariableDeclaration = BaseNode<'VariableDeclaration'> & {
655
664
} ;
656
665
type VariableDeclarator = BaseNode < 'VariableDeclarator' > & {
657
666
id :
658
- | ( BaseNode < string > & { name : string ; loc : BodyLocation ; type : 'Identifier' | '<other>' } )
659
- | ( BaseNode < 'ObjectPattern' > & {
660
- name : string ;
661
- properties : { type : 'Property' ; key : { name : string } ; value : { name : string } } [ ] ;
662
- } )
663
- | ( BaseNode < 'ArrayPattern' > & {
664
- name : string ;
665
- elements : { name : string ; type : 'Identifier' } [ ] ;
666
- } ) ;
667
+ | ( BaseNode < string > & { name : string ; loc : BodyLocation ; type : 'Identifier' | '<other>' } )
668
+ | ( BaseNode < 'ObjectPattern' > & {
669
+ name : string ;
670
+ properties : { type : 'Property' ; key : { name : string } ; value : { name : string } } [ ] ;
671
+ } )
672
+ | ( BaseNode < 'ArrayPattern' > & {
673
+ name : string ;
674
+ elements : { name : string ; type : 'Identifier' } [ ] ;
675
+ } ) ;
667
676
init ?: { loc : BodyLocation } ;
668
677
loc : BodyLocation ;
669
678
} ;
@@ -677,14 +686,14 @@ type BlockStatement = {
677
686
} ;
678
687
type ExpressionStatement = BaseNode < 'ExpressionStatement' > & {
679
688
expression :
689
+ | ( BaseNode < 'CallExpression' > & {
690
+ callee :
691
+ | ( BaseNode < 'ArrowFunctionExpression' > & { body : BlockStatement } )
680
692
| ( BaseNode < 'CallExpression' > & {
681
- callee :
682
- | ( BaseNode < 'ArrowFunctionExpression' > & { body : BlockStatement } )
683
- | ( BaseNode < 'CallExpression' > & {
684
- body : BlockStatement ;
685
- callee : { name : string ; loc : BodyLocation } ;
686
- } ) ;
687
- } )
688
- | BaseNode < 'other' > ;
693
+ body : BlockStatement ;
694
+ callee : { name : string ; loc : BodyLocation } ;
695
+ } ) ;
696
+ } )
697
+ | BaseNode < 'other' > ;
689
698
loc : BodyLocation ;
690
699
} ;
0 commit comments