Esprima

EsLint入门

余生长醉 提交于 2021-02-14 08:36:27
EsLint入门 介绍 官方地址:http://eslint.org/ EsLint帮助我们检查Javascript编程时的语法错误。比如:在Javascript应用中,你很难找到你漏泄的变量或者方法。EsLint能够帮助我们分析JS代码,找到bug并确保一定程度的JS语法书写的正确性。 EsLint是建立在Esprima(ECMAScript解析架构)的基础上的。Esprima支持ES5.1,本身也是用ECMAScript编写的,用于多用途分析。EsLint不但提供一些默认的规则(可扩展),也提供用户自定义规则来约束我们写的Javascript代码。 EsLint提供以下支持: ES6 AngularJS JSX Style检查 自定义错误和提示 EsLint提供以下几种校验: 语法错误校验 不重要或丢失的标点符号,如分号 没法运行到的代码块(使用过WebStorm的童鞋应该了解) 未被使用的参数提醒 漏掉的结束符,如} 确保样式的统一规则,如sass或者less 检查变量的命名 使用 一、安装 Npm install gulp-eslint –save-dev 在你的项目目录下,运行:eslint –init将会产生一个.eslintrc的文件,文件内容包含一些校验规则 { "rules": { "semi": ["error", "always"], "quotes": [

JS 逆向高阶 | JS 逆向的噩梦

梦想与她 提交于 2020-12-24 16:00:05
点击上方“ 咸鱼学Python ”,选择“ 加为星标 ” 第一时间关注Python技术干货! 作者:yacan8 原文:https://github.com/yacan8/blog/blob/master/posts/JavaScript抽象语法树AST.md 前言 Babel为当前最流行的代码JavaScript编译器了,其使用的JavaScript解析器为 babel-parser [1] ,最初是从 Acorn 项目 fork 出来的。Acorn 非常快,易于使用,并且针对非标准特性(以及那些未来的标准特性) 设计了一个基于插件的架构。本文主要介绍 esprima [2] 解析生成的抽象语法树节点, esprima 的实现也是基于Acorn的。 解析器 Parser JavaScript Parser 是把js源码转化为抽象语法树(AST)的解析器。这个步骤分为两个阶段: 词法分析(Lexical Analysis) [3] 和 语法分析(Syntactic Analysis) [4] 。 常用的JavaScript Parser: • esprima [5] • uglifyJS2 [6] • traceur [7] • acorn [8] • espree [9] • @babel/parser [10] 词法分析 词法分析阶段把字符串形式的代码转换为 令牌(tokens

Javascript混淆与解混淆的那些事儿

被刻印的时光 ゝ 提交于 2020-11-24 03:36:20
像软件加密与解密一样,javascript的混淆与解混淆同属于同一个范畴。道高一尺,魔高一丈。没有永恒的黑,也没有永恒的白。一切都是资本市场驱动行为,现在都流行你能为人解决什么问题,这个概念。那么市场究竟能容纳多少个能解决这种问题的利益者。JS没有秘密。 其实本人不赞成javascript进行hash混淆处理,一拖慢运行时速度,二体积大。JS代码前端可获取,天生赋予“开源”属性,都可以在chrome devTools下查看。JS非压缩性混淆完全违法前端优化准则。 目前网络上可以搜索的JS混淆工具不外乎以下几种: eval混淆 ,也是最早JS出现的混淆加密,据说第一天就被破解,修改一下代码,alert一下就可以破解了。这种方法从出生的那天就失去了意义。其实JS加密(混淆)是相对于可读性而言的,其实真正有意义的就是压缩型混淆uglify这一类,即可减少体重,也可减少可读性。 但是,也不能排除部分商业源代码使用hash类型混淆源代码,比如 miniui 使用的 JSA加密 , fundebug使用的 javascript-obfuscator 。 下面通过代码来说明 JSA加密 和 javascript-obfuscator 的区别: 要混淆的代码: function logG(message) { console.log('\x1b[32m%s\x1b[0m', message); }

transpiler battle: breaking out of nested function, with vs without throw

若如初见. 提交于 2020-08-26 13:54:08
问题 I have just finished writing "version 0" of my first (toy) transpiler. It works. It turns a string of "pseudo JavaScript" (JavaScript with an additional feature) into a string of runnable JavaScript. Now, I want to improve it. The work area possibly most interesting for other SO users is this: The compiled code (i.e., output of my transpiler) does not heed a coding style recommendation as given in an accepted answer to some earlier SO question. If I would have at my hands a second transpiler

