-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[Transforms] Import external helpers module #9097
Conversation
CC: @mhegazy, @vladima, @ahejlsberg |
@@ -415,7 +415,7 @@ namespace ts { | |||
BlockScoped = Let | Const, | |||
|
|||
ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn, | |||
EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions, | |||
EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions | HasJsxSpreadAttribute, |
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.
side note, we should get rid of this flag, specially that it is not used except in one place, and is at bit 30, which will cause a conversion on node-32 bit.
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.
Actually, this is a bug in printer. This flag needs to be used and isn't.
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.
Also, we need to consolidate the node flag values now that I've extracted the modifiers out of NodeFlags
, that should help us avoid the SMI overflow on 32-bit node.
__asing seems to be emitted still. other than that, can you add a test for something that explicitly includes an import to tslib. |
We previously talked about adding a check in the program creating to make sure that |
if (helpers) { | ||
const exports = helpers.exports; | ||
if (requestedHelpers & NodeFlags.HasClassExtends && languageVersion < ScriptTarget.ES6) { | ||
verifyHelperSymbol(exports, "__extends", SymbolFlags.Value); |
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.
consider returning after the first error, to avoid reporting the same error for every file.
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.
I need to traverse each file to determine which helpers I need to verify. I can possibly add some additional short-circuiting logic, but nothing as simple as "bail on first error".
Baselines need to be updated for error spans i would expect. |
👍 |
Will be useful to allow specify own module name. In my project https://github.com/electron-userland/electron-builder/blob/master/src/codeSign.ts I need only awaiter and since bluebird is forbidden, I disable emit helpers and add custom awaiter impl to each file. And new option is not solution because I cannot specify helper module name. |
Will the new |
@gilboa23, no it doesn't yet apply to |
Yes, but I was not referring to the existing // @module: amd
// @importHelpers: true
export * from "A";
export * from "B"; Output: define(["require", "exports", "A", "B"], function (require, exports, A_1, B_1) {
"use strict";
var tslib_1 = require("tslib");
tslib_1.__export(A_1, exports);
tslib_1.__export(B_1, exports);
}); |
Allows ES5 helpers such as _extends to be placed into one external source file, rather than inlined into every module. Also removes ts-loader in favour of experimenting with just tsc. See: microsoft/TypeScript#9097
[email protected] is missing should tslib on npm be updated and release a new version? |
So, if I would like to use |
|
This change adds support for referencing emit helpers from an external module.
Compiler Options
--importHelpers
- Import emit helpers from "tslib".Emit
When
importHelpers
is specified, a syntheticImportDeclaration
is added to the top of each external module that needs an emit helper, such as__extends
. As a result, no emit helpers will be added to these files during emit. In addition, any place where the emit helper would be referenced, it would instead reference a member of the imported module.For example:
Outputs:
Script files
If a file is detected as a non-external-module (e.g. script file), the existing behavior for emit helpers is used. As long as the
--noEmitHelpers
option is not set, emit helpers will be added to the top of the file as usual.Fixes #3364