jslike 1.5.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5606,8 +5606,672 @@ Parser.acorn = {
5606
5606
  lineBreakG,
5607
5607
  nonASCIIwhitespace
5608
5608
  };
5609
- function parse3(input, options) {
5610
- return Parser.parse(input, options);
5609
+ var XHTMLEntities = {
5610
+ quot: '"',
5611
+ amp: "&",
5612
+ apos: "'",
5613
+ lt: "<",
5614
+ gt: ">",
5615
+ nbsp: "\xA0",
5616
+ iexcl: "\xA1",
5617
+ cent: "\xA2",
5618
+ pound: "\xA3",
5619
+ curren: "\xA4",
5620
+ yen: "\xA5",
5621
+ brvbar: "\xA6",
5622
+ sect: "\xA7",
5623
+ uml: "\xA8",
5624
+ copy: "\xA9",
5625
+ ordf: "\xAA",
5626
+ laquo: "\xAB",
5627
+ not: "\xAC",
5628
+ shy: "\xAD",
5629
+ reg: "\xAE",
5630
+ macr: "\xAF",
5631
+ deg: "\xB0",
5632
+ plusmn: "\xB1",
5633
+ sup2: "\xB2",
5634
+ sup3: "\xB3",
5635
+ acute: "\xB4",
5636
+ micro: "\xB5",
5637
+ para: "\xB6",
5638
+ middot: "\xB7",
5639
+ cedil: "\xB8",
5640
+ sup1: "\xB9",
5641
+ ordm: "\xBA",
5642
+ raquo: "\xBB",
5643
+ frac14: "\xBC",
5644
+ frac12: "\xBD",
5645
+ frac34: "\xBE",
5646
+ iquest: "\xBF",
5647
+ Agrave: "\xC0",
5648
+ Aacute: "\xC1",
5649
+ Acirc: "\xC2",
5650
+ Atilde: "\xC3",
5651
+ Auml: "\xC4",
5652
+ Aring: "\xC5",
5653
+ AElig: "\xC6",
5654
+ Ccedil: "\xC7",
5655
+ Egrave: "\xC8",
5656
+ Eacute: "\xC9",
5657
+ Ecirc: "\xCA",
5658
+ Euml: "\xCB",
5659
+ Igrave: "\xCC",
5660
+ Iacute: "\xCD",
5661
+ Icirc: "\xCE",
5662
+ Iuml: "\xCF",
5663
+ ETH: "\xD0",
5664
+ Ntilde: "\xD1",
5665
+ Ograve: "\xD2",
5666
+ Oacute: "\xD3",
5667
+ Ocirc: "\xD4",
5668
+ Otilde: "\xD5",
5669
+ Ouml: "\xD6",
5670
+ times: "\xD7",
5671
+ Oslash: "\xD8",
5672
+ Ugrave: "\xD9",
5673
+ Uacute: "\xDA",
5674
+ Ucirc: "\xDB",
5675
+ Uuml: "\xDC",
5676
+ Yacute: "\xDD",
5677
+ THORN: "\xDE",
5678
+ szlig: "\xDF",
5679
+ agrave: "\xE0",
5680
+ aacute: "\xE1",
5681
+ acirc: "\xE2",
5682
+ atilde: "\xE3",
5683
+ auml: "\xE4",
5684
+ aring: "\xE5",
5685
+ aelig: "\xE6",
5686
+ ccedil: "\xE7",
5687
+ egrave: "\xE8",
5688
+ eacute: "\xE9",
5689
+ ecirc: "\xEA",
5690
+ euml: "\xEB",
5691
+ igrave: "\xEC",
5692
+ iacute: "\xED",
5693
+ icirc: "\xEE",
5694
+ iuml: "\xEF",
5695
+ eth: "\xF0",
5696
+ ntilde: "\xF1",
5697
+ ograve: "\xF2",
5698
+ oacute: "\xF3",
5699
+ ocirc: "\xF4",
5700
+ otilde: "\xF5",
5701
+ ouml: "\xF6",
5702
+ divide: "\xF7",
5703
+ oslash: "\xF8",
5704
+ ugrave: "\xF9",
5705
+ uacute: "\xFA",
5706
+ ucirc: "\xFB",
5707
+ uuml: "\xFC",
5708
+ yacute: "\xFD",
5709
+ thorn: "\xFE",
5710
+ yuml: "\xFF",
5711
+ OElig: "\u0152",
5712
+ oelig: "\u0153",
5713
+ Scaron: "\u0160",
5714
+ scaron: "\u0161",
5715
+ Yuml: "\u0178",
5716
+ fnof: "\u0192",
5717
+ circ: "\u02C6",
5718
+ tilde: "\u02DC",
5719
+ Alpha: "\u0391",
5720
+ Beta: "\u0392",
5721
+ Gamma: "\u0393",
5722
+ Delta: "\u0394",
5723
+ Epsilon: "\u0395",
5724
+ Zeta: "\u0396",
5725
+ Eta: "\u0397",
5726
+ Theta: "\u0398",
5727
+ Iota: "\u0399",
5728
+ Kappa: "\u039A",
5729
+ Lambda: "\u039B",
5730
+ Mu: "\u039C",
5731
+ Nu: "\u039D",
5732
+ Xi: "\u039E",
5733
+ Omicron: "\u039F",
5734
+ Pi: "\u03A0",
5735
+ Rho: "\u03A1",
5736
+ Sigma: "\u03A3",
5737
+ Tau: "\u03A4",
5738
+ Upsilon: "\u03A5",
5739
+ Phi: "\u03A6",
5740
+ Chi: "\u03A7",
5741
+ Psi: "\u03A8",
5742
+ Omega: "\u03A9",
5743
+ alpha: "\u03B1",
5744
+ beta: "\u03B2",
5745
+ gamma: "\u03B3",
5746
+ delta: "\u03B4",
5747
+ epsilon: "\u03B5",
5748
+ zeta: "\u03B6",
5749
+ eta: "\u03B7",
5750
+ theta: "\u03B8",
5751
+ iota: "\u03B9",
5752
+ kappa: "\u03BA",
5753
+ lambda: "\u03BB",
5754
+ mu: "\u03BC",
5755
+ nu: "\u03BD",
5756
+ xi: "\u03BE",
5757
+ omicron: "\u03BF",
5758
+ pi: "\u03C0",
5759
+ rho: "\u03C1",
5760
+ sigmaf: "\u03C2",
5761
+ sigma: "\u03C3",
5762
+ tau: "\u03C4",
5763
+ upsilon: "\u03C5",
5764
+ phi: "\u03C6",
5765
+ chi: "\u03C7",
5766
+ psi: "\u03C8",
5767
+ omega: "\u03C9",
5768
+ thetasym: "\u03D1",
5769
+ upsih: "\u03D2",
5770
+ piv: "\u03D6",
5771
+ ensp: "\u2002",
5772
+ emsp: "\u2003",
5773
+ thinsp: "\u2009",
5774
+ zwnj: "\u200C",
5775
+ zwj: "\u200D",
5776
+ lrm: "\u200E",
5777
+ rlm: "\u200F",
5778
+ ndash: "\u2013",
5779
+ mdash: "\u2014",
5780
+ lsquo: "\u2018",
5781
+ rsquo: "\u2019",
5782
+ sbquo: "\u201A",
5783
+ ldquo: "\u201C",
5784
+ rdquo: "\u201D",
5785
+ bdquo: "\u201E",
5786
+ dagger: "\u2020",
5787
+ Dagger: "\u2021",
5788
+ bull: "\u2022",
5789
+ hellip: "\u2026",
5790
+ permil: "\u2030",
5791
+ prime: "\u2032",
5792
+ Prime: "\u2033",
5793
+ lsaquo: "\u2039",
5794
+ rsaquo: "\u203A",
5795
+ oline: "\u203E",
5796
+ frasl: "\u2044",
5797
+ euro: "\u20AC",
5798
+ image: "\u2111",
5799
+ weierp: "\u2118",
5800
+ real: "\u211C",
5801
+ trade: "\u2122",
5802
+ alefsym: "\u2135",
5803
+ larr: "\u2190",
5804
+ uarr: "\u2191",
5805
+ rarr: "\u2192",
5806
+ darr: "\u2193",
5807
+ harr: "\u2194",
5808
+ crarr: "\u21B5",
5809
+ lArr: "\u21D0",
5810
+ uArr: "\u21D1",
5811
+ rArr: "\u21D2",
5812
+ dArr: "\u21D3",
5813
+ hArr: "\u21D4",
5814
+ forall: "\u2200",
5815
+ part: "\u2202",
5816
+ exist: "\u2203",
5817
+ empty: "\u2205",
5818
+ nabla: "\u2207",
5819
+ isin: "\u2208",
5820
+ notin: "\u2209",
5821
+ ni: "\u220B",
5822
+ prod: "\u220F",
5823
+ sum: "\u2211",
5824
+ minus: "\u2212",
5825
+ lowast: "\u2217",
5826
+ radic: "\u221A",
5827
+ prop: "\u221D",
5828
+ infin: "\u221E",
5829
+ ang: "\u2220",
5830
+ and: "\u2227",
5831
+ or: "\u2228",
5832
+ cap: "\u2229",
5833
+ cup: "\u222A",
5834
+ "int": "\u222B",
5835
+ there4: "\u2234",
5836
+ sim: "\u223C",
5837
+ cong: "\u2245",
5838
+ asymp: "\u2248",
5839
+ ne: "\u2260",
5840
+ equiv: "\u2261",
5841
+ le: "\u2264",
5842
+ ge: "\u2265",
5843
+ sub: "\u2282",
5844
+ sup: "\u2283",
5845
+ nsub: "\u2284",
5846
+ sube: "\u2286",
5847
+ supe: "\u2287",
5848
+ oplus: "\u2295",
5849
+ otimes: "\u2297",
5850
+ perp: "\u22A5",
5851
+ sdot: "\u22C5",
5852
+ lceil: "\u2308",
5853
+ rceil: "\u2309",
5854
+ lfloor: "\u230A",
5855
+ rfloor: "\u230B",
5856
+ lang: "\u2329",
5857
+ rang: "\u232A",
5858
+ loz: "\u25CA",
5859
+ spades: "\u2660",
5860
+ clubs: "\u2663",
5861
+ hearts: "\u2665",
5862
+ diams: "\u2666"
5863
+ };
5864
+ var hexNumber = /^[\da-fA-F]+$/;
5865
+ var decimalNumber = /^\d+$/;
5866
+ var acornJsxMap = /* @__PURE__ */ new WeakMap();
5867
+ function getJsxTokens(acorn) {
5868
+ acorn = acorn.Parser.acorn || acorn;
5869
+ let acornJsx2 = acornJsxMap.get(acorn);
5870
+ if (!acornJsx2) {
5871
+ const tt = acorn.tokTypes;
5872
+ const TokContext3 = acorn.TokContext;
5873
+ const TokenType3 = acorn.TokenType;
5874
+ const tc_oTag = new TokContext3("<tag", false);
5875
+ const tc_cTag = new TokContext3("</tag", false);
5876
+ const tc_expr = new TokContext3("<tag>...</tag>", true, true);
5877
+ const tokContexts = {
5878
+ tc_oTag,
5879
+ tc_cTag,
5880
+ tc_expr
5881
+ };
5882
+ const tokTypes = {
5883
+ jsxName: new TokenType3("jsxName"),
5884
+ jsxText: new TokenType3("jsxText", { beforeExpr: true }),
5885
+ jsxTagStart: new TokenType3("jsxTagStart", { startsExpr: true }),
5886
+ jsxTagEnd: new TokenType3("jsxTagEnd")
5887
+ };
5888
+ tokTypes.jsxTagStart.updateContext = function() {
5889
+ this.context.push(tc_expr);
5890
+ this.context.push(tc_oTag);
5891
+ this.exprAllowed = false;
5892
+ };
5893
+ tokTypes.jsxTagEnd.updateContext = function(prevType) {
5894
+ let out = this.context.pop();
5895
+ if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
5896
+ this.context.pop();
5897
+ this.exprAllowed = this.curContext() === tc_expr;
5898
+ } else {
5899
+ this.exprAllowed = true;
5900
+ }
5901
+ };
5902
+ acornJsx2 = { tokContexts, tokTypes };
5903
+ acornJsxMap.set(acorn, acornJsx2);
5904
+ }
5905
+ return acornJsx2;
5906
+ }
5907
+ function getQualifiedJSXName(object) {
5908
+ if (!object)
5909
+ return object;
5910
+ if (object.type === "JSXIdentifier")
5911
+ return object.name;
5912
+ if (object.type === "JSXNamespacedName")
5913
+ return object.namespace.name + ":" + object.name.name;
5914
+ if (object.type === "JSXMemberExpression")
5915
+ return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
5916
+ }
5917
+ function acornJsx(options) {
5918
+ options = options || {};
5919
+ return function(Parser3) {
5920
+ return plugin({
5921
+ allowNamespaces: options.allowNamespaces !== false,
5922
+ allowNamespacedObjects: !!options.allowNamespacedObjects
5923
+ }, Parser3);
5924
+ };
5925
+ }
5926
+ function plugin(options, Parser3) {
5927
+ const acorn = Parser3.acorn || { tokTypes: tt, TokContext, TokenType, isNewLine: isNewLine2, isIdentifierStart: isIdentifierStart2, isIdentifierChar: isIdentifierChar2, tokContexts };
5928
+ const acornJsx2 = getJsxTokens(acorn);
5929
+ const tt = acorn.tokTypes;
5930
+ const tok = acornJsx2.tokTypes;
5931
+ const tokContexts = acorn.tokContexts;
5932
+ const tc_oTag = acornJsx2.tokContexts.tc_oTag;
5933
+ const tc_cTag = acornJsx2.tokContexts.tc_cTag;
5934
+ const tc_expr = acornJsx2.tokContexts.tc_expr;
5935
+ const isNewLine2 = acorn.isNewLine;
5936
+ const isIdentifierStart2 = acorn.isIdentifierStart;
5937
+ const isIdentifierChar2 = acorn.isIdentifierChar;
5938
+ return class extends Parser3 {
5939
+ // Expose actual `tokTypes` and `tokContexts` to other plugins.
5940
+ static get acornJsx() {
5941
+ return acornJsx2;
5942
+ }
5943
+ // Reads inline JSX contents token.
5944
+ jsx_readToken() {
5945
+ let out = "", chunkStart = this.pos;
5946
+ for (; ; ) {
5947
+ if (this.pos >= this.input.length)
5948
+ this.raise(this.start, "Unterminated JSX contents");
5949
+ let ch = this.input.charCodeAt(this.pos);
5950
+ switch (ch) {
5951
+ case 60:
5952
+ // '<'
5953
+ case 123:
5954
+ if (this.pos === this.start) {
5955
+ if (ch === 60 && this.exprAllowed) {
5956
+ ++this.pos;
5957
+ return this.finishToken(tok.jsxTagStart);
5958
+ }
5959
+ return this.getTokenFromCode(ch);
5960
+ }
5961
+ out += this.input.slice(chunkStart, this.pos);
5962
+ return this.finishToken(tok.jsxText, out);
5963
+ case 38:
5964
+ out += this.input.slice(chunkStart, this.pos);
5965
+ out += this.jsx_readEntity();
5966
+ chunkStart = this.pos;
5967
+ break;
5968
+ case 62:
5969
+ // '>'
5970
+ case 125:
5971
+ this.raise(
5972
+ this.pos,
5973
+ "Unexpected token `" + this.input[this.pos] + "`. Did you mean `" + (ch === 62 ? "&gt;" : "&rbrace;") + '` or `{"' + this.input[this.pos] + '"}`?'
5974
+ );
5975
+ default:
5976
+ if (isNewLine2(ch)) {
5977
+ out += this.input.slice(chunkStart, this.pos);
5978
+ out += this.jsx_readNewLine(true);
5979
+ chunkStart = this.pos;
5980
+ } else {
5981
+ ++this.pos;
5982
+ }
5983
+ }
5984
+ }
5985
+ }
5986
+ jsx_readNewLine(normalizeCRLF) {
5987
+ let ch = this.input.charCodeAt(this.pos);
5988
+ let out;
5989
+ ++this.pos;
5990
+ if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
5991
+ ++this.pos;
5992
+ out = normalizeCRLF ? "\n" : "\r\n";
5993
+ } else {
5994
+ out = String.fromCharCode(ch);
5995
+ }
5996
+ if (this.options.locations) {
5997
+ ++this.curLine;
5998
+ this.lineStart = this.pos;
5999
+ }
6000
+ return out;
6001
+ }
6002
+ jsx_readString(quote) {
6003
+ let out = "", chunkStart = ++this.pos;
6004
+ for (; ; ) {
6005
+ if (this.pos >= this.input.length)
6006
+ this.raise(this.start, "Unterminated string constant");
6007
+ let ch = this.input.charCodeAt(this.pos);
6008
+ if (ch === quote) break;
6009
+ if (ch === 38) {
6010
+ out += this.input.slice(chunkStart, this.pos);
6011
+ out += this.jsx_readEntity();
6012
+ chunkStart = this.pos;
6013
+ } else if (isNewLine2(ch)) {
6014
+ out += this.input.slice(chunkStart, this.pos);
6015
+ out += this.jsx_readNewLine(false);
6016
+ chunkStart = this.pos;
6017
+ } else {
6018
+ ++this.pos;
6019
+ }
6020
+ }
6021
+ out += this.input.slice(chunkStart, this.pos++);
6022
+ return this.finishToken(tt.string, out);
6023
+ }
6024
+ jsx_readEntity() {
6025
+ let str = "", count = 0, entity;
6026
+ let ch = this.input[this.pos];
6027
+ if (ch !== "&")
6028
+ this.raise(this.pos, "Entity must start with an ampersand");
6029
+ let startPos = ++this.pos;
6030
+ while (this.pos < this.input.length && count++ < 10) {
6031
+ ch = this.input[this.pos++];
6032
+ if (ch === ";") {
6033
+ if (str[0] === "#") {
6034
+ if (str[1] === "x") {
6035
+ str = str.substr(2);
6036
+ if (hexNumber.test(str))
6037
+ entity = String.fromCharCode(parseInt(str, 16));
6038
+ } else {
6039
+ str = str.substr(1);
6040
+ if (decimalNumber.test(str))
6041
+ entity = String.fromCharCode(parseInt(str, 10));
6042
+ }
6043
+ } else {
6044
+ entity = XHTMLEntities[str];
6045
+ }
6046
+ break;
6047
+ }
6048
+ str += ch;
6049
+ }
6050
+ if (!entity) {
6051
+ this.pos = startPos;
6052
+ return "&";
6053
+ }
6054
+ return entity;
6055
+ }
6056
+ // Read a JSX identifier (valid tag or attribute name).
6057
+ //
6058
+ // Optimized version since JSX identifiers can't contain
6059
+ // escape characters and so can be read as single slice.
6060
+ // Also assumes that first character was already checked
6061
+ // by isIdentifierStart in readToken.
6062
+ jsx_readWord() {
6063
+ let ch, start = this.pos;
6064
+ do {
6065
+ ch = this.input.charCodeAt(++this.pos);
6066
+ } while (isIdentifierChar2(ch) || ch === 45);
6067
+ return this.finishToken(tok.jsxName, this.input.slice(start, this.pos));
6068
+ }
6069
+ // Parse next token as JSX identifier
6070
+ jsx_parseIdentifier() {
6071
+ let node = this.startNode();
6072
+ if (this.type === tok.jsxName)
6073
+ node.name = this.value;
6074
+ else if (this.type.keyword)
6075
+ node.name = this.type.keyword;
6076
+ else
6077
+ this.unexpected();
6078
+ this.next();
6079
+ return this.finishNode(node, "JSXIdentifier");
6080
+ }
6081
+ // Parse namespaced identifier.
6082
+ jsx_parseNamespacedName() {
6083
+ let startPos = this.start, startLoc = this.startLoc;
6084
+ let name = this.jsx_parseIdentifier();
6085
+ if (!options.allowNamespaces || !this.eat(tt.colon)) return name;
6086
+ var node = this.startNodeAt(startPos, startLoc);
6087
+ node.namespace = name;
6088
+ node.name = this.jsx_parseIdentifier();
6089
+ return this.finishNode(node, "JSXNamespacedName");
6090
+ }
6091
+ // Parses element name in any form - namespaced, member
6092
+ // or single identifier.
6093
+ jsx_parseElementName() {
6094
+ if (this.type === tok.jsxTagEnd) return "";
6095
+ let startPos = this.start, startLoc = this.startLoc;
6096
+ let node = this.jsx_parseNamespacedName();
6097
+ if (this.type === tt.dot && node.type === "JSXNamespacedName" && !options.allowNamespacedObjects) {
6098
+ this.unexpected();
6099
+ }
6100
+ while (this.eat(tt.dot)) {
6101
+ let newNode = this.startNodeAt(startPos, startLoc);
6102
+ newNode.object = node;
6103
+ newNode.property = this.jsx_parseIdentifier();
6104
+ node = this.finishNode(newNode, "JSXMemberExpression");
6105
+ }
6106
+ return node;
6107
+ }
6108
+ // Parses any type of JSX attribute value.
6109
+ jsx_parseAttributeValue() {
6110
+ switch (this.type) {
6111
+ case tt.braceL:
6112
+ let node = this.jsx_parseExpressionContainer();
6113
+ if (node.expression.type === "JSXEmptyExpression")
6114
+ this.raise(node.start, "JSX attributes must only be assigned a non-empty expression");
6115
+ return node;
6116
+ case tok.jsxTagStart:
6117
+ case tt.string:
6118
+ return this.parseExprAtom();
6119
+ default:
6120
+ this.raise(this.start, "JSX value should be either an expression or a quoted JSX text");
6121
+ }
6122
+ }
6123
+ // JSXEmptyExpression is unique type since it doesn't actually parse anything,
6124
+ // and so it should start at the end of last read token (left brace) and finish
6125
+ // at the beginning of the next one (right brace).
6126
+ jsx_parseEmptyExpression() {
6127
+ let node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
6128
+ return this.finishNodeAt(node, "JSXEmptyExpression", this.start, this.startLoc);
6129
+ }
6130
+ // Parses JSX expression enclosed into curly brackets.
6131
+ jsx_parseExpressionContainer() {
6132
+ let node = this.startNode();
6133
+ this.next();
6134
+ node.expression = this.type === tt.braceR ? this.jsx_parseEmptyExpression() : this.parseExpression();
6135
+ this.expect(tt.braceR);
6136
+ return this.finishNode(node, "JSXExpressionContainer");
6137
+ }
6138
+ // Parses following JSX attribute name-value pair.
6139
+ jsx_parseAttribute() {
6140
+ let node = this.startNode();
6141
+ if (this.eat(tt.braceL)) {
6142
+ this.expect(tt.ellipsis);
6143
+ node.argument = this.parseMaybeAssign();
6144
+ this.expect(tt.braceR);
6145
+ return this.finishNode(node, "JSXSpreadAttribute");
6146
+ }
6147
+ node.name = this.jsx_parseNamespacedName();
6148
+ node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
6149
+ return this.finishNode(node, "JSXAttribute");
6150
+ }
6151
+ // Parses JSX opening tag starting after '<'.
6152
+ jsx_parseOpeningElementAt(startPos, startLoc) {
6153
+ let node = this.startNodeAt(startPos, startLoc);
6154
+ node.attributes = [];
6155
+ let nodeName = this.jsx_parseElementName();
6156
+ if (nodeName) node.name = nodeName;
6157
+ while (this.type !== tt.slash && this.type !== tok.jsxTagEnd)
6158
+ node.attributes.push(this.jsx_parseAttribute());
6159
+ node.selfClosing = this.eat(tt.slash);
6160
+ this.expect(tok.jsxTagEnd);
6161
+ return this.finishNode(node, nodeName ? "JSXOpeningElement" : "JSXOpeningFragment");
6162
+ }
6163
+ // Parses JSX closing tag starting after '</'.
6164
+ jsx_parseClosingElementAt(startPos, startLoc) {
6165
+ let node = this.startNodeAt(startPos, startLoc);
6166
+ let nodeName = this.jsx_parseElementName();
6167
+ if (nodeName) node.name = nodeName;
6168
+ this.expect(tok.jsxTagEnd);
6169
+ return this.finishNode(node, nodeName ? "JSXClosingElement" : "JSXClosingFragment");
6170
+ }
6171
+ // Parses entire JSX element, including it's opening tag
6172
+ // (starting after '<'), attributes, contents and closing tag.
6173
+ jsx_parseElementAt(startPos, startLoc) {
6174
+ let node = this.startNodeAt(startPos, startLoc);
6175
+ let children = [];
6176
+ let openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
6177
+ let closingElement = null;
6178
+ if (!openingElement.selfClosing) {
6179
+ contents: for (; ; ) {
6180
+ switch (this.type) {
6181
+ case tok.jsxTagStart:
6182
+ startPos = this.start;
6183
+ startLoc = this.startLoc;
6184
+ this.next();
6185
+ if (this.eat(tt.slash)) {
6186
+ closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
6187
+ break contents;
6188
+ }
6189
+ children.push(this.jsx_parseElementAt(startPos, startLoc));
6190
+ break;
6191
+ case tok.jsxText:
6192
+ children.push(this.parseExprAtom());
6193
+ break;
6194
+ case tt.braceL:
6195
+ children.push(this.jsx_parseExpressionContainer());
6196
+ break;
6197
+ default:
6198
+ this.unexpected();
6199
+ }
6200
+ }
6201
+ if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
6202
+ this.raise(
6203
+ closingElement.start,
6204
+ "Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">"
6205
+ );
6206
+ }
6207
+ }
6208
+ let fragmentOrElement = openingElement.name ? "Element" : "Fragment";
6209
+ node["opening" + fragmentOrElement] = openingElement;
6210
+ node["closing" + fragmentOrElement] = closingElement;
6211
+ node.children = children;
6212
+ if (this.type === tt.relational && this.value === "<") {
6213
+ this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
6214
+ }
6215
+ return this.finishNode(node, "JSX" + fragmentOrElement);
6216
+ }
6217
+ // Parse JSX text
6218
+ jsx_parseText() {
6219
+ let node = this.parseLiteral(this.value);
6220
+ node.type = "JSXText";
6221
+ return node;
6222
+ }
6223
+ // Parses entire JSX element from current position.
6224
+ jsx_parseElement() {
6225
+ let startPos = this.start, startLoc = this.startLoc;
6226
+ this.next();
6227
+ return this.jsx_parseElementAt(startPos, startLoc);
6228
+ }
6229
+ parseExprAtom(refShortHandDefaultPos) {
6230
+ if (this.type === tok.jsxText)
6231
+ return this.jsx_parseText();
6232
+ else if (this.type === tok.jsxTagStart)
6233
+ return this.jsx_parseElement();
6234
+ else
6235
+ return super.parseExprAtom(refShortHandDefaultPos);
6236
+ }
6237
+ readToken(code) {
6238
+ let context = this.curContext();
6239
+ if (context === tc_expr) return this.jsx_readToken();
6240
+ if (context === tc_oTag || context === tc_cTag) {
6241
+ if (isIdentifierStart2(code)) return this.jsx_readWord();
6242
+ if (code == 62) {
6243
+ ++this.pos;
6244
+ return this.finishToken(tok.jsxTagEnd);
6245
+ }
6246
+ if ((code === 34 || code === 39) && context == tc_oTag)
6247
+ return this.jsx_readString(code);
6248
+ }
6249
+ if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
6250
+ ++this.pos;
6251
+ return this.finishToken(tok.jsxTagStart);
6252
+ }
6253
+ return super.readToken(code);
6254
+ }
6255
+ updateContext(prevType) {
6256
+ if (this.type == tt.braceL) {
6257
+ var curContext = this.curContext();
6258
+ if (curContext == tc_oTag) this.context.push(tokContexts.b_expr);
6259
+ else if (curContext == tc_expr) this.context.push(tokContexts.b_tmpl);
6260
+ else super.updateContext(prevType);
6261
+ this.exprAllowed = true;
6262
+ } else if (this.type === tt.slash && prevType === tok.jsxTagStart) {
6263
+ this.context.length -= 2;
6264
+ this.context.push(tc_cTag);
6265
+ this.exprAllowed = false;
6266
+ } else {
6267
+ return super.updateContext(prevType);
6268
+ }
6269
+ }
6270
+ };
6271
+ }
6272
+ var JSXParser = Parser.extend(acornJsx());
6273
+ function jsxParse(input, options) {
6274
+ return JSXParser.parse(input, options);
5611
6275
  }
