Skip to content
Commits on Jun 25, 2011
  1. Add accessor to NodeStatementWithExpression

    committed Jun 25, 2011
    This node is kind of stupid anyway.. should be separate nodes but we're
    lazy.
Commits on Dec 15, 2010
  1. Support for accessors in object literals

    committed Dec 16, 2010
    Summary:
    This adds optional support for "get" and "set" syntax in object literals. The grammar is kind of hacky here, but this was the easiest way without hacking up the lexer and is overall pretty self-contained.
    
    Test Plan:
    Parsed a file which used this syntax extensively.
    
    Reviewed By: epriestley
  2. Line number refactor

    committed Dec 16, 2010
    Summary:
    Line number handling in libfbjs was pretty poor. Lots of times rerendered trees would all end up on one line at
    
    Test Plan:
    Rendered a self-calling function and confirmed line numbers were sane.
    
    Reviewed By: epriestley
  3. Adding .gitignore

    committed Dec 16, 2010
    Summary:
    Long overdue.
    
    Test Plan:
    git st
    
    Reviewed By: epriestley
Commits on Nov 19, 2010
  1. Add convenience casting for NodeWalker

    committed Nov 19, 2010
    Summary:
    It can be a pain to have to cast subclasses of NodeWalker all the time using static_cast and dynamic_cast, especially with auto_ptr's. This adds an overloaded template cast() function for use in subclasses of NodeWalker; so you can do `cast(MyNodeWalkerClass).some_var` to cast your class. It will throw if you pass an invalid class so you can just all NodeWalker* instances without error-checking.
    
    Test Plan:
    Compiles
    
    Reviewed By: epriestley
  2. E4X parsing support

    committed Nov 19, 2010
    Summary:
    This adds optional support for E4X as specified by ECMA-357. By default this is off, but you can enable it at run-time with PARSER_E4X.
    
    Test Plan:
    Basically nothing at all.
    
    Reviewed By: epriestley
  3. Support for typehints and object literal elisons

    committed Nov 19, 2010
    Summary:
    Included in this diff is support for type declarations as made popular by ActionScript. While not part of ECMAScript, if typing ever does make it into the language it will most likely look similar to this. By default type declarations will still yield a syntax error, however you may elect to tell the parser to allow these declarations by passing PARSE_TYPEHINT to the second parameter of NodeProgram.
    
    Additionally this adds support for trailing commas in object literals. While expressly allowed by ECMA-262, trailing commas in object literals have become defacto forbidden in most client-side JavaScript applications due to poor browser option.
    
    Test Plan:
    Compiles
    
    Reviewed By: epriestley
  4. Cleanup various deficiencies

    committed Nov 19, 2010
    Summary:
    This cleans up a lot of junk in the code like stray virtuals, missing refs and consts where applicable, better exceptions, and proper string literal rendering.
    
    Test Plan:
    Compiles
    
    Reviewed By: epriestley
  5. NodeWalker and removal of reduce()

    committed Nov 19, 2010
    Summary:
    A general solution is needed for walking these AST's and applying a transformation to them. This implements a typical visitor class from which you can extend to subscribe to nodes you want to handle. There's built-in methods for manipulating the tree as you go, and getting data from your children.
    
    Test Plan:
    Built a few walkers for another application, adapting this API as I found use cases.
    
    Reviewed By: epriestley
Commits on Dec 7, 2009
  1. Don't optimize future reserved keywords

    Feng Qian committed Dec 7, 2009
    Summary: It breaks Safari. For example, class is a future reserved keyword,
             don't change b['class'] to b.class.
    
    Reviewed By: lklots
    
    Test Plan: test following js file:
    
               var a = {'class' : 10}
               print(a['class'])
    
               It should not be changed to
               var a = {'class' : 10} print(a.class)
    
    Revert: OK
    
    DiffCamp Revision: 78052
