jslike 1.4.5 → 1.6.0

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
@@ -5784,19 +6448,36 @@ var Interpreter = class _Interpreter {
5784
6448
  this.moduleCache = /* @__PURE__ */ new Map();
5785
6449
  this.moduleExports = {};
5786
6450
  this.abortSignal = options.abortSignal;
6451
+ this.executionController = options.executionController;
5787
6452
  }
5788
- // Check if execution should be aborted
6453
+ // Check if execution should be aborted (sync version)
5789
6454
  checkAbortSignal() {
6455
+ if (this.executionController) {
6456
+ this.executionController._checkAbortSync();
6457
+ return;
6458
+ }
5790
6459
  if (this.abortSignal && this.abortSignal.aborted) {
5791
6460
  const error = new Error("The operation was aborted");
5792
6461
  error.name = "AbortError";
5793
6462
  throw error;
5794
6463
  }
5795
6464
  }
6465
+ // Checkpoint that returns a promise only when controller is present
6466
+ // When no controller, returns null to signal no await needed
6467
+ _getCheckpointPromise(node, env) {
6468
+ if (this.executionController) {
6469
+ this.executionController._setEnv(env);
6470
+ return this.executionController._checkpoint(node);
6471
+ } else {
6472
+ this.checkAbortSignal();
6473
+ return null;
6474
+ }
6475
+ }
5796
6476
  // Async evaluation for async functions - handles await expressions
