Giter Site home page Giter Site logo

cmd-util's People

Contributors

lepture avatar lizzie avatar popomore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmd-util's Issues

Invalid Version: 0.1.1a1

npm i cmd-util
npm ERR! Invalid Version: 0.1.1a1

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache_logs\2022-10-08T03_30_45_407Z-debug-0.log

ast.js中,获取函数名的方式有错

ast.js代码中多处出现以下类似代码,用于判断代码结点是否为对函数名为require的调用,然后再获取其参数,比如模块 id

if(node instanceof UglifyJS.AST_Call && node.start.value === 'require')

此种方式对如下代码也能判断通过

require('module-a')('abc')

但是,此时 node.args[0] 其实是 'abc',而不是 'module-a',也就是说通过上述方式解析require 对应的模块 id 参数值,很有可能是错的

正确的方式应该是

if(node instanceof UglifyJS.AST_Call && node.expression.name === 'require') {
  var id = node.args[0].value
}

关于css转换的ast,下面的情况怎么归类?

/*! define a */
/*! block e */
/*! import d */
a {color: ablack}
/*! endblock */

这里转换后import d应该归于谁呢?
第一种归于所属模块

[
  {
    "id": "a",
    "type": "block",
    "code": [
      {
        "id": "e",
        "type": "block",
        "code": [
          {
            "id": "d",
            "type": "import"
          },
          {
            "type": "string",
            "code": "a {color:black;}"
          }
        ]
      }
    ]
  }
]

第二种归于全局

[
  {
    "id": "a",
    "type": "block",
    "code": [
      {
        "id": "e",
        "type": "block",
        "code": [
          {
            "type": "string",
            "code": "a {color:black;}"
          }
        ]
      },
      {
        "id": "d",
        "type": "import"
      }
    ]
  }
]

个人觉得注释写的归于相应模块,@import写的归于全局 😄 求讨论 @popomore @army8735

重写了css模块,速度提升一倍,支持压缩过的样式,误伤几乎为零

直接上 性能测试 😄 有时间更新到版本库~

样式转换前:

/*! define a */
@charset "utf-8";
@import url('nav.css');
@import "foot.css";

/* import common.css *//**/

body { color: red; font-size: 12px; }

/* hello world */

/*! block e */
.a { color: black }
/*! endblock */

/*! block f */
.b { color: white }
/*! block g */
.c { color: yellow }
/*! endblock */
.d { color: green }
/*! endblock */

新版转换后:

/*! block a */
@charset "utf-8";
/*! import nav.css */
/*! import foot.css */

/* import common.css *//**/

body { color: red; font-size: 12px; }

/* hello world */

/*! block e */
.a { color: black }
/*! endblock e */

/*! block f */
.b { color: white }
/*! block g */
.c { color: yellow }
/*! endblock g */
.d { color: green }
/*! endblock f */
/*! endblock a */

上面样式转换10000次新旧效率对比:
qq20140427174238

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.