jslike 1.5.0 → 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/esm/interpreter/interpreter.js +285 -0
- package/dist/esm/parser.js +781 -3
- package/dist/esm/runtime/builtins.js +14 -0
- package/dist/index.cjs +913 -7
- package/dist/index.d.cts +1044 -11
- package/dist/index.d.ts +1044 -11
- package/dist/index.js +913 -7
- package/dist/validator/index.cjs +669 -5
- package/dist/validator/index.js +669 -5
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -5606,8 +5606,672 @@ Parser.acorn = {
|
|
|
5606
5606
|
lineBreakG,
|
|
5607
5607
|
nonASCIIwhitespace
|
|
5608
5608
|
};
|
|
5609
|
-
|
|
5610
|
-
|
|
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 ? ">" : "}") + '` 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
|
}
|
|
@@ -7041,7 +7732,7 @@ var Interpreter = class _Interpreter {
|
|
|
7041
7732
|
throw new Error(`Cannot find module '${modulePath}'`);
|
|
7042
7733
|
}
|
|
7043
7734
|
const moduleCode = typeof resolution === "string" ? resolution : resolution.code;
|
|
7044
|
-
const moduleAst =
|
|
7735
|
+
const moduleAst = jsxParse(moduleCode, {
|
|
7045
7736
|
ecmaVersion: 2020,
|
|
7046
7737
|
sourceType: "module",
|
|
7047
7738
|
locations: false
|
|
@@ -7470,6 +8161,210 @@ var Interpreter = class _Interpreter {
|
|
|
7470
8161
|
evaluateProperty(node, env) {
|
|
7471
8162
|
return void 0;
|
|
7472
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
|
+
}
|
|
7473
8368
|
};
|
|
7474
8369
|
|
|
7475
8370
|
// src/runtime/builtins.js
|
|
@@ -7551,6 +8446,17 @@ function createGlobalEnvironment(env) {
|
|
|
7551
8446
|
env.define("ReferenceError", ReferenceError);
|
|
7552
8447
|
env.define("SyntaxError", SyntaxError);
|
|
7553
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"));
|
|
7554
8460
|
env.define("log", (...args) => {
|
|
7555
8461
|
console.log(...args);
|
|
7556
8462
|
return void 0;
|
|
@@ -8214,14 +9120,14 @@ function containsModuleSyntax(code) {
|
|
|
8214
9120
|
}
|
|
8215
9121
|
return false;
|
|
8216
9122
|
}
|
|
8217
|
-
function
|
|
9123
|
+
function parse3(code, options = {}) {
|
|
8218
9124
|
var _a;
|
|
8219
9125
|
let sourceType = options.sourceType || "script";
|
|
8220
9126
|
if (!options.sourceType && containsModuleSyntax(code)) {
|
|
8221
9127
|
sourceType = "module";
|
|
8222
9128
|
}
|
|
8223
9129
|
try {
|
|
8224
|
-
return
|
|
9130
|
+
return jsxParse(code, {
|
|
8225
9131
|
ecmaVersion: 2022,
|
|
8226
9132
|
// Support ES2022 features (including top-level await)
|
|
8227
9133
|
sourceType,
|
|
@@ -8275,7 +9181,7 @@ async function execute(code, env = null, options = {}) {
|
|
|
8275
9181
|
controller._start();
|
|
8276
9182
|
}
|
|
8277
9183
|
try {
|
|
8278
|
-
const ast =
|
|
9184
|
+
const ast = parse3(code, options);
|
|
8279
9185
|
if (!env) {
|
|
8280
9186
|
env = createGlobalEnvironment(new Environment());
|
|
8281
9187
|
}
|
|
@@ -8347,5 +9253,5 @@ export {
|
|
|
8347
9253
|
createEnvironment,
|
|
8348
9254
|
execute,
|
|
8349
9255
|
isTopLevelAwait,
|
|
8350
|
-
|
|
9256
|
+
parse3 as parse
|
|
8351
9257
|
};
|