Commits on Nov 25, 2009
  1. More on code reduction

    Feng Qian committed Nov 24, 2009
    Summary: The outcome of 'jsxmin --replace' is that these are some if
             statements with empty blocks. This diff removes these if statements
             if the expression has no side effects. Currently I can think of
             assignment and function calls have side-effects. Please let me know
             if you can think more expressions with side effects.
    
    Reviewed By: lklots
    
    Test Plan: Run all existing JS tests.
    
    Revert: OK
    
    DiffCamp Revision: 76206
Commits on Nov 21, 2009
  1. Using fbconfig/fbmake for libfbjs and jsxmin

    Feng Qian committed Nov 20, 2009
    Summary: 1. move applications from libfbjs to fbjstools directory;
             2. create fbconfg/fbmake TARGETS files for libfbjs and fbjstools;
    
             Fbconfig/fbmake's handling of flex/bison files are limited, the
             make rule for generated files does not include original directory
             in the path. To keep old libfbjs/Makefile working, I have to add a
             workaround, passing NOT_FBMAKE to g++. A simple fix in fbconfig
             should fix this issue by including the original directory in the
             include path.
    
    Reviewed By: marcel
    
    Test Plan: Tested fbconfig/fbmake both dbg|opt and run all JS tests.
    
    Revert: OK
    
    DiffCamp Revision: 75837
Commits on Nov 20, 2009
  1. Integrate jsbeautify into jsxmin

    Feng Qian committed Nov 20, 2009
    Summary: It is easier for deployment to have one binary. A few changes in
             this diff:
    
             1 use google-gflags, I made a copy of gflags from
             fbcode/external/gflags (it is insane), see my plan at the end;
             2.converted jsbeautify to jsxmin_reduction, the replacement patten
             is passed as:
               --replace "pattern1 : replacement1 , pattern2 : replacement2",
             assuming patterns and replacements don't contain ':' and ','. We
             can come up a different scheme if we hit cases where it does not
             work;
             3. each optimization is controlled by individual flag: e.g.,
             --novariable_renaming, --nocode_reduction, etc
    
             OK, back to gflags thing. the number of jsxmin files is growing, I
             feel we should move them out of libfbjs so that libfbjs is kept
             small and clean. I'd like to move these optimizations to an upper
             directory in fbcode and use fbconfig/fbmake. What do you guys
             think?
    
    Reviewed By: lklots
    
    Other Commenters: jsobel
    
    Test Plan: See my on-the-fly jsxminified sandbox
    
               JSXMIN has following options:
               --replace "Util.isDevelopmentEnvironment():false,__DEV__:0"
               --reduce --pretty --debug
    
    Revert: OK
    
    DiffCamp Revision: 75621
Commits on Nov 19, 2009
  1. Better local variable renaming

    Feng Qian committed Nov 19, 2009
    Summary: Instead of using 4-plus characters for new names, try to use
             shorter names as much as possible. On the largest JS package,
             better local renaming gives about 5% size reduction.
    
             The diff itself also re-organize jsxmin code towards OO style.
    
             Private global variable and property renaming is almost working, I
             am hitting some cases where variable/functions are named as private
             property (starting with '_'), but actually been used by files in
             different packages. By default, both property and global renaming
             are disable.
    
             This is the first cut. It is big so you can start reviewing it
             early. I will make more testing and improvement at the same time.
    
    Reviewed By: lklots
    
    Test Plan: Added several tests.
    
               My sandbox uses new jsxmin. You can browse it to see if you get any
               JS errors.
    
    Revert: OK
    
    DiffCamp Revision: 75098
Commits on Nov 17, 2009
  1. Fix exponent parsing

    committed Nov 17, 2009
    Summary: libfbjs fails on 1e+1. Fixing that. Also using strtod instead of
             sscanf, as strtod is more precise.
    
    Reviewed By: fengqian
    
    Test Plan: marcel@dev050 ~/libfbjs $ cat tests/exponent.js | ./jsbeautify
               print(1e+07);
               print(1e-07);
               print(1e+07);
    
    Revert: OK
    
    DiffCamp Revision: 74797
