babel

@babel/traverse 使用方法小记

我只是一个虾纸丫 提交于 2019-12-01 02:16:27
@babel/traverse 官网: https://babeljs.io/docs/en/babel-traverse github: https://github.com/babel/babel/blob/master/packages/babel-traverse/test/traverse.js 了解一个东西最直接的方法就是看官网了解怎么用,看github源码的Test,看代码使用的测试。 @babel/traverse 可以用来遍历更新@babel/parser生成的AST 两种使用方法 对语法书中特定的节点进行操作 对所有的操作 traverse(ast, { CallExpression(p) { // 对语法书中特定的节点进行操作 参考@babel/types (特定节点类型) // CallExpression 特定节点 }, FunctionDeclaration: function(path) { // 对语法书中特定的节点进行操作 参考@babel/types (特定节点类型) // FunctionDeclaration 特定节点 } // ..... enter(path) { if (path.node.type === "ThisExpression"){ // 对所有的操作 }; } }) 来源: https://www.cnblogs.com

How can I choose the language, using Flask + Babel?

帅比萌擦擦* 提交于 2019-11-30 22:48:17
Now I'm developing a project, which should support two languages: English, as default, and Russian. It's pretty easy to do, using HTTP_ACCEPT_LANGUAGE header, the code is bellow: babel = Babel(app) @babel.localeselector def get_locale(): return request.accept_languages.best_match(app.config["LANGUAGES"].keys()) Languages are hardcoded in application config file: LANGUAGES = { 'en': 'English', 'ru': 'Russian' } But I also want to add a button, like Switch language to English . What is the best practice to realise it? This is the solution I came across: First you set a route that will handle the

translating strings from database flask-babel

笑着哭i 提交于 2019-11-30 20:30:02
I'm using Flask-Babel for translating string. In some templates I'm reading the strings from the database(postgresql). How can I translate the strings from the database using Flask-Babel? It's not possible to use Babel in database translations, as database content is dynamic and babel translations are static (they didn't change). If you read the strings from the database you must save the translations on the database. You can create a translation table, something like (locale, source, destination), and get the translated values with a query. I would suggest having a engineering text in the

企业级开发(1)

眉间皱痕 提交于 2019-11-30 19:26:06
一、关于 ECMAScript6 ECMAScript 6.0 (以下简称 ES6 )是 JavaScript 语言的 新 一代标准,已经在 2015 年 6 月正式发布了。它的目标,是使得 JavaScript 语言可以用来编写复杂的大型应用程序,成为企业级开发语言。 ES6 是 ES5 的升级版,提供了简洁的语法和新的特性。 ES6 在浏览器上兼容性差一些,但是在 NodeJS上可以完全兼容。 因此,为了解决当下的兼容性问题,主要采用将开发用的 ES6 转化为 ES5 使其能够顺利运行在浏览器端的方案。 二、模块化机制 1. 概述 Node.js 采用模块化结构,按照 CommonJS 规范定义和使用模块。在 Node 中,以模块为单位划分所有功能,并且提供一个完整的模块加载机制,使得我们可以将应用程序划分为各个不同的部分,并且对这些部分进行很好的协同管理。 JavaScript 是一种功能强大的面向对象语言,具有一些最快速的动态语言解释器。官方 JavaScript 规范定义了一些用于构建基于浏览器的应用程序的对象的 API。但是,规范并没有定义一个用于对于构建更广泛的应用程序的标准库。 CommonJS API 将通过定义处理许多常见应用程序需求的 API 来填补这一空白,最终提供与 Python 、 Ruby 和 Java 一样丰富的标准库

How can I choose the language, using Flask + Babel?

亡梦爱人 提交于 2019-11-30 18:27:56
问题 Now I'm developing a project, which should support two languages: English, as default, and Russian. It's pretty easy to do, using HTTP_ACCEPT_LANGUAGE header, the code is bellow: babel = Babel(app) @babel.localeselector def get_locale(): return request.accept_languages.best_match(app.config["LANGUAGES"].keys()) Languages are hardcoded in application config file: LANGUAGES = { 'en': 'English', 'ru': 'Russian' } But I also want to add a button, like Switch language to English . What is the best

