File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -1143,9 +1143,14 @@ namespace ts {
1143
1143
if ( options . importHelpers
1144
1144
&& ( options . isolatedModules || isExternalModuleFile )
1145
1145
&& ! file . isDeclarationFile ) {
1146
- const externalHelpersModuleReference = < StringLiteral > createNode ( SyntaxKind . StringLiteral ) ;
1146
+ // synthesize 'import "tslib"' declaration
1147
+ const externalHelpersModuleReference = < StringLiteral > createSynthesizedNode ( SyntaxKind . StringLiteral ) ;
1147
1148
externalHelpersModuleReference . text = externalHelpersModuleNameText ;
1148
- externalHelpersModuleReference . parent = file ;
1149
+ const importDecl = createSynthesizedNode ( SyntaxKind . ImportDeclaration ) ;
1150
+
1151
+ importDecl . parent = file ;
1152
+ externalHelpersModuleReference . parent = importDecl ;
1153
+
1149
1154
imports = [ externalHelpersModuleReference ] ;
1150
1155
}
1151
1156
Original file line number Diff line number Diff line change @@ -2576,4 +2576,21 @@ namespace ts.projectSystem {
2576
2576
assert . isTrue ( diags . length === 0 ) ;
2577
2577
} ) ;
2578
2578
} ) ;
2579
+
2580
+ describe ( "import helpers" , ( ) => {
2581
+ it ( "should not crash in tsserver" , ( ) => {
2582
+ const f1 = {
2583
+ path : "/a/app.ts" ,
2584
+ content : "export async function foo() { return 100; }"
2585
+ } ;
2586
+ const tslib = {
2587
+ path : "/a/node_modules/tslib/index.d.ts" ,
2588
+ content : ""
2589
+ } ;
2590
+ const host = createServerHost ( [ f1 , tslib ] ) ;
2591
+ const service = createProjectService ( host ) ;
2592
+ service . openExternalProject ( { projectFileName : "p" , rootFiles : [ toExternalFile ( f1 . path ) ] , options : { importHelpers : true } } ) ;
2593
+ service . checkNumberOfProjects ( { externalProjects : 1 } ) ;
2594
+ } ) ;
2595
+ } ) ;
2579
2596
}
You can’t perform that action at this time.
0 commit comments