Skip to content

Commit

Permalink
feat(tslib): add tslib helpers to global (#6351)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
m-abs authored and Alexander Vakrilov committed Oct 5, 2018
1 parent c3fabd6 commit 1232d1e
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
}
},
"dependencies": {
"tns-core-modules": "*"
"tns-core-modules": "*",
"tslib": "^1.9.3"
},
"devDependencies": {
"babel-traverse": "6.9.0",
Expand Down
32 changes: 0 additions & 32 deletions tns-core-modules/globals/decorators.ts

This file was deleted.

15 changes: 1 addition & 14 deletions tns-core-modules/globals/globals.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
30 changes: 30 additions & 0 deletions tns-core-modules/globals/ts-helpers.ts
Original file line number Diff line number Diff line change
@@ -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];
}
2 changes: 1 addition & 1 deletion tns-core-modules/inspector_modules.ios.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
3 changes: 2 additions & 1 deletion tns-core-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tns-core-modules/ui/styling/style-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -1098,4 +1098,4 @@ export const visibilityProperty = new CssProperty<Style, Visibility>({
target.view.isCollapsed = (newValue === Visibility.COLLAPSE);
}
});
visibilityProperty.register(Style);
visibilityProperty.register(Style);
2 changes: 1 addition & 1 deletion tns-platform-declarations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
},
"homepage": "https://github.com/NativeScript/NativeScript#readme",
"devDependencies": {
"typescript": "^2.6.1"
"typescript": "~2.6.1"
}
}

0 comments on commit 1232d1e

Please sign in to comment.