UNPKG

3.63 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.TypeScriptServiceHost = void 0;
7const tsserverlibrary_1 = __importDefault(require("typescript/lib/tsserverlibrary"));
8const merge_deep_1 = __importDefault(require("merge-deep"));
9const utils_1 = require("./utils");
10// see https://github.com/denoland/deno/blob/2debbdacb935cfe1eb7bb8d1f40a5063b339d90b/js/compiler.ts#L159-L170
11const OPTIONS = {
12 allowJs: true,
13 checkJs: true,
14 esModuleInterop: true,
15 module: tsserverlibrary_1.default.ModuleKind.ESNext,
16 moduleResolution: tsserverlibrary_1.default.ModuleResolutionKind.NodeJs,
17 jsx: tsserverlibrary_1.default.JsxEmit.React,
18 noEmit: true,
19 strict: true,
20 outDir: "$deno$",
21 removeComments: true,
22 stripComments: true,
23 resolveJsonModule: true,
24 sourceMap: true,
25 target: tsserverlibrary_1.default.ScriptTarget.ESNext,
26 typeRoots: [],
27};
28const OPTIONS_OVERWRITE_BY_DENO = {
29 allowNonTsExtensions: false,
30 jsx: OPTIONS.jsx,
31 module: OPTIONS.module,
32 moduleResolution: OPTIONS.moduleResolution,
33 resolveJsonModule: OPTIONS.resolveJsonModule,
34 strict: OPTIONS.strict,
35 noEmit: OPTIONS.noEmit,
36 noEmitHelpers: OPTIONS.noEmitHelpers,
37 target: tsserverlibrary_1.default.ScriptTarget.ESNext,
38 paths: {
39 abc: ["./c.ts"],
40 "abc.ts": ["./c.ts"],
41 },
42};
43/**
44 * An implementation of a `LanguageServiceHost` for a TypeScript project.
45 *
46 * The `TypeScriptServiceHost` implements the Deno `LanguageServiceHost` using
47 * the TypeScript language services.
48 */
49class TypeScriptServiceHost {
50 constructor(tsLsHost,
51 // private readonly tsLS: ts_module.LanguageService,
52 logger) {
53 this.tsLsHost = tsLsHost;
54 this.logger = logger;
55 }
56 getCompilationSettings() {
57 this.logger.info("getCompilationSettings");
58 const projectConfig = this.tsLsHost.getCompilationSettings();
59 const compilationSettings = merge_deep_1.default(merge_deep_1.default(OPTIONS, projectConfig), OPTIONS_OVERWRITE_BY_DENO);
60 compilationSettings.baseUrl = this.tsLsHost.getCurrentDirectory();
61 this.logger.info(`compilationSettings:${JSON.stringify(compilationSettings)}`);
62 return compilationSettings;
63 }
64 resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, options) {
65 if (!this.tsLsHost.resolveModuleNames) {
66 this.logger.info("resolveModuleNames is undefined.");
67 return [];
68 }
69 this.logger.info("resolvedModule:\n" + JSON.stringify(moduleNames, null, " "));
70 const resolvedModule = this.tsLsHost.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, options);
71 return resolvedModule;
72 }
73 getScriptFileNames() {
74 const scriptFileNames = this.tsLsHost.getScriptFileNames();
75 const denoDtsPath = utils_1.getDenoDtsPath("lib.deno.d.ts");
76 if (denoDtsPath) {
77 scriptFileNames.push(denoDtsPath);
78 }
79 return scriptFileNames;
80 }
81 // TODO
82 resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, options) {
83 if (!this.tsLsHost.resolveTypeReferenceDirectives) {
84 return [];
85 }
86 return this.tsLsHost.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, options);
87 }
88}
89exports.TypeScriptServiceHost = TypeScriptServiceHost;
90//# sourceMappingURL=typescript_host.js.map
\No newline at end of file