5612
6276
 
5613
6277
  // src/runtime/environment.js
@@ -6281,6 +6945,21 @@ var Interpreter = class _Interpreter {
6281
6945
  if (node.type === "ClassExpression") {
6282
6946
  return this.evaluateClassExpression(node, env);
6283
6947
  }
6948
+ if (node.type === "JSXElement") {
6949
+ return await this.evaluateJSXElementAsync(node, env);
6950
+ }
6951
+ if (node.type === "JSXFragment") {
6952
+ return await this.evaluateJSXFragmentAsync(node, env);
6953
+ }
6954
+ if (node.type === "JSXExpressionContainer") {
6955
+ if (node.expression.type === "JSXEmptyExpression") {
6956
+ return void 0;
6957
+ }
6958
+ return await this.evaluateAsync(node.expression, env);
6959
+ }
6960
+ if (node.type === "JSXText") {
6961
+ return this.normalizeJSXText(node.value);
6962
+ }
6284
6963
  if ([
6285
6964
  "Literal",
6286
6965
  "Identifier",
@@ -6403,6 +7082,18 @@ var Interpreter = class _Interpreter {
6403
7082
  return this.evaluateAssignmentPattern(node, env);
6404
7083
  case "Property":
6405
7084
  return this.evaluateProperty(node, env);
7085
+ // JSX Support
7086
+ case "JSXElement":
7087
+ return this.evaluateJSXElement(node, env);
7088
+ case "JSXFragment":
7089
+ return this.evaluateJSXFragment(node, env);
7090
+ case "JSXExpressionContainer":
7091
+ if (node.expression.type === "JSXEmptyExpression") {
7092
+ return void 0;
7093
+ }
7094
+ return this.evaluate(node.expression, env);
7095
+ case "JSXText":
7096
+ return this.normalizeJSXText(node.value);
6406
7097
  default:
6407
7098
  throw new Error(`Unknown node type: ${node.type}`);
6408
7099
  }
@@ -7040,20 +7731,25 @@ var Interpreter = class _Interpreter {
7040
7731
  if (!resolution) {
7041
7732
  throw new Error(`Cannot find module '${modulePath}'`);
7042
7733
  }
7043
- const moduleCode = typeof resolution === "string" ? resolution : resolution.code;
7044
- const moduleAst = parse3(moduleCode, {
7045
- ecmaVersion: 2020,
7046
- sourceType: "module",
7047
- locations: false
7048
- });
7049
- const moduleEnv = new Environment(this.globalEnv);
7050
- const moduleInterpreter = new _Interpreter(this.globalEnv, {
7051
- moduleResolver: this.moduleResolver
7052
- });
7053
- moduleInterpreter.moduleCache = this.moduleCache;
7054
- await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
7055
- moduleExports = moduleInterpreter.moduleExports;
7056
- this.moduleCache.set(modulePath, moduleExports);
7734
+ if (resolution.exports) {
7735
+ moduleExports = resolution.exports;
7736
+ this.moduleCache.set(modulePath, moduleExports);
7737
+ } else {
7738
+ const moduleCode = typeof resolution === "string" ? resolution : resolution.code;
7739
+ const moduleAst = jsxParse(moduleCode, {
7740
+ ecmaVersion: 2020,
7741
+ sourceType: "module",
7742
+ locations: false
7743
+ });
7744
+ const moduleEnv = new Environment(this.globalEnv);
7745
+ const moduleInterpreter = new _Interpreter(this.globalEnv, {
7746
+ moduleResolver: this.moduleResolver
7747
+ });
7748
+ moduleInterpreter.moduleCache = this.moduleCache;
7749
+ await moduleInterpreter.evaluateAsync(moduleAst, moduleEnv);
7750
+ moduleExports = moduleInterpreter.moduleExports;
7751
+ this.moduleCache.set(modulePath, moduleExports);
7752
+ }
7057
7753
  }
7058
7754
  for (const specifier of node.specifiers) {
7059
7755
  if (specifier.type === "ImportSpecifier") {
@@ -7470,6 +8166,210 @@ var Interpreter = class _Interpreter {
7470
8166
  evaluateProperty(node, env) {
7471
8167
  return void 0;
7472
8168
  }
8169
+ // ===== JSX Support =====
8170
+ evaluateJSXElement(node, env) {
8171
+ const createElement = this.getCreateElement(env);
8172
+ const { type, props } = this.evaluateJSXOpeningElement(node.openingElement, env);
8173
+ const children = this.evaluateJSXChildren(node.children, env);
8174
+ if (children.length === 0) {
8175
+ return createElement(type, props);
8176
+ } else if (children.length === 1) {
8177
+ return createElement(type, props, children[0]);
8178
+ }
8179
+ return createElement(type, props, ...children);
8180
+ }
8181
+ evaluateJSXFragment(node, env) {
8182
+ const createElement = this.getCreateElement(env);
8183
+ const Fragment = this.getFragment(env);
8184
+ const children = this.evaluateJSXChildren(node.children, env);
8185
+ if (children.length === 0) {
8186
+ return createElement(Fragment, null);
8187
+ } else if (children.length === 1) {
8188
+ return createElement(Fragment, null, children[0]);
8189
+ }
8190
+ return createElement(Fragment, null, ...children);
8191
+ }
8192
+ evaluateJSXOpeningElement(node, env) {
8193
+ const type = this.evaluateJSXElementName(node.name, env);
8194
+ const props = {};
8195
+ for (const attr of node.attributes) {
8196
+ if (attr.type === "JSXAttribute") {
8197
+ const name = attr.name.type === "JSXIdentifier" ? attr.name.name : `${attr.name.namespace.name}:${attr.name.name.name}`;
8198
+ const value = attr.value ? this.evaluateJSXAttributeValue(attr.value, env) : true;
8199
+ props[name] = value;
8200
+ } else if (attr.type === "JSXSpreadAttribute") {
8201
+ Object.assign(props, this.evaluate(attr.argument, env));
8202
+ }
8203
+ }
8204
+ return { type, props: Object.keys(props).length > 0 ? props : null };
8205
+ }
8206
+ evaluateJSXElementName(node, env) {
8207
+ if (node.type === "JSXIdentifier") {
8208
+ const name = node.name;
8209
+ if (name[0] === name[0].toLowerCase()) {
8210
+ return name;
8211
+ }
8212
+ return env.get(name);
8213
+ } else if (node.type === "JSXMemberExpression") {
8214
+ const object = this.evaluateJSXElementName(node.object, env);
8215
+ return object[node.property.name];
8216
+ } else if (node.type === "JSXNamespacedName") {
8217
+ return `${node.namespace.name}:${node.name.name}`;
8218
+ }
8219
+ throw new Error(`Unknown JSX element name type: ${node.type}`);
8220
+ }
8221
+ evaluateJSXAttributeValue(node, env) {
8222
+ if (node.type === "Literal") return node.value;
8223
+ if (node.type === "JSXExpressionContainer") {
8224
+ return this.evaluate(node.expression, env);
8225
+ }
8226
+ if (node.type === "JSXElement") return this.evaluateJSXElement(node, env);
8227
+ if (node.type === "JSXFragment") return this.evaluateJSXFragment(node, env);
8228
+ throw new Error(`Unknown JSX attribute value type: ${node.type}`);
8229
+ }
8230
+ evaluateJSXChildren(children, env) {
8231
+ const result = [];
8232
+ for (const child of children) {
8233
+ if (child.type === "JSXText") {
8234
+ const text = this.normalizeJSXText(child.value);
8235
+ if (text) result.push(text);
8236
+ } else if (child.type === "JSXExpressionContainer") {
8237
+ if (child.expression.type !== "JSXEmptyExpression") {
8238
+ const value = this.evaluate(child.expression, env);
8239
+ if (Array.isArray(value)) {
8240
+ result.push(...value);
8241
+ } else if (value !== null && value !== void 0 && value !== false) {
8242
+ result.push(value);
8243
+ }
8244
+ }
8245
+ } else if (child.type === "JSXElement") {
8246
+ result.push(this.evaluateJSXElement(child, env));
8247
+ } else if (child.type === "JSXFragment") {
8248
+ result.push(this.evaluateJSXFragment(child, env));
8249
+ }
8250
+ }
8251
+ return result;
8252
+ }
8253
+ normalizeJSXText(text) {
8254
+ const lines = text.split("\n");
8255
+ const normalized = lines.map((line, i) => {
8256
+ let result = line;
8257
+ if (i === 0) result = result.trimStart();
8258
+ if (i === lines.length - 1) result = result.trimEnd();
8259
+ return result;
8260
+ }).filter((line) => line.length > 0).join(" ");
8261
+ return normalized || null;
8262
+ }
8263
+ getCreateElement(env) {
8264
+ try {
8265
+ const React = env.get("React");
8266
+ if (React && React.createElement) {
8267
+ return React.createElement.bind(React);
8268
+ }
8269
+ } catch (e) {
8270
+ }
8271
+ try {
8272
+ return env.get("createElement");
8273
+ } catch (e) {
8274
+ }
8275
+ return (type, props, ...children) => ({
8276
+ $$typeof: Symbol.for("react.element"),
8277
+ type,
8278
+ props: {
8279
+ ...props,
8280
+ children: children.length === 0 ? void 0 : children.length === 1 ? children[0] : children
8281
+ },
8282
+ key: (props == null ? void 0 : props.key) ?? null,
8283
+ ref: (props == null ? void 0 : props.ref) ?? null
8284
+ });
8285
+ }
8286
+ getFragment(env) {
8287
+ try {
8288
+ const React = env.get("React");
8289
+ if (React && React.Fragment) {
8290
+ return React.Fragment;
8291
+ }
8292
+ } catch (e) {
8293
+ }
8294
+ try {
8295
+ return env.get("Fragment");
8296
+ } catch (e) {
8297
+ }
8298
+ return Symbol.for("react.fragment");
8299
+ }
8300
+ // ===== Async JSX Support =====
8301
+ async evaluateJSXElementAsync(node, env) {
8302
+ const checkpointPromise = this._getCheckpointPromise(node, env);
8303
+ if (checkpointPromise) await checkpointPromise;
8304
+ const createElement = this.getCreateElement(env);
8305
+ const { type, props } = await this.evaluateJSXOpeningElementAsync(node.openingElement, env);
8306
+ const children = await this.evaluateJSXChildrenAsync(node.children, env);
8307
+ if (children.length === 0) {
8308
+ return createElement(type, props);
8309
+ } else if (children.length === 1) {
8310
+ return createElement(type, props, children[0]);
8311
+ }
8312
+ return createElement(type, props, ...children);
8313
+ }
8314
+ async evaluateJSXFragmentAsync(node, env) {
8315
+ const checkpointPromise = this._getCheckpointPromise(node, env);
8316
+ if (checkpointPromise) await checkpointPromise;
8317
+ const createElement = this.getCreateElement(env);
8318
+ const Fragment = this.getFragment(env);
8319
+ const children = await this.evaluateJSXChildrenAsync(node.children, env);
8320
+ if (children.length === 0) {
8321
+ return createElement(Fragment, null);
8322
+ } else if (children.length === 1) {
8323
+ return createElement(Fragment, null, children[0]);
8324
+ }
8325
+ return createElement(Fragment, null, ...children);
8326
+ }
8327
+ async evaluateJSXOpeningElementAsync(node, env) {
8328
+ const type = this.evaluateJSXElementName(node.name, env);
8329
+ const props = {};
8330
+ for (const attr of node.attributes) {
8331
+ if (attr.type === "JSXAttribute") {
8332
+ const name = attr.name.type === "JSXIdentifier" ? attr.name.name : `${attr.name.namespace.name}:${attr.name.name.name}`;
8333
+ const value = attr.value ? await this.evaluateJSXAttributeValueAsync(attr.value, env) : true;
8334
+ props[name] = value;
8335
+ } else if (attr.type === "JSXSpreadAttribute") {
8336
+ Object.assign(props, await this.evaluateAsync(attr.argument, env));
8337
+ }
8338
+ }
8339
+ return { type, props: Object.keys(props).length > 0 ? props : null };
8340
+ }
8341
+ async evaluateJSXAttributeValueAsync(node, env) {
8342
+ if (node.type === "Literal") return node.value;
8343
+ if (node.type === "JSXExpressionContainer") {
8344
+ return await this.evaluateAsync(node.expression, env);
8345
+ }
8346
+ if (node.type === "JSXElement") return await this.evaluateJSXElementAsync(node, env);
8347
+ if (node.type === "JSXFragment") return await this.evaluateJSXFragmentAsync(node, env);
8348
+ throw new Error(`Unknown JSX attribute value type: ${node.type}`);
8349
+ }
8350
+ async evaluateJSXChildrenAsync(children, env) {
8351
+ const result = [];
8352
+ for (const child of children) {
8353
+ if (child.type === "JSXText") {
8354
+ const text = this.normalizeJSXText(child.value);
8355
+ if (text) result.push(text);
8356
+ } else if (child.type === "JSXExpressionContainer") {
8357
+ if (child.expression.type !== "JSXEmptyExpression") {
8358
+ const value = await this.evaluateAsync(child.expression, env);
8359
+ if (Array.isArray(value)) {
8360
+ result.push(...value);
8361
+ } else if (value !== null && value !== void 0 && value !== false) {
8362
+ result.push(value);
8363
+ }
8364
+ }
8365
+ } else if (child.type === "JSXElement") {
8366
+ result.push(await this.evaluateJSXElementAsync(child, env));
8367
+ } else if (child.type === "JSXFragment") {
8368
+ result.push(await this.evaluateJSXFragmentAsync(child, env));
8369
+ }
8370
+ }
8371
+ return result;
8372
+ }
7473
8373
  };
7474
8374
 
7475
8375
  // src/runtime/builtins.js
@@ -7551,6 +8451,17 @@ function createGlobalEnvironment(env) {
7551
8451
  env.define("ReferenceError", ReferenceError);
7552
8452
  env.define("SyntaxError", SyntaxError);
7553
8453
  env.define("RangeError", RangeError);
8454
+ env.define("createElement", (type, props, ...children) => ({
8455
+ $$typeof: Symbol.for("react.element"),
8456
+ type,
8457
+ props: {
8458
+ ...props,
8459
+ children: children.length === 0 ? void 0 : children.length === 1 ? children[0] : children
8460
+ },
8461
+ key: (props == null ? void 0 : props.key) ?? null,
8462
+ ref: (props == null ? void 0 : props.ref) ?? null
8463
+ }));
8464
+ env.define("Fragment", Symbol.for("react.fragment"));
7554
8465
  env.define("log", (...args) => {
7555
8466
  console.log(...args);
7556
8467
  return void 0;
@@ -8214,14 +9125,14 @@ function containsModuleSyntax(code) {
8214
9125
  }
8215
9126
  return false;
8216
9127
  }
8217
- function parse4(code, options = {}) {
9128
+ function parse3(code, options = {}) {
8218
9129
  var _a;
8219
9130
  let sourceType = options.sourceType || "script";
8220
9131
  if (!options.sourceType && containsModuleSyntax(code)) {
8221
9132
  sourceType = "module";
8222
9133
  }
8223
9134
  try {
8224
- return parse3(code, {
9135
+ return jsxParse(code, {
8225
9136
  ecmaVersion: 2022,
8226
9137
  // Support ES2022 features (including top-level await)
8227
9138
  sourceType,
@@ -8275,7 +9186,7 @@ async function execute(code, env = null, options = {}) {
8275
9186
  controller._start();
8276
9187
  }
8277
9188
  try {
8278
- const ast = parse4(code, options);
9189
+ const ast = parse3(code, options);
8279
9190
  if (!env) {
8280
9191
  env = createGlobalEnvironment(new Environment());
8281
9192
  }
@@ -8347,5 +9258,5 @@ export {
8347
9258
  createEnvironment,
8348
9259
  execute,
8349
9260
  isTopLevelAwait,
8350
- parse4 as parse
9261
+ parse3 as parse
8351
9262
  };