feat(tslib): add tslib helpers to global (#6351)

* feat(tslib): add tslib helpers to global

* Adds tslib as a dependency to tns-core-modules
* Replaces globals/decorators with globals/tslib
* Adds support for async/await, rest and spread operators.

* refactor: rename tslib to ts-helpers to avoid confusion with npm package
This commit is contained in:
Morten Sjøgren
2018-10-05 16:12:45 +02:00
committed by Alexander Vakrilov
parent c3fabd66f7
commit 1232d1edfd
9 changed files with 40 additions and 53 deletions

View File

@ -39,7 +39,7 @@
"shelljs": "^0.7.0", "shelljs": "^0.7.0",
"source-map-support": "^0.4.17", "source-map-support": "^0.4.17",
"time-grunt": "1.3.0", "time-grunt": "1.3.0",
"tslib": "^1.7.1", "tslib": "^1.9.3",
"tslint": "^5.4.3", "tslint": "^5.4.3",
"typedoc": "^0.5.10", "typedoc": "^0.5.10",
"typedoc-plugin-external-module-name": "git://github.com/PanayotCankov/typedoc-plugin-external-module-name.git#with-js", "typedoc-plugin-external-module-name": "git://github.com/PanayotCankov/typedoc-plugin-external-module-name.git#with-js",

View File

@ -13,7 +13,8 @@
} }
}, },
"dependencies": { "dependencies": {
"tns-core-modules": "*" "tns-core-modules": "*",
"tslib": "^1.9.3"
}, },
"devDependencies": { "devDependencies": {
"babel-traverse": "6.9.0", "babel-traverse": "6.9.0",

View File

@ -1,32 +0,0 @@
if (typeof (<any>global).__decorate !== "function") {
(<any>global).__decorate = function (decorators, target, key, desc) {
var c = arguments.length;
var r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof (<any>global).Reflect === "object" && typeof (<any>global).Reflect.decorate === "function") {
r = (<any>global).Reflect.decorate(decorators, target, key, desc);
}
else {
for (var i = decorators.length - 1; i >= 0; i--) {
if (d = decorators[i]) {
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
}
}
}
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
}
if (typeof (<any>global).__metadata !== "function") {
(<any>global).__metadata = function (k, v) {
if (typeof (<any>global).Reflect === "object" && typeof (<any>global).Reflect.metadata === "function") {
return (<any>global).Reflect.metadata(k, v);
}
};
}
if (typeof (<any>global).__param !== "function") {
(<any>global).__param = (global && (<any>global).__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
}

View File

@ -1,18 +1,5 @@
// Required by TypeScript compiler // Required by TypeScript compiler
require("./decorators"); require("./ts-helpers");
// Required by V8 snapshot generator
if (!global.__extends) {
global.__extends = function (d, b) {
for (var p in b) {
if (b.hasOwnProperty(p)) {
d[p] = b[p];
}
}
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
}
// This method iterates all the keys in the source exports object and copies them to the destination exports one. // This method iterates all the keys in the source exports object and copies them to the destination exports one.
// Note: the method will not check for naming collisions and will override any already existing entries in the destination exports. // Note: the method will not check for naming collisions and will override any already existing entries in the destination exports.

View File

@ -0,0 +1,30 @@
// Required by V8 snapshot generator
if (!global.__extends) {
global.__extends = function (d, b) {
for (var p in b) {
if (b.hasOwnProperty(p)) {
d[p] = b[p];
}
}
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
}
import * as tslib from "tslib";
// Bind the tslib helpers to global scope.
// This is needed when we don't use importHelpers, which
// breaks extending native-classes
for (const fnName of Object.keys(tslib)) {
if (typeof tslib[fnName] !== "function") {
continue;
}
if (fnName in global) {
// Don't override globals that are already defined (ex. __extends)
continue;
}
global[fnName] = tslib[fnName];
}

View File

@ -1,5 +1,5 @@
console.log("Loading inspector modules..."); console.log("Loading inspector modules...");
require("./globals/decorators"); require("./globals/ts-helpers");
require("./debugger/webinspector-network"); require("./debugger/webinspector-network");
require("./debugger/webinspector-dom"); require("./debugger/webinspector-dom");
require("./debugger/webinspector-css"); require("./debugger/webinspector-css");

View File

@ -26,7 +26,8 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"typings": "tns-core-modules.d.ts", "typings": "tns-core-modules.d.ts",
"dependencies": { "dependencies": {
"tns-core-modules-widgets": "next" "tns-core-modules-widgets": "next",
"tslib": "^1.9.3"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "~7.0.5", "@types/node": "~7.0.5",

View File

@ -495,7 +495,7 @@ export function transformConverter(text: string): TransformFunctionsInfo {
const usedTransforms = transformations.map(t => t.property); const usedTransforms = transformations.map(t => t.property);
if (!hasDuplicates(usedTransforms)) { if (!hasDuplicates(usedTransforms)) {
const fullTransformations = Object.assign({}, IDENTITY_TRANSFORMATION); const fullTransformations = { ...IDENTITY_TRANSFORMATION };
transformations.forEach(transform => { transformations.forEach(transform => {
fullTransformations[transform.property] = transform.value; fullTransformations[transform.property] = transform.value;
}); });

View File

@ -32,6 +32,6 @@
}, },
"homepage": "https://github.com/NativeScript/NativeScript#readme", "homepage": "https://github.com/NativeScript/NativeScript#readme",
"devDependencies": { "devDependencies": {
"typescript": "^2.6.1" "typescript": "~2.6.1"
} }
} }