mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
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:

committed by
Alexander Vakrilov

parent
c3fabd66f7
commit
1232d1edfd
@ -39,7 +39,7 @@
|
||||
"shelljs": "^0.7.0",
|
||||
"source-map-support": "^0.4.17",
|
||||
"time-grunt": "1.3.0",
|
||||
"tslib": "^1.7.1",
|
||||
"tslib": "^1.9.3",
|
||||
"tslint": "^5.4.3",
|
||||
"typedoc": "^0.5.10",
|
||||
"typedoc-plugin-external-module-name": "git://github.com/PanayotCankov/typedoc-plugin-external-module-name.git#with-js",
|
||||
|
@ -13,7 +13,8 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"tns-core-modules": "*"
|
||||
"tns-core-modules": "*",
|
||||
"tslib": "^1.9.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-traverse": "6.9.0",
|
||||
|
@ -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); }
|
||||
};
|
||||
}
|
@ -1,18 +1,5 @@
|
||||
// Required by TypeScript compiler
|
||||
require("./decorators");
|
||||
|
||||
// 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 __());
|
||||
};
|
||||
}
|
||||
require("./ts-helpers");
|
||||
|
||||
// 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.
|
||||
|
30
tns-core-modules/globals/ts-helpers.ts
Normal file
30
tns-core-modules/globals/ts-helpers.ts
Normal 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];
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
console.log("Loading inspector modules...");
|
||||
require("./globals/decorators");
|
||||
require("./globals/ts-helpers");
|
||||
require("./debugger/webinspector-network");
|
||||
require("./debugger/webinspector-dom");
|
||||
require("./debugger/webinspector-css");
|
||||
|
@ -26,7 +26,8 @@
|
||||
"license": "Apache-2.0",
|
||||
"typings": "tns-core-modules.d.ts",
|
||||
"dependencies": {
|
||||
"tns-core-modules-widgets": "next"
|
||||
"tns-core-modules-widgets": "next",
|
||||
"tslib": "^1.9.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "~7.0.5",
|
||||
|
@ -495,7 +495,7 @@ export function transformConverter(text: string): TransformFunctionsInfo {
|
||||
|
||||
const usedTransforms = transformations.map(t => t.property);
|
||||
if (!hasDuplicates(usedTransforms)) {
|
||||
const fullTransformations = Object.assign({}, IDENTITY_TRANSFORMATION);
|
||||
const fullTransformations = { ...IDENTITY_TRANSFORMATION };
|
||||
transformations.forEach(transform => {
|
||||
fullTransformations[transform.property] = transform.value;
|
||||
});
|
||||
|
@ -32,6 +32,6 @@
|
||||
},
|
||||
"homepage": "https://github.com/NativeScript/NativeScript#readme",
|
||||
"devDependencies": {
|
||||
"typescript": "^2.6.1"
|
||||
"typescript": "~2.6.1"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user