babeljs

Babel 6 CLI: Unexpected token export?

懵懂的女人 提交于 2019-12-18 10:53:02
问题 I'm trying to run Babel through it's CLI using babel-node but I keep getting the Unexpected token export error. I understand that Babel 6 is all about plugins and that I need to set the plugin through .babelrc but it doesn't seem to work properly. So here are my questions: Should I be using the syntax-export-extensions plugin? I've also tried using the alternative method which is setting the plugin through package.json but still no luck. Also, does Babel 6's CLI have a global .babelrc option?

Exporting a default & declaring anon function all in one

笑着哭i 提交于 2019-12-18 09:39:00
问题 Here's an example of something I want to do and currently throws an error. I'm not sure I understand why, but it's not syntactically correct to export, assign default, and assign a variable on one line. The benefit of having it be an anon function is that i can use the fat arrow => and open up a return value with ( and ) instead of opening { and } to return jsx . export default let Checkbox = (props) => ( <div style={styles.checkboxContainer}> <input styleName={styles.checkbox} type="checkbox

Render an array of Objects in ReactJs

戏子无情 提交于 2019-12-18 09:14:11
问题 I am trying to go through object properties (Name for this example) and list them within easy loop in function. I have found some pretty awkward way of doing this but it doesn't seem right. Here is what i got: const ItemsToSell = [{"Name":"Cup","Price":"99.99"},{"Name":"IPhone","Price":"99.99"},{ "Name":"Pen","Price":"99.99"}] function ListItem(props) { return <li>{props.value}</li>; } function NumberList(props) { const a = props.numbers; return ( <ul> {a.map((number) => <ListItem value=

How to await and return the result of a http.request(), so that multiple requests run serially?

点点圈 提交于 2019-12-18 04:35:09
问题 Assume there is a function doRequest(options) , which is supposed to perform an HTTP request and uses http.request() for that. If doRequest() is called in a loop, I want that the next request is made after the previous finished (serial execution, one after another). In order to not mess with callbacks and Promises, I want to use the async/await pattern (transpiled with Babel.js to run with Node 6+). However, it is unclear to me, how to wait for the response object for further processing and

BABEL Note: The code generator has deoptimised the styling of “app.js” as it exceeds the max of "100KB in Meteor

倾然丶 夕夏残阳落幕 提交于 2019-12-18 04:29:21
问题 My app.js file in meteor has exceeded the limit of 100KB How do I fix this now? Does It affects my application? Is that because of installing packages? 回答1: This is not a real issue. Just a warning. When babel compiles some code, it try to offer a readable output, but when files become big (>100KB), babel considers (by default) that it's not useful to keep this option enabled (because yes it's an option, see https://stackoverflow.com/a/30879872/988941 for more information). It's not a problem

Webpack not converting ES6 to ES5

你说的曾经没有我的故事 提交于 2019-12-17 23:37:09
问题 I'm very new to Webpack. I think I'm doing it incorrectly. I would like to convert an ES6 function to ES5 function using babel. So I did some research and I found babel-loader. However, I'm not sure what I'm doing. I ran npm install babel-loader --save-dev and it got added into my package.json // package.json { "name": "kanban", "version": "1.0.0", "description": "kanban", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC",

Service mocked with Jest causes “The module factory of jest.mock() is not allowed to reference any out-of-scope variables” error

主宰稳场 提交于 2019-12-17 23:34:05
问题 I'm trying to mock a call to a service but I'm struggeling with the following message: The module factory of jest.mock() is not allowed to reference any out-of-scope variables . I'm using babel with ES6 syntax, jest and enzyme. I have a simple component called Vocabulary which gets a list of VocabularyEntry -Objects from a vocabularyService and renders it. import React from 'react'; import vocabularyService from '../services/vocabularyService'; export default class Vocabulary extends React

Optional chaining operator support in VSCode

可紊 提交于 2019-12-17 23:09:07
问题 React Native 0.56 provides native support of Optional Chaining Operator i.e ?. However the latest stable release of VS Code can not recognize this syntax and throw a TypeScript validation error: [ts] Expression expected. while no complie-time or eslint error was thrown. How can I do to fix it? Update on 2019/12/11: Optional chaining is offically supported by TypeScript since 3.7! 😍 If you still meet this error, probably the TypeScript lib shipped with your VSCode is < 3.7. You can fix it

Babel 6 transform-runtime: $export is not a function

南笙酒味 提交于 2019-12-17 22:44:18
问题 I'm trying to incorporate Babel's transform-runtime to make my code compatible with IE9. But since integrating it, the code won't even run on Chrome. I get the error Uncaught TypeError: $export is not a function on es6.object.define-property.js:3 . Without the "transform-runtime" line in my .babelrc, everything runs fine. Any ideas? Here is my .babelrc : { "plugins": [ "transform-runtime" ], "presets": [ "es2015", "react" ] } And my webpack.config.js : var webpack = require('webpack'); var

Inject JSX-formatted string into React Component

感情迁移 提交于 2019-12-17 20:29:24
问题 I have a small react page that should compile and display html string. the html in the string written in react-foundation The page looks like this : import * as React from 'react'; import * as ReactDOM from 'react-dom'; import { Link, Button, Colors } from 'react-foundation'; require('./foundation.css') var htmlFromApi = '<div className="button-basics-example"><Button color={Colors.SUCCESS}>Save</Button><Button color={Colors.ALERT}>Delete</Button></div>'; var App = ({ html }) => { return <div