gulp-babel-nativescript
replace gulp-babel compiled es5 content to match nativescript(now is v1.4.2)'s rule
Usage:
// babelNativescript signature: //// babelNativescript(tnsCoreModules: {${moduleName}: true}, babelEs5CommonUtilFunctionsModulePath: string)//// About tnsCoreModules, see ./script/tns-core-modules.json for more infomationvar babelNativescript = var getTnsCoreModules = gulp
Notice:
- the name of the required tns-core-modules can not be renamed to another variable name after required. because the require of tns-core-module is find by RexExp string match.
Example:
// es6; Observable { super thiscounter = 42 this; } { thiscounter--; if thiscounter <= 0 this; else this; } { console super; } static { super }var mainViewModel =
// babel => es5, this is horrible for nativescript//// 1. redundant es5 helper functions like `_createClass`, `_inherits` in every files// => extract all babel-es5-helper-functions to a individual module, and then require it.// 2. babel module system is not ipentity with nativescript(cmd) like the `default` attribute in module.exports// => stop `_interopRequireWildcard` and `_interopRequireDefault` the required object // that it add `default` attribute and replace all attribute from the origin to // a new object which the original object is bind to the system like `application.mainModule`!// 3. babel-es5's Class System is different with nativescript.// => every class which inherit the tns-core-module will be replaced to the nativescript inheritence way.// => nativescript's inheritence have weak feature that `__extends(Child, Super);` must be the // first sentence in the Class block, means if this sentence execute after any operate to // the Child-Class, nativescript will be crashed!! "use strict"; Object; var _createClass = { { for var i = 0; i < propslength; i++ var descriptor = propsi; descriptorenumerable = descriptorenumerable || false; descriptorconfigurable = true; if "value" in descriptor descriptorwritable = true; Object; } return { if protoProps ; if staticProps ; return Constructor; }; }; var { var _again = true; _function: while _again var object = _x property = _x2 receiver = _x3; desc = parent = getter = undefined; _again = false; if object === null object = Functionprototype; var desc = Object; if desc === undefined var parent = Object; if parent === null return undefined; else _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; else if "value" in desc return descvalue; else var getter = descget; if getter === undefined return undefined; return getter; }; { if obj && obj__esModule return obj; else var newObj = {}; if obj != null for var key in obj if ObjectprototypehasOwnProperty newObjkey = objkey; newObj"default" = obj; return newObj; } { if !instance instanceof Constructor throw "Cannot call a class as a function"; } { if typeof superClass !== "function" && superClass !== null throw "Super expression must either be null or a function, not " + typeof superClass; subClassprototype = Object
// es5 after this tool replaced the babel-es5 content"use strict";// this module path is the function's second argument as a absolute pathvar _babelEs5CommonUtil = ; Object; var _dataObservable = ; var observable = _dataObservable; var HelloWorldModel = { ; { _babelEs5CommonUtil; _observable$Observable; thiscounter = 42; this; } _babelEs5CommonUtil; return HelloWorldModel;}observableObservable; exportsHelloWorldModel = HelloWorldModel;var mainViewModel = ;exportsmainViewModel = mainViewModel;