Commits on Oct 23, 2009
  1. Fix the buggy code dealing with nested if's

    Feng Qian committed Oct 23, 2009
    Summary: Old code only deals with
             if () {
               if ()
             } else {}
    
             but does not handle following case properly
             if () {
               for () {
                 if ()
               }
             } else {}
    
             This patch has a quick fix that always put braces around TRUE
             statements if there is an else part.
    
    Reviewed By: rdbayer
    
    Test Plan: The code triggers this bug is in html/js/lib/ui/sort.js
    
               See the reduced test case, and tested on my sandbox, it works
               fine.
    
    Revert: OK
    
    DiffCamp Revision: 70592
Commits on Oct 21, 2009
  1. Fix another bug that can generates infinite loops

    Feng Qian committed Oct 20, 2009
    Summary: The code generation, render, can skip braces incorrectly, see the
             test case.
    
             Also add an opt mode with -O2 gcc option.
    
    Reviewed By: lklots
    
    Test Plan: See the test case.
    
    Revert: OK
    
    DiffCamp Revision: 70031
  2. Small improvement in renaming

    Feng Qian committed Oct 20, 2009
    Summary: Don't rename a variable if the orignal name is shorter then the new
             name.
    
             Also move 'unsafe' to 'g_unsafe'.
    
    Reviewed By: lklots
    
    Test Plan: Run the script and works fine.
    
    Revert: OK
    
    DiffCamp Revision: 70032
Commits on Oct 20, 2009
  1. Don't rename for functions with eval and with

    Feng Qian committed Oct 20, 2009
    Summary: We cannot get it right because the dynamic nature.
    
    Reviewed By: lklots
    
    Test Plan: Two tests are attached.
    
    Revert: OK
    
    DiffCamp Revision: 69923
Commits on Oct 13, 2009
  1. Testing tool enhancement and more test cases

    Feng Qian committed Oct 13, 2009
    Summary: 1. add a script that jsxminifies all JS files in a directory,
             useful for testing large JS benchmarks;
    
             See tools/README for more details.
    
             2. add three test cases in bugs/ directory, which are accepted by
             SpiderMonkey, but rejected by jsxmin parser
    
    Reviewed By: marcel
    
    Test Plan: A local tool for testing, run it locally on mozilla and v8
               benchmarks and it works fine.
    
    Revert: OK
    
    DiffCamp Revision: 68736
Commits on Oct 12, 2009
  1. Fix instanceof on new line

    committed Oct 12, 2009
    Summary: This expression fails to parse:
             (foo
             instanceof bar);
    
             This is because of libfbjs's crazy virtual semicolon logic. I
             cleaned some of that up and fixed the bug.
    
             This also fixes the DEBUG_FLEX option, which is apparently broken.
    
             And it improves the dependencies in the Makefile so that make -j10
             works and the build goes really fast.
    
    Reviewed By: fengqian
    
    Test Plan: (foo
               instanceof bar);
    
    Revert: OK
    
    DiffCamp Revision: 68397
Commits on Oct 10, 2009
  1. Fix a parsing issue

    Feng Qian committed Oct 9, 2009
    Summary: The grammar of handling switch statement is slightly off the spec.
             jsxmin generated invalid code if no case statements are in a switch
             statement body.
    
             The patch makes the case clauses the same as spec.
    
             A test case is attached.
    
    Reviewed By: marcel
    
    Test Plan: See the test case. Currently jsxmin generates:
    
               case default::
    
    Revert: OK
    
    DiffCamp Revision: 68392
  2. Improve the test script

    Feng Qian committed Oct 9, 2009
    Summary: 1. renamed bin/ directory to tools/ directory
             2. make jsshell, jsxmin as options and the script accept a list or
             tests or test dirs and can recursively search for files end with
             'js' (case-insensitive) and verify.
             3. add a --pretty option to jsxmin for easy debugging
    
    Reviewed By: lklots
    
    Test Plan: Manually tested options and different flags.
    
    Revert: OK
    
    DiffCamp Revision: 68312
