Giter Site home page Giter Site logo

polygonplanet / chiffon Goto Github PK

View Code? Open in Web Editor NEW
55.0 55.0 4.0 1.14 MB

A small ECMAScript parser, tokenizer and minifier written in JavaScript.

Home Page: https://polygonplanet.github.io/Chiffon/demo/javascript-parser-demo.html

License: MIT License

JavaScript 86.56% HTML 13.44%
ast ecmascript javascript parser regex tokenizer

chiffon's People

Contributors

mathiasbynens avatar polygonplanet avatar vankhoawin 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

Watchers

 avatar  avatar  avatar  avatar

chiffon's Issues

Accepts invalid Class syntax

This one:

  • It is a Syntax Error if PropName of MethodDefinition is not "constructor" and HasDirectSuper of MethodDefinition is true.
class A {
    foo() {
        super()  // Invalid 'super()'.
    }
}

http://www.ecma-international.org/ecma-262/6.0/#sec-class-definitions-static-semantics-early-errors

And also this one

class A {
    static foo() {
        super()  // Invalid 'super()'.
    }

    static prototype() {  // Invalid method.
    }
}

For this bugs

  • It is a Syntax Error if FormalParameters Contains SuperProperty is true.
  • It is a Syntax Error if FunctionBody Contains SuperProperty is true.
  • It is a Syntax Error if FormalParameters Contains SuperCall is true.
  • It is a Syntax Error if FunctionBody Contains SuperCall is true.
//-
function foo() {
    super()  // Invalid `super`.
    super.foo()  // Invalid `super`.
}
var foo = function() {
    super()  // Invalid `super`.
    super.foo()  // Invalid `super`.
}

function wrap() {
    function foo(a = super(), b = super.foo()) {  // Invalid 'super'.
    }
}

Breaks with ES6 - Harmony specs

@polygonplanet I noticed this parser is not 100% Harmony compatible?

I tried a few different comboes, and they all failed for me.

//-
function* wrap() {\n(a = yield b)\n}

//-
async function foo() { }

//- a reference and a normal function declaration if there is a linebreak between 'async' and 'function'.
async\nfunction foo() { }

//- 
export async function foo() { }

//-
export default async function() { }

//- 'await' is valid as function names.
async function await() { }

//- async === true
(async function foo() { })

//- export default
export default (async function() { })

//- 
async a => a

//-
async () => a

//-
async (await)

//-
async yield => 1

//-
({async foo() { }})

//-
({async await() { }})

// -
({ x(...[ a, b ]){} })

// -
({ x({ a: { w, x }, b: [y, z] }, ...[a, b, c]){} })

//-
(...a) => {}

//-
(a, ...b) => {}

//-
({ a }) => {}

//-
({ a }, ...b) => {} 

//-
({ a: [a, b] }, ...c) => {}

//-
({ a: b, c }, [d, e], ...f) => {}

//-
[a, ...[b, c]] = d

//-
var [a, ...[b, c]] = d

//-
func(...a)

//-
func(a, ...b)

//-
func(...a, b)

//-
/[a-z]/u

//-
({x = 0}) => x

//-
({*yield() {}})

//-
class A { static() {} }

//-
'`${/\\d/.exec('1')[0]}` // unknown '1'

//-
var await = 0

//-
(([,]) => 0

//-
function* yield() {} // yield as function name
//-
function* foo(a = function*(b) { yield b }) { }

not ESPRIMA compatible anymore

@polygonplanet Great work with this projet!! But it seems to be a lot of minor differences vs Esprima now. Example run this test:
https://github.com/jquery/esprima/blob/master/test/api-tests.js#L900

This will break!
And there are also various AST differences.

E.g. Esprima now have this at the end of the object: sourceType": "script"

Esprima also now supports ECMA 2017 by default. And this module only supports ES2015.

And also Esprima have a delegate option as the third argument for the tokenizer.

Has anyone told you just how beautiful this parser is?

Hi
I'm not sure this is a professionally correct thing to do, but I could not restrain myself admiring your work.
There certainly are some points that ask for further improvement, but the sheer amount of work this parser can do in such a relatively small amount of code is just impressive.
I just wonder why I had not come across it sooner.
Keep up the great work! (And beware this project's relatively low profile might let opportunists steal your code under their name, without attributing anything to you; sigh.)

What is the status on the project?

Hi, @polygonplanet I looked at your module and seems to be a great work, but not compatible with latest ECMA specs. And some open tickets.

What is the plan with this module? Could I expect an refreshment of the module or should I look around for other options such as Acorn and Esprima?

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.