- var inFunction, labels, strict, inXJSChild, inXJSTag;From 35c8f104bd409b82f6b90a6ce226a55e6a7b3e7c Mon Sep 17 00:00:00 2001
From: Ingvar Stepanyan The main exported interface (under self.acorn when in the
browser) is a parse function that takes a code string and
returns an abstract syntax tree as specified by Mozilla parser
-API, with the caveat that the SpiderMonkey-specific syntax
-(let, yield, inline XML, etc) is not recognized.
ecmaVersion indicates the ECMAScript version to parse. Must
be either 3, or 5, or 6. This influences support for strict
mode, the set of reserved words, support for getters and
-setters and other features. ES6 support is only partial.
Interal state for the tokenizer. To distinguish between division +
Internal state for the tokenizer. To distinguish between division
operators and regular expressions, it remembers whether the last
token was one that is allowed to be followed by an expression.
(If it is, a slash is probably a regexp, if it isn’t it’s a
@@ -533,14 +532,15 @@ when finishing a node and assigning its end position.
This is the parser’s state. inFunction is used to reject
-return statements outside of functions, labels to verify that
-break and continue have somewhere to jump to, and strict
-indicates whether strict mode is on.
return statements outside of functions, inGenerator to
+reject yields outside of generators, labels to verify
+that break and continue have somewhere to jump to, and
+strict indicates whether strict mode is on.
- var inFunction, labels, strict, inXJSChild, inXJSTag;This counter is used for checking that arrow expressions did +not contain nested parentheses in argument list.
+ + + +
+ var metParenL;This is used by parser for detecting if it’s inside ES6 +Template String. If it is, it should treat ‘$’ as prefix before +‘{expression}’ and everything else as string literals.
+ +
+ var inTemplate = false;This function is used to raise exceptions on parse errors. It
takes an offset integer (into the current input) to indicate
the location of the error, attaches the position to the end
@@ -571,11 +606,11 @@ message.
Reused empty array added for node fields that are always empty.
@@ -587,42 +622,13 @@ message. -The assignment of fine-grained, information-carrying type objects -allows the tokenizer to store the information it has about a -token in a way that is very cheap for the parser to look up.
- -All token type variables start with an underscore, to make them -easy to recognize.
+The assignment of fine-grained, information-carrying type objects +allows the tokenizer to store the information it has about a +token in a way that is very cheap for the parser to look up.
+ +All token type variables start with an underscore, to make them +easy to recognize.
+ +These are the general types. The type property is only used to
make them recognizeable when debugging.
These are JSX-specific token types
@@ -663,11 +698,11 @@ make them recognizeable when debugging. -Keyword tokens. The keyword property (also used in keyword-like
operators) indicates that the token originated from an
@@ -691,16 +726,19 @@ continue jumps to that label.
The keywords that denote values.
@@ -713,11 +751,11 @@ continue jumps to that label. -Some keywords are treated as regular operators. in sometimes
(when parsing for) needs to be tested against specifically, so
@@ -731,11 +769,11 @@ we assign a variable name to it for quick comparing.
Map keyword names to token types.
@@ -752,16 +790,18 @@ we assign a variable name to it for quick comparing. "instanceof": {keyword: "instanceof", binop: 7, beforeExpr: true}, "this": _this, "typeof": {keyword: "typeof", prefix: true, beforeExpr: true}, "void": {keyword: "void", prefix: true, beforeExpr: true}, - "delete": {keyword: "delete", prefix: true, beforeExpr: true}};Punctuation token types. Again, the type property is purely for debugging.
Operators. These carry several kinds of properties to help the parser use them properly (the presence of these properties is @@ -815,11 +857,41 @@ in AssignmentExpression nodes.
- var _star = {binop: 10, beforeExpr: true};‘<’, ‘>’ may be relational or have special meaning in JSX
+ + var _lt = {binop: 7, beforeExpr: true}, _gt = {binop: 7, beforeExpr: true};Provide access to the token types for external users of the tokenizer.
@@ -831,18 +903,18 @@ tokenizer. parenL: _parenL, parenR: _parenR, comma: _comma, semi: _semi, colon: _colon, dot: _dot, ellipsis: _ellipsis, question: _question, slash: _slash, eq: _eq, name: _name, eof: _eof, num: _num, regexp: _regexp, string: _string, + arrow: _arrow, bquote: _bquote, dollarBraceL: _dollarBraceL, xjsName: _xjsName, xjsText: _xjsText}; - for (var kw in keywordTypes) exports.tokTypes["_" + kw] = keywordTypes[kw];This is a trick taken from Esprima. It turns out that, on non-Chrome browsers, to check whether a string is in a set, a @@ -876,11 +948,11 @@ predicate from a space-separated string of words.
-When there are more than three length categories, an outer switch first dispatches on the lengths, to save on comparisons.
@@ -901,11 +973,11 @@ switch first dispatches on the lengths, to save on comparisons. -Otherwise, simply generate a flat switch statement.
The ECMAScript 3 reserved word list.
@@ -937,11 +1009,11 @@ switch first dispatches on the lengths, to save on comparisons. -ECMAScript 5 reserved words.
@@ -953,11 +1025,11 @@ switch first dispatches on the lengths, to save on comparisons. -The additional reserved words in strict mode.
@@ -969,11 +1041,11 @@ switch first dispatches on the lengths, to save on comparisons. -The forbidden variable names in strict mode.
@@ -985,11 +1057,11 @@ switch first dispatches on the lengths, to save on comparisons. -And the keywords.
@@ -1000,18 +1072,18 @@ switch first dispatches on the lengths, to save on comparisons. var isEcma5AndLessKeyword = makePredicate(ecma5AndLessKeywords); - var isEcma6Keyword = makePredicate(ecma5AndLessKeywords + " let const"); + var isEcma6Keyword = makePredicate(ecma5AndLessKeywords + " let const class extends export import yield"); var isKeyword = isEcma5AndLessKeyword;Big ugly regular expressions that match characters in the whitespace, identifier, and identifier-start categories. These are only applied when a character is found to actually have a -code point above 128.
+code point above 128. +Generated bytools/generate-identifier-regex.js.
var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
- var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
- var nonASCIIidentifierChars = "\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df-\u09e0\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5f-\u0b60\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62-\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2-\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d46-\u0d48\u0d57\u0d62-\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e34-\u0e3a\u0e40-\u0e45\u0e50-\u0e59\u0eb4-\u0eb9\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f41-\u0f47\u0f71-\u0f84\u0f86-\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u1029\u1040-\u1049\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u170e-\u1710\u1720-\u1730\u1740-\u1750\u1772\u1773\u1780-\u17b2\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u1920-\u192b\u1930-\u193b\u1951-\u196d\u19b0-\u19c0\u19c8-\u19c9\u19d0-\u19d9\u1a00-\u1a15\u1a20-\u1a53\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b46-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1bb0-\u1bb9\u1be6-\u1bf3\u1c00-\u1c22\u1c40-\u1c49\u1c5b-\u1c7d\u1cd0-\u1cd2\u1d00-\u1dbe\u1e01-\u1f15\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2d81-\u2d96\u2de0-\u2dff\u3021-\u3028\u3099\u309a\ua640-\ua66d\ua674-\ua67d\ua69f\ua6f0-\ua6f1\ua7f8-\ua800\ua806\ua80b\ua823-\ua827\ua880-\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8f3-\ua8f7\ua900-\ua909\ua926-\ua92d\ua930-\ua945\ua980-\ua983\ua9b3-\ua9c0\uaa00-\uaa27\uaa40-\uaa41\uaa4c-\uaa4d\uaa50-\uaa59\uaa7b\uaae0-\uaae9\uaaf2-\uaaf3\uabc0-\uabe1\uabec\uabed\uabf0-\uabf9\ufb20-\ufb28\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
+ var nonASCIIidentifierStartChars = "\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC";
+ var nonASCIIidentifierChars = "\u0300-\u036F\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08E4-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\u096F\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09E6-\u09EF\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A66-\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B66-\u0B6F\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0CE6-\u0CEF\u0D01-\u0D03\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D66-\u0D6F\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0E50-\u0E59\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0ED0-\u0ED9\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1040-\u1049\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u18A9\u1920-\u192B\u1930-\u193B\u1946-\u194F\u19B0-\u19C0\u19C8\u19C9\u19D0-\u19D9\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AB0-\u1ABD\u1B00-\u1B04\u1B34-\u1B44\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BB0-\u1BB9\u1BE6-\u1BF3\u1C24-\u1C37\u1C40-\u1C49\u1C50-\u1C59\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF8\u1CF9\u1DC0-\u1DF5\u1DFC-\u1DFF\u200C\u200D\u203F\u2040\u2054\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA620-\uA629\uA66F\uA674-\uA67D\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F1\uA900-\uA909\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9D0-\uA9D9\uA9E5\uA9F0-\uA9F9\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA50-\uAA59\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uABF0-\uABF9\uFB1E\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFF10-\uFF19\uFF3F";
var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");Whether a single character denotes a newline.
@@ -1059,11 +1132,11 @@ code point above 128. -Matches a whole line break (where CRLF is considered a single line break). Used to count lines.
@@ -1076,11 +1149,11 @@ line break). Used to count lines. -Test whether a given character code starts an identifier.
@@ -1098,11 +1171,11 @@ line break). Used to count lines. -Test whether a given character is part of an identifier.
@@ -1122,11 +1195,11 @@ line break). Used to count lines. -These are used when options.locations is on, for the
tokStartLoc and tokEndLoc properties.
Called at the end of every token. Sets tokEnd, tokVal, and
tokRegexpAllowed, and skips the space after the token, so that
@@ -1194,7 +1268,7 @@ the next one’s tokStart will point at the right position.
tokStart will point at the right position.
- Called at the start of the parse and after every token. Skips whitespace and comments, and.
@@ -1290,11 +1364,11 @@ whitespace and comments, and. -This is the function that is called to fetch the next token. It is somewhat obscure, because it works in character codes rather @@ -1340,10 +1414,10 @@ into it.
return finishOp(_slash, 1); } - function readToken_mult_modulo() { // '%*' + function readToken_mult_modulo(code) { // '%*' var next = input.charCodeAt(tokPos + 1); if (next === 61) return finishOp(_assign, 2); - return finishOp(_multiplyModulo, 1); + return finishOp(code === 42 ? _star : _multiplyModulo, 1); } function readToken_pipe_amp(code) { // '|&' @@ -1368,11 +1442,11 @@ into it. -A --> line comment
<!--, an XML-style comment that should be interpreted as a line comment
‘</‘, beginning of JSX closing element
+ + size = 2;
+ return finishOp(_ltSlash, size);
+ }
+ return finishOp(code === 60 ? _lt : _gt, size);
}
- function readToken_eq_excl(code) { // '=!'
+ function readToken_eq_excl(code) { // '=!', '=>'
var next = input.charCodeAt(tokPos + 1);
if (next === 61) return finishOp(_equality, input.charCodeAt(tokPos + 2) === 61 ? 3 : 2);
+ if (code === 61 && next === 62 && options.ecmaVersion >= 6) { // '=>'
+ tokPos += 2;
+ return finishToken(_arrow);
+ }
return finishOp(code === 61 ? _eq : _prefix, 1);
}
- function getTokenFromCode(code) {
+ function getTokenFromCode(code) {Special rules work inside ES6 template strings.
+ + if (inTemplate) {‘`’ and ‘${‘ have special meanings, but they should follow string (can be empty)
+ + if (tokType === _string) {
+ if (code === 96) { // '`'
+ ++tokPos;
+ return finishToken(_bquote);
+ }
+ if (code === 36 && input.charCodeAt(tokPos + 1) === 123) { // '${'
+ tokPos += 2;
+ return finishToken(_dollarBraceL);
+ }
+ }anything else is considered string literal
+ + return readString();
+ }
+
switch(code) {The interpretation of a dot depends on whether it is followed by a digit or another two dots.
@@ -1452,11 +1606,11 @@ by a digit or another two dots. - case 48: // '0'
+ case 96: // '`'
+ if (options.ecmaVersion >= 6) {
+ ++tokPos;
+ return finishToken(_bquote);
+ }
+
+ case 48: // '0'
var next = input.charCodeAt(tokPos + 1);
- if (next === 120 || next === 88) return readHexNumber();Anything else beginning with a digit is an integer, octal number, or float.
@@ -1510,11 +1661,11 @@ number, or float. -Quotes produce strings.
@@ -1526,11 +1677,11 @@ number, or float. -Operators are parsed inline in tiny state machines. ‘=’ (61) is
often referred to. finishOp simply skips the amount of
@@ -1544,7 +1695,7 @@ of the type given by its first argument.
JSX content - either simple text, start of
Identifier or keyword. ‘\uXXXX’ sequences are allowed in identifiers, so ‘\’ also dispatches to that.
if (isIdentifierStart(code) || code === 92 /* '\' */) return readWord();
+ if (!inTemplate && (isIdentifierStart(code) || code === 92 /* '\' */)) return readWord();
var tok = getTokenFromCode(code);
@@ -1617,11 +1768,11 @@ identifiers, so ‘\’ also dispatches to that.
-
+
If we are here, we either found a non-ASCII identifier
character, or something that’s entirely disallowed.
@@ -1644,11 +1795,11 @@ character, or something that’s entirely disallowed.
-
+
Parse a regular expression. Some context-awareness is necessary,
since a ‘/‘ inside a ‘[]’ set does not end the expression.
@@ -1676,11 +1827,11 @@ since a ‘/‘ inside a ‘[]’ set does not end the expression.
-
+
Need to use readWord1 because ‘\uXXXX’ sequences are allowed
here (don’t ask).
@@ -1701,11 +1852,11 @@ here (don’t ask).
-
+
Read an integer in the given radix. Return null if zero digits
were read, the integer value otherwise. When len is given, this
@@ -1731,10 +1882,10 @@ will return null unless the integer has exactly len di
return total;
}
- function readHexNumber() {
+ function readRadixNumber(radix) {
tokPos += 2; // 0x
- var val = readInt(16);
- if (val == null) raise(tokStart + 2, "Expected hexadecimal number");
+ var val = readInt(radix);
+ if (val == null) raise(tokStart + 2, "Expected number in radix " + radix);
if (isIdentifierStart(input.charCodeAt(tokPos))) raise(tokPos, "Identifier directly after number");
return finishToken(_num, val);
}
@@ -1742,11 +1893,11 @@ will return null unless the integer has exactly len di
-
+
Read an integer, octal integer, or floating-point number.
@@ -1781,24 +1932,61 @@ will return null unless the integer has exactly len di
-
+
+ function readCodePoint() {
+ var ch = input.charCodeAt(tokPos), code;
+
+ if (ch === 123) {
+ if (options.ecmaVersion < 6) unexpected();
+ ++tokPos;
+ code = readHexChar(input.indexOf('}', tokPos) - tokPos);
+ ++tokPos;
+ if (code > 0x10FFFF) unexpected();
+ } else {
+ code = readHexChar(4);
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ UTF-16 Encoding
+
+
+
+ if (code <= 0xFFFF) {
+ return String.fromCharCode(code);
+ }
+ var cu1 = ((code - 0x10000) >> 10) + 0xD800;
+ var cu2 = ((code - 0x10000) & 1023) + 0xDC00;
+ return String.fromCharCode(cu1, cu2);
+ }
+
function readString(quote) {
- tokPos++;
+ if (!inTemplate) tokPos++;
var out = "";
for (;;) {
if (tokPos >= inputLen) raise(tokStart, "Unterminated string constant");
var ch = input.charCodeAt(tokPos);
- if (ch === quote) {
+ if (inTemplate) {
+ if (ch === 96 || ch === 36 && input.charCodeAt(tokPos + 1) === 123) // '`', '${'
+ return finishToken(_string, out);
+ } else if (ch === quote) {
++tokPos;
return finishToken(_string, out);
}
@@ -1818,7 +2006,7 @@ will return null unless the integer has exactly len di
case 110: out += "\n"; break; // 'n' -> '\n'
case 114: out += "\r"; break; // 'r' -> '\r'
case 120: out += String.fromCharCode(readHexChar(2)); break; // 'x'
- case 117: out += String.fromCharCode(readHexChar(4)); break; // 'u'
+ case 117: out += readCodePoint(); break; // 'u'
case 85: out += String.fromCharCode(readHexChar(8)); break; // 'U'
case 116: out += "\t"; break; // 't' -> '\t'
case 98: out += "\b"; break; // 'b' -> '\b'
@@ -1833,9 +2021,22 @@ will return null unless the integer has exactly len di
}
}
} else {
- if (ch === 13 || ch === 10 || ch === 8232 || ch === 8233) raise(tokStart, "Unterminated string constant");
- out += String.fromCharCode(ch); // '\'
++tokPos;
+ if (newline.test(String.fromCharCode(ch))) {
+ if (inTemplate) {
+ if (ch === 13 && input.charCodeAt(tokPos) === 10) {
+ ++tokPos;
+ ch = 10;
+ }
+ if (options.locations) {
+ ++tokCurLine;
+ tokLineStart = tokPos;
+ }
+ } else {
+ raise(tokStart, "Unterminated string constant");
+ }
+ }
+ out += String.fromCharCode(ch); // '\'
}
}
}
@@ -2170,11 +2371,11 @@ will return null unless the integer has exactly len di
-
+
Used to read character escape sequences (‘\x’, ‘\u’, ‘\U’).
@@ -2190,11 +2391,11 @@ will return null unless the integer has exactly len di
-
+
Used to signal to callers of readWord1 whether the word
contained any escape sequences. This is needed because words with
@@ -2208,11 +2409,11 @@ escape sequences must not be interpreted as keywords.
-
+
Read an identifier, and return it as a string. Sets containsEsc
to whether the word contained a ‘\u’ escape.
@@ -2253,11 +2454,11 @@ containeds an escape, as a micro-optimization.
-
+
Read an identifier or keyword token. Will check for reserved
words when necessary.
@@ -2276,11 +2477,11 @@ words when necessary.
-
+
Parser
@@ -2289,11 +2490,11 @@ words when necessary.
-
+
A recursive descent parser operates by defining functions for all
syntactic elements, and recursively calling those, each function
@@ -2315,11 +2516,11 @@ precedence levels that JavaScript defines.
-
+
Parser utilities
@@ -2328,11 +2529,11 @@ precedence levels that JavaScript defines.
-
+
Continue to the next token.
@@ -2349,11 +2550,11 @@ precedence levels that JavaScript defines.
-
+
Enter strict mode. Re-reads the next token to please pedantic
tests (“use strict”; 010; — should fail).
@@ -2377,11 +2578,11 @@ tests (“use strict”; 010; — should fail).
-
+
Start an AST node, attaching a start offset.
@@ -2416,11 +2617,11 @@ tests (“use strict”; 010; — should fail).
-
+
Start a node whose start offset information should be based on
the start of another node. For example, a binary operator node is
@@ -2445,11 +2646,11 @@ only started after its left-hand side has already been parsed.
-
+
Finish an AST node, adding type and end properties.
@@ -2469,11 +2670,11 @@ only started after its left-hand side has already been parsed.
-
+
Test whether a statement node is the string literal "use strict".
@@ -2488,11 +2689,11 @@ only started after its left-hand side has already been parsed.
-
+
-
+
Test whether a semicolon can be inserted at the current position.
@@ -2529,11 +2732,11 @@ type, and if yes, consumes it as a side effect.
-
+
Consume a semicolon, or, failing that, see if we are allowed to
pretend that there is a semicolon at this position.
@@ -2548,11 +2751,11 @@ pretend that there is a semicolon at this position.
-
+
Expect a token of a given type. If found, consume it, otherwise,
raise an unexpected token error.
@@ -2561,18 +2764,17 @@ raise an unexpected token error.
function expect(type) {
- if (tokType === type) next();
- else unexpected();
+ eat(type) || unexpected();
}
-
+
Expect a char. If found, consume it, otherwise,
raise an unexpected token error.
@@ -2588,11 +2790,11 @@ raise an unexpected token error.
-
+
Get following char.
@@ -2606,29 +2808,193 @@ raise an unexpected token error.
-
+
- function unexpected() {
- raise(tokStart, "Unexpected token");
+ function unexpected(pos) {
+ raise(pos != null ? pos : tokStart, "Unexpected token");
}
-
+
+
+
+ function hash() {
+ return Object.create(null);
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Convert existing expression atom to assignable pattern
+if possible.
+
+
+
+
+ function toAssignable(node, allowSpread, checkType) {
+ if (options.ecmaVersion >= 6 && node) {
+ switch (node.type) {
+ case "Identifier":
+ case "MemberExpression":
+ break;
+
+ case "ObjectExpression":
+ node.type = "ObjectPattern";
+ for (var i = 0; i < node.properties.length; i++) {
+ var prop = node.properties[i];
+ if (prop.kind !== "init") unexpected(prop.key.start);
+ toAssignable(prop.value, false, checkType);
+ }
+ break;
+
+ case "ArrayExpression":
+ node.type = "ArrayPattern";
+ for (var i = 0, lastI = node.elements.length - 1; i <= lastI; i++) {
+ toAssignable(node.elements[i], i === lastI, checkType);
+ }
+ break;
+
+ case "SpreadElement":
+ if (allowSpread) {
+ toAssignable(node.argument, false, checkType);
+ checkSpreadAssign(node.argument);
+ } else {
+ unexpected(node.start);
+ }
+ break;
+
+ default:
+ if (checkType) unexpected(node.start);
+ }
+ }
+ return node;
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Checks if node can be assignable spread argument.
+
+
+
+
+ function checkSpreadAssign(node) {
+ if (node.type !== "Identifier" && node.type !== "ArrayPattern")
+ unexpected(node.start);
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Verify that argument names are not repeated, and it does not
+try to bind the words eval or arguments.
+
+
+
+
+ function checkFunctionParam(param, nameHash) {
+ switch (param.type) {
+ case "Identifier":
+ if (isStrictReservedWord(param.name) || isStrictBadIdWord(param.name))
+ raise(param.start, "Defining '" + param.name + "' in strict mode");
+ if (nameHash[param.name])
+ raise(param.start, "Argument name clash in strict mode");
+ nameHash[param.name] = true;
+ break;
+
+ case "ObjectPattern":
+ for (var i = 0; i < param.properties.length; i++)
+ checkFunctionParam(param.properties[i].value, nameHash);
+ break;
+
+ case "ArrayPattern":
+ for (var i = 0; i < param.elements.length; i++)
+ checkFunctionParam(param.elements[i], nameHash);
+ break;
+ }
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Check if property name clashes with already added.
+Object/class getters and setters are not allowed to clash —
+either with each other or with an init property — and in
+strict mode, init properties are also not allowed to be repeated.
+
+
+
+
+ function checkPropClash(prop, propHash) {
+ var key = prop.key, name;
+ switch (key.type) {
+ case "Identifier": name = key.name; break;
+ case "Literal": name = String(key.value); break;
+ default: return;
+ }
+ var kind = prop.kind || "init", other = propHash[name];
+ if (other) {
+ var isGetSet = kind !== "init";
+ if ((strict || isGetSet) && other[kind] || !(isGetSet ^ other.init))
+ raise(key.start, "Redefinition of property");
+ } else {
+ other = propHash[name] = hash();
+ other.init = other.get = other.set = false;
+ }
+ other[kind] = true;
+ }
+
+
+
+
+
+
+
+
+ ¶
Verify that a node is an lval — something that can be assigned
to.
@@ -2636,21 +3002,47 @@ to.
- function checkLVal(expr) {
- if (expr.type !== "Identifier" && expr.type !== "MemberExpression")
+ function checkLVal(expr, isBinding) {
+ switch (expr.type) {
+ case "Identifier":
+ if (strict && (isStrictBadIdWord(expr.name) || isStrictReservedWord(expr.name)))
+ raise(expr.start, isBinding
+ ? "Binding " + expr.name + " in strict mode"
+ : "Assigning to " + expr.name + " in strict mode"
+ );
+ break;
+
+ case "MemberExpression":
+ if (!isBinding) break;
+
+ case "ObjectPattern":
+ for (var i = 0; i < expr.properties.length; i++)
+ checkLVal(expr.properties[i].value, isBinding);
+ break;
+
+ case "ArrayPattern":
+ for (var i = 0; i < expr.elements.length; i++) {
+ var elem = expr.elements[i];
+ if (elem) checkLVal(elem, isBinding);
+ }
+ break;
+
+ case "SpreadElement":
+ break;
+
+ default:
raise(expr.start, "Assigning to rvalue");
- if (strict && expr.type === "Identifier" && isStrictBadIdWord(expr.name))
- raise(expr.start, "Assigning to " + expr.name + " in strict mode");
+ }
}
-
+
Statement parsing
@@ -2659,11 +3051,11 @@ to.
-
+
Parse a program. Initializes the parser, reads any number of
statements, and wraps them in a Program node. Optionally takes a
@@ -2676,7 +3068,7 @@ to its body instead of creating a new node.
function parseTopLevel(program) {
lastStart = lastEnd = tokPos;
if (options.locations) lastEndLoc = new Position;
- inFunction = strict = null;
+ inFunction = inGenerator = strict = null;
labels = [];
readToken();
@@ -2696,11 +3088,11 @@ to its body instead of creating a new node.
-
+
Parse a single statement.
If expecting a statement and finding a slash operator, parse a
@@ -2720,11 +3112,11 @@ does not help.
-
+
Most types of statements are recognized by the keyword they
start with. Many are trivial to parse, some require a bit of
@@ -2739,6 +3131,7 @@ complexity.
case _do: return parseDoStatement(node);
case _for: return parseForStatement(node);
case _function: return parseFunctionStatement(node);
+ case _class: return parseClass(node, true);
case _if: return parseIfStatement(node);
case _return: return parseReturnStatement(node);
case _switch: return parseSwitchStatement(node);
@@ -2748,16 +3141,18 @@ complexity.
case _while: return parseWhileStatement(node);
case _with: return parseWithStatement(node);
case _braceL: return parseBlock(); // no point creating a function for this
- case _semi: return parseEmptyStatement(node);
+ case _semi: return parseEmptyStatement(node);
+ case _export: return parseExport(node);
+ case _import: return parseImport(node);
-
+
If the statement does not start with a statement keyword or a
brace, it’s an ExpressionStatement or LabeledStatement. We
@@ -2788,11 +3183,11 @@ Identifier node, we switch to interpreting it as a label.
-
+
Verify that there is an actual destination to break or
continue to.
@@ -2830,19 +3225,19 @@ continue to.
-
+
- Disambiguating between a for and a for/in loop is
-non-trivial. Basically, we have to parse the init var
+
Disambiguating between a for and a for/in or for/of
+loop is non-trivial. Basically, we have to parse the init var
statement or expression, disallowing the in operator (see
the second parameter to parseExpression), and then check
-whether the next token is in. When there is no init part
-(semicolon immediately after the opening parenthesis), it is
-a regular for loop.
+whether the next token is in or of. When there is no init
+part (semicolon immediately after the opening parenthesis), it
+is a regular for loop.
@@ -2853,16 +3248,20 @@ a regular for loop.
expect(_parenL);
if (tokType === _semi) return parseFor(node, null);
if (tokType === _var || tokType === _let) {
- var init = startNode(), varKind = tokType.keyword;
+ var init = startNode(), varKind = tokType.keyword, isLet = tokType === _let;
next();
parseVar(init, true, varKind);
finishNode(init, "VariableDeclaration");
- if (init.declarations.length === 1 && eat(_in))
+ if ((tokType === _in || (tokType === _name && tokVal === "of")) && init.declarations.length === 1 &&
+ !(isLet && init.declarations[0].init))
return parseForIn(node, init);
return parseFor(node, init);
}
var init = parseExpression(false, true);
- if (eat(_in)) {checkLVal(init); return parseForIn(node, init);}
+ if (tokType === _in || (tokType === _name && tokVal === "of")) {
+ checkLVal(init);
+ return parseForIn(node, init);
+ }
return parseFor(node, init);
}
@@ -2887,11 +3286,11 @@ a regular for loop.
-
+
In return (and break/continue), the keywords with
optional arguments, we eagerly look for a semicolon or the
@@ -2915,11 +3314,11 @@ possibility to insert one.
-
+
Statements under must be grouped (by label) in SwitchCase
nodes. cur is used to keep the node that we are currently
@@ -2958,11 +3357,6 @@ adding statements to.
raise(lastEnd, "Illegal newline after throw");
node.argument = parseExpression();
semicolon();
- return finishNode(node, "ThrowStatement");next();
- if (newline.test(input.slice(lastEnd, tokStart)))
- raise(lastEnd, "Illegal newline after throw");
- node.argument = parseExpression();
- semicolon();
return finishNode(node, "ThrowStatement");
}
@@ -3038,11 +3432,11 @@ adding statements to.
-
+
Used for constructs like switch and if that insist on
parentheses around their expression.
@@ -3060,11 +3454,11 @@ parentheses around their expression.
-
+
Parse a semicolon-enclosed block of statements, handling "use
strict" declarations when allowStrict is true (used for
@@ -3093,11 +3487,11 @@ function bodies).
-
+
Parse a regular for loop. The disambiguation code in
parseStatement will already have parsed the init statement or
@@ -3121,34 +3515,37 @@ expression.
-
+
- Parse a for/in loop.
+ Parse a for/in and for/of loop, which are almost
+same from parser’s perspective.
function parseForIn(node, init) {
+ var type = tokType === _in ? "ForInStatement" : "ForOfStatement";
+ next();
node.left = init;
node.right = parseExpression();
expect(_parenR);
node.body = parseStatement();
labels.pop();
- return finishNode(node, "ForInStatement");
+ return finishNode(node, type);
}
-
+
Parse a list of variable declarations.
@@ -3160,9 +3557,8 @@ expression.
node.kind = kind;
for (;;) {
var decl = startNode();
- decl.id = parseIdent();
- if (strict && isStrictBadIdWord(decl.id.name))
- raise(decl.id.start, "Binding " + decl.id.name + " in strict mode");
+ decl.id = options.ecmaVersion >= 6 ? toAssignable(parseExprAtom()) : parseIdent();
+ checkLVal(decl.id, true);
decl.init = eat(_eq) ? parseExpression(true, noIn) : (kind === _const.keyword ? unexpected() : null);
node.declarations.push(finishNode(decl, "VariableDeclarator"));
if (!eat(_comma)) break;
@@ -3173,11 +3569,11 @@ expression.
-
+
Expression parsing
@@ -3186,11 +3582,11 @@ expression.
-
+
These nest, from the most general expression type at the top to
‘atomic’, nondivisible expression types at the bottom. Most of
@@ -3203,11 +3599,11 @@ the AST node that the inner parser gave them in another node.
-
+
Parse a full expression. The arguments are used to forbid comma
sequences (in argument lists, array literals, or object literals)
@@ -3230,11 +3626,11 @@ or the in operator (in for loops initalization expressions).
-
+
Parse an assignment expression. This includes applications of
operators like +=.
@@ -3247,10 +3643,10 @@ operators like +=.
if (tokType.isAssign) {
var node = startNodeFrom(left);
node.operator = tokVal;
- node.left = left;
+ node.left = tokType === _eq ? toAssignable(left) : left;
+ checkLVal(left);
next();
node.right = parseMaybeAssign(noIn);
- checkLVal(left);
return finishNode(node, "AssignmentExpression");
}
return left;
@@ -3259,11 +3655,11 @@ operators like +=.
-
+
Parse a ternary conditional (?:) operator.
@@ -3286,11 +3682,11 @@ operators like +=.
-
+
Start the precedence parser.
@@ -3304,11 +3700,11 @@ operators like +=.
-
+
Parse binary operators with the operator precedence parsing
algorithm. left is the left-hand side of the operator.
@@ -3339,11 +3735,11 @@ operator that has a lower precedence than the set it is parsing.
-
+
Parse unary operators, both prefix and postfix.
@@ -3380,11 +3776,11 @@ operator that has a lower precedence than the set it is parsing.
-
+
Parse call, dot, and []-subscript expressions.
@@ -3414,17 +3810,22 @@ operator that has a lower precedence than the set it is parsing.
node.callee = base;
node.arguments = parseExprList(_parenR, false);
return parseSubscripts(finishNode(node, "CallExpression"), noCalls);
- } else return base;
+ } else if (tokType === _bquote) {
+ var node = startNodeFrom(base);
+ node.tag = base;
+ node.quasi = parseTemplate();
+ return parseSubscripts(finishNode(node, "TaggedTemplateExpression"), noCalls);
+ } return base;
}
-
+
Parse an atomic expression — either a single token that is an
expression, an expression started by a keyword like function or
@@ -3440,8 +3841,17 @@ or {}.
var node = startNode();
next();
return finishNode(node, "ThisExpression");
+
+ case _yield:
+ if (inGenerator) return parseYield();
+
case _name:
- return parseIdent();
+ var id = parseIdent(tokType !== _name);
+ if (eat(_arrow)) {
+ return parseArrowExpression(startNodeFrom(id), [id]);
+ }
+ return id;
+
case _num: case _string: case _regexp: case _xjsText:
var node = startNode();
node.value = tokVal;
@@ -3457,23 +3867,131 @@ or {}.
return finishNode(node, "Literal");
case _parenL:
- var tokStartLoc1 = tokStartLoc, tokStart1 = tokStart;
+ var node = startNode(), tokStartLoc1 = tokStartLoc, tokStart1 = tokStart, val, exprList;
next();
- var val = parseExpression();
+ var oldParenL = ++metParenL;
+ if (tokType !== _parenR) {
+ val = parseExpression();
+ exprList = val.type === "SequenceExpression" ? val.expressions : [val];
+ } else {
+ exprList = [];
+ }
+ expect(_parenR);
+
+
+
+
+
+
+
+
+ ¶
+
+ if ‘=>’ follows ‘(…)’, convert contents to arguments
+
+
+
+ if (metParenL === oldParenL && eat(_arrow)) {
+ val = parseArrowExpression(node, exprList);
+ } else {
+
+
+
+
+
+
+
+
+ ¶
+
+ forbid ‘()’ before everything but ‘=>’
+
+
+
+ if (!val) unexpected(lastStart);
+
+
+
+
+
+
+
+
+ ¶
+
+ forbid ‘…’ in sequence expressions
+
+
+
+ if (options.ecmaVersion >= 6) {
+ for (var i = 0; i < exprList.length; i++) {
+ if (exprList[i].type === "SpreadElement") unexpected();
+ }
+ }
+ }
val.start = tokStart1;
- val.end = tokEnd;
+ val.end = lastEnd;
if (options.locations) {
val.loc.start = tokStartLoc1;
- val.loc.end = tokEndLoc;
+ val.loc.end = lastEndLoc;
+ }
+ if (options.ranges) {
+ val.range = [tokStart1, lastEnd];
}
- if (options.ranges)
- val.range = [tokStart1, tokEnd];
- expect(_parenR);
return val;
case _bracketL:
var node = startNode();
- next();
+ next();
+
+
+
+
+
+
+
+
+ ¶
+
+ check whether this is array comprehension or regular array
+
+
+
+ if (options.ecmaVersion >= 6 && tokType === _for) {
+ node.blocks = [];
+ while (tokType === _for) {
+ var block = startNode();
+ next();
+ expect(_parenL);
+ block.left = toAssignable(parseExprAtom());
+ checkLVal(block.left, true);
+ if (tokType !== _name || tokVal !== "of") unexpected();
+ next();
+
+
+
+
+
+
+
+
+ ¶
+
+ of property is here for compatibility with Esprima’s AST
+which also supports deprecated [for (… in …) expr]
+
+
+
+ block.of = true;
+ block.right = parseExpression();
+ expect(_parenR);
+ node.blocks.push(finishNode(block, "ComprehensionBlock"));
+ }
+ node.filter = eat(_if) ? parseParenExpression() : null;
+ node.body = parseExpression();
+ expect(_bracketR);
+ return finishNode(node, "ComprehensionExpression");
+ }
node.elements = parseExprList(_bracketR, true, true);
return finishNode(node, "ArrayExpression");
@@ -3485,13 +4003,20 @@ or {}.
next();
return parseFunction(node, false);
+ case _class:
+ return parseClass(startNode(), false);
+
case _new:
return parseNew();
- case _relational:
- if (tokVal === '<') {
- return parseXJSElement();
- }
+ case _ellipsis:
+ return parseSpread();
+
+ case _bquote:
+ return parseTemplate();
+
+ case _lt:
+ return parseXJSElement();
default:
unexpected();
@@ -3501,11 +4026,11 @@ or {}.
-
+
New’s precedence is slightly tricky. It must allow its argument
to be a [] or dot subscript expression, but not a call — at
@@ -3526,11 +4051,72 @@ least, not without wrapping it in parentheses. Thus, it uses the
-
+
+
+
+ function parseSpread() {
+ var node = startNode();
+ next();
+ node.argument = parseExpression(true);
+ return finishNode(node, "SpreadElement");
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Parse template expression.
+
+
+
+
+ function parseTemplate() {
+ var node = startNode();
+ node.expressions = [];
+ node.quasis = [];
+ inTemplate = true;
+ next();
+ for (;;) {
+ var elem = startNode();
+ elem.value = {cooked: tokVal, raw: input.slice(tokStart, tokEnd)};
+ elem.tail = false;
+ next();
+ node.quasis.push(finishNode(elem, "TemplateElement"));
+ if (eat(_bquote)) { // '`', end of template
+ elem.tail = true;
+ break;
+ }
+ inTemplate = false;
+ expect(_dollarBraceL);
+ node.expressions.push(parseExpression());
+ inTemplate = true;
+ expect(_braceR);
+ }
+ inTemplate = false;
+ return finishNode(node, "TemplateLiteral");
+ }
+
+
+
+
+
+
+
+
+ ¶
Parse an object literal.
@@ -3538,7 +4124,7 @@ least, not without wrapping it in parentheses. Thus, it uses the
function parseObj() {
- var node = startNode(), first = true, sawGetSet = false;
+ var node = startNode(), first = true, propHash = hash();
node.properties = [];
next();
while (!eat(_braceR)) {
@@ -3547,64 +4133,84 @@ least, not without wrapping it in parentheses. Thus, it uses the
if (options.allowTrailingCommas && eat(_braceR)) break;
} else first = false;
- var prop = {key: parsePropertyName()}, isGetSet = false, kind;
+ var prop = startNode(), kind, isGenerator;
+ if (options.ecmaVersion >= 6) {
+ prop.method = false;
+ prop.shorthand = false;
+ isGenerator = eat(_star);
+ }
+ parsePropertyName(prop);
if (eat(_colon)) {
prop.value = parseExpression(true);
kind = prop.kind = "init";
- } else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" &&
+ } else if (options.ecmaVersion >= 6 && tokType === _parenL) {
+ kind = prop.kind = "init";
+ prop.method = true;
+ prop.value = parseMethod(isGenerator);
+ } else if (options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set")) {
- isGetSet = sawGetSet = true;
+ if (isGenerator) unexpected();
kind = prop.kind = prop.key.name;
- prop.key = parsePropertyName();
- if (tokType !== _parenL) unexpected();
- prop.value = parseFunction(startNode(), false);
- } else unexpected();
-
-
-
-
-
-
-
-
- ¶
-
- getters and setters are not allowed to clash — either with
-each other or with an init property — and in strict mode,
-init properties are also not allowed to be repeated.
+ parsePropertyName(prop);
+ prop.value = parseMethod(false);
+ } else if (options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
+ kind = prop.kind = "init";
+ prop.value = prop.key;
+ prop.shorthand = true;
+ } else unexpected();
-
-
-
- if (prop.key.type === "Identifier" && (strict || sawGetSet)) {
- for (var i = 0; i < node.properties.length; ++i) {
- var other = node.properties[i];
- if (other.key.name === prop.key.name) {
- var conflict = kind == other.kind || isGetSet && other.kind === "init" ||
- kind === "init" && (other.kind === "get" || other.kind === "set");
- if (conflict && !strict && kind === "init" && other.kind === "init") conflict = false;
- if (conflict) raise(prop.key.start, "Redefinition of property");
+ checkPropClash(prop, propHash);
+ node.properties.push(finishNode(prop, "Property"));
}
- }
- }
- node.properties.push(prop);
- }
return finishNode(node, "ObjectExpression");
- }
+ }
- function parsePropertyName() {
- if (tokType === _num || tokType === _string) return parseExprAtom();
- return parseIdent(true);
+ function parsePropertyName(prop) {
+ if (options.ecmaVersion >= 6) {
+ if (eat(_bracketL)) {
+ prop.computed = true;
+ prop.key = parseExpression();
+ expect(_bracketR);
+ return;
+ } else {
+ prop.computed = false;
+ }
+ }
+ prop.key = (tokType === _num || tokType === _string) ? parseExprAtom() : parseIdent(true);
}
-
+
+
+
+ function initFunction(node) {
+ node.id = null;
+ node.params = [];
+ if (options.ecmaVersion >= 6) {
+ node.defaults = [];
+ node.rest = null;
+ node.generator = false;
+ }
+ }
+
+
+
+
+
+
+
+
+ ¶
Parse a function declaration or literal (depending on the
isStatement parameter).
@@ -3612,56 +4218,186 @@ init properties are also not allowed to be repeated.
- function parseFunction(node, isStatement) {
- if (tokType === _name) node.id = parseIdent();
- else if (isStatement) unexpected();
- else node.id = null;
- node.params = [];
- node.rest = null;
+ function parseFunction(node, isStatement, allowExpressionBody) {
+ initFunction(node);
+ if (options.ecmaVersion >= 6) {
+ node.generator = eat(_star);
+ }
+ if (isStatement || tokType === _name) {
+ node.id = parseIdent();
+ }
+ parseFunctionParams(node);
+ parseFunctionBody(node, allowExpressionBody);
+ return finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Parse object or class method.
+
+
+
+
+ function parseMethod(isGenerator) {
+ var node = startNode();
+ initFunction(node);
+ parseFunctionParams(node);
+ var allowExpressionBody;
+ if (options.ecmaVersion >= 6) {
+ node.generator = isGenerator;
+ allowExpressionBody = true;
+ } else {
+ allowExpressionBody = false;
+ }
+ parseFunctionBody(node, allowExpressionBody);
+ return finishNode(node, "FunctionExpression");
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Parse arrow function expression with given parameters.
+
+
+
+
+ function parseArrowExpression(node, params) {
+ initFunction(node);
+
+ var defaults = node.defaults, hasDefaults = false;
+
+ for (var i = 0, lastI = params.length - 1; i <= lastI; i++) {
+ var param = params[i];
+
+ if (param.type === "AssignmentExpression" && param.operator === "=") {
+ hasDefaults = true;
+ params[i] = param.left;
+ defaults.push(param.right);
+ } else {
+ toAssignable(param, i === lastI, true);
+ defaults.push(null);
+ if (param.type === "SpreadElement") {
+ params.length--;
+ node.rest = param.argument;
+ break;
+ }
+ }
+ }
+
+ node.params = params;
+ if (!hasDefaults) node.defaults = [];
+
+ parseFunctionBody(node, true);
+ return finishNode(node, "ArrowFunctionExpression");
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Parse function parameters.
+
+
+
+
+ function parseFunctionParams(node) {
+ var defaults = [], hasDefaults = false;
+
expect(_parenL);
for (;;) {
if (eat(_parenR)) {
break;
} else if (options.ecmaVersion >= 6 && eat(_ellipsis)) {
- node.rest = parseIdent();
+ node.rest = toAssignable(parseExprAtom(), false, true);
+ checkSpreadAssign(node.rest);
expect(_parenR);
break;
} else {
- node.params.push(parseIdent());
+ node.params.push(options.ecmaVersion >= 6 ? toAssignable(parseExprAtom(), false, true) : parseIdent());
+ if (options.ecmaVersion >= 6 && tokType === _eq) {
+ next();
+ hasDefaults = true;
+ defaults.push(parseExpression(true));
+ }
if (!eat(_comma)) {
expect(_parenR);
break;
}
}
- }
+ }
+
+ if (hasDefaults) node.defaults = defaults;
+ }
-
+
+
+
+ function parseFunctionBody(node, allowExpression) {
+ var isExpression = allowExpression && tokType !== _braceL;
+
+ if (isExpression) {
+ node.body = parseExpression(true);
+ node.expression = true;
+ } else {
+
+
+
+
+
+
+
+
+ ¶
Start a new scope with regard to labels and the inFunction
flag (restore them to their old value afterwards).
- var oldInFunc = inFunction, oldLabels = labels;
- inFunction = true; labels = [];
+ var oldInFunc = inFunction, oldInGen = inGenerator, oldLabels = labels;
+ inFunction = true; inGenerator = node.generator; labels = [];
node.body = parseBlock(true);
- inFunction = oldInFunc; labels = oldLabels;
+ node.expression = false;
+ inFunction = oldInFunc; inGenerator = oldInGen; labels = oldLabels;
+ }
-
+
If this is a strict mode function, verify that argument names
are not repeated, and it does not try to bind the words eval
@@ -3669,49 +4405,73 @@ or arguments.
- if (strict || node.body.body.length && isUseStrict(node.body.body[0])) {
-
-
-
-
-
-
-
-
- ¶
-
- Negative indices are used to reuse loop body for node.rest and node.id
-
-
-
- for (var i = -2, id; i < node.params.length; ++i) {
- if (i >= 0) {
- id = node.params[i];
- } else if (i == -2) {
- if (node.rest) id = node.rest;
- else continue;
- } else {
- if (node.id) id = node.id;
- else continue;
- }
- if (isStrictReservedWord(id.name) || isStrictBadIdWord(id.name))
- raise(id.start, "Defining '" + id.name + "' in strict mode");
- if (i >= 0) for (var j = 0; j < i; ++j) if (id.name === node.params[j].name)
- raise(id.start, "Argument name clash in strict mode");
- }
+ if (strict || !isExpression && node.body.body.length && isUseStrict(node.body.body[0])) {
+ var nameHash = hash();
+ if (node.id)
+ checkFunctionParam(node.id, nameHash);
+ for (var i = 0; i < node.params.length; i++)
+ checkFunctionParam(node.params[i], nameHash);
+ if (node.rest)
+ checkFunctionParam(node.rest, nameHash);
}
-
- return finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
}
-
+
+
+
+ function parseClass(node, isStatement) {
+ next();
+ node.id = tokType === _name ? parseIdent() : isStatement ? unexpected() : null;
+ node.superClass = eat(_extends) ? parseExpression() : null;
+ var classBody = startNode(), methodHash = hash(), staticMethodHash = hash();
+ classBody.body = [];
+ expect(_braceL);
+ while (!eat(_braceR)) {
+ var method = startNode();
+ if (tokType === _name && tokVal === "static") {
+ next();
+ method.static = true;
+ } else {
+ method.static = false;
+ }
+ var isGenerator = eat(_star);
+ method.key = parseIdent(true);
+ if ((method.key.name === "get" || method.key.name === "set") && tokType === _name) {
+ if (isGenerator) unexpected();
+ method.kind = method.key.name;
+ method.key = parseIdent(true);
+ } else {
+ method.kind = "";
+ }
+ method.value = parseMethod(isGenerator);
+ checkPropClash(method, method.static ? staticMethodHash : methodHash);
+ classBody.body.push(finishNode(method, "MethodDefinition"));
+ eat(_semi);
+ }
+ node.body = finishNode(classBody, "ClassBody");
+ return finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
+ }
+
+
+
+
+
+
+
+
+ ¶
Parses a comma-separated list of expressions, and returns them as
an array. close is the token type that ends the list, and
@@ -3739,11 +4499,11 @@ for array literals).
-
+
Parse the next token as an identifier. If liberal is true (used
when parsing properties), it will also convert keywords into
@@ -3776,11 +4536,320 @@ identifiers.
-
+
+
+
+ function parseExport(node) {
+ next();
+
+
+
+
+
+
+
+
+ ¶
+
+ export var|const|let|function|class …;
+
+
+
+ if (tokType === _var || tokType === _const || tokType === _let || tokType === _function || tokType === _class) {
+ node.declaration = parseStatement();
+ node.default = false;
+ node.specifiers = null;
+ node.source = null;
+ } else
+
+
+
+
+
+
+
+
+ ¶
+
+ export default …;
+
+
+
+ if (eat(_default)) {
+ node.declaration = parseExpression(true);
+ node.default = true;
+ node.specifiers = null;
+ node.source = null;
+ semicolon();
+ } else {
+
+
+
+
+
+
+
+
+ ¶
+
+ export * from ‘…’
+export { x, y as z } [from ‘…’]
+
+
+
+ var isBatch = tokType === _star;
+ node.declaration = null;
+ node.default = false;
+ node.specifiers = parseExportSpecifiers();
+ if (tokType === _name && tokVal === "from") {
+ next();
+ node.source = tokType === _string ? parseExprAtom() : unexpected();
+ } else {
+ if (isBatch) unexpected();
+ node.source = null;
+ }
+ }
+ return finishNode(node, "ExportDeclaration");
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Parses a comma-separated list of module exports.
+
+
+
+
+ function parseExportSpecifiers() {
+ var nodes = [], first = true;
+ if (tokType === _star) {
+
+
+
+
+
+
+
+
+ ¶
+
+ export * from ‘…’
+
+
+
+ var node = startNode();
+ next();
+ nodes.push(finishNode(node, "ExportBatchSpecifier"));
+ } else {
+
+
+
+
+
+
+
+
+ ¶
+
+ export { x, y as z } [from ‘…’]
+
+
+
+ expect(_braceL);
+ while (!eat(_braceR)) {
+ if (!first) {
+ expect(_comma);
+ if (options.allowTrailingCommas && eat(_braceR)) break;
+ } else first = false;
+
+ var node = startNode();
+ node.id = parseIdent();
+ if (tokType === _name && tokVal === "as") {
+ next();
+ node.name = parseIdent(true);
+ } else {
+ node.name = null;
+ }
+ nodes.push(finishNode(node, "ExportSpecifier"));
+ }
+ }
+ return nodes;
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Parses import declaration.
+
+
+
+
+ function parseImport(node) {
+ next();
+
+
+
+
+
+
+
+
+ ¶
+
+ import ‘…’;
+
+
+
+ if (tokType === _string) {
+ node.specifiers = [];
+ node.source = parseExprAtom();
+ node.kind = "";
+ } else {
+ node.specifiers = parseImportSpecifiers();
+ if (tokType !== _name || tokVal !== "from") unexpected();
+ next();
+ node.source = tokType === _string ? parseExprAtom() : unexpected();
+
+
+
+
+
+
+
+
+ ¶
+
+ only for backward compatibility with Esprima’s AST
+(it doesn’t support mixed default + named yet)
+
+
+
+ node.kind = node.specifiers[0].default ? "default" : "named";
+ }
+ return finishNode(node, "ImportDeclaration");
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Parses a comma-separated list of module imports.
+
+
+
+
+ function parseImportSpecifiers() {
+ var nodes = [], first = true;
+ if (tokType === _star) {
+ var node = startNode();
+ next();
+ if (tokType !== _name || tokVal !== "as") unexpected();
+ next();
+ node.name = parseIdent();
+ checkLVal(node.name, true);
+ nodes.push(finishNode(node, "ImportBatchSpecifier"));
+ return nodes;
+ }
+ if (tokType === _name) {
+
+
+
+
+
+
+
+
+ ¶
+
+ import defaultObj, { x, y as z } from ‘…’
+
+
+
+ var node = startNode();
+ node.id = parseIdent();
+ checkLVal(node.id, true);
+ node.name = null;
+ node.default = true;
+ nodes.push(finishNode(node, "ImportSpecifier"));
+ if (!eat(_comma)) return nodes;
+ }
+ expect(_braceL);
+ while (!eat(_braceR)) {
+ if (!first) {
+ expect(_comma);
+ if (options.allowTrailingCommas && eat(_braceR)) break;
+ } else first = false;
+
+ var node = startNode();
+ node.id = parseIdent(true);
+ if (tokType === _name && tokVal === "as") {
+ next();
+ node.name = parseIdent();
+ } else {
+ node.name = null;
+ }
+ checkLVal(node.name || node.id, true);
+ node.default = false;
+ nodes.push(finishNode(node, "ImportSpecifier"));
+ }
+ return nodes;
+ }
+
+
+
+
+
+
+
+
+ ¶
+
+ Parses yield expression inside generator.
+
+
+
+
+ function parseYield() {
+ var node = startNode();
+ next();
+ node.delegate = eat(_star);
+ node.argument = parseExpression(true);
+ return finishNode(node, "YieldExpression");
+ }
+
+
+
+
+
+
+
+
+ ¶
Transforms JSX element name to string.
@@ -3805,11 +4874,11 @@ identifiers.
-
+
Parse next token as JSX identifier
@@ -3833,11 +4902,11 @@ identifiers.
-
+
Parse namespaced identifier.
@@ -3857,11 +4926,11 @@ identifiers.
-
+
Parse JSX object.
@@ -3884,11 +4953,11 @@ identifiers.
-
+
Parses element name in any form - namespaced, object
or single identifier.
@@ -3912,11 +4981,11 @@ or single identifier.
-
+
Parses attribute name as optionally namespaced identifier.
@@ -3934,11 +5003,11 @@ or single identifier.
-
+
Parses any type of JSX attribute value.
@@ -3946,34 +5015,37 @@ or single identifier.
function parseXJSAttributeValue() {
- var node;
- if (tokType === _braceL) {
- node = parseXJSExpressionContainer();
- if (node.expression.type === "XJSEmptyExpression") {
- raise(
- node.start,
- 'XJS attributes must only be assigned a non-empty ' +
- 'expression'
- );
- }
- } else if (tokVal === '<') {
- node = parseXJSElement();
- } else if (tokType === _xjsText) {
- node = parseExprAtom();
- } else {
- raise(tokStart, "XJS value should be either an expression or a quoted XJS text");
+ switch (tokType) {
+ case _braceL:
+ var node = parseXJSExpressionContainer();
+ if (node.expression.type === "XJSEmptyExpression") {
+ raise(
+ node.start,
+ 'XJS attributes must only be assigned a non-empty ' +
+ 'expression'
+ );
+ }
+ return node;
+
+ case _lt:
+ return parseXJSElement();
+
+ case _xjsText:
+ return parseExprAtom();
+
+ default:
+ raise(tokStart, "XJS value should be either an expression or a quoted XJS text");
}
- return node;
}
-
+
XJSEmptyExpression is unique type since it doesn’t actually parse anything,
and so it should start at the end of last read token (left brace) and finish
@@ -4003,11 +5075,11 @@ at the beginning of the next one (right brace).
-
+
Parses JSX expression enclosed into curly brackets.
@@ -4020,25 +5092,23 @@ at the beginning of the next one (right brace).
var origInXJSTag = inXJSTag;
inXJSTag = false;
- expect(_braceL);
-
+ next();
node.expression = tokType === _braceR ? parseXJSEmptyExpression() : parseExpression();
inXJSTag = origInXJSTag;
-
+
expect(_braceR);
-
return finishNode(node, "XJSExpressionContainer");
}
-
+
Parses following JSX attribute name-value pair.
@@ -4046,26 +5116,54 @@ at the beginning of the next one (right brace).
function parseXJSAttribute() {
- var node = startNode();
+ if (tokType === _braceL) {
+ var tokStart1 = tokStart, tokStartLoc1 = tokStartLoc;
+ var origInXJSTag = inXJSTag;
+ inXJSTag = false;
+
+ next();
+ var node = parseSpread();
+
+ inXJSTag = origInXJSTag;
+
+ expect(_braceR);
+ node.type = "XJSSpreadAttribute";
+
+ node.start = tokStart1;
+ node.end = lastEnd;
+ if (options.locations) {
+ node.loc.start = tokStartLoc1;
+ node.loc.end = lastEndLoc;
+ }
+ if (options.ranges) {
+ node.range = [tokStart1, lastEnd];
+ }
+
+ return node;
+ }
+
+ var node = startNode();
node.name = parseXJSAttributeName();
-
+
- if (tokVal === "=") {
+ if (tokType === _eq) {
next();
node.value = parseXJSAttributeValue();
+ } else {
+ node.value = null;
}
return finishNode(node, "XJSAttribute");
@@ -4074,11 +5172,11 @@ at the beginning of the next one (right brace).
-
+
Parses any type of JSX contents (expression, text or another tag).
@@ -4101,11 +5199,11 @@ at the beginning of the next one (right brace).
-
+
Parses JSX open tag.
@@ -4120,11 +5218,11 @@ at the beginning of the next one (right brace).
inXJSChild = false;
inXJSTag = true;
- expectChar('<');
+ next();
node.name = parseXJSElementName();
- while (tokType !== _eof && tokType !== _slash && tokVal !== '>') {
+ while (tokType !== _eof && tokType !== _slash && tokType !== _gt) {
attributes.push(parseXJSAttribute());
}
@@ -4137,7 +5235,7 @@ at the beginning of the next one (right brace).
inXJSChild = true;
}
- expectChar('>');
+ expect(_gt);
return finishNode(node, "XJSOpeningElement");
}
@@ -4145,11 +5243,11 @@ at the beginning of the next one (right brace).
-
+
-
+
A valid token is expected after >, so parser needs to know
whether to look for a standard JS token or an XJS text node
@@ -4185,18 +5282,18 @@ whether to look for a standard JS token or an XJS text node
inXJSChild = origInXJSChild;
inXJSTag = origInXJSTag;
tokRegexpAllowed = false;
- expectChar('>');
+ expect(_gt);
return finishNode(node, "XJSClosingElement");
}
-
+
Parses entire JSX element, including it’s opening tag,
attributes, contents and closing tag.
@@ -4210,14 +5307,15 @@ attributes, contents and closing tag.
var origInXJSChild = inXJSChild;
var openingElement = parseXJSOpeningElement();
+ var closingElement = null;
if (!openingElement.selfClosing) {
- while (tokType !== _eof && !(tokVal === '<' && nextChar() === '/')) {
+ while (tokType !== _eof && tokType !== _ltSlash) {
inXJSChild = true;
children.push(parseXJSChild());
}
inXJSChild = origInXJSChild;
- var closingElement = parseXJSClosingElement();
+ closingElement = parseXJSClosingElement();
if (getQualifiedXJSName(closingElement.name) !== getQualifiedXJSName(openingElement.name)) {
raise(
closingElement.start,
@@ -4229,11 +5327,11 @@ attributes, contents and closing tag.
-
+
When (erroneously) writing two adjacent tags like
var x = <div>one</div><div>two</div>;
@@ -4245,7 +5343,7 @@ was intended, the left tag can be wrapped in parentheses.)
- if (!origInXJSChild && tokVal === '<') {
+ if (!origInXJSChild && tokType === _lt) {
raise(tokStart, "Adjacent XJS elements must be wrapped in an enclosing tag");
}
diff --git a/package.json b/package.json
index 4d238cf157..2261fd0c60 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "acorn-jsx",
"description": "Alternative React JSX parser",
"main": "acorn.js",
- "version": "0.7.1",
+ "version": "0.7.1-1",
"maintainers": [
{
"name": "Marijn Haverbeke",
diff --git a/test/run.js b/test/run.js
index 2d44344745..e1a2753f9e 100644
--- a/test/run.js
+++ b/test/run.js
@@ -1,6 +1,7 @@
var driver = require("./driver.js");
require("./tests.js");
require("./tests-harmony.js");
+require("./tests-jsx.js");
var testsRun = 0, failed = 0;
function report(state, code, message) {
diff --git a/test/tests-jsx.js b/test/tests-jsx.js
index bd2b7d307f..940b855df8 100644
--- a/test/tests-jsx.js
+++ b/test/tests-jsx.js
@@ -1,486 +1,505 @@
// React JSX tests
-if (typeof exports !== "undefined") {
- var test = require("./driver.js").test;
-}
-
-// Simply taken from esprima-fb/fbtest.js
var fbTestFixture = {
- '': {
- type: "ExpressionStatement",
- expression: {
- type: "XJSElement",
- openingElement: {
- type: "XJSOpeningElement",
- name: {
- type: "XJSIdentifier",
- name: "a",
- range: [1, 2],
- loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 2 }
- }
- },
- selfClosing: true,
- attributes: [],
- range: [0, 5],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 5 }
- }
- },
- children: [],
- range: [0, 5],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 5 }
- }
- },
- range: [0, 5],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 5 }
- }
- },
- ' ': {
- type: 'ExpressionStatement',
- expression: {
- type: 'XJSElement',
- openingElement: {
- type: 'XJSOpeningElement',
- name: {
- type: 'XJSNamespacedName',
- namespace: {
- type: 'XJSIdentifier',
- name: 'n',
+ // Taken and adapted from esprima-fb/fbtest.js.
+ 'XJS': {
+ '': {
+ type: "ExpressionStatement",
+ expression: {
+ type: "XJSElement",
+ openingElement: {
+ type: "XJSOpeningElement",
+ name: {
+ type: "XJSIdentifier",
+ name: "a",
range: [1, 2],
loc: {
start: { line: 1, column: 1 },
end: { line: 1, column: 2 }
}
},
- name: {
- type: 'XJSIdentifier',
- name: 'a',
- range: [3, 4],
- loc: {
- start: { line: 1, column: 3 },
- end: { line: 1, column: 4 }
- }
- },
- range: [1, 4],
+ selfClosing: true,
+ attributes: [],
+ range: [0, 5],
loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 4 }
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 5 }
}
},
- selfClosing: true,
- attributes: [{
- type: 'XJSAttribute',
+ closingElement: null,
+ children: [],
+ range: [0, 5],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 5 }
+ }
+ },
+ range: [0, 5],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 5 }
+ }
+ },
+ ' ': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
name: {
type: 'XJSNamespacedName',
namespace: {
type: 'XJSIdentifier',
name: 'n',
- range: [5, 6],
+ range: [1, 2],
loc: {
- start: { line: 1, column: 5 },
- end: { line: 1, column: 6 }
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 2 }
}
},
name: {
type: 'XJSIdentifier',
- name: 'v',
- range: [7, 8],
- loc: {
- start: { line: 1, column: 7 },
- end: { line: 1, column: 8 }
- }
- },
- range: [5, 8],
- loc: {
- start: { line: 1, column: 5 },
- end: { line: 1, column: 8 }
- }
- },
- range: [5, 8],
- loc: {
- start: { line: 1, column: 5 },
- end: { line: 1, column: 8 }
- }
- }],
- range: [0, 11],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 11 }
- }
- },
- children: [],
- range: [0, 11],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 11 }
- }
- },
- range: [0, 11],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 11 }
- }
- },
- ' {value} ': {
- type: 'ExpressionStatement',
- expression: {
- type: 'XJSElement',
- openingElement: {
- type: 'XJSOpeningElement',
- name: {
- type: 'XJSIdentifier',
- name: 'a',
- range: [1, 2],
- loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 2 }
- }
- },
- selfClosing: false,
- attributes: [{
- type: 'XJSAttribute',
- name: {
- type: 'XJSNamespacedName',
- namespace: {
- type: 'XJSIdentifier',
- name: 'n',
+ name: 'a',
range: [3, 4],
loc: {
start: { line: 1, column: 3 },
end: { line: 1, column: 4 }
}
},
+ range: [1, 4],
+ loc: {
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 4 }
+ }
+ },
+ selfClosing: true,
+ attributes: [{
+ type: 'XJSAttribute',
name: {
- type: 'XJSIdentifier',
- name: 'foo',
+ type: 'XJSNamespacedName',
+ namespace: {
+ type: 'XJSIdentifier',
+ name: 'n',
+ range: [5, 6],
+ loc: {
+ start: { line: 1, column: 5 },
+ end: { line: 1, column: 6 }
+ }
+ },
+ name: {
+ type: 'XJSIdentifier',
+ name: 'v',
+ range: [7, 8],
+ loc: {
+ start: { line: 1, column: 7 },
+ end: { line: 1, column: 8 }
+ }
+ },
range: [5, 8],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 8 }
}
},
- range: [3, 8],
+ value: null,
+ range: [5, 8],
loc: {
- start: { line: 1, column: 3 },
+ start: { line: 1, column: 5 },
end: { line: 1, column: 8 }
}
- },
- value: {
- type: 'Literal',
- value: 'bar',
- raw: '"bar"',
- range: [9, 14],
- loc: {
- start: { line: 1, column: 9 },
- end: { line: 1, column: 14 }
- }
- },
- range: [3, 14],
+ }],
+ range: [0, 11],
loc: {
- start: { line: 1, column: 3 },
- end: { line: 1, column: 14 }
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 11 }
}
- }],
- range: [0, 15],
+ },
+ closingElement: null,
+ children: [],
+ range: [0, 11],
loc: {
start: { line: 1, column: 0 },
- end: { line: 1, column: 15 }
+ end: { line: 1, column: 11 }
}
},
- closingElement: {
- type: 'XJSClosingElement',
- name: {
- type: 'XJSIdentifier',
- name: 'a',
- range: [38, 39],
- loc: {
- start: { line: 1, column: 38 },
- end: { line: 1, column: 39 }
- }
- },
- range: [36, 40],
- loc: {
- start: { line: 1, column: 36 },
- end: { line: 1, column: 40 }
- }
- },
- children: [{
- type: 'Literal',
- value: ' ',
- raw: ' ',
- range: [15, 16],
- loc: {
- start: { line: 1, column: 15 },
- end: { line: 1, column: 16 }
- }
- }, {
- type: 'XJSExpressionContainer',
- expression: {
- type: 'Identifier',
- name: 'value',
- range: [17, 22],
- loc: {
- start: { line: 1, column: 17 },
- end: { line: 1, column: 22 }
- }
- },
- range: [16, 23],
- loc: {
- start: { line: 1, column: 16 },
- end: { line: 1, column: 23 }
- }
- }, {
- type: 'Literal',
- value: ' ',
- raw: ' ',
- range: [23, 24],
- loc: {
- start: { line: 1, column: 23 },
- end: { line: 1, column: 24 }
- }
- }, {
+ range: [0, 11],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 11 }
+ }
+ },
+ ' {value} ': {
+ type: 'ExpressionStatement',
+ expression: {
type: 'XJSElement',
openingElement: {
type: 'XJSOpeningElement',
name: {
type: 'XJSIdentifier',
- name: 'b',
- range: [25, 26],
+ name: 'a',
+ range: [1, 2],
loc: {
- start: { line: 1, column: 25 },
- end: { line: 1, column: 26 }
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 2 }
}
},
selfClosing: false,
- attributes: [],
- range: [24, 27],
+ attributes: [{
+ type: 'XJSAttribute',
+ name: {
+ type: 'XJSNamespacedName',
+ namespace: {
+ type: 'XJSIdentifier',
+ name: 'n',
+ range: [3, 4],
+ loc: {
+ start: { line: 1, column: 3 },
+ end: { line: 1, column: 4 }
+ }
+ },
+ name: {
+ type: 'XJSIdentifier',
+ name: 'foo',
+ range: [5, 8],
+ loc: {
+ start: { line: 1, column: 5 },
+ end: { line: 1, column: 8 }
+ }
+ },
+ range: [3, 8],
+ loc: {
+ start: { line: 1, column: 3 },
+ end: { line: 1, column: 8 }
+ }
+ },
+ value: {
+ type: 'Literal',
+ value: 'bar',
+ raw: '"bar"',
+ range: [9, 14],
+ loc: {
+ start: { line: 1, column: 9 },
+ end: { line: 1, column: 14 }
+ }
+ },
+ range: [3, 14],
+ loc: {
+ start: { line: 1, column: 3 },
+ end: { line: 1, column: 14 }
+ }
+ }],
+ range: [0, 15],
loc: {
- start: { line: 1, column: 24 },
- end: { line: 1, column: 27 }
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 15 }
}
},
closingElement: {
type: 'XJSClosingElement',
name: {
type: 'XJSIdentifier',
- name: 'b',
- range: [34, 35],
+ name: 'a',
+ range: [38, 39],
loc: {
- start: { line: 1, column: 34 },
- end: { line: 1, column: 35 }
+ start: { line: 1, column: 38 },
+ end: { line: 1, column: 39 }
}
},
- range: [32, 36],
+ range: [36, 40],
loc: {
- start: { line: 1, column: 32 },
- end: { line: 1, column: 36 }
+ start: { line: 1, column: 36 },
+ end: { line: 1, column: 40 }
}
},
children: [{
+ type: 'Literal',
+ value: ' ',
+ raw: ' ',
+ range: [15, 16],
+ loc: {
+ start: { line: 1, column: 15 },
+ end: { line: 1, column: 16 }
+ }
+ }, {
+ type: 'XJSExpressionContainer',
+ expression: {
+ type: 'Identifier',
+ name: 'value',
+ range: [17, 22],
+ loc: {
+ start: { line: 1, column: 17 },
+ end: { line: 1, column: 22 }
+ }
+ },
+ range: [16, 23],
+ loc: {
+ start: { line: 1, column: 16 },
+ end: { line: 1, column: 23 }
+ }
+ }, {
+ type: 'Literal',
+ value: ' ',
+ raw: ' ',
+ range: [23, 24],
+ loc: {
+ start: { line: 1, column: 23 },
+ end: { line: 1, column: 24 }
+ }
+ }, {
type: 'XJSElement',
openingElement: {
type: 'XJSOpeningElement',
name: {
type: 'XJSIdentifier',
- name: 'c',
- range: [28, 29],
+ name: 'b',
+ range: [25, 26],
loc: {
- start: { line: 1, column: 28 },
- end: { line: 1, column: 29 }
+ start: { line: 1, column: 25 },
+ end: { line: 1, column: 26 }
}
},
- selfClosing: true,
+ selfClosing: false,
attributes: [],
+ range: [24, 27],
+ loc: {
+ start: { line: 1, column: 24 },
+ end: { line: 1, column: 27 }
+ }
+ },
+ closingElement: {
+ type: 'XJSClosingElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'b',
+ range: [34, 35],
+ loc: {
+ start: { line: 1, column: 34 },
+ end: { line: 1, column: 35 }
+ }
+ },
+ range: [32, 36],
+ loc: {
+ start: { line: 1, column: 32 },
+ end: { line: 1, column: 36 }
+ }
+ },
+ children: [{
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'c',
+ range: [28, 29],
+ loc: {
+ start: { line: 1, column: 28 },
+ end: { line: 1, column: 29 }
+ }
+ },
+ selfClosing: true,
+ attributes: [],
+ range: [27, 32],
+ loc: {
+ start: { line: 1, column: 27 },
+ end: { line: 1, column: 32 }
+ }
+ },
+ closingElement: null,
+ children: [],
range: [27, 32],
loc: {
start: { line: 1, column: 27 },
end: { line: 1, column: 32 }
}
- },
- children: [],
- range: [27, 32],
+ }],
+ range: [24, 36],
loc: {
- start: { line: 1, column: 27 },
- end: { line: 1, column: 32 }
+ start: { line: 1, column: 24 },
+ end: { line: 1, column: 36 }
}
}],
- range: [24, 36],
+ range: [0, 40],
loc: {
- start: { line: 1, column: 24 },
- end: { line: 1, column: 36 }
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 40 }
}
- }],
+ },
range: [0, 40],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 40 }
}
},
- range: [0, 40],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 40 }
- }
- },
- '': {
- type: "ExpressionStatement",
- expression: {
- type: "XJSElement",
- openingElement: {
- type: "XJSOpeningElement",
- name: {
- type: "XJSIdentifier",
- name: "a",
- range: [1, 2],
- loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 2 }
- }
- },
- selfClosing: true,
- attributes: [
- {
- type: "XJSAttribute",
- name: {
- type: "XJSIdentifier",
- name: "b",
- range: [3, 4],
- loc: {
- start: { line: 1, column: 3 },
- end: { line: 1, column: 4 }
- }
- },
- value: {
- type: "XJSExpressionContainer",
- expression: {
- type: "Literal",
- value: " ",
- raw: "\" \"",
- range: [6, 9],
+ '': {
+ type: "ExpressionStatement",
+ expression: {
+ type: "XJSElement",
+ openingElement: {
+ type: "XJSOpeningElement",
+ name: {
+ type: "XJSIdentifier",
+ name: "a",
+ range: [1, 2],
+ loc: {
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 2 }
+ }
+ },
+ selfClosing: true,
+ attributes: [
+ {
+ type: "XJSAttribute",
+ name: {
+ type: "XJSIdentifier",
+ name: "b",
+ range: [3, 4],
loc: {
- start: { line: 1, column: 6 },
- end: { line: 1, column: 9 }
+ start: { line: 1, column: 3 },
+ end: { line: 1, column: 4 }
}
},
- range: [5, 10],
+ value: {
+ type: "XJSExpressionContainer",
+ expression: {
+ type: "Literal",
+ value: " ",
+ raw: "\" \"",
+ range: [6, 9],
+ loc: {
+ start: { line: 1, column: 6 },
+ end: { line: 1, column: 9 }
+ }
+ },
+ range: [5, 10],
+ loc: {
+ start: { line: 1, column: 5 },
+ end: { line: 1, column: 10 }
+ }
+ },
+ range: [3, 10],
loc: {
- start: { line: 1, column: 5 },
+ start: { line: 1, column: 3 },
end: { line: 1, column: 10 }
}
},
- range: [3, 10],
- loc: {
- start: { line: 1, column: 3 },
- end: { line: 1, column: 10 }
- }
- },
- {
- type: "XJSAttribute",
- name: {
- type: "XJSIdentifier",
- name: "c",
- range: [11, 12],
+ {
+ type: "XJSAttribute",
+ name: {
+ type: "XJSIdentifier",
+ name: "c",
+ range: [11, 12],
+ loc: {
+ start: { line: 1, column: 11 },
+ end: { line: 1, column: 12 }
+ }
+ },
+ value: {
+ type: "Literal",
+ value: " ",
+ raw: "\" \"",
+ range: [13, 16],
+ loc: {
+ start: { line: 1, column: 13 },
+ end: { line: 1, column: 16 }
+ }
+ },
+ range: [11, 16],
loc: {
start: { line: 1, column: 11 },
- end: { line: 1, column: 12 }
- }
- },
- value: {
- type: "Literal",
- value: " ",
- raw: "\" \"",
- range: [13, 16],
- loc: {
- start: { line: 1, column: 13 },
end: { line: 1, column: 16 }
}
},
- range: [11, 16],
- loc: {
- start: { line: 1, column: 11 },
- end: { line: 1, column: 16 }
- }
- },
- {
- type: "XJSAttribute",
- name: {
- type: "XJSIdentifier",
- name: "d",
- range: [17, 18],
+ {
+ type: "XJSAttribute",
+ name: {
+ type: "XJSIdentifier",
+ name: "d",
+ range: [17, 18],
+ loc: {
+ start: { line: 1, column: 17 },
+ end: { line: 1, column: 18 }
+ }
+ },
+ value: {
+ type: "Literal",
+ value: "&",
+ raw: "\"&\"",
+ range: [19, 26],
+ loc: {
+ start: { line: 1, column: 19 },
+ end: { line: 1, column: 26 }
+ }
+ },
+ range: [17, 26],
loc: {
start: { line: 1, column: 17 },
- end: { line: 1, column: 18 }
- }
- },
- value: {
- type: "Literal",
- value: "&",
- raw: "\"&\"",
- range: [19, 26],
- loc: {
- start: { line: 1, column: 19 },
end: { line: 1, column: 26 }
}
- },
- range: [17, 26],
- loc: {
- start: { line: 1, column: 17 },
- end: { line: 1, column: 26 }
}
+ ],
+ range: [0, 29],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 29 }
}
- ],
+ },
+ closingElement: null,
+ children: [],
range: [0, 29],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 29 }
}
},
- children: [],
range: [0, 29],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 29 }
}
},
- range: [0, 29],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 29 }
- }
- },
- '': {
- type: "ExpressionStatement",
- expression: {
- type: "XJSElement",
- openingElement: {
- type: "XJSOpeningElement",
- name: {
- type: "XJSIdentifier",
- name: "a",
+ '': {
+ type: "ExpressionStatement",
+ expression: {
+ type: "XJSElement",
+ openingElement: {
+ type: "XJSOpeningElement",
+ name: {
+ type: "XJSIdentifier",
+ name: "a",
+ range: [
+ 1,
+ 2
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 1
+ },
+ end: {
+ line: 1,
+ column: 2
+ }
+ }
+ },
+ selfClosing: true,
+ attributes: [],
range: [
- 1,
- 2
+ 0,
+ 5
],
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
- line: 1,
+ line: 2,
column: 2
}
}
},
- selfClosing: true,
- attributes: [],
+ closingElement: null,
+ children: [],
range: [
0,
5
@@ -496,7 +515,6 @@ var fbTestFixture = {
}
}
},
- children: [],
range: [
0,
5
@@ -512,884 +530,67 @@ var fbTestFixture = {
}
}
},
- range: [
- 0,
- 5
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 2,
- column: 2
- }
- }
- },
- '<日本語>日本語>': {
- type: "ExpressionStatement",
- expression: {
- type: "XJSElement",
- openingElement: {
- type: "XJSOpeningElement",
- name: {
- type: "XJSIdentifier",
- name: "日本語",
- range: [
- 1,
- 4
- ],
- loc: {
- start: {
- line: 1,
- column: 1
- },
- end: {
- line: 1,
- column: 4
- }
- }
- },
- selfClosing: false,
- attributes: [],
- range: [
- 0,
- 5
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 1,
- column: 5
- }
- }
- },
- closingElement: {
- type: "XJSClosingElement",
- name: {
- type: "XJSIdentifier",
- name: "日本語",
- range: [
- 7,
- 10
- ],
- loc: {
- start: {
- line: 1,
- column: 7
- },
- end: {
- line: 1,
- column: 10
- }
- }
- },
- range: [
- 5,
- 11
- ],
- loc: {
- start: {
- line: 1,
- column: 5
- },
- end: {
- line: 1,
- column: 11
- }
- }
- },
- children: [],
- range: [
- 0,
- 11
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 1,
- column: 11
- }
- }
- },
- range: [
- 0,
- 11
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 1,
- column: 11
- }
- }
- },
-
- '\nbar\nbaz\r\n ': {
- type: "ExpressionStatement",
- expression: {
- type: "XJSElement",
- openingElement: {
- type: "XJSOpeningElement",
- name: {
- type: "XJSIdentifier",
- name: "AbC-def",
- range: [
- 1,
- 8
- ],
- loc: {
- start: {
- line: 1,
- column: 1
- },
- end: {
- line: 1,
- column: 8
- }
- }
- },
- selfClosing: false,
- attributes: [
- {
- type: "XJSAttribute",
- name: {
- type: "XJSIdentifier",
- name: "test",
- range: [
- 11,
- 15
- ],
- loc: {
- start: {
- line: 2,
- column: 2
- },
- end: {
- line: 2,
- column: 6
- }
- }
- },
- value: {
- type: "Literal",
- value: "&&",
- raw: "\"&&\"",
- range: [
- 16,
- 31
- ],
- loc: {
- start: {
- line: 2,
- column: 7
- },
- end: {
- line: 2,
- column: 22
- }
- }
- },
- range: [
- 11,
- 31
- ],
- loc: {
- start: {
- line: 2,
- column: 2
- },
- end: {
- line: 2,
- column: 22
- }
- }
- }
- ],
- range: [
- 0,
- 32
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 2,
- column: 23
- }
- }
- },
- closingElement: {
- type: "XJSClosingElement",
- name: {
- type: "XJSIdentifier",
- name: "AbC-def",
- range: [
- 44,
- 51
- ],
- loc: {
- start: {
- line: 5,
- column: 2
- },
- end: {
- line: 5,
- column: 9
- }
- }
- },
- range: [
- 42,
- 52
- ],
- loc: {
- start: {
- line: 5,
- column: 0
- },
- end: {
- line: 5,
- column: 10
- }
- }
- },
- children: [
- {
- type: "Literal",
- value: "\nbar\nbaz\r\n",
- raw: "\nbar\nbaz\r\n",
- range: [
- 32,
- 42
- ],
- loc: {
- start: {
- line: 2,
- column: 23
- },
- end: {
- line: 5,
- column: 0
- }
- }
- }
- ],
- range: [
- 0,
- 52
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 5,
- column: 10
- }
- }
- },
- range: [
- 0,
- 52
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 5,
- column: 10
- }
- }
- },
-
- ' : } />': {
- type: "ExpressionStatement",
- expression: {
- type: "XJSElement",
- openingElement: {
- type: "XJSOpeningElement",
- name: {
- type: "XJSIdentifier",
- name: "a",
- range: [
- 1,
- 2
- ],
- loc: {
- start: {
- line: 1,
- column: 1
- },
- end: {
- line: 1,
- column: 2
- }
- }
- },
- selfClosing: true,
- attributes: [
- {
- type: "XJSAttribute",
- name: {
- type: "XJSIdentifier",
- name: "b",
- range: [
- 3,
- 4
- ],
- loc: {
- start: {
- line: 1,
- column: 3
- },
- end: {
- line: 1,
- column: 4
- }
- }
- },
- value: {
- type: "XJSExpressionContainer",
- expression: {
- type: "ConditionalExpression",
- test: {
- type: "Identifier",
- name: "x",
- range: [
- 6,
- 7
- ],
- loc: {
- start: {
- line: 1,
- column: 6
- },
- end: {
- line: 1,
- column: 7
- }
- }
- },
- consequent: {
- type: "XJSElement",
- openingElement: {
- type: "XJSOpeningElement",
- name: {
- type: "XJSIdentifier",
- name: "c",
- range: [
- 11,
- 12
- ],
- loc: {
- start: {
- line: 1,
- column: 11
- },
- end: {
- line: 1,
- column: 12
- }
- }
- },
- selfClosing: true,
- attributes: [],
- range: [
- 10,
- 15
- ],
- loc: {
- start: {
- line: 1,
- column: 10
- },
- end: {
- line: 1,
- column: 15
- }
- }
- },
- children: [],
- range: [
- 10,
- 15
- ],
- loc: {
- start: {
- line: 1,
- column: 10
- },
- end: {
- line: 1,
- column: 15
- }
- }
- },
- alternate: {
- type: "XJSElement",
- openingElement: {
- type: "XJSOpeningElement",
- name: {
- type: "XJSIdentifier",
- name: "d",
- range: [
- 19,
- 20
- ],
- loc: {
- start: {
- line: 1,
- column: 19
- },
- end: {
- line: 1,
- column: 20
- }
- }
- },
- selfClosing: true,
- attributes: [],
- range: [
- 18,
- 23
- ],
- loc: {
- start: {
- line: 1,
- column: 18
- },
- end: {
- line: 1,
- column: 23
- }
- }
- },
- children: [],
- range: [
- 18,
- 23
- ],
- loc: {
- start: {
- line: 1,
- column: 18
- },
- end: {
- line: 1,
- column: 23
- }
- }
- },
- range: [
- 6,
- 23
- ],
- loc: {
- start: {
- line: 1,
- column: 6
- },
- end: {
- line: 1,
- column: 23
- }
- }
- },
- range: [
- 5,
- 24
- ],
- loc: {
- start: {
- line: 1,
- column: 5
- },
- end: {
- line: 1,
- column: 24
- }
- }
- },
- range: [
- 3,
- 24
- ],
- loc: {
- start: {
- line: 1,
- column: 3
- },
- end: {
- line: 1,
- column: 24
- }
- }
- }
- ],
- range: [
- 0,
- 27
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 1,
- column: 27
- }
- }
- },
- children: [],
- range: [
- 0,
- 27
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 1,
- column: 27
- }
- }
- },
- range: [
- 0,
- 27
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 1,
- column: 27
- }
- }
- },
-
- '{}': {
- type: 'ExpressionStatement',
- expression: {
- type: 'XJSElement',
- openingElement: {
- type: 'XJSOpeningElement',
- name: {
- type: 'XJSIdentifier',
- name: 'a',
- range: [1, 2],
- loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 2 }
- }
- },
- selfClosing: false,
- attributes: [],
- range: [0, 3],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 3 }
- }
- },
- closingElement: {
- type: 'XJSClosingElement',
- name: {
- type: 'XJSIdentifier',
- name: 'a',
- range: [7, 8],
- loc: {
- start: { line: 1, column: 7 },
- end: { line: 1, column: 8 }
- }
- },
- range: [5, 9],
- loc: {
- start: { line: 1, column: 5 },
- end: { line: 1, column: 9 }
- }
- },
- children: [{
- type: 'XJSExpressionContainer',
- expression: {
- type: 'XJSEmptyExpression',
- range: [4, 4],
- loc: {
- start: { line: 1, column: 4 },
- end: { line: 1, column: 4 }
- }
- },
- range: [3, 5],
- loc: {
- start: { line: 1, column: 3 },
- end: { line: 1, column: 5 }
- }
- }],
- range: [0, 9],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 9 }
- }
- },
- range: [0, 9],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 9 }
- }
- },
-
- '{/* this is a comment */}': {
- type: 'ExpressionStatement',
- expression: {
- type: 'XJSElement',
- openingElement: {
- type: 'XJSOpeningElement',
- name: {
- type: 'XJSIdentifier',
- name: 'a',
- range: [1, 2],
- loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 2 }
- }
- },
- selfClosing: false,
- attributes: [],
- range: [0, 3],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 3 }
- }
- },
- closingElement: {
- type: 'XJSClosingElement',
- name: {
- type: 'XJSIdentifier',
- name: 'a',
- range: [30, 31],
- loc: {
- start: { line: 1, column: 30 },
- end: { line: 1, column: 31 }
- }
- },
- range: [28, 32],
- loc: {
- start: { line: 1, column: 28 },
- end: { line: 1, column: 32 }
- }
- },
- children: [{
- type: 'XJSExpressionContainer',
- expression: {
- type: 'XJSEmptyExpression',
- range: [4, 27],
- loc: {
- start: { line: 1, column: 4 },
- end: { line: 1, column: 27 }
- }
- },
- range: [3, 28],
- loc: {
- start: { line: 1, column: 3 },
- end: { line: 1, column: 28 }
- }
- }],
- range: [0, 32],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 32 }
- }
- },
- range: [0, 32],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 32 }
- }
- },
-
- '@test content': {
- type: 'ExpressionStatement',
- expression: {
- type: 'XJSElement',
- openingElement: {
- type: 'XJSOpeningElement',
- name: {
- type: 'XJSIdentifier',
- name: 'div',
- range: [1, 4],
- loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 4 }
- }
- },
- selfClosing: false,
- attributes: [],
- range: [0, 5],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 5 }
- }
- },
- closingElement: {
- type: 'XJSClosingElement',
- name: {
- type: 'XJSIdentifier',
- name: 'div',
- range: [20, 23],
- loc: {
- start: { line: 1, column: 20 },
- end: { line: 1, column: 23 }
- }
- },
- range: [18, 24],
- loc: {
- start: { line: 1, column: 18 },
- end: { line: 1, column: 24 }
- }
- },
- children: [{
- type: 'Literal',
- value: '@test content',
- raw: '@test content',
- range: [5, 18],
- loc: {
- start: { line: 1, column: 5 },
- end: { line: 1, column: 18 }
- }
- }],
- range: [0, 24],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 24 }
- }
- },
- range: [0, 24],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 24 }
- }
- },
-
- '
7x invalid-js-identifier': {
- type: 'ExpressionStatement',
- expression: {
- type: 'XJSElement',
- openingElement: {
- type: 'XJSOpeningElement',
- name: {
- type: 'XJSIdentifier',
- name: 'div',
- range: [
- 1,
- 4
- ],
- loc: {
- start: {
- line: 1,
- column: 1
- },
- end: {
- line: 1,
- column: 4
- }
- }
- },
- selfClosing: false,
- attributes: [],
- range: [
- 0,
- 5
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 1,
- column: 5
- }
- }
- },
- closingElement: {
- type: 'XJSClosingElement',
- name: {
- type: 'XJSIdentifier',
- name: 'div',
- range: [
- 37,
- 40
- ],
- loc: {
- start: {
- line: 1,
- column: 37
- },
- end: {
- line: 1,
- column: 40
- }
- }
- },
- range: [
- 35,
- 41
- ],
- loc: {
- start: {
- line: 1,
- column: 35
- },
- end: {
- line: 1,
- column: 41
- }
- }
- },
- children: [{
- type: 'XJSElement',
+ '<日本語>日本語>': {
+ type: "ExpressionStatement",
+ expression: {
+ type: "XJSElement",
openingElement: {
- type: 'XJSOpeningElement',
+ type: "XJSOpeningElement",
name: {
- type: 'XJSIdentifier',
- name: 'br',
+ type: "XJSIdentifier",
+ name: "日本語",
range: [
- 6,
- 8
+ 1,
+ 4
],
loc: {
start: {
line: 1,
- column: 6
+ column: 1
},
end: {
line: 1,
- column: 8
+ column: 4
}
}
},
- selfClosing: true,
+ selfClosing: false,
attributes: [],
+ range: [
+ 0,
+ 5
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 5
+ }
+ }
+ },
+ closingElement: {
+ type: "XJSClosingElement",
+ name: {
+ type: "XJSIdentifier",
+ name: "日本語",
+ range: [
+ 7,
+ 10
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 7
+ },
+ end: {
+ line: 1,
+ column: 10
+ }
+ }
+ },
range: [
5,
11
@@ -1407,38 +608,859 @@ var fbTestFixture = {
},
children: [],
range: [
- 5,
+ 0,
11
],
loc: {
start: {
line: 1,
- column: 5
+ column: 0
},
end: {
line: 1,
column: 11
}
}
- }, {
- type: 'Literal',
- value: '7x invalid-js-identifier',
- raw: '7x invalid-js-identifier',
+ },
+ range: [
+ 0,
+ 11
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 11
+ }
+ }
+ },
+
+ '\nbar\nbaz\n ': {
+ type: "ExpressionStatement",
+ expression: {
+ type: "XJSElement",
+ openingElement: {
+ type: "XJSOpeningElement",
+ name: {
+ type: "XJSIdentifier",
+ name: "AbC-def",
+ range: [
+ 1,
+ 8
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 1
+ },
+ end: {
+ line: 1,
+ column: 8
+ }
+ }
+ },
+ selfClosing: false,
+ attributes: [
+ {
+ type: "XJSAttribute",
+ name: {
+ type: "XJSIdentifier",
+ name: "test",
+ range: [
+ 11,
+ 15
+ ],
+ loc: {
+ start: {
+ line: 2,
+ column: 2
+ },
+ end: {
+ line: 2,
+ column: 6
+ }
+ }
+ },
+ value: {
+ type: "Literal",
+ value: "&&",
+ raw: "\"&&\"",
+ range: [
+ 16,
+ 31
+ ],
+ loc: {
+ start: {
+ line: 2,
+ column: 7
+ },
+ end: {
+ line: 2,
+ column: 22
+ }
+ }
+ },
+ range: [
+ 11,
+ 31
+ ],
+ loc: {
+ start: {
+ line: 2,
+ column: 2
+ },
+ end: {
+ line: 2,
+ column: 22
+ }
+ }
+ }
+ ],
+ range: [
+ 0,
+ 32
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 2,
+ column: 23
+ }
+ }
+ },
+ closingElement: {
+ type: "XJSClosingElement",
+ name: {
+ type: "XJSIdentifier",
+ name: "AbC-def",
+ range: [
+ 43,
+ 50
+ ],
+ loc: {
+ start: {
+ line: 5,
+ column: 2
+ },
+ end: {
+ line: 5,
+ column: 9
+ }
+ }
+ },
+ range: [
+ 41,
+ 51
+ ],
+ loc: {
+ start: {
+ line: 5,
+ column: 0
+ },
+ end: {
+ line: 5,
+ column: 10
+ }
+ }
+ },
+ children: [
+ {
+ type: "Literal",
+ value: "\nbar\nbaz\n",
+ raw: "\nbar\nbaz\n",
+ range: [
+ 32,
+ 41
+ ],
+ loc: {
+ start: {
+ line: 2,
+ column: 23
+ },
+ end: {
+ line: 5,
+ column: 0
+ }
+ }
+ }
+ ],
range: [
- 11,
- 35
+ 0,
+ 51
],
loc: {
start: {
line: 1,
- column: 11
+ column: 0
+ },
+ end: {
+ line: 5,
+ column: 10
+ }
+ }
+ },
+ range: [
+ 0,
+ 51
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 5,
+ column: 10
+ }
+ }
+ },
+
+ ' : } />': {
+ type: "ExpressionStatement",
+ expression: {
+ type: "XJSElement",
+ openingElement: {
+ type: "XJSOpeningElement",
+ name: {
+ type: "XJSIdentifier",
+ name: "a",
+ range: [
+ 1,
+ 2
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 1
+ },
+ end: {
+ line: 1,
+ column: 2
+ }
+ }
+ },
+ selfClosing: true,
+ attributes: [
+ {
+ type: "XJSAttribute",
+ name: {
+ type: "XJSIdentifier",
+ name: "b",
+ range: [
+ 3,
+ 4
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 3
+ },
+ end: {
+ line: 1,
+ column: 4
+ }
+ }
+ },
+ value: {
+ type: "XJSExpressionContainer",
+ expression: {
+ type: "ConditionalExpression",
+ test: {
+ type: "Identifier",
+ name: "x",
+ range: [
+ 6,
+ 7
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 6
+ },
+ end: {
+ line: 1,
+ column: 7
+ }
+ }
+ },
+ consequent: {
+ type: "XJSElement",
+ openingElement: {
+ type: "XJSOpeningElement",
+ name: {
+ type: "XJSIdentifier",
+ name: "c",
+ range: [
+ 11,
+ 12
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 11
+ },
+ end: {
+ line: 1,
+ column: 12
+ }
+ }
+ },
+ selfClosing: true,
+ attributes: [],
+ range: [
+ 10,
+ 15
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 10
+ },
+ end: {
+ line: 1,
+ column: 15
+ }
+ }
+ },
+ closingElement: null,
+ children: [],
+ range: [
+ 10,
+ 15
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 10
+ },
+ end: {
+ line: 1,
+ column: 15
+ }
+ }
+ },
+ alternate: {
+ type: "XJSElement",
+ openingElement: {
+ type: "XJSOpeningElement",
+ name: {
+ type: "XJSIdentifier",
+ name: "d",
+ range: [
+ 19,
+ 20
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 19
+ },
+ end: {
+ line: 1,
+ column: 20
+ }
+ }
+ },
+ selfClosing: true,
+ attributes: [],
+ range: [
+ 18,
+ 23
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 18
+ },
+ end: {
+ line: 1,
+ column: 23
+ }
+ }
+ },
+ closingElement: null,
+ children: [],
+ range: [
+ 18,
+ 23
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 18
+ },
+ end: {
+ line: 1,
+ column: 23
+ }
+ }
+ },
+ range: [
+ 6,
+ 23
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 6
+ },
+ end: {
+ line: 1,
+ column: 23
+ }
+ }
+ },
+ range: [
+ 5,
+ 24
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 5
+ },
+ end: {
+ line: 1,
+ column: 24
+ }
+ }
+ },
+ range: [
+ 3,
+ 24
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 3
+ },
+ end: {
+ line: 1,
+ column: 24
+ }
+ }
+ }
+ ],
+ range: [
+ 0,
+ 27
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 27
+ }
+ }
+ },
+ closingElement: null,
+ children: [],
+ range: [
+ 0,
+ 27
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 0
},
end: {
line: 1,
- column: 35
+ column: 27
}
}
- }],
+ },
+ range: [
+ 0,
+ 27
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 27
+ }
+ }
+ },
+
+ '{}': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'a',
+ range: [1, 2],
+ loc: {
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 2 }
+ }
+ },
+ selfClosing: false,
+ attributes: [],
+ range: [0, 3],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 3 }
+ }
+ },
+ closingElement: {
+ type: 'XJSClosingElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'a',
+ range: [7, 8],
+ loc: {
+ start: { line: 1, column: 7 },
+ end: { line: 1, column: 8 }
+ }
+ },
+ range: [5, 9],
+ loc: {
+ start: { line: 1, column: 5 },
+ end: { line: 1, column: 9 }
+ }
+ },
+ children: [{
+ type: 'XJSExpressionContainer',
+ expression: {
+ type: 'XJSEmptyExpression',
+ range: [4, 4],
+ loc: {
+ start: { line: 1, column: 4 },
+ end: { line: 1, column: 4 }
+ }
+ },
+ range: [3, 5],
+ loc: {
+ start: { line: 1, column: 3 },
+ end: { line: 1, column: 5 }
+ }
+ }],
+ range: [0, 9],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 9 }
+ }
+ },
+ range: [0, 9],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 9 }
+ }
+ },
+
+ '{/* this is a comment */}': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'a',
+ range: [1, 2],
+ loc: {
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 2 }
+ }
+ },
+ selfClosing: false,
+ attributes: [],
+ range: [0, 3],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 3 }
+ }
+ },
+ closingElement: {
+ type: 'XJSClosingElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'a',
+ range: [30, 31],
+ loc: {
+ start: { line: 1, column: 30 },
+ end: { line: 1, column: 31 }
+ }
+ },
+ range: [28, 32],
+ loc: {
+ start: { line: 1, column: 28 },
+ end: { line: 1, column: 32 }
+ }
+ },
+ children: [{
+ type: 'XJSExpressionContainer',
+ expression: {
+ type: 'XJSEmptyExpression',
+ range: [4, 27],
+ loc: {
+ start: { line: 1, column: 4 },
+ end: { line: 1, column: 27 }
+ }
+ },
+ range: [3, 28],
+ loc: {
+ start: { line: 1, column: 3 },
+ end: { line: 1, column: 28 }
+ }
+ }],
+ range: [0, 32],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 32 }
+ }
+ },
+ range: [0, 32],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 32 }
+ }
+ },
+
+ '@test content': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'div',
+ range: [1, 4],
+ loc: {
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 4 }
+ }
+ },
+ selfClosing: false,
+ attributes: [],
+ range: [0, 5],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 5 }
+ }
+ },
+ closingElement: {
+ type: 'XJSClosingElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'div',
+ range: [20, 23],
+ loc: {
+ start: { line: 1, column: 20 },
+ end: { line: 1, column: 23 }
+ }
+ },
+ range: [18, 24],
+ loc: {
+ start: { line: 1, column: 18 },
+ end: { line: 1, column: 24 }
+ }
+ },
+ children: [{
+ type: 'Literal',
+ value: '@test content',
+ raw: '@test content',
+ range: [5, 18],
+ loc: {
+ start: { line: 1, column: 5 },
+ end: { line: 1, column: 18 }
+ }
+ }],
+ range: [0, 24],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 24 }
+ }
+ },
+ range: [0, 24],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 24 }
+ }
+ },
+
+ '
7x invalid-js-identifier': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'div',
+ range: [
+ 1,
+ 4
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 1
+ },
+ end: {
+ line: 1,
+ column: 4
+ }
+ }
+ },
+ selfClosing: false,
+ attributes: [],
+ range: [
+ 0,
+ 5
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 5
+ }
+ }
+ },
+ closingElement: {
+ type: 'XJSClosingElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'div',
+ range: [
+ 37,
+ 40
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 37
+ },
+ end: {
+ line: 1,
+ column: 40
+ }
+ }
+ },
+ range: [
+ 35,
+ 41
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 35
+ },
+ end: {
+ line: 1,
+ column: 41
+ }
+ }
+ },
+ children: [{
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'br',
+ range: [
+ 6,
+ 8
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 6
+ },
+ end: {
+ line: 1,
+ column: 8
+ }
+ }
+ },
+ selfClosing: true,
+ attributes: [],
+ range: [
+ 5,
+ 11
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 5
+ },
+ end: {
+ line: 1,
+ column: 11
+ }
+ }
+ },
+ closingElement: null,
+ children: [],
+ range: [
+ 5,
+ 11
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 5
+ },
+ end: {
+ line: 1,
+ column: 11
+ }
+ }
+ }, {
+ type: 'Literal',
+ value: '7x invalid-js-identifier',
+ raw: '7x invalid-js-identifier',
+ range: [
+ 11,
+ 35
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 11
+ },
+ end: {
+ line: 1,
+ column: 35
+ }
+ }
+ }],
+ range: [
+ 0,
+ 41
+ ],
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 41
+ }
+ }
+ },
range: [
0,
41
@@ -1454,92 +1476,94 @@ var fbTestFixture = {
}
}
},
- range: [
- 0,
- 41
- ],
- loc: {
- start: {
- line: 1,
- column: 0
- },
- end: {
- line: 1,
- column: 41
- }
- }
- },
- ' right=monkeys /> gorillas />': {
- "type": "ExpressionStatement",
- "expression": {
- "type": "XJSElement",
- "openingElement": {
- "type": "XJSOpeningElement",
- "name": {
- "type": "XJSIdentifier",
- "name": "LeftRight",
- "range": [
- 1,
- 10
- ],
- "loc": {
- "start": {
- "line": 1,
- "column": 1
- },
- "end": {
- "line": 1,
- "column": 10
- }
- }
- },
- "selfClosing": true,
- "attributes": [
- {
- "type": "XJSAttribute",
- "name": {
- "type": "XJSIdentifier",
- "name": "left",
- "range": [
- 11,
- 15
- ],
- "loc": {
- "start": {
- "line": 1,
- "column": 11
- },
- "end": {
- "line": 1,
- "column": 15
- }
+ ' right=monkeys /> gorillas />': {
+ "type": "ExpressionStatement",
+ "expression": {
+ "type": "XJSElement",
+ "openingElement": {
+ "type": "XJSOpeningElement",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "LeftRight",
+ "range": [
+ 1,
+ 10
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 1
+ },
+ "end": {
+ "line": 1,
+ "column": 10
}
- },
- "value": {
- "type": "XJSElement",
- "openingElement": {
- "type": "XJSOpeningElement",
- "name": {
- "type": "XJSIdentifier",
- "name": "a",
+ }
+ },
+ "selfClosing": true,
+ "attributes": [
+ {
+ "type": "XJSAttribute",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "left",
+ "range": [
+ 11,
+ 15
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 11
+ },
+ "end": {
+ "line": 1,
+ "column": 15
+ }
+ }
+ },
+ "value": {
+ "type": "XJSElement",
+ "openingElement": {
+ "type": "XJSOpeningElement",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "a",
+ "range": [
+ 17,
+ 18
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 17
+ },
+ "end": {
+ "line": 1,
+ "column": 18
+ }
+ }
+ },
+ "selfClosing": true,
+ "attributes": [],
"range": [
- 17,
- 18
+ 16,
+ 21
],
"loc": {
"start": {
"line": 1,
- "column": 17
+ "column": 16
},
"end": {
"line": 1,
- "column": 18
+ "column": 21
}
}
},
- "selfClosing": true,
- "attributes": [],
+ closingElement: null,
+ "children": [],
"range": [
16,
21
@@ -1555,15 +1579,14 @@ var fbTestFixture = {
}
}
},
- "children": [],
"range": [
- 16,
+ 11,
21
],
"loc": {
"start": {
"line": 1,
- "column": 16
+ "column": 11
},
"end": {
"line": 1,
@@ -1571,167 +1594,169 @@ var fbTestFixture = {
}
}
},
- "range": [
- 11,
- 21
- ],
- "loc": {
- "start": {
- "line": 1,
- "column": 11
- },
- "end": {
- "line": 1,
- "column": 21
- }
- }
- },
- {
- "type": "XJSAttribute",
- "name": {
- "type": "XJSIdentifier",
- "name": "right",
- "range": [
- 22,
- 27
- ],
- "loc": {
- "start": {
- "line": 1,
- "column": 22
- },
- "end": {
- "line": 1,
- "column": 27
+ {
+ "type": "XJSAttribute",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "right",
+ "range": [
+ 22,
+ 27
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 22
+ },
+ "end": {
+ "line": 1,
+ "column": 27
+ }
}
- }
- },
- "value": {
- "type": "XJSElement",
- "openingElement": {
- "type": "XJSOpeningElement",
- "name": {
- "type": "XJSIdentifier",
- "name": "b",
+ },
+ "value": {
+ "type": "XJSElement",
+ "openingElement": {
+ "type": "XJSOpeningElement",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "b",
+ "range": [
+ 29,
+ 30
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 29
+ },
+ "end": {
+ "line": 1,
+ "column": 30
+ }
+ }
+ },
+ "selfClosing": false,
+ "attributes": [],
"range": [
- 29,
- 30
+ 28,
+ 31
],
"loc": {
"start": {
"line": 1,
- "column": 29
+ "column": 28
},
"end": {
"line": 1,
- "column": 30
+ "column": 31
}
}
},
- "selfClosing": false,
- "attributes": [],
+ "closingElement": {
+ "type": "XJSClosingElement",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "b",
+ "range": [
+ 52,
+ 53
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 52
+ },
+ "end": {
+ "line": 1,
+ "column": 53
+ }
+ }
+ },
+ "range": [
+ 50,
+ 54
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 50
+ },
+ "end": {
+ "line": 1,
+ "column": 54
+ }
+ }
+ },
+ "children": [
+ {
+ "type": "Literal",
+ "value": "monkeys /> gorillas",
+ "raw": "monkeys /> gorillas",
+ "range": [
+ 31,
+ 50
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 31
+ },
+ "end": {
+ "line": 1,
+ "column": 50
+ }
+ }
+ }
+ ],
"range": [
28,
- 31
+ 54
],
"loc": {
"start": {
"line": 1,
"column": 28
},
- "end": {
- "line": 1,
- "column": 31
- }
- }
- },
- "closingElement": {
- "type": "XJSClosingElement",
- "name": {
- "type": "XJSIdentifier",
- "name": "b",
- "range": [
- 52,
- 53
- ],
- "loc": {
- "start": {
- "line": 1,
- "column": 52
- },
- "end": {
- "line": 1,
- "column": 53
- }
- }
- },
- "range": [
- 50,
- 54
- ],
- "loc": {
- "start": {
- "line": 1,
- "column": 50
- },
"end": {
"line": 1,
"column": 54
}
}
},
- "children": [
- {
- "type": "Literal",
- "value": "monkeys /> gorillas",
- "raw": "monkeys /> gorillas",
- "range": [
- 31,
- 50
- ],
- "loc": {
- "start": {
- "line": 1,
- "column": 31
- },
- "end": {
- "line": 1,
- "column": 50
- }
- }
- }
- ],
"range": [
- 28,
+ 22,
54
],
"loc": {
"start": {
"line": 1,
- "column": 28
+ "column": 22
},
"end": {
"line": 1,
"column": 54
}
}
+ }
+ ],
+ "range": [
+ 0,
+ 57
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
},
- "range": [
- 22,
- 54
- ],
- "loc": {
- "start": {
- "line": 1,
- "column": 22
- },
- "end": {
- "line": 1,
- "column": 54
- }
+ "end": {
+ "line": 1,
+ "column": 57
}
}
- ],
+ },
+ closingElement: null,
+ "children": [],
"range": [
0,
57
@@ -1747,7 +1772,6 @@ var fbTestFixture = {
}
}
},
- "children": [],
"range": [
0,
57
@@ -1763,119 +1787,14 @@ var fbTestFixture = {
}
}
},
- "range": [
- 0,
- 57
- ],
- "loc": {
- "start": {
- "line": 1,
- "column": 0
- },
- "end": {
- "line": 1,
- "column": 57
- }
- }
- },
- ' ': {
- type: 'ExpressionStatement',
- expression: {
- type: 'XJSElement',
- openingElement: {
- type: 'XJSOpeningElement',
- name: {
- type: 'XJSMemberExpression',
- object: {
- type: 'XJSIdentifier',
- name: 'a',
- range: [1, 2],
- loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 2 }
- }
- },
- property: {
- type: 'XJSIdentifier',
- name: 'b',
- range: [3, 4],
- loc: {
- start: { line: 1, column: 3 },
- end: { line: 1, column: 4 }
- }
- },
- range: [1, 4],
- loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 4 }
- }
- },
- selfClosing: false,
- attributes: [],
- range: [0, 5],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 5 }
- }
- },
- closingElement: {
- type: 'XJSClosingElement',
- name: {
- type: 'XJSMemberExpression',
- object: {
- type: 'XJSIdentifier',
- name: 'a',
- range: [7, 8],
- loc: {
- start: { line: 1, column: 7 },
- end: { line: 1, column: 8 }
- }
- },
- property: {
- type: 'XJSIdentifier',
- name: 'b',
- range: [9, 10],
- loc: {
- start: { line: 1, column: 9 },
- end: { line: 1, column: 10 }
- }
- },
- range: [7, 10],
- loc: {
- start: { line: 1, column: 7 },
- end: { line: 1, column: 10 }
- }
- },
- range: [5, 11],
- loc: {
- start: { line: 1, column: 5 },
- end: { line: 1, column: 11 }
- }
- },
- children: [],
- range: [0, 11],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 11 }
- }
- },
- range: [0, 11],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 11 }
- }
- },
-
- ' ': {
- type: 'ExpressionStatement',
- expression: {
- type: 'XJSElement',
- openingElement: {
- type: 'XJSOpeningElement',
- name: {
- type: 'XJSMemberExpression',
- object: {
+ ' ': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
+ name: {
type: 'XJSMemberExpression',
object: {
type: 'XJSIdentifier',
@@ -1901,156 +1820,782 @@ var fbTestFixture = {
end: { line: 1, column: 4 }
}
},
- property: {
- type: 'XJSIdentifier',
- name: 'c',
- range: [5, 6],
- loc: {
- start: { line: 1, column: 5 },
- end: { line: 1, column: 6 }
- }
- },
- range: [1, 6],
+ selfClosing: false,
+ attributes: [],
+ range: [0, 5],
loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 6 }
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 5 }
}
},
- selfClosing: false,
- attributes: [],
- range: [0, 7],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 7 }
- }
- },
- closingElement: {
- type: 'XJSClosingElement',
- name: {
- type: 'XJSMemberExpression',
- object: {
+ closingElement: {
+ type: 'XJSClosingElement',
+ name: {
type: 'XJSMemberExpression',
object: {
type: 'XJSIdentifier',
name: 'a',
+ range: [7, 8],
+ loc: {
+ start: { line: 1, column: 7 },
+ end: { line: 1, column: 8 }
+ }
+ },
+ property: {
+ type: 'XJSIdentifier',
+ name: 'b',
range: [9, 10],
loc: {
start: { line: 1, column: 9 },
end: { line: 1, column: 10 }
}
},
+ range: [7, 10],
+ loc: {
+ start: { line: 1, column: 7 },
+ end: { line: 1, column: 10 }
+ }
+ },
+ range: [5, 11],
+ loc: {
+ start: { line: 1, column: 5 },
+ end: { line: 1, column: 11 }
+ }
+ },
+ children: [],
+ range: [0, 11],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 11 }
+ }
+ },
+ range: [0, 11],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 11 }
+ }
+ },
+
+ ' ': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
+ name: {
+ type: 'XJSMemberExpression',
+ object: {
+ type: 'XJSMemberExpression',
+ object: {
+ type: 'XJSIdentifier',
+ name: 'a',
+ range: [1, 2],
+ loc: {
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 2 }
+ }
+ },
+ property: {
+ type: 'XJSIdentifier',
+ name: 'b',
+ range: [3, 4],
+ loc: {
+ start: { line: 1, column: 3 },
+ end: { line: 1, column: 4 }
+ }
+ },
+ range: [1, 4],
+ loc: {
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 4 }
+ }
+ },
property: {
type: 'XJSIdentifier',
- name: 'b',
- range: [11, 12],
+ name: 'c',
+ range: [5, 6],
loc: {
- start: { line: 1, column: 11 },
+ start: { line: 1, column: 5 },
+ end: { line: 1, column: 6 }
+ }
+ },
+ range: [1, 6],
+ loc: {
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 6 }
+ }
+ },
+ selfClosing: false,
+ attributes: [],
+ range: [0, 7],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 7 }
+ }
+ },
+ closingElement: {
+ type: 'XJSClosingElement',
+ name: {
+ type: 'XJSMemberExpression',
+ object: {
+ type: 'XJSMemberExpression',
+ object: {
+ type: 'XJSIdentifier',
+ name: 'a',
+ range: [9, 10],
+ loc: {
+ start: { line: 1, column: 9 },
+ end: { line: 1, column: 10 }
+ }
+ },
+ property: {
+ type: 'XJSIdentifier',
+ name: 'b',
+ range: [11, 12],
+ loc: {
+ start: { line: 1, column: 11 },
+ end: { line: 1, column: 12 }
+ }
+ },
+ range: [9, 12],
+ loc: {
+ start: { line: 1, column: 9 },
end: { line: 1, column: 12 }
}
},
- range: [9, 12],
+ property: {
+ type: 'XJSIdentifier',
+ name: 'c',
+ range: [13, 14],
+ loc: {
+ start: { line: 1, column: 13 },
+ end: { line: 1, column: 14 }
+ }
+ },
+ range: [9, 14],
loc: {
start: { line: 1, column: 9 },
- end: { line: 1, column: 12 }
- }
- },
- property: {
- type: 'XJSIdentifier',
- name: 'c',
- range: [13, 14],
- loc: {
- start: { line: 1, column: 13 },
end: { line: 1, column: 14 }
}
},
- range: [9, 14],
+ range: [7, 15],
loc: {
- start: { line: 1, column: 9 },
- end: { line: 1, column: 14 }
+ start: { line: 1, column: 7 },
+ end: { line: 1, column: 15 }
}
},
- range: [7, 15],
+ children: [],
+ range: [0, 15],
loc: {
- start: { line: 1, column: 7 },
+ start: { line: 1, column: 0 },
end: { line: 1, column: 15 }
}
},
- children: [],
range: [0, 15],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 15 }
}
},
- range: [0, 15],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 15 }
- }
- },
- // In order to more useful parse errors, we disallow following an
- // XJSElement by a less-than symbol. In the rare case that the binary
- // operator was intended, the tag can be wrapped in parentheses:
- '() < x;': {
- type: 'ExpressionStatement',
- expression: {
- type: 'BinaryExpression',
- operator: '<',
- left: {
- type: 'XJSElement',
- openingElement: {
- type: 'XJSOpeningElement',
- name: {
- type: 'XJSIdentifier',
- name: 'div',
- range: [2, 5],
+ // In order to more useful parse errors, we disallow following an
+ // XJSElement by a less-than symbol. In the rare case that the binary
+ // operator was intended, the tag can be wrapped in parentheses:
+ '() < x;': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'BinaryExpression',
+ operator: '<',
+ left: {
+ type: 'XJSElement',
+ openingElement: {
+ type: 'XJSOpeningElement',
+ name: {
+ type: 'XJSIdentifier',
+ name: 'div',
+ range: [2, 5],
+ loc: {
+ start: { line: 1, column: 2 },
+ end: { line: 1, column: 5 }
+ }
+ },
+ selfClosing: true,
+ attributes: [],
+ range: [1, 8],
loc: {
- start: { line: 1, column: 2 },
- end: { line: 1, column: 5 }
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 8 }
}
},
- selfClosing: true,
- attributes: [],
- range: [1, 8],
+ closingElement: null,
+ children: [],
+ range: [0, 9],
loc: {
- start: { line: 1, column: 1 },
- end: { line: 1, column: 8 }
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 9 }
}
},
- children: [],
- range: [0, 9],
+ right: {
+ type: 'Identifier',
+ name: 'x',
+ range: [12, 13],
+ loc: {
+ start: { line: 1, column: 12 },
+ end: { line: 1, column: 13 }
+ }
+ },
+ range: [0, 13],
loc: {
start: { line: 1, column: 0 },
- end: { line: 1, column: 9 }
- }
- },
- right: {
- type: 'Identifier',
- name: 'x',
- range: [12, 13],
- loc: {
- start: { line: 1, column: 12 },
end: { line: 1, column: 13 }
}
},
- range: [0, 13],
+ range: [0, 14],
loc: {
start: { line: 1, column: 0 },
- end: { line: 1, column: 13 }
+ end: { line: 1, column: 14 }
}
},
- range: [0, 14],
- loc: {
- start: { line: 1, column: 0 },
- end: { line: 1, column: 14 }
+
+ '': {
+ "type": "ExpressionStatement",
+ "expression": {
+ "type": "XJSElement",
+ "openingElement": {
+ "type": "XJSOpeningElement",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "div",
+ "range": [
+ 1,
+ 4
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 1
+ },
+ "end": {
+ "line": 1,
+ "column": 4
+ }
+ }
+ },
+ "selfClosing": true,
+ "attributes": [
+ {
+ "type": "XJSSpreadAttribute",
+ "argument": {
+ "type": "Identifier",
+ "name": "props",
+ "range": [
+ 9,
+ 14
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 9
+ },
+ "end": {
+ "line": 1,
+ "column": 14
+ }
+ }
+ },
+ "range": [
+ 5,
+ 15
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 5
+ },
+ "end": {
+ "line": 1,
+ "column": 15
+ }
+ }
+ }
+ ],
+ "range": [
+ 0,
+ 18
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 18
+ }
+ }
+ },
+ closingElement: null,
+ "children": [],
+ "range": [
+ 0,
+ 18
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 18
+ }
+ }
+ },
+ "range": [
+ 0,
+ 18
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 18
+ }
+ }
+ },
+
+ '': {
+ "type": "ExpressionStatement",
+ "expression": {
+ "type": "XJSElement",
+ "openingElement": {
+ "type": "XJSOpeningElement",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "div",
+ "range": [
+ 1,
+ 4
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 1
+ },
+ "end": {
+ "line": 1,
+ "column": 4
+ }
+ }
+ },
+ "selfClosing": true,
+ "attributes": [
+ {
+ "type": "XJSSpreadAttribute",
+ "argument": {
+ "type": "Identifier",
+ "name": "props",
+ "range": [
+ 9,
+ 14
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 9
+ },
+ "end": {
+ "line": 1,
+ "column": 14
+ }
+ }
+ },
+ "range": [
+ 5,
+ 15
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 5
+ },
+ "end": {
+ "line": 1,
+ "column": 15
+ }
+ }
+ },
+ {
+ "type": "XJSAttribute",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "post",
+ "range": [
+ 16,
+ 20
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 16
+ },
+ "end": {
+ "line": 1,
+ "column": 20
+ }
+ }
+ },
+ "value": {
+ "type": "Literal",
+ "value": "attribute",
+ "raw": "\"attribute\"",
+ "range": [
+ 21,
+ 32
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 21
+ },
+ "end": {
+ "line": 1,
+ "column": 32
+ }
+ }
+ },
+ "range": [
+ 16,
+ 32
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 16
+ },
+ "end": {
+ "line": 1,
+ "column": 32
+ }
+ }
+ }
+ ],
+ "range": [
+ 0,
+ 35
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 35
+ }
+ }
+ },
+ closingElement: null,
+ "children": [],
+ "range": [
+ 0,
+ 35
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 35
+ }
+ }
+ },
+ "range": [
+ 0,
+ 35
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 35
+ }
+ }
+ },
+
+ '': {
+ "type": "ExpressionStatement",
+ "expression": {
+ "type": "XJSElement",
+ "openingElement": {
+ "type": "XJSOpeningElement",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "div",
+ "range": [
+ 1,
+ 4
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 1
+ },
+ "end": {
+ "line": 1,
+ "column": 4
+ }
+ }
+ },
+ "selfClosing": false,
+ "attributes": [
+ {
+ "type": "XJSAttribute",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "pre",
+ "range": [
+ 5,
+ 8
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 5
+ },
+ "end": {
+ "line": 1,
+ "column": 8
+ }
+ }
+ },
+ "value": {
+ "type": "Literal",
+ "value": "leading",
+ "raw": "\"leading\"",
+ "range": [
+ 9,
+ 18
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 9
+ },
+ "end": {
+ "line": 1,
+ "column": 18
+ }
+ }
+ },
+ "range": [
+ 5,
+ 18
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 5
+ },
+ "end": {
+ "line": 1,
+ "column": 18
+ }
+ }
+ },
+ {
+ "type": "XJSAttribute",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "pre2",
+ "range": [
+ 19,
+ 23
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 19
+ },
+ "end": {
+ "line": 1,
+ "column": 23
+ }
+ }
+ },
+ "value": {
+ "type": "Literal",
+ "value": "attribute",
+ "raw": "\"attribute\"",
+ "range": [
+ 24,
+ 35
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 24
+ },
+ "end": {
+ "line": 1,
+ "column": 35
+ }
+ }
+ },
+ "range": [
+ 19,
+ 35
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 19
+ },
+ "end": {
+ "line": 1,
+ "column": 35
+ }
+ }
+ },
+ {
+ "type": "XJSSpreadAttribute",
+ "argument": {
+ "type": "Identifier",
+ "name": "props",
+ "range": [
+ 40,
+ 45
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 40
+ },
+ "end": {
+ "line": 1,
+ "column": 45
+ }
+ }
+ },
+ "range": [
+ 36,
+ 46
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 36
+ },
+ "end": {
+ "line": 1,
+ "column": 46
+ }
+ }
+ }
+ ],
+ "range": [
+ 0,
+ 47
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 47
+ }
+ }
+ },
+ "closingElement": {
+ "type": "XJSClosingElement",
+ "name": {
+ "type": "XJSIdentifier",
+ "name": "div",
+ "range": [
+ 49,
+ 52
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 49
+ },
+ "end": {
+ "line": 1,
+ "column": 52
+ }
+ }
+ },
+ "range": [
+ 47,
+ 53
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 47
+ },
+ "end": {
+ "line": 1,
+ "column": 53
+ }
+ }
+ },
+ "children": [],
+ "range": [
+ 0,
+ 53
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 53
+ }
+ }
+ },
+ "range": [
+ 0,
+ 53
+ ],
+ "loc": {
+ "start": {
+ "line": 1,
+ "column": 0
+ },
+ "end": {
+ "line": 1,
+ "column": 53
+ }
+ }
}
}
};
-for (var code in fbTestFixture) {
+if (typeof exports !== "undefined") {
+ var test = require("./driver.js").test;
+}
+
+for (var code in fbTestFixture.XJS) {
test(code, {
type: 'Program',
- body: [fbTestFixture[code]]
- }, {locations: true, ranges: true});
+ body: [fbTestFixture.XJS[code]]
+ }, {
+ ecmaVersion: 6,
+ locations: true,
+ ranges: true
+ });
}
\ No newline at end of file
diff --git a/test/tests.js b/test/tests.js
index 5f058bd42e..2259f75e59 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -6,7 +6,6 @@ if (typeof exports != "undefined") {
var testFail = require("./driver.js").testFail;
var testAssert = require("./driver.js").testAssert;
var acorn = require("..");
- require("./tests-jsx.js");
}
test("this\n", {