transpiler battle: breaking out of nested function, with vs without throw

橙三吉。 提交于 2020-08-26 13:54:05
问题 I have just finished writing "version 0" of my first (toy) transpiler. It works. It turns a string of "pseudo JavaScript" (JavaScript with an additional feature) into a string of runnable JavaScript. Now, I want to improve it. The work area possibly most interesting for other SO users is this: The compiled code (i.e., output of my transpiler) does not heed a coding style recommendation as given in an accepted answer to some earlier SO question. If I would have at my hands a second transpiler

How to use npm module in DENO?

本小妞迷上赌 提交于 2020-07-26 07:57:48
问题 Deno is super cool. I saw it in the morning and want to migrate to deno now. I was trying to move my existing nodejs script to deno. Can any one help me on how to use npm modules in deno. I need esprima module. This one has the package https://github.com/denoland/deno_third_party/tree/master/node_modules but i am not able to figure out how to use that. 回答1: Deno provides a Node Compatibility Library, that will allow to use some NPM packages that do not use non-polyfilled Node.js APIs. You'll

How to use npm module in DENO?

筅森魡賤 提交于 2020-07-26 07:55:53
问题 Deno is super cool. I saw it in the morning and want to migrate to deno now. I was trying to move my existing nodejs script to deno. Can any one help me on how to use npm modules in deno. I need esprima module. This one has the package https://github.com/denoland/deno_third_party/tree/master/node_modules but i am not able to figure out how to use that. 回答1: Deno provides a Node Compatibility Library, that will allow to use some NPM packages that do not use non-polyfilled Node.js APIs. You'll

【你应该了解的】抽象语法树AST

余生颓废 提交于 2020-04-14 17:44:14
【推荐阅读】微服务还能火多久?>>> 团队: skFeTeam  本文作者:李世伟 作为前端程序员,webpack,rollup,babel,eslint这些是不是经常用到?他们是打包工具,代码编译工具,语法检查工具。他们是如何实现的呢?本文介绍的抽象语法树,就是他们用到的技术,是不是应该了解一下呢? 本文没有晦涩难懂的理论,也没有大段大段的代码,完全从零开始,小白阅读也无任何障碍。通过本文的阅读,您将会了解AST的基本原理以及使用方法。 前言 什么是抽象语法树? AST(Abstract Syntax Tree)是源代码的抽象语法结构树状表现形式。下面这张图示意了一段JavaScript代码的抽象语法树的表现形式。 抽象语法树有什么用呢? IDE的错误提示、代码格式化、代码高亮、代码自动补全等 JSLint、JSHint、ESLint对代码错误或风格的检查等 webpack、rollup进行代码打包等 Babel 转换 ES6 到 ES5 语法 注入代码统计单元测试覆盖率 目录 1.AST解析器 2.AST in Babel 3.Demo with esprima 4.思考题 1.AST解析器 1.1 JS Parser解析器 AST是如何生成的? 能够将JavaScript源码转化为抽象语法树(AST)的工具叫做JS Parser解析器。 JS Parser的解析过程包括两部分

TypeScript -> AST -> TypeScript

余生颓废 提交于 2019-12-23 10:00:06
问题 Is there a way to parse a TypeScript file to an AST, modify the AST, and parse it then back to TypeScript as the tools Esprima + Escodegen are able to? Important is that I do NOT want to compile/transpile the TypeScript code first into JavaScript. 回答1: Yes, with Typescript 2.x you can transform ast. Here is a good blog post about it http://blog.scottlogic.com/2017/05/02/typescript-compiler-api-revisited.html. In the official typescript wiki it is not well documented yet. 来源: https:/

What characters can be operators in JavaScript using Esprima?

a 夏天 提交于 2019-12-12 16:16:57
问题 From the previous question I learned how to extend JavaScript language to support more operators (created by me). There @Benjamin used Esprima and created # operator. Using Esprima we can do the following: esprima.parse("10 # 2") That returns this object: { "type": "Program", "body": [ { "type": "ExpressionStatement", "expression": { "type": "BinaryExpression", "operator": "#", "left": { "type": "Literal", "value": 10, "raw": "10" }, "right": { "type": "Literal", "value": 2, "raw": "2" } } }