Bump default JS target for scripts in html (#150240)

* Bump default JS target for scripts in html

For JS/TS files, we target ES2020 by default. However in html files we're still stuck targetting es6

This change aligns the two

* use es2020.full (includes dom), fix web, avoid searching in node_modules

Co-authored-by: Martin Aeschlimann <martinae@microsoft.com>
This commit is contained in:
Matt Bierner 2022-05-25 02:50:44 -07:00 committed by GitHub
parent 9ade6a6636
commit a6724dcc10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View file

@ -31,7 +31,7 @@ module.exports = function () {
queue.push(name);
};
enqueue('es6');
enqueue('es2020.full');
var result = [];
while (queue.length > 0) {

View file

@ -24,7 +24,7 @@ export function loadLibrary(name: string) {
try {
content = readFileSync(libPath).toString();
} catch (e) {
console.log(`Unable to load library ${name} at ${libPath}: ${e.message}`);
console.log(`Unable to load library ${name} at ${libPath}`);
content = '';
}
contents[name] = content;

View file

@ -19,7 +19,7 @@ import { getSemanticTokens, getSemanticTokenLegend } from './javascriptSemanticT
const JS_WORD_REGEX = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g;
function getLanguageServiceHost(scriptKind: ts.ScriptKind) {
const compilerOptions: ts.CompilerOptions = { allowNonTsExtensions: true, allowJs: true, lib: ['lib.es6.d.ts'], target: ts.ScriptTarget.Latest, moduleResolution: ts.ModuleResolutionKind.Classic, experimentalDecorators: false };
const compilerOptions: ts.CompilerOptions = { allowNonTsExtensions: true, allowJs: true, lib: ['lib.es2020.full.d.ts'], target: ts.ScriptTarget.Latest, moduleResolution: ts.ModuleResolutionKind.Classic, experimentalDecorators: false };
let currentTextDocument = TextDocument.create('init', 'javascript', 1, '');
const jsLanguageService = import(/* webpackChunkName: "javascriptLibs" */ './javascriptLibs').then(libs => {
@ -52,7 +52,7 @@ function getLanguageServiceHost(scriptKind: ts.ScriptKind) {
};
},
getCurrentDirectory: () => '',
getDefaultLibFileName: (_options: ts.CompilerOptions) => 'es6',
getDefaultLibFileName: (_options: ts.CompilerOptions) => 'es2020.full',
readFile: (path: string, _encoding?: string | undefined): string | undefined => {
if (path === currentTextDocument.uri) {
return currentTextDocument.getText();
@ -66,6 +66,15 @@ function getLanguageServiceHost(scriptKind: ts.ScriptKind) {
} else {
return !!libs.loadLibrary(path);
}
},
directoryExists: (path: string): boolean => {
// typescript tries to first find libraries in node_modules/@types and node_modules/@typescript
// there's no node_modules in our setup
if (path.startsWith('node_modules')) {
return false;
}
return true;
}
};
return ts.createLanguageService(host);