Search code examples
javascriptparsinge4xecma262

Are there any syntactic differences between ECMA-262 and ECMA-357?


I'm writing a JavaScript parser based on ECMA-262. I'd be interested to know how much I'd need to change to make it ECMA-357 compatible.

Are there any syntactic differences?


Solution

  • There is a number of syntax extensions. The most important one are the XML literals (see section 11.1.4 and 11.1.5):

    var foo = <xml>
      foo
    </xml>;
    var bar = <>
      <tag attr={(1+2).toFixed(2)}/>
      {foo}
    </>;
    

    The example above shows the special case of an empty root tag and JavaScript expressions in XML code.

    You also have some expressions that aren't valid in ECMA-262 (see section 11.2):

    xml.@attr           // get attribute attr
    xml.*               // get all child elements
    xml.@*              // get all attributes
    xml..foo            // get all <foo> tags
    xml..foo.(@id == 1) // filter <foo> tags by id attribute
    

    There are namespaces (see section 11.1.2):

    xml.soap::foo       // get <foo> child tags with namespace soap
    xml.@soap::attr     // get attribute with namespace soap
    

    There is the default XML namespace statement which is syntactically a very unusual construct (see section 12.1):

    default xml namespace = new Namespace("http://foo/bar");
    

    Finally, there is the for each .. in loop which is similar to for .. in (see section 12.3):

    for each (var foo in xml)
    {
    
    }
    

    As far as I know these are all the syntax differences - but you've probably got more than enough already.