Coder Social home page Coder Social logo

jsdc's People

Contributors

army8735 avatar

Stargazers

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

Watchers

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

jsdc's Issues

set/get重复报错

Cannot redefine property

class的同名属性进行set和get方法设置后,因转换为两次同名的Object.defineProperty操作报错。
先用一个临时变量存储之,最后进行统一get、set。

yield结束后停止还是回归初始状态

function *hello() {
  yield 'hello';
  yield 'world';
}
var test = hello();
console.log(test.next().value)
console.log(test.next().value)

console.log(test.next().value)

第三次应该是啥?undefined还是hello?

windows 1.8.1前者,mac后者。

@hax 麻烦解答下规范了……

语法转换设计

仅设计支持正式规范的语法,或者成熟的草案且已经在浏览器中实现的趋势语法。确保转换后代码执行一致,调试行数一致。

以下按实现逻辑顺序排列

var迁移

将var申明迁移至最近的作用域起始处

function() {
  if(true) {
    var a = 1;
  }
}
function() {var a;
  if(true) {
    a = 1;
  }
}

{}块级作用域

必要时将{}替换为function作用域

{
  let a = 1;
}
(function() {
  let a = 1;
}).call(this);

let关键字

将let替换为var

let a = 1;
var a = 1;

const关键字

将const替换为var

const a = 1;
var a = 1;

class类实现

原型继承,class语法糖仅作简单转换,虽然尚未定案和现实标准实现,但是这是比较稳定的即将实现的特例

class Test() {
  constructor(a) {
    this.a = a;
  }
  method() {
  }
  get data() {
    return this.a;
  }
}
function Test(a) {

  this.a = a;

  this.data = a;


}
Test.prototype.method = function() {
}

extends继承实现

使用寄生组合式继承

class Father() {
  constructor(a) {
    this.a = a;
  }
  method() {
    return this.a;
  }
}
class Child() {
  constructor(a) {
    super(a);
  }
  method() {
    return super.method();
  }
}
function Father(a) {

  this.a = a;

}
Father.prototype.method = function() {
  return this.a;
}
function Child(a) {

  Father.call(this, a);

}
Child.prototype.method = function() {
  return Father.prototype.method.call(this);
}
//这行以下为可阅读性多行写,本应附加在上面行末尾
;(function() {
  var prototype = Object.create(Father.prototype);
  prototype.constructor = Father;
  Child.prototype = prototype;
)();

默认参数值

根据是否全等undefined赋值,默认参数后不能出现非默认参数

function method(a, b = 1) {
}
function method(a, b) {if(typeof b == "undefined") b = 1;
}

可变参数

将可变参数通过arguments转换为数组

function method(a, ...args) {
}
function method(a, args) {args = Array.prototype.slice.call(arguments, 1);
}

module

等待es6正式规范或者现实标准实现

module {
  exports = {};
}

template

等待es6正式规范或者现实标准实现

`template`

rest param bug

a(...b) -> a.apply(this, [].concat(b))

b可能不是个array,使用iterator

new a().b(...c)

需要解决

new ...rest的this指向

new A(...this.xxx)
new (Function.prototype.bind.apply(A, [null].concat(function(){ this.xxx }()));

this指向错误,变成window了,需要在new之前保存当前context,替换掉this。

支持sourcemap和更好的代码排版

其他几个transpiler也是保持行数一致,但是我个人觉得6to5的做法更好。

因为生成代码可读性对于支持调试其实也很重要。但是强制源码行数一致必定导致生成代码可读性的实际下降。而且仅行数对应,也不能解决行较长没有col位置的问题。

现在浏览器都支持sourcemap,所以建议放弃行数对应,改为支持sourcemap,并给出更好的代码排版,甚至可加入注释。比如在注释中包含源码(这样还能解决不支持sourcemap的老浏览器的调试问题)。

需要 spread 对 new 的支持.

new Cls(...args);

在 traceur 中是展开为:

new (Function.prototype.bind.apply(Cls, $traceurRuntime.spread([null], args)))();

Arrow Function 的实现不符合规范.

this 与 arguments 需要处理

function test() {
  var fn = (a, b, c) => console.log(this, arguments, a, b, c);
  fn.call({name: "inner"}, 4, 5, 6);
}
test.call({name: "outer"}, 1, 2, 3);

// 实际应该输出
// {name: "outer"} [1, 2, 3] 4 5 6

// 你这个实现的输出
// {name: "inner"} [4, 5, 6] 4 5 6

对比实现:

参考链接:

需要 rest 支持

var fn = (...arg) => console.log(arg);

上面代码应该正常解析.

only allow super call in class constructor

class Test {
  method() {
    super()  // <- should throw syntax error here
  }
}

It should also apply to normal functions or generators.

See HasDirectSuper static semantics in the draft.

提供直接执行的cli?

像babel提供了两个命令行:
babel用于编译
babel-node用于直接基于node执行

jsdc有jsdc-cli提供了,再搞个jsdc-node?

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.