Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions 9 src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1140,9 +1140,14 @@ namespace ts {
if (options.importHelpers
&& (options.isolatedModules || isExternalModuleFile)
&& !file.isDeclarationFile) {
const externalHelpersModuleReference = <StringLiteral>createNode(SyntaxKind.StringLiteral);
// synthesize 'import "tslib"' declaration
const externalHelpersModuleReference = <StringLiteral>createSynthesizedNode(SyntaxKind.StringLiteral);
externalHelpersModuleReference.text = externalHelpersModuleNameText;
externalHelpersModuleReference.parent = file;
const importDecl = createSynthesizedNode(SyntaxKind.ImportDeclaration);

importDecl.parent = file;
externalHelpersModuleReference.parent = importDecl;

imports = [externalHelpersModuleReference];
}

Expand Down
17 changes: 17 additions & 0 deletions 17 src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2576,4 +2576,21 @@ namespace ts.projectSystem {
assert.isTrue(diags.length === 0);
});
});

describe("import helpers", () => {
it("should not crash in tsserver", () => {
const f1 = {
path: "/a/app.ts",
content: "export async function foo() { return 100; }"
};
const tslib = {
path: "/a/node_modules/tslib/index.d.ts",
content: ""
};
const host = createServerHost([f1, tslib]);
const service = createProjectService(host);
service.openExternalProject({ projectFileName: "p", rootFiles: [toExternalFile(f1.path)], options: { importHelpers: true } });
service.checkNumberOfProjects({ externalProjects: 1 });
});
});
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.