babeljs

How to map JSON data to a class

点点圈 提交于 2019-12-20 11:56:09
问题 I created a ES6 class by Babel and I want to map JSON data which is gotten from a server to the ES6 class. Is there anything common way to do that? User.js export default class User { constructor() { this.firstName; this.lastName; this.sex; } } app.js import User from "./classes/User"; var data = JSON.parse(req.responseText); console.log(data.firstname); //Bob //now...just set data one by one? 回答1: I would merge the JSON object into this using Object.assign , as follows: class User {

How do I use babel's `useBuiltIns: 'usage'` option on the vendors bundle?

北城余情 提交于 2019-12-20 10:49:10
问题 Since I need to support also IE11, I need to transpile also node_modules . This is the babel config I use on the node_modules: presets: [ ['@babel/preset-env', { modules: false, useBuiltIns: 'usage' }], ], I use the useBuiltIns options because it was giving an error Symbol is not defined , the polyfill was needed. However this configuration breaks at compile time, supposedly because it injects some imports in the code, here is the error: Basically it's not liking the module.exports . So how

` __webpack_require__(…) is not a function` when using babel 6

旧巷老猫 提交于 2019-12-20 10:17:56
问题 Everything seems to build fine: http://d.pr/i/1aZxR with the following configs. However, when I run the code I get the following error this (via webpack-dev-server): Uncaught TypeError: __webpack_require__(...) is not a function(anonymous function) @ login.js:4__webpack_require__ @ bootstrap 38790ff45722f55eb700?6a08:50(anonymous function) @ bootstrap.js:2363__webpack_require__ @ bootstrap 38790ff45722f55eb700?6a08:50(anonymous function) @ app.38790ff45722f55eb700.js:29__webpack_require__ @

Decorators on functions

纵饮孤独 提交于 2019-12-20 09:46:23
问题 I see that babel.js decorators (available in "stage 1") implement the spec at https://github.com/wycats/javascript-decorators. It appears that decorators are limited to (1) classes, (2) accessors, and (3) methods. In my case, I want to use decorators on plain old functions , as in @chainable function foo() { } where (just an example) function chainable(fn) { return function() { fn.apply(this, arguments); return this; }; } I don't see any logical reason why decorators should not be able to

Breakpoint debugging minfied/mangled/compiled variables

此生再无相见时 提交于 2019-12-20 08:46:44
问题 Working on building JavaScript sourcemaps into my workflow and I've been looking for some documentation on a particular part of debugging source maps. In the picture below I'm running compressed Javascript code, but through the magic of source maps Chrome debugger was able to reconstruct the seemingly uncompressed code for me to debug: However, if you look at the local variables, someNumber and someOtherNumber are not defined. Instead, we have a and r , which are the compiled variable names

How do I write angular2 without decorator syntax?

社会主义新天地 提交于 2019-12-20 05:25:28
问题 I'm roughly following JavaScript/TypeScript quickstart for Angular2 to write my app in ES6 but can't get the decoractor to works entry.js import * as stylesheet from '../assets/styles/app.scss'; import jQuery from '../node_modules/jquery/dist/jquery'; import $ from '../node_modules/jquery/dist/jquery'; import * as semanticUi from '../node_modules/semantic-ui/dist/semantic'; import '../node_modules/angular2/bundles/angular2-polyfills' import '../node_modules/rxjs/bundles/Rx.umd' import '..

What does “register” mean in “babel/register”

ぐ巨炮叔叔 提交于 2019-12-20 02:01:21
问题 In order to do runtime transformations in Babel you need to require and use babel-core/register . I have no idea what register means in this sense, i.e. the actual definition. The page isn't very helpful. What does this actually mean? 回答1: ok, so the purpose of babel as you know is to transpile your js current code to an understandable version of js for the given environment, tool, framework you're using. Those vary as listed here, How to use Babel with your tool of choice. In the node

How to upgrade to babel 7

落爺英雄遲暮 提交于 2019-12-19 17:32:53
问题 I tried to upgrade Webpack and babel to 4, 7 respectively but couldn’t make it work. Also the official doc isn’t helping much with the upgrade I am getting following issue compiler error: ERROR in Cannot find module '@babel/core' @ multi main dependencies I am using: "babel-core": "^6.26.3", "babel-eslint": "^9.0.0", "babel-loader": "^8.0.0", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-polyfill": "^6.26.0", "babel-preset

Babel not Polyfilling Fetch when using babel-preset-env

佐手、 提交于 2019-12-19 17:20:53
问题 I'm using Webpack and Babel to build and transpile my ES6 code. However I am missing important Polyfills when trying to support older browsers. e.g iOS8. Here's my Webpack.config const versions = { v1: './src/js/v1.js', v2: './src/js/v2.js', v3: './src/js/v3.js', }; module.exports = { entry: versions, output: { path: __dirname + '/dist', filename: '[name].min.js' }, externals: { 'jquery': 'jQuery' }, module: { loaders: [ { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader', }, {

Babel error: JSX value should be either an expression or a quoted JSX text

半城伤御伤魂 提交于 2019-12-18 18:52:28
问题 I'm getting an error from Babel when trying to compile my JSX code into JS. I'm new to react so apologies if this is an obvious issue, I wasn't able to find anything about it that seemed related. I'm attempting to use props in this chunk of code, and pass a pageTitle prop to my FieldContainer component. This is giving me an issue, though, that isn't letting the code compile to JS. I discovered in my searching that prop values should be passed between {} , but adding these did not help. Any