5797
6477
  async evaluateAsync(node, env) {
5798
6478
  if (!node) return void 0;
5799
- this.checkAbortSignal();
6479
+ const checkpointPromise = this._getCheckpointPromise(node, env);
6480
+ if (checkpointPromise) await checkpointPromise;
5800
6481
  if (node.type === "AwaitExpression") {
5801
6482
  const promise = await this.evaluateAsync(node.argument, env);
5802
6483
  return await promise;
@@ -5967,6 +6648,8 @@ var Interpreter = class _Interpreter {
5967
6648
  await this.evaluateAsync(node.init, forEnv);
5968
6649
  }
5969
6650
  while (!node.test || await this.evaluateAsync(node.test, forEnv)) {
6651
+ const cp1 = this._getCheckpointPromise(node, forEnv);
6652
+ if (cp1) await cp1;
5970
6653
  const result = await this.evaluateAsync(node.body, forEnv);
5971
6654
  if (result instanceof BreakSignal) {
5972
6655
  break;
@@ -5992,6 +6675,8 @@ var Interpreter = class _Interpreter {
5992
6675
  const declarator = node.left.declarations[0];
5993
6676
  const isConst = node.left.kind === "const";
5994
6677
  for (const value of iterable) {
6678
+ const cp2 = this._getCheckpointPromise(node, forEnv);
6679
+ if (cp2) await cp2;
5995
6680
  const iterEnv = forEnv.extend();
5996
6681
  if (declarator.id.type === "Identifier") {
5997
6682
  iterEnv.define(declarator.id.name, value, isConst);
@@ -6022,6 +6707,8 @@ var Interpreter = class _Interpreter {
6022
6707
  const varName = node.left.declarations[0].id.name;
6023
6708
  forEnv.define(varName, void 0);
6024
6709
  for (const key in obj) {
6710
+ const cp3 = this._getCheckpointPromise(node, forEnv);
6711
+ if (cp3) await cp3;
6025
6712
  forEnv.set(varName, key);
6026
6713
  const result = await this.evaluateAsync(node.body, forEnv);
6027
6714
  if (result instanceof BreakSignal) {
@@ -6038,6 +6725,8 @@ var Interpreter = class _Interpreter {
6038
6725
  }
6039
6726
  if (node.type === "WhileStatement") {
6040
6727
  while (await this.evaluateAsync(node.test, env)) {
6728
+ const cp4 = this._getCheckpointPromise(node, env);
6729
+ if (cp4) await cp4;
6041
6730
  const result = await this.evaluateAsync(node.body, env);
6042
6731
  if (result instanceof BreakSignal) {
6043
6732
  break;
@@ -6053,6 +6742,8 @@ var Interpreter = class _Interpreter {
6053
6742
  }
6054
6743
  if (node.type === "DoWhileStatement") {
6055
6744
  do {
6745
+ const cp5 = this._getCheckpointPromise(node, env);
6746
+ if (cp5) await cp5;
6056
6747
  const result = await this.evaluateAsync(node.body, env);
6057
6748
  if (result instanceof BreakSignal) {
6058
6749
  break;
@@ -6254,6 +6945,21 @@ var Interpreter = class _Interpreter {
6254
6945
  if (node.type === "ClassExpression") {
6255
6946
  return this.evaluateClassExpression(node, env);
6256
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
+ }
6257
6963
  if ([
6258
6964
  "Literal",
6259
6965
  "Identifier",
@@ -6376,6 +7082,18 @@ var Interpreter = class _Interpreter {
6376
7082
  return this.evaluateAssignmentPattern(node, env);
6377
7083
  case "Property":
6378
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);
6379
7097
  default:
6380
7098
  throw new Error(`Unknown node type: ${node.type}`);
6381
7099
  }
@@ -6695,6 +7413,7 @@ var Interpreter = class _Interpreter {
6695
7413
  callUserFunction(func, args, callingEnv, thisContext = void 0) {
6696
7414
  const metadata = func.__metadata || func;
6697
7415
  const funcEnv = new Environment(metadata.closure);
7416
+ const funcName = metadata.name || func.name || "anonymous";
6698
7417
  if (thisContext !== void 0) {
6699
7418
  funcEnv.define("this", thisContext);
6700
7419
  }
@@ -6717,15 +7436,46 @@ var Interpreter = class _Interpreter {
6717
7436
  }
6718
7437
  }
6719
7438
  if (metadata.async) {
7439
+ if (this.executionController) {
7440
+ this.executionController._pushCall(funcName);
7441
+ }
6720
7442
  return (async () => {
7443
+ try {
7444
+ if (metadata.expression) {
7445
+ const result = await this.evaluateAsync(metadata.body, funcEnv);
7446
+ if (result instanceof ThrowSignal) {
7447
+ throw result.value;
7448
+ }
7449
+ return result;
7450
+ } else {
7451
+ const result = await this.evaluateAsync(metadata.body, funcEnv);
7452
+ if (result instanceof ReturnValue) {
7453
+ return result.value;
7454
+ }
7455
+ if (result instanceof ThrowSignal) {
7456
+ throw result.value;
7457
+ }
7458
+ return void 0;
7459
+ }
7460
+ } finally {
7461
+ if (this.executionController) {
7462
+ this.executionController._popCall();
7463
+ }
7464
+ }
7465
+ })();
7466
+ } else {
7467
+ if (this.executionController) {
7468
+ this.executionController._pushCall(funcName);
7469
+ }
7470
+ try {
6721
7471
  if (metadata.expression) {
6722
- const result = await this.evaluateAsync(metadata.body, funcEnv);
7472
+ const result = this.evaluate(metadata.body, funcEnv);
6723
7473
  if (result instanceof ThrowSignal) {
6724
7474
  throw result.value;
6725
7475
  }
6726
7476
  return result;
6727
7477
  } else {
6728
- const result = await this.evaluateAsync(metadata.body, funcEnv);
7478
+ const result = this.evaluate(metadata.body, funcEnv);
6729
7479
  if (result instanceof ReturnValue) {
6730
7480
  return result.value;
6731
7481
  }
@@ -6734,23 +7484,10 @@ var Interpreter = class _Interpreter {
6734
7484
  }
6735
7485
  return void 0;
6736
7486
  }
6737
- })();
6738
- } else {
6739
- if (metadata.expression) {
6740
- const result = this.evaluate(metadata.body, funcEnv);
6741
- if (result instanceof ThrowSignal) {
6742
- throw result.value;
6743
- }
6744
- return result;
6745
- } else {
6746
- const result = this.evaluate(metadata.body, funcEnv);
6747
- if (result instanceof ReturnValue) {
6748
- return result.value;
6749
- }
6750
- if (result instanceof ThrowSignal) {
6751
- throw result.value;
7487
+ } finally {
7488
+ if (this.executionController) {
7489
+ this.executionController._popCall();
6752
7490
  }
6753
- return void 0;
6754
7491
  }
6755
7492
  }
6756
7493
  }
@@ -6995,7 +7732,7 @@ var Interpreter = class _Interpreter {
6995
7732
  throw new Error(`Cannot find module '${modulePath}'`);
6996
7733
  }
6997
7734
  const moduleCode = typeof resolution === "string" ? resolution : resolution.code;
6998
- const moduleAst = parse3(moduleCode, {
7735
+ const moduleAst = jsxParse(moduleCode, {
6999
7736
  ecmaVersion: 2020,
7000
7737
  sourceType: "module",
7001
7738
  locations: false
@@ -7424,6 +8161,210 @@ var Interpreter = class _Interpreter {
7424
8161
  evaluateProperty(node, env) {
7425
8162
  return void 0;
7426
8163
  }
8164
+ // ===== JSX Support =====
8165
+ evaluateJSXElement(node, env) {
8166
+ const createElement = this.getCreateElement(env);
8167
+ const { type, props } = this.evaluateJSXOpeningElement(node.openingElement, env);
8168
+ const children = this.evaluateJSXChildren(node.children, env);
8169
+ if (children.length === 0) {
8170
+ return createElement(type, props);
8171
+ } else if (children.length === 1) {
8172
+ return createElement(type, props, children[0]);
8173
+ }
8174
+ return createElement(type, props, ...children);
8175
+ }
8176
+ evaluateJSXFragment(node, env) {
8177
+ const createElement = this.getCreateElement(env);
8178
+ const Fragment = this.getFragment(env);
8179
+ const children = this.evaluateJSXChildren(node.children, env);
8180
+ if (children.length === 0) {
8181
+ return createElement(Fragment, null);
8182
+ } else if (children.length === 1) {
8183
+ return createElement(Fragment, null, children[0]);
8184
+ }
8185
+ return createElement(Fragment, null, ...children);
8186
+ }
8187
+ evaluateJSXOpeningElement(node, env) {
8188
+ const type = this.evaluateJSXElementName(node.name, env);
8189
+ const props = {};
8190
+ for (const attr of node.attributes) {
8191
+ if (attr.type === "JSXAttribute") {
8192
+ const name = attr.name.type === "JSXIdentifier" ? attr.name.name : `${attr.name.namespace.name}:${attr.name.name.name}`;
8193
+ const value = attr.value ? this.evaluateJSXAttributeValue(attr.value, env) : true;
8194
+ props[name] = value;
8195
+ } else if (attr.type === "JSXSpreadAttribute") {
8196
+ Object.assign(props, this.evaluate(attr.argument, env));
8197
+ }
8198
+ }
8199
+ return { type, props: Object.keys(props).length > 0 ? props : null };
8200
+ }
8201
+ evaluateJSXElementName(node, env) {
8202
+ if (node.type === "JSXIdentifier") {
8203
+ const name = node.name;
8204
+ if (name[0] === name[0].toLowerCase()) {
8205
+ return name;
8206
+ }
8207
+ return env.get(name);
8208
+ } else if (node.type === "JSXMemberExpression") {
8209
+ const object = this.evaluateJSXElementName(node.object, env);
8210
+ return object[node.property.name];
8211
+ } else if (node.type === "JSXNamespacedName") {
8212
+ return `${node.namespace.name}:${node.name.name}`;
8213
+ }
8214
+ throw new Error(`Unknown JSX element name type: ${node.type}`);
8215
+ }
8216
+ evaluateJSXAttributeValue(node, env) {
8217
+ if (node.type === "Literal") return node.value;
8218
+ if (node.type === "JSXExpressionContainer") {
8219
+ return this.evaluate(node.expression, env);
8220
+ }
8221
+ if (node.type === "JSXElement") return this.evaluateJSXElement(node, env);
8222
+ if (node.type === "JSXFragment") return this.evaluateJSXFragment(node, env);
8223
+ throw new Error(`Unknown JSX attribute value type: ${node.type}`);
8224
+ }
8225
+ evaluateJSXChildren(children, env) {
8226
+ const result = [];
8227
+ for (const child of children) {
8228
+ if (child.type === "JSXText") {
8229
+ const text = this.normalizeJSXText(child.value);
8230
+ if (text) result.push(text);
8231
+ } else if (child.type === "JSXExpressionContainer") {
8232
+ if (child.expression.type !== "JSXEmptyExpression") {
8233
+ const value = this.evaluate(child.expression, env);
8234
+ if (Array.isArray(value)) {
8235
+ result.push(...value);
8236
+ } else if (value !== null && value !== void 0 && value !== false) {
8237
+ result.push(value);
8238
+ }
8239
+ }
8240
+ } else if (child.type === "JSXElement") {
8241
+ result.push(this.evaluateJSXElement(child, env));
8242
+ } else if (child.type === "JSXFragment") {
8243
+ result.push(this.evaluateJSXFragment(child, env));
8244
+ }
8245
+ }
8246
+ return result;
8247
+ }
8248
+ normalizeJSXText(text) {
8249
+ const lines = text.split("\n");
8250
+ const normalized = lines.map((line, i) => {
8251
+ let result = line;
8252
+ if (i === 0) result = result.trimStart();
8253
+ if (i === lines.length - 1) result = result.trimEnd();
8254
+ return result;
8255
+ }).filter((line) => line.length > 0).join(" ");
8256
+ return normalized || null;
8257
+ }
8258
+ getCreateElement(env) {
8259
+ try {
8260
+ const React = env.get("React");
8261
+ if (React && React.createElement) {
8262
+ return React.createElement.bind(React);
8263
+ }
8264
+ } catch (e) {
8265
+ }
8266
+ try {
8267
+ return env.get("createElement");
8268
+ } catch (e) {
8269
+ }
8270
+ return (type, props, ...children) => ({
8271
+ $$typeof: Symbol.for("react.element"),
8272
+ type,
8273
+ props: {
8274
+ ...props,
8275
+ children: children.length === 0 ? void 0 : children.length === 1 ? children[0] : children
8276
+ },
8277
+ key: (props == null ? void 0 : props.key) ?? null,
8278
+ ref: (props == null ? void 0 : props.ref) ?? null
8279
+ });
8280
+ }
8281
+ getFragment(env) {
8282
+ try {
8283
+ const React = env.get("React");
8284
+ if (React && React.Fragment) {
8285
+ return React.Fragment;
8286
+ }
8287
+ } catch (e) {
8288
+ }
8289
+ try {
8290
+ return env.get("Fragment");
8291
+ } catch (e) {
8292
+ }
8293
+ return Symbol.for("react.fragment");
8294
+ }
8295
+ // ===== Async JSX Support =====
8296
+ async evaluateJSXElementAsync(node, env) {
8297
+ const checkpointPromise = this._getCheckpointPromise(node, env);
8298
+ if (checkpointPromise) await checkpointPromise;
8299
+ const createElement = this.getCreateElement(env);
8300
+ const { type, props } = await this.evaluateJSXOpeningElementAsync(node.openingElement, env);
8301
+ const children = await this.evaluateJSXChildrenAsync(node.children, env);
8302
+ if (children.length === 0) {
8303
+ return createElement(type, props);
8304
+ } else if (children.length === 1) {
8305
+ return createElement(type, props, children[0]);
8306
+ }
8307
+ return createElement(type, props, ...children);
8308
+ }
8309
+ async evaluateJSXFragmentAsync(node, env) {
8310
+ const checkpointPromise = this._getCheckpointPromise(node, env);
8311
+ if (checkpointPromise) await checkpointPromise;
8312
+ const createElement = this.getCreateElement(env);
8313
+ const Fragment = this.getFragment(env);
8314
+ const children = await this.evaluateJSXChildrenAsync(node.children, env);
8315
+ if (children.length === 0) {
8316
+ return createElement(Fragment, null);
8317
+ } else if (children.length === 1) {
8318
+ return createElement(Fragment, null, children[0]);
8319
+ }
8320
+ return createElement(Fragment, null, ...children);
8321
+ }
8322
+ async evaluateJSXOpeningElementAsync(node, env) {
8323
+ const type = this.evaluateJSXElementName(node.name, env);
8324
+ const props = {};
8325
+ for (const attr of node.attributes) {
8326
+ if (attr.type === "JSXAttribute") {
8327
+ const name = attr.name.type === "JSXIdentifier" ? attr.name.name : `${attr.name.namespace.name}:${attr.name.name.name}`;
8328
+ const value = attr.value ? await this.evaluateJSXAttributeValueAsync(attr.value, env) : true;
8329
+ props[name] = value;
8330
+ } else if (attr.type === "JSXSpreadAttribute") {
8331
+ Object.assign(props, await this.evaluateAsync(attr.argument, env));
8332
+ }
8333
+ }
8334
+ return { type, props: Object.keys(props).length > 0 ? props : null };
8335
+ }
8336
+ async evaluateJSXAttributeValueAsync(node, env) {
8337
+ if (node.type === "Literal") return node.value;
8338
+ if (node.type === "JSXExpressionContainer") {
8339
+ return await this.evaluateAsync(node.expression, env);
8340
+ }
8341
+ if (node.type === "JSXElement") return await this.evaluateJSXElementAsync(node, env);
8342
+ if (node.type === "JSXFragment") return await this.evaluateJSXFragmentAsync(node, env);
8343
+ throw new Error(`Unknown JSX attribute value type: ${node.type}`);
8344
+ }
8345
+ async evaluateJSXChildrenAsync(children, env) {
8346
+ const result = [];
8347
+ for (const child of children) {
8348
+ if (child.type === "JSXText") {
8349
+ const text = this.normalizeJSXText(child.value);
8350
+ if (text) result.push(text);
8351
+ } else if (child.type === "JSXExpressionContainer") {
8352
+ if (child.expression.type !== "JSXEmptyExpression") {
8353
+ const value = await this.evaluateAsync(child.expression, env);
8354
+ if (Array.isArray(value)) {
8355
+ result.push(...value);
8356
+ } else if (value !== null && value !== void 0 && value !== false) {
8357
+ result.push(value);
8358
+ }
8359
+ }
8360
+ } else if (child.type === "JSXElement") {
8361
+ result.push(await this.evaluateJSXElementAsync(child, env));
8362
+ } else if (child.type === "JSXFragment") {
8363
+ result.push(await this.evaluateJSXFragmentAsync(child, env));
8364
+ }
8365
+ }
8366
+ return result;
8367
+ }
7427
8368
  };
7428
8369
 
7429
8370
  // src/runtime/builtins.js
@@ -7505,6 +8446,17 @@ function createGlobalEnvironment(env) {
7505
8446
  env.define("ReferenceError", ReferenceError);
7506
8447
  env.define("SyntaxError", SyntaxError);
7507
8448
  env.define("RangeError", RangeError);
8449
+ env.define("createElement", (type, props, ...children) => ({
8450
+ $$typeof: Symbol.for("react.element"),
8451
+ type,
8452
+ props: {
8453
+ ...props,
8454
+ children: children.length === 0 ? void 0 : children.length === 1 ? children[0] : children
8455
+ },
8456
+ key: (props == null ? void 0 : props.key) ?? null,
8457
+ ref: (props == null ? void 0 : props.ref) ?? null
8458
+ }));
8459
+ env.define("Fragment", Symbol.for("react.fragment"));
7508
8460
  env.define("log", (...args) => {
7509
8461
  console.log(...args);
7510
8462
  return void 0;
@@ -7893,7 +8845,8 @@ var WangInterpreter = class {
7893
8845
  }
7894
8846
  const hasTopLevelReturn = this.hasTopLevelReturn(code);
7895
8847
  const options = {
7896
- moduleResolver: this.moduleResolver
8848
+ moduleResolver: this.moduleResolver,
8849
+ executionController: userOptions.executionController
7897
8850
  // sourceType will be auto-detected from code
7898
8851
  };
7899
8852
  let result;
@@ -7972,6 +8925,191 @@ var InMemoryModuleResolver = class {
7972
8925
  }
7973
8926
  };
7974
8927
 
8928
+ // src/runtime/execution-controller.js
8929
+ var ExecutionController = class {
8930
+ constructor() {
8931
+ this.state = "idle";
8932
+ this.pauseRequested = false;
8933
+ this.abortRequested = false;
8934
+ this.stepCount = 0;
8935
+ this.currentNode = null;
8936
+ this.callStack = [];
8937
+ this.currentEnv = null;
8938
+ this._resolveResume = null;
8939
+ }
8940
+ // --- Control methods (called by user) ---
8941
+ /**
8942
+ * Request pause at next checkpoint. Only works during async evaluation.
8943
+ */
8944
+ pause() {
8945
+ if (this.state === "running") {
8946
+ this.pauseRequested = true;
8947
+ }
8948
+ }
8949
+ /**
8950
+ * Resume execution after pause.
8951
+ */
8952
+ resume() {
8953
+ if (this.state === "paused" && this._resolveResume) {
8954
+ this.pauseRequested = false;
8955
+ this._resolveResume();
8956
+ this._resolveResume = null;
8957
+ }
8958
+ }
8959
+ /**
8960
+ * Abort execution. Works for both sync and async evaluation.
8961
+ * If paused, will resume and then abort.
8962
+ */
8963
+ abort() {
8964
+ this.abortRequested = true;
8965
+ if (this._resolveResume) {
8966
+ this._resolveResume();
8967
+ this._resolveResume = null;
8968
+ }
8969
+ }
8970
+ // --- Status (called by user) ---
8971
+ /**
8972
+ * Get current execution status with full debug information.
8973
+ * @returns {Object} Status object with state, stepCount, currentNode, callStack, and variables
8974
+ */
8975
+ getStatus() {
8976
+ var _a;
8977
+ return {
8978
+ state: this.state,
8979
+ stepCount: this.stepCount,
8980
+ currentNode: ((_a = this.currentNode) == null ? void 0 : _a.type) || null,
8981
+ callStack: [...this.callStack],
8982
+ variables: this._getEnvironmentVariables()
8983
+ };
8984
+ }
8985
+ /**
8986
+ * Check if abort has been requested.
8987
+ * Compatible with AbortSignal interface.
8988
+ */
8989
+ get aborted() {
8990
+ return this.abortRequested;
8991
+ }
8992
+ // --- Internal methods (called by interpreter) ---
8993
+ /**
8994
+ * Mark execution as started. Called by execute().
8995
+ * @internal
8996
+ */
8997
+ _start() {
8998
+ this.state = "running";
8999
+ this.stepCount = 0;
9000
+ this.currentNode = null;
9001
+ this.callStack = [];
9002
+ this.pauseRequested = false;
9003
+ }
9004
+ /**
9005
+ * Mark execution as completed. Called by execute().
9006
+ * @internal
9007
+ */
9008
+ _complete() {
9009
+ this.state = "completed";
9010
+ }
9011
+ /**
9012
+ * Push a function call onto the call stack.
9013
+ * @internal
9014
+ */
9015
+ _pushCall(name) {
9016
+ this.callStack.push(name);
9017
+ }
9018
+ /**
9019
+ * Pop a function call from the call stack.
9020
+ * @internal
9021
+ */
9022
+ _popCall() {
9023
+ this.callStack.pop();
9024
+ }
9025
+ /**
9026
+ * Set the current environment for variable introspection.
9027
+ * @internal
9028
+ */
9029
+ _setEnv(env) {
9030
+ this.currentEnv = env;
9031
+ }
9032
+ /**
9033
+ * Async checkpoint - yields if paused, throws if aborted.
9034
+ * Called at coarse granularity points (loops, function calls).
9035
+ * @internal
9036
+ */
9037
+ async _checkpoint(node) {
9038
+ this.stepCount++;
9039
+ this.currentNode = node;
9040
+ if (this.abortRequested) {
9041
+ this.state = "aborted";
9042
+ const error = new Error("The operation was aborted");
9043
+ error.name = "AbortError";
9044
+ throw error;
9045
+ }
9046
+ if (this.pauseRequested && this.state === "running") {
9047
+ this.state = "paused";
9048
+ await new Promise((resolve) => {
9049
+ this._resolveResume = resolve;
9050
+ });
9051
+ this.state = "running";
9052
+ if (this.abortRequested) {
9053
+ this.state = "aborted";
9054
+ const error = new Error("The operation was aborted");
9055
+ error.name = "AbortError";
9056
+ throw error;
9057
+ }
9058
+ }
9059
+ }
9060
+ /**
9061
+ * Sync abort check - only throws if aborted, cannot pause.
9062
+ * Used in sync evaluate() path.
9063
+ * @internal
9064
+ */
9065
+ _checkAbortSync() {
9066
+ if (this.abortRequested) {
9067
+ this.state = "aborted";
9068
+ const error = new Error("The operation was aborted");
9069
+ error.name = "AbortError";
9070
+ throw error;
9071
+ }
9072
+ }
9073
+ /**
9074
+ * Get all variables from current environment chain.
9075
+ * @internal
9076
+ */
9077
+ _getEnvironmentVariables() {
9078
+ if (!this.currentEnv) return {};
9079
+ const vars = {};
9080
+ let env = this.currentEnv;
9081
+ while (env) {
9082
+ if (env.vars) {
9083
+ for (const [key, value] of env.vars) {
9084
+ if (!(key in vars)) {
9085
+ vars[key] = this._serializeValue(value);
9086
+ }
9087
+ }
9088
+ }
9089
+ env = env.parent;
9090
+ }
9091
+ return vars;
9092
+ }
9093
+ /**
9094
+ * Serialize a value for status reporting.
9095
+ * @internal
9096
+ */
9097
+ _serializeValue(value) {
9098
+ if (value === void 0) return { type: "undefined" };
9099
+ if (value === null) return { type: "null" };
9100
+ if (typeof value === "function" || value && value.__isFunction) {
9101
+ return { type: "function", name: value.name || "anonymous" };
9102
+ }
9103
+ if (Array.isArray(value)) {
9104
+ return { type: "array", length: value.length };
9105
+ }
9106
+ if (typeof value === "object") {
9107
+ return { type: "object", preview: Object.keys(value).slice(0, 5) };
9108
+ }
9109
+ return { type: typeof value, value };
9110
+ }
9111
+ };
9112
+
7975
9113
  // src/index.js
7976
9114
  function containsModuleSyntax(code) {
7977
9115
  if (/^\s*(import|export)\s+/m.test(code)) {
@@ -7982,14 +9120,14 @@ function containsModuleSyntax(code) {
7982
9120
  }
7983
9121
  return false;
7984
9122
  }
7985
- function parse4(code, options = {}) {
9123
+ function parse3(code, options = {}) {
7986
9124
  var _a;
7987
9125
  let sourceType = options.sourceType || "script";
7988
9126
  if (!options.sourceType && containsModuleSyntax(code)) {
7989
9127
  sourceType = "module";
7990
9128
  }
7991
9129
  try {
7992
- return parse3(code, {
9130
+ return jsxParse(code, {
7993
9131
  ecmaVersion: 2022,
7994
9132
  // Support ES2022 features (including top-level await)
7995
9133
  sourceType,
@@ -8038,21 +9176,39 @@ function containsTopLevelAwait(node) {
8038
9176
  return false;
8039
9177
  }
8040
9178
  async function execute(code, env = null, options = {}) {
8041
- const ast = parse4(code, options);
8042
- if (!env) {
8043
- env = createGlobalEnvironment(new Environment());
9179
+ const controller = options.executionController;
9180
+ if (controller) {
9181
+ controller._start();
8044
9182
  }
8045
- const interpreter = new Interpreter(env, {
8046
- moduleResolver: options.moduleResolver,
8047
- abortSignal: options.abortSignal
8048
- });
8049
- const needsAsync = options.sourceType === "module" || containsModuleDeclarations(ast) || containsTopLevelAwait(ast);
8050
- if (needsAsync) {
8051
- const result = await interpreter.evaluateAsync(ast, env);
8052
- return result instanceof ReturnValue ? result.value : result;
8053
- } else {
8054
- const result = interpreter.evaluate(ast, env);
8055
- return result instanceof ReturnValue ? result.value : result;
9183
+ try {
9184
+ const ast = parse3(code, options);
9185
+ if (!env) {
9186
+ env = createGlobalEnvironment(new Environment());
9187
+ }
9188
+ const interpreter = new Interpreter(env, {
9189
+ moduleResolver: options.moduleResolver,
9190
+ abortSignal: options.abortSignal,
9191
+ executionController: controller
9192
+ });
9193
+ const needsAsync = options.sourceType === "module" || containsModuleDeclarations(ast) || containsTopLevelAwait(ast) || controller != null;
9194
+ if (needsAsync) {
9195
+ const result = await interpreter.evaluateAsync(ast, env);
9196
+ if (controller) {
9197
+ controller._complete();
9198
+ }
9199
+ return result instanceof ReturnValue ? result.value : result;
9200
+ } else {
9201
+ const result = interpreter.evaluate(ast, env);
9202
+ if (controller) {
9203
+ controller._complete();
9204
+ }
9205
+ return result instanceof ReturnValue ? result.value : result;
9206
+ }
9207
+ } catch (e) {
9208
+ if (controller && e.name === "AbortError") {
9209
+ controller.state = "aborted";
9210
+ }
9211
+ throw e;
8056
9212
  }
8057
9213
  }
8058
9214
  function createEnvironment() {
@@ -8089,6 +9245,7 @@ var ModuleResolver = class {
8089
9245
  };
8090
9246
  export {
8091
9247
  Environment,
9248
+ ExecutionController,
8092
9249
  InMemoryModuleResolver,
8093
9250
  Interpreter,
8094
9251
  ModuleResolver,
@@ -8096,5 +9253,5 @@ export {
8096
9253
  createEnvironment,
8097
9254
  execute,
8098
9255
  isTopLevelAwait,
8099
- parse4 as parse
9256
+ parse3 as parse
8100
9257
  };