Commits on Oct 6, 2009
  1. Rename function in local scope

    Feng Qian committed Oct 6, 2009
    Summary: Fix the issue happened in the dev site where a function declared
             inside another function is not renamed, but references to the inner
             function name in the outer function got renamed.
    
             Also add several test cases reduced from real code.
    
             Added a test script bin/run_tests.py and a SpiderMonkey 1.7
             executable so that we can run tests. The script does following:
             for each test in tests/ directory:
               1. run js test and get output
               2. run jsxmin on the test and run js on the result, get output
               3. if outputs from 1 and 2 are not the same, print out FAIL,
             otherwise, print out PASS
             Going forward, we can create more test cases and add many existing
             test cases from Mozilla, WebKit and V8.
    
    Reviewed By: lklots
    
    Test Plan: Apply the patch and invoke bin/run_tests.py, all tests should
               PASS.
    
    Revert: OK
    
    DiffCamp Revision: 67483
Commits on Oct 2, 2009
  1. bypass libfbjs segfault on empty if(){}

    Levy Klots committed Oct 2, 2009
    Summary:
    Got a segfault running jsxmin based of the parser in fbcode/libfbjs/ with head at 12964. A dynamic_cast was failing because the children nodes of an if statement are being populated incorrectly when the body of an if statement is empty.
    Codez
    
      if (whatever) {
    
      }
    
    Stack trace
    
      > #1  0x0000000000411d1c in fbjs::NodeIf::render (this=0x6b3b70,
      > guts=0x7fff31d312f0, indentation=1) at node.cpp:978
      > 978         while (firstStatement &&
      > dynamic_cast<NodeStatementList*>(firstStatement) != NULL
    
    I doubt that this is the 100% correct fix but it works.
    
    Reviewed By: marcel
    
    Test Plan:
    build ran jsxmin on test case and worked ok. ran jsxmin against all files no more segfaults.
    
    Revert: OK
    
    DiffCamp Revision: 65907
Commits on Sep 29, 2009
  1. Fix function renaming issue in jsxmin #131179

    Feng Qian committed Sep 29, 2009
    Summary: The first child node of a function declaration/expression is the
             function identifier (name), it should not be renamed.
    
    Reviewed By: epriestley
    
    Test Plan: Here is the test case:
    
               function test() {
                 var test =1;
               }
    
               The output should preserve the function name as "test".
    
               Another verification step is to enable jsxmin in dev mode and
               load the home page, it should not throw a JS exception that
               "values not found" or something like that.
    
    Revert: OK
    
    DiffCamp Revision: 66603
Commits on Aug 18, 2009
  1. Require braces while rendering nested if's

    committed Aug 18, 2009
    Summary: libfbjs was changing the meaning of certain nested if statements by
             removing braces. Now when rendering we check to see if we're
             rendering an if statement with no else in which case braces are
             required.
    
             There is also a huge chance this doesn't work and I don't have any
             unit tests to confirm whether or not that's the case...
    
    Reviewed By: epriestley
    
    Test Plan: marcel@dev050 ~/libfbjs $ echo 'if(a){if(b)ab();}else nota();'  |
               ./jsbeautify -c
               if(a){if(b)ab();}else nota();
               marcel@dev050 ~/libfbjs $ echo 'if(a){if(b)ab();}else nota();'  |
               ./jsbeautify -c | ./jsbeautify
               if (a) {
                 if (b) {
                   ab();
                 }
               } else {
                 nota();
               }
    
               marcel@dev050 ~/libfbjs $ echo 'if(a){if(b)ab();else 1;}else
               nota();'  | ./jsbeautify -c
               if(a)if(b)ab();else 1;else nota();
               marcel@dev050 ~/libfbjs $ echo 'if(a){if(b)ab();else 1;}else
               nota();'  | ./jsbeautify -c | ./jsbeautify
               if (a) {
                 if (b) {
                   ab();
                 } else {
                   1;
                 }
               } else {
                 nota();
               }
    
    Revert: OK
    
    DiffCamp Revision: 60166
Commits on Aug 13, 2009
  1. Add "--unsafe" flag to jsxmin.

    Evan Priestley committed Aug 13, 2009
Commits on Jul 18, 2009
  1. Fix segfault in jsbeautify

    committed Jul 17, 2009
    Summary: This was happening because the optimization was removing the `else`
             NULL placeholder. The default behavior on a NULL reduction is to
             remove it from childNodes, but that actually should only apply to
             StatementList's
    
    Reviewed By: epriestley
    
    Test Plan: marcel@dev050 ~/libfbjs $ echo 'if (x) {} else if (0) {}' |
               ./jsbeautify -o
               if (x);
               marcel@dev050 ~/libfbjs $ echo 'false && foo(); bar();' |
               ./jsbeautify -o
               bar();
    
    Revert: OK
    
    DiffCamp Revision: 55386
Commits on Jul 12, 2009
  1. jsxmin

    Evan Priestley committed Jul 12, 2009
    Summary: Renames locals, arguments, and any identifier beginning with an "_"
             into some sort of garbage. I remap everything into the "_" scope
             since those identifiers are off-limits and subject to renaming
             anyway. This does mean that minification isn't stable (in the sense
             that min(min(JS)) is not the same as min(JS)) but this is academic
             anyway.
    
    Reviewed By: marcel
    
    Test Plan: Minified some files, no apparent breaks except when frickin'
               variables are hardcoded into string constants. I'm not going to
               roll this out immediately, but my plan for when I do is probably
               to tag like every file in the codebase with
               "@preserve-identifiers" or something and then make tomocchino or
               someone go vet them all I guess.
    
    Revert: OK
    
    DiffCamp Revision: 51209
