-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile down to es6 #47144
Compile down to es6 #47144
Conversation
var src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src('node_modules/typescript/lib/lib.d.ts')); | ||
var src = es.merge(gulp.src('src/**', { base: 'src' }), | ||
// gulp.src('node_modules/typescript/lib/lib.dom.d.ts'), | ||
gulp.src('node_modules/typescript/lib/lib.es6.d.ts')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful with that because I believe it leaks globals into the CU that we cannot use, e.g Symbol.iterator
etc. We need to configure the compiler so that it emits ES6 but doesn't use ES6 globals...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we use that, is it not in electron's Node?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The monaco editor supports IE11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must use a different compilation pass for the monaco editor. But I do see the problem that we might bring in references to unavailable stuff without realising it. Could we also solve that with some linting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have src/tsconfig.monaco.json
which is only the monaco editor. Problem is that tsserver can only use one project file so that you won't see compile errors in VS Code, e.g. when using Symbol.iterator
in vs/base
or vs/editor
. Running tsc -p tsconifg.monaco.json
takes around 15secs which I'd say is too much for a pre-commit hook. It does already run travis et al but with little respect...
So, I believe the challenge is that our This is the tsconfig.json-file {
"compilerOptions": {
"module": "amd",
"moduleResolution": "classic",
"noImplicitAny": false,
"removeComments": false,
"preserveConstEnums": true,
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"es2015.collection",
"es2015.core",
"es2015.generator",
"es2015.iterable",
"es2015.promise",
"es2015.proxy",
"es2015.reflect",
"es2015.symbol",
"webworker"
],
"sourceMap": false,
"experimentalDecorators": true,
"declaration": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noImplicitThis": true,
"alwaysStrict": true,
"baseUrl": ".",
"outDir": "../out",
"typeRoots": [
"typings"
]
},
"exclude": [
"./typings/lib.ie11_safe_es6.d.ts",
"./typings/es6-promise.d.ts"
]
} and there errors are generated
|
I'll have to follow up tomorrow on the TPromise issue, but the reason you are seeing other build errors with the custom 'lib' section is that none of those specific libraries entries references the 'es5' lib. If you add 'es5' to that list then the compile errors should go away. |
@rbuckton when adding |
@jrieken the "promise errors" are about using Regarding the other issue of using Is the issue that you are attempting to compile some parts of the project to both ES5 and ES6? If that is the case, your only recourse might be to define a global |
Yeah, this is the problem: The monaco-editor and VS Code are in the same codebase/project and because the editor still supports IE11 we cannot leak 'modern' globals, like In fact, we have a shim for the native promise but the migration is quite expensive; there are subtle semantic differences which means care must be taken and then such changes are quite viral because WinJS.Promise and (native) promise are not assignable. Then, our native-promise-shim won't ever be compatible with the native promise+well-known-symbols because of the lacks of such well-known-symbols. Not sure what to do about that... |
We chose to require native Promise in ES6 and higher for async functions since native async functions in later versions do not give you the option to use a different Promise type. However, it is possible to use a different Promise implementation at runtime (though not design time) by implementing a custom |
That means you get compile errors, right? |
@joaomoreno let's make a push next debt-week to reduce the amount of async-TPromise-usages? |
Sure, I can lend a day or two. 👍 |
Ok - tho great care must be taken... I have seen very unhappy thing happen when merging the worlds of TPromise and the native promise, esp. Promise.resolve(TPromise) will cause trouble... |
Maybe we can come up with the general guidelines w/ pitfalls? |
@jrieken const es6Promise = Promise.resolve({
then: function (fulfilled, failed) {
return wp.then(fulfilled, failed);
}
}); It would be best if we could come up with a solution that does not require tweaking each case. Especially when we gradually move from TPromises to ES6 Promises, we might often not be aware where our changes create new TPromise to ES6 Promise boundaries. |
A JS Bin I have used to look into the promise incompatibility: http://jsbin.com/cavequh/edit?js,output |
We could try to add another overload to |
Not necessarily, it means that whatever Promise implementation you use has to at least align to the ES2015 Promise API.
I'm curious what issues you've seen. My prior experience with WinJS promises were that they violate guidelines for asynchronous APIs, often resulting in unpredictable timing of operations. However, it sounds like there's some other incompatibility when a native Also, another way to adapt a WinJS Promise to a native Promise might be the following: new Promise((resolve, reject) => tPromise.then(resolve, reject)); |
I ran the code sample from the JSBin in NodeJS and I think I understand why |
If this starts occurring more often we might want to look into a permanent work around. I'm testing one here: #49034 |
Next challenge... We have now a happy compile but we hit a road block when running es6-compiled-code because of how 3rd parties depend on our JavaScript code. var TelemetryReporter = /** @class */ (function (_super) {
__extends(TelemetryReporter, _super);
function TelemetryReporter(extensionId, extensionVersion, key) {
var _this = _super.call(this, function () { return _this.toDispose.forEach(function (d) { return d && d.dispose(); }); }) || this;
//...more...
return _this;
}
//...more...
return TelemetryReporter;
}(vscode.Disposable)); So, This puts us in a bad spot because we cannot ask extensions to change/recompile their code. Maybe @rbuckton has some advise. Is there a way, maybe via emit-helpers, to change how super is being called? I think it would need some switch depending on the type of _super - (we made a similar change 835abba to our create-type util). |
@rbuckton Could this be a case transformers? Like, we wanna use the normal es6-emitting but for classes we wanna use the es5-emitting. Does that sound reasonable? |
Closing as |
Could we compile our sources to ES6? This can bring many engineering advantages, especially around debugging our sources, and possibly perf improvements.
This branch now has a couple of errors.
Most of them are related to the fact that it doesn't seem to be possible to use async and TPromise with ES6 anymore:
@mjbvz Is this a real limitation, or can we get around it somehow, without converting all our promises?
Other errors lie in
lib.ie11_safe_es6.d.ts
:There are a few others, but let's get these out of the way; they seem bigger.
cc @Microsoft/vscode