Skip to content

Commit 1232d1e

Browse files
m-absAlexander Vakrilov
authored andcommitted
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
1 parent c3fabd6 commit 1232d1e

File tree

9 files changed

+40
-53
lines changed

9 files changed

+40
-53
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"shelljs": "^0.7.0",
4040
"source-map-support": "^0.4.17",
4141
"time-grunt": "1.3.0",
42-
"tslib": "^1.7.1",
42+
"tslib": "^1.9.3",
4343
"tslint": "^5.4.3",
4444
"typedoc": "^0.5.10",
4545
"typedoc-plugin-external-module-name": "git://github.com/PanayotCankov/typedoc-plugin-external-module-name.git#with-js",

tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
}
1414
},
1515
"dependencies": {
16-
"tns-core-modules": "*"
16+
"tns-core-modules": "*",
17+
"tslib": "^1.9.3"
1718
},
1819
"devDependencies": {
1920
"babel-traverse": "6.9.0",

tns-core-modules/globals/decorators.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

tns-core-modules/globals/globals.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
// Required by TypeScript compiler
2-
require("./decorators");
3-
4-
// Required by V8 snapshot generator
5-
if (!global.__extends) {
6-
global.__extends = function (d, b) {
7-
for (var p in b) {
8-
if (b.hasOwnProperty(p)) {
9-
d[p] = b[p];
10-
}
11-
}
12-
function __() { this.constructor = d; }
13-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14-
};
15-
}
2+
require("./ts-helpers");
163

174
// This method iterates all the keys in the source exports object and copies them to the destination exports one.
185
// Note: the method will not check for naming collisions and will override any already existing entries in the destination exports.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Required by V8 snapshot generator
2+
if (!global.__extends) {
3+
global.__extends = function (d, b) {
4+
for (var p in b) {
5+
if (b.hasOwnProperty(p)) {
6+
d[p] = b[p];
7+
}
8+
}
9+
function __() { this.constructor = d; }
10+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
11+
};
12+
}
13+
14+
import * as tslib from "tslib";
15+
16+
// Bind the tslib helpers to global scope.
17+
// This is needed when we don't use importHelpers, which
18+
// breaks extending native-classes
19+
for (const fnName of Object.keys(tslib)) {
20+
if (typeof tslib[fnName] !== "function") {
21+
continue;
22+
}
23+
24+
if (fnName in global) {
25+
// Don't override globals that are already defined (ex. __extends)
26+
continue;
27+
}
28+
29+
global[fnName] = tslib[fnName];
30+
}

tns-core-modules/inspector_modules.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
console.log("Loading inspector modules...");
2-
require("./globals/decorators");
2+
require("./globals/ts-helpers");
33
require("./debugger/webinspector-network");
44
require("./debugger/webinspector-dom");
55
require("./debugger/webinspector-css");

tns-core-modules/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"license": "Apache-2.0",
2727
"typings": "tns-core-modules.d.ts",
2828
"dependencies": {
29-
"tns-core-modules-widgets": "next"
29+
"tns-core-modules-widgets": "next",
30+
"tslib": "^1.9.3"
3031
},
3132
"devDependencies": {
3233
"@types/node": "~7.0.5",

tns-core-modules/ui/styling/style-properties.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ export function transformConverter(text: string): TransformFunctionsInfo {
495495

496496
const usedTransforms = transformations.map(t => t.property);
497497
if (!hasDuplicates(usedTransforms)) {
498-
const fullTransformations = Object.assign({}, IDENTITY_TRANSFORMATION);
498+
const fullTransformations = { ...IDENTITY_TRANSFORMATION };
499499
transformations.forEach(transform => {
500500
fullTransformations[transform.property] = transform.value;
501501
});
@@ -1098,4 +1098,4 @@ export const visibilityProperty = new CssProperty<Style, Visibility>({
10981098
target.view.isCollapsed = (newValue === Visibility.COLLAPSE);
10991099
}
11001100
});
1101-
visibilityProperty.register(Style);
1101+
visibilityProperty.register(Style);

tns-platform-declarations/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
},
3333
"homepage": "https://github.com/NativeScript/NativeScript#readme",
3434
"devDependencies": {
35-
"typescript": "^2.6.1"
35+
"typescript": "~2.6.1"
3636
}
3737
}

0 commit comments

Comments
 (0)