Babel-loader,babel-core和babel-preset之间是什么关系

江枫思渺然 提交于 2019-11-30 18:12:45
`babel-loader` 是一个 npm 包,它使得 webpack 可以通过 babel 转译 JavaScript 代码。 (在 babel 7 中 `babel-core` 和 `babel-preset` 被建议使用 `@babel` 开头声明作用域,因此应该分别下载 `@babel/core` 和· `@babel/presets`。 就类似于 vue-cli 升级后 使用@vue/cli一样的道理 ) babel 的功能在于「代码转译」,具体一点,即将目标代码转译为能够符合期望语法规范的代码。在转译的过程中,babel 内部经历了「解析 - 转换 - 生成」三个步骤。而 `@babel/core` 这个库则负责「解析」,具体的「转换」和「生成」步骤则交给各种插件(plugin)和预设(preset)来完成。 `@babel/preset-*` 实际上就是各种插件的打包组合,也就是说各种转译规则的统一设定,目的是告诉loader要以什么规则来转化成对应的js版本 --- .babelrc示例 {   "presets": [     [       '@babel/preset-env',       {         'target':{           "browser":["ie>=8","chrome>=62"],           "node":"8

ES6 modules: imported constants are undefined at first; they become available later

我的未来我决定 提交于 2019-11-30 17:05:12
I use ES6 modules in my JavaScript application. The sources are compiled with webpack and babel. This is a shortened version of the file that causes me trouble: export const JUST_FORM = 0; export const AS_PAGE = 1; console.log(AS_PAGE); // ** export default function doSomething(mode = AS_PAGE) { console.log(mode); console.log(JUST_FORM); } I use this functionality just as you would expect. import doSomething, { AS_PAGE } from './doSomething' console.log(AS_PAGE); doSomething(); When I run the app, it prints three times undefined and only once the expected value AS_PAGE which is the console.log

Jest TypeError: Path must be a string. Received undefined

故事扮演 提交于 2019-11-30 16:57:24
Below settings for my package.json If I run from command line npm test all jest test cases are executed properly. In case I use directly the command jest from command line I receive this error: Test suite failed to run TypeError: Path must be a string. Received undefined at assertPath (path.js:7:11) at Object.relative (path.js:538:5) This happens on any test files. Any idea what could be wrong and how to fix it? "scripts": { "test": "standard && jest", "format": "standard --fix", "start": "webpack-dev-server --config webpack.config.dev.js", "build": "webpack --config webpack.config.prod.js" },

babel 7 - how to prevent adding of “strict mode” [duplicate]

人走茶凉 提交于 2019-11-30 14:18:03
This question already has an answer here: How to stop babel from transpiling 'this' to 'undefined' (and inserting “use strict”) 2 answers I looked at many posts but still cannot get this to work :( I have .babelrc { "comments": false, "presets": [ ["@babel/env", { "targets": { "browsers": ["ios 7"] } }], ["minify"] ] } I want to tell babel to not add "use strict" (anywhere) How is this done ? Babel assumes by default that files being transformed are ES modules. Since that is not the case for you, you'll want to tell it that. You can check out the docs for the "sourceType" option , but

method 'assign' not supported in IE, what to do

和自甴很熟 提交于 2019-11-30 12:53:09
I have a small /javascript,Babel script, that runs just fine in Chrome and Firefox browsers, but it fails in Internet Explorer 11. I hope somebody can help me. Here is my function: getDaysWithEvents() { // Get all the days in this months calendar view // Sibling Months included const days = this.getCalendarDays(); // Set Range Limits on calendar this.calendar.setStartDate(days[0]); this.calendar.setEndDate(days[days.length - 1]); // Iterate over each of the supplied events this.props.events.forEach((eventItem) => { const eventStart = this.getCalendarDayObject(eventItem.start); const eventEnd =