From 4fefe8993f13508a5da97d6ef643fcc7bcb7eaae Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Fri, 28 Feb 2020 10:42:01 -0500 Subject: [PATCH] Ensure that the default es2015 libraries include dom, webworker, and scripthost --- src/lib/lib.ts | 5 ++++- src/tsWorker.ts | 14 +++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib/lib.ts b/src/lib/lib.ts index 6b43acc9..c77c383e 100644 --- a/src/lib/lib.ts +++ b/src/lib/lib.ts @@ -31,4 +31,7 @@ export const lib_es5_dts: string = "/*! **************************************** export const lib_es2015_dts: string = "/*! *****************************************************************************\nCopyright (c) Microsoft Corporation. All rights reserved. \nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\nthis file except in compliance with the License. You may obtain a copy of the\nLicense at http://www.apache.org/licenses/LICENSE-2.0 \n \nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, \nMERCHANTABLITY OR NON-INFRINGEMENT. \n \nSee the Apache Version 2.0 License for specific language governing permissions\nand limitations under the License.\n***************************************************************************** */\n\n\n\n/// \n\n" + lib_es5_dts + "" + lib_es2015_core_dts + "" + lib_es2015_collection_dts + "" + lib_es2015_generator_dts + "" + lib_es2015_promise_dts + "" + lib_es2015_iterable_dts + "" + lib_es2015_proxy_dts + "" + lib_es2015_reflect_dts + "" + lib_es2015_symbol_dts + "" + lib_es2015_symbol_wellknown_dts + ""; -export const lib_dts: string = "/*! *****************************************************************************\nCopyright (c) Microsoft Corporation. All rights reserved. \nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\nthis file except in compliance with the License. You may obtain a copy of the\nLicense at http://www.apache.org/licenses/LICENSE-2.0 \n \nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, \nMERCHANTABLITY OR NON-INFRINGEMENT. \n \nSee the Apache Version 2.0 License for specific language governing permissions\nand limitations under the License.\n***************************************************************************** */\n\n\n\n/// \n\n" + lib_es5_dts + "" + lib_dom_dts + "" + lib_webworker_importscripts_dts + "" + lib_scripthost_dts + ""; +export const lib_es5_bundled_dts: string = "/*! *****************************************************************************\nCopyright (c) Microsoft Corporation. All rights reserved. \nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\nthis file except in compliance with the License. You may obtain a copy of the\nLicense at http://www.apache.org/licenses/LICENSE-2.0 \n \nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, \nMERCHANTABLITY OR NON-INFRINGEMENT. \n \nSee the Apache Version 2.0 License for specific language governing permissions\nand limitations under the License.\n***************************************************************************** */\n\n\n\n/// \n\n" + lib_es5_dts + "" + lib_dom_dts + "" + lib_webworker_importscripts_dts + "" + lib_scripthost_dts + ""; + +/** This is the DTS which is used by default in monaco-typescript */ +export const lib_es2015_bundled_dts = lib_es2015_dts + "" + lib_dom_dts + "" + lib_webworker_importscripts_dts + "" + lib_scripthost_dts + "" diff --git a/src/tsWorker.ts b/src/tsWorker.ts index 89436c07..5f00f72e 100644 --- a/src/tsWorker.ts +++ b/src/tsWorker.ts @@ -5,19 +5,19 @@ 'use strict'; import * as ts from './lib/typescriptServices'; -import { lib_dts, lib_es2015_dts } from './lib/lib'; +import { lib_es5_dts, lib_es2015_bundled_dts } from './lib/lib'; import { IExtraLibs } from './monaco.contribution'; import IWorkerContext = monaco.worker.IWorkerContext; -const DEFAULT_LIB = { +const DEFAULT_ES5_LIB = { NAME: 'defaultLib:lib.d.ts', - CONTENTS: lib_dts + CONTENTS: lib_es5_dts }; const ES2015_LIB = { NAME: 'defaultLib:lib.es2015.d.ts', - CONTENTS: lib_es2015_dts + CONTENTS: lib_es2015_bundled_dts }; export class TypeScriptWorker implements ts.LanguageServiceHost, monaco.languages.typescript.TypeScriptWorker { @@ -84,8 +84,8 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, monaco.language // extra lib text = this._extraLibs[fileName].content; - } else if (fileName === DEFAULT_LIB.NAME) { - text = DEFAULT_LIB.CONTENTS; + } else if (fileName === DEFAULT_ES5_LIB.NAME) { + text = DEFAULT_ES5_LIB.CONTENTS; } else if (fileName === ES2015_LIB.NAME) { text = ES2015_LIB.CONTENTS; } else { @@ -127,7 +127,7 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, monaco.language getDefaultLibFileName(options: ts.CompilerOptions): string { // TODO@joh support lib.es7.d.ts - return (options.target || ts.ScriptTarget.ES2015) <= ts.ScriptTarget.ES2015 ? DEFAULT_LIB.NAME : ES2015_LIB.NAME; + return (options.target || ts.ScriptTarget.ES2015) < ts.ScriptTarget.ES2015 ? DEFAULT_ES5_LIB.NAME : ES2015_LIB.NAME; } isDefaultLibFileName(fileName: string): boolean {