Skip to content

Commit a6724dc

Browse files
mjbvzaeschli
andauthored
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>
1 parent 9ade6a6 commit a6724dc

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

extensions/html-language-features/server/build/javaScriptLibraryLoader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = function () {
3131
queue.push(name);
3232
};
3333

34-
enqueue('es6');
34+
enqueue('es2020.full');
3535

3636
var result = [];
3737
while (queue.length > 0) {

extensions/html-language-features/server/src/modes/javascriptLibs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function loadLibrary(name: string) {
2424
try {
2525
content = readFileSync(libPath).toString();
2626
} catch (e) {
27-
console.log(`Unable to load library ${name} at ${libPath}: ${e.message}`);
27+
console.log(`Unable to load library ${name} at ${libPath}`);
2828
content = '';
2929
}
3030
contents[name] = content;

extensions/html-language-features/server/src/modes/javascriptMode.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { getSemanticTokens, getSemanticTokenLegend } from './javascriptSemanticT
1919
const JS_WORD_REGEX = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g;
2020

2121
function getLanguageServiceHost(scriptKind: ts.ScriptKind) {
22-
const compilerOptions: ts.CompilerOptions = { allowNonTsExtensions: true, allowJs: true, lib: ['lib.es6.d.ts'], target: ts.ScriptTarget.Latest, moduleResolution: ts.ModuleResolutionKind.Classic, experimentalDecorators: false };
22+
const compilerOptions: ts.CompilerOptions = { allowNonTsExtensions: true, allowJs: true, lib: ['lib.es2020.full.d.ts'], target: ts.ScriptTarget.Latest, moduleResolution: ts.ModuleResolutionKind.Classic, experimentalDecorators: false };
2323

2424
let currentTextDocument = TextDocument.create('init', 'javascript', 1, '');
2525
const jsLanguageService = import(/* webpackChunkName: "javascriptLibs" */ './javascriptLibs').then(libs => {
@@ -52,7 +52,7 @@ function getLanguageServiceHost(scriptKind: ts.ScriptKind) {
5252
};
5353
},
5454
getCurrentDirectory: () => '',
55-
getDefaultLibFileName: (_options: ts.CompilerOptions) => 'es6',
55+
getDefaultLibFileName: (_options: ts.CompilerOptions) => 'es2020.full',
5656
readFile: (path: string, _encoding?: string | undefined): string | undefined => {
5757
if (path === currentTextDocument.uri) {
5858
return currentTextDocument.getText();
@@ -66,6 +66,15 @@ function getLanguageServiceHost(scriptKind: ts.ScriptKind) {
6666
} else {
6767
return !!libs.loadLibrary(path);
6868
}
69+
},
70+
directoryExists: (path: string): boolean => {
71+
// typescript tries to first find libraries in node_modules/@types and node_modules/@typescript
72+
// there's no node_modules in our setup
73+
if (path.startsWith('node_modules')) {
74+
return false;
75+
}
76+
return true;
77+
6978
}
7079
};
7180
return ts.createLanguageService(host);

0 commit comments

Comments
 (0)