babeljs

Babel plugins run order

北城余情 提交于 2019-12-21 07:08:41
问题 TL;DR: Is there a way how to specify the order in which the Babel plugins are supposed to be run? How does Babel determine this order? Is there any spec how this works apart from diving into Babel sources? I'm developing my own Babel plugin. I noticed, that when I run it, my plugin is run before other es2015 plugins. For example having code such as: const a = () => 1 and visitor such as: visitor: { ArrowFunctionExpression(path) { console.log('ArrowFunction') }, FunctionExpression(path) {

Gulp babel es2015 transform very slow

◇◆丶佛笑我妖孽 提交于 2019-12-21 07:04:50
问题 I am trying to run the babel-preset-es2015 on my JavaScript using gulp, but it takes forever even on one line of code. I originally tried with my script bundle that is about 700 loc, and then with a dummy script that is 1 line. The first case takes about 9s - with 1 line i takes 8.38s. This is my exact setup: package.json: { "devDependencies": { "gulp": "^3.9.0", "gulp-babel": "^6.1.1", "babel": "^6.3.26", "babel-preset-es2015": "^6.3.13" }, "babel": { "presets": [ "es2015" ] } } gulpfile.js:

Babel: Function parameter types in ES6

旧时模样 提交于 2019-12-21 03:53:09
问题 If I write the following piece of code and transpile it through Babel (6.5.0) it works correctly. function foo (first: string, second: number) { // code here } : string and : number are just removed from the transpiled ES5 code. If I call the function using wrong parameter types, it does not result in any error/warning. They are informative even though do not have any functionality. I cannot find proper information about ES6's parameter typing on internet. Is parameter typing even part of ES6

Gulp + babelify + browserify issue

◇◆丶佛笑我妖孽 提交于 2019-12-21 02:44:17
问题 I'm trying to create a gulp task with browserify and babelify. Here is the task: var gulp = require('gulp'); var browserify = require('gulp-browserify'); var source = require('vinyl-source-stream'); var babelify = require('babelify'); gulp.task('js', function () { browserify('./resources/js/*.js') .transform(babelify) .bundle() .pipe(source('*.js')) .pipe(gulp.dest('./public/js')); }); I found a few sample code, tried to use them, but the result was always the same. When i run the task, and

Ability to abort asynchronous call

十年热恋 提交于 2019-12-20 20:28:52
问题 I'm using babeljs with es7 style async/await methods. I have a main script that will call a async method on an array of objects that all return promises. I use Promise.all() to wait for all of those to return, however, these tasks could take a long time and if they exceed a threshold I would like to abort all of them, and the task handle that in an appropriate way. Is there anyway to accomplish such a thing? Currently the only way that I can think of is by spawning a process that does the

Why does my ES6 (using Babel) class say `this` is undefined in an instance method?

二次信任 提交于 2019-12-20 20:28:08
问题 I am building an application in Node using Hapi.JS. I have a class for an authentication plugin that is giving me all sorts of problems. When I attempt to reference this from within a method on the class, I get an error saying that this is undefined. Why is this happening? An excerpt: class OAuth { constructor () {} register (server, err, next) { this.server = server; this.registerRoutes(); } registerRoutes () { console.log(this.server.route); this.server.route([ { method: 'POST', path: '

Why does my ES6 (using Babel) class say `this` is undefined in an instance method?

孤街浪徒 提交于 2019-12-20 20:28:08
问题 I am building an application in Node using Hapi.JS. I have a class for an authentication plugin that is giving me all sorts of problems. When I attempt to reference this from within a method on the class, I get an error saying that this is undefined. Why is this happening? An excerpt: class OAuth { constructor () {} register (server, err, next) { this.server = server; this.registerRoutes(); } registerRoutes () { console.log(this.server.route); this.server.route([ { method: 'POST', path: '

Asynchronous map function that await's returns Promise instead of value

孤街醉人 提交于 2019-12-20 18:30:36
问题 I have this code async function addFiles(dir,tree) { return (await readDir(dir)) .map(async (name) => {await readDir(dir); return name;}) } but unfortunately, it just returns a bunch of promises, because there the async function in map is not waited upon. I'm wondering if there is any way to await the mapped function in the above code. 回答1: try async function addFiles(dir,tree) { const files = await readDir(dir) await Promise.all(files.map(async (name) => {await readDir(dir); return name;}) }

babel 6 async / await: Unexpected token

你。 提交于 2019-12-20 17:37:59
问题 Im having trouble getting async / await transforms working. What am I missing? My .babelrc: { "presets": [ "es2015", "stage-0" ] } My package.json (snipped): { "babel-core": "^6.1.2", "babel-plugin-transform-runtime": "^6.1.2", "babel-preset-es2015": "^6.1.2", "babel-preset-stage-0": "^6.1.2" } Output: babel src/server SyntaxError: src/server/index.js: Unexpected token (7:21) 5 | 6 | try { > 7 | let server = await server('localhost', env.NODE_PORT || 3000) | ^ 8 | console.log(`Server started

How babel and JSX related or differ?

泄露秘密 提交于 2019-12-20 15:33:57
问题 I am learning on React JS and I have got information on JSX and babel. But I am not getting clarity on how these are helping React and how these or differ from each other 回答1: React JS while building an app using React, you can create the components/views in two ways using standard React object and methods using JSX JSX JSX is a separate technology from React and completely optional while building React application, however it makes life much easier when you combine JSX with React. Let's see