Commits on Jul 10, 2009
  1. js intl parser: fix parse exception

    Levy Klots committed Jul 10, 2009
    Summary: Including the filename when dealing with a parse exception.
    
    Reviewed By: marcel
    
    Test Plan: parse exceptions on multiple files more understandable
    
    DiffCamp Revision: 54371
  2. js intl: verify tx() calls in c++ binary

    Levy Klots committed Jul 10, 2009
    Summary:
    The php js parser is slow and prohibits, for example, running the parser as part of analyze_resources. Porting the parser to C++ makes the parsing two orders of magnitude faster.
    
    For this first round, just using the parser to verify that developers are using tx() correctly. The integration with analyze_resources is coming in a separate diff. Can also include it as part of an svn hook.
    
    Eventually the php parser will be completely deprecated in favor of this C++ binary (although the parser has problems with things like function() { a({})} which needs to be fixed before going forward).
    
    Reviewed By: marcel
    
    Test Plan:
    1. ran parser against all js files html/js and all checked out ok.
         2. inserted a bad call like tx(lklots) and correct, helpful error message cameup
    
    Revert: OK
    
    DiffCamp Revision: 54296
  3. documentation change

    committed Jul 10, 2009
    Summary:
    none
    
    Reviewed By: no one
    
    Test Plan: none
    
    Revert Plan: ok
  4. don't render line break at the start of pretty output

    committed Jul 10, 2009
    Summary:
    jsbeautify always started with an extra linebreak, which was annoying
    
    Reviewed By: epriestley
    
    Test Plan: make
    
    Revert Plan: ok
  5. Fix remove Flex default rule conditions

    committed Jul 9, 2009
    Summary: There existed a few conditions in which Flex's default rule would
             be hit. I disabled the default rule and cleaned up the cases in
             which this would occur.
    
    Reviewed By: lklots
    
    Test Plan: var foo = bar.
               etc;
    
               var foo = /test
               /;
    
    Revert: OK
    
    DiffCamp Revision: 54283
Something went wrong with that request. Please try again.