Coder Social home page Coder Social logo

cmd-util's Introduction

cmd-util

Utilities for common module definition.


This package is designed for developers, if you are a user, don't read this.

Build Status Coverage Status

Implements

  • ast: parse cmd javascript code, do whatever you want.
  • css: css parser
  • iduri: solutions for id and uri.

Install

$ npm install cmd-util

Contribute

Yes, please do contribute. But before this, you should read our Contributing Guide.

Changelog

August 12th, 2013 0.3.13

  1. @import without quote

August 5th, 2013 0.3.12

  1. Can modify require.async

July 23rd, 2013 0.3.11

  1. Parsing dependencies for define(id, factory)

June 18th, 2013 0.3.10

  1. Passing parent node to filter for css.stringify

Jun 9th, 2013 0.3.9

  1. Update uglify js dependency.

May 22nd, 2013 0.3.8

  1. Little fix #4

May 21st, 2013 0.3.7

  1. Family can has - in its name.

April 19th, 2013 0.3.6

  1. Support parse dependency of define('id', null, factory) #2

April 8th, 2013 0.3.5

  1. Fix parse dependency of require('foo')('bar')

Mar 29, 2013 0.3.4

  1. Only parse require, don't parse require.async

Mar 19, 2013 0.3.3

  1. Enhancement of ast. Delete a dependency by return null

Mar 16, 2013 0.3.2

  1. add iduri.validateFormat

Mar 14, 2013 0.3.1

  1. make css.walk the right way
  2. add css.strigify

Mar 14, 2013 0.3.0

  1. add css parser

Mar 2, 2013 0.2.0

  1. ast.modify return ast instead of string
  2. iduri.resolve only resolve cmd uri
  3. rewrite ast parser

Feb 1, 2013 0.1.0

This first version.

cmd-util's People

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmd-util's Issues

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
}

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

重写了